diff --git a/samples/new-sample.sh b/samples/new-sample.sh new file mode 100755 index 00000000..2b2daac6 --- /dev/null +++ b/samples/new-sample.sh @@ -0,0 +1,166 @@ +#!/bin/bash + +# A script to generate boilerplate for a new Google Maps JavaScript sample. +# Usage: ./new-sample.sh + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +NAME=$1 +# Replace hyphens with underscores for the region tag +REGION_TAG="maps_${NAME//-/_}" + +# Create the directory +mkdir -p "$NAME" + +# Create index.ts +cat > "$NAME/index.ts" << EOF +/* + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// [START $REGION_TAG] + +// [END $REGION_TAG] +EOF + +# Create index.html +cat > "$NAME/index.html" << EOF + + + + + + $NAME + + + + +EOF + +# Use 'EOF' to prevent expansion of the loader script +cat >> "$NAME/index.html" << 'EOF' + +EOF + +cat >> "$NAME/index.html" << EOF + + + +
+

$NAME

+
+
+ + + +EOF + +# Create style.css +cat > "$NAME/style.css" << EOF +/* + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* [START $REGION_TAG] */ +gmp-map { + height: 100%; +} + +html, +body { + height: 100%; + margin: 0; + padding: 0; +} +/* [END $REGION_TAG] */ +EOF + +# Create package.json +cat > "$NAME/package.json" << EOF +{ + "name": "@js-api-samples/$NAME", + "version": "1.0.0", + "scripts": { + "build": "tsc && bash ../jsfiddle.sh $NAME && bash ../app.sh $NAME && bash ../docs.sh $NAME && npm run build:vite --workspace=. && bash ../dist.sh $NAME", + "test": "tsc && npm run build:vite --workspace=.", + "start": "tsc && vite build --base './' && vite", + "build:vite": "vite build --base './'", + "preview": "vite preview" + }, + "dependencies": {} +} +EOF + +# Create tsconfig.json +cat > "$NAME/tsconfig.json" << 'EOF' +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": ["es2015", "esnext", "es6", "dom", "dom.iterable"], + "moduleResolution": "Node", + "jsx": "preserve" + } +} +EOF + +# Create README.md +cat > "$NAME/README.md" << EOF +# Google Maps JavaScript Sample + +## $NAME + +Sample generated from $NAME + +## Setup + +### Before starting run: + +\`npm i\` + +### Run an example on a local web server + +\`cd samples/$NAME\` +\`npm start\` + +### Build an individual example + +\`cd samples/$NAME\` +\`npm run build\` + +From 'samples': + +\`npm run build --workspace=$NAME/\` + +### Build all of the examples. + +From 'samples': + +\`npm run build-all\` + +### Run lint to check for problems + +\`cd samples/$NAME\` +\`npx eslint index.ts\` + +## Feedback + +For feedback related to this sample, please open a new issue on +[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues). +EOF + +echo "Sample $NAME created successfully in directory ./$NAME"