-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
310 lines (252 loc) · 8.57 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
set -e
set -o pipefail
set -u
function step { >&2 echo -e "\033[1m\033[36m* $@\033[0m"; }
DEF_PACKAGE_NAME="aeris-js-sample-module"
DEF_MODULE_NAME="SampleModule"
DEF_VERSION="0.1.0"
DEF_AUTHOR=""
DEF_HOMEPAGE=""
DEF_GROUP_NAME="SampleGroup"
HAS_GROUP="n"
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
step "Setting up a new Aeris JS map module project..."
read -p "Enter a name for your package [${DEF_PACKAGE_NAME}]: " PACKAGE_NAME
read -p "Enter a class name for your module [${DEF_MODULE_NAME}]: " MODULE_NAME
read -p "Do you want to setup a module group that contains multiple modules (Y/n)? [n]: " HAS_GROUP
if [[ "${HAS_GROUP}" = "Y" || "${HAS_GROUP}" = "y" ]]; then
read -p "Enter a class name for your module group [${DEF_GROUP_NAME}]: " GROUP_NAME
fi
read -p "Enter the package version [${DEF_VERSION}]: " VERSION
read -p "Enter the author [${DEF_AUTHOR}]: " AUTHOR
read -p "Enter the package homepage [${DEF_HOMEPAGE}]: " HOMEPAGE
read -p "Enter your Aeris account ID []: " AERIS_ID
read -p "Enter your secret key for your Aeris application []: " AERIS_SECRET
PACKAGE_NAME="${PACKAGE_NAME:-$DEF_PACKAGE_NAME}"
MODULE_NAME="${MODULE_NAME:-$DEF_MODULE_NAME}"
GROUP_NAME="${GROUP_NAME:-$DEF_GROUP_NAME}"
VERSION="${VERSION:-$DEF_VERSION}"
AUTHOR="${AUTHOR:-$DEF_AUTHOR}"
HOMEPAGE="${HOMEPAGE:-$DEF_HOMEPAGE}"
MODULE_ID=$(echo ${MODULE_NAME} \
| sed 's/\(.\)\([A-Z]\)/\1-\2/g' \
| tr '[:upper:]' '[:lower:]')
GROUP_ID=$(echo ${GROUP_NAME} \
| sed 's/\(.\)\([A-Z]\)/\1-\2/g' \
| tr '[:upper:]' '[:lower:]')
step "Creating package.json..."
cat > package.json <<EOF
{
"name": "${PACKAGE_NAME}",
"moduleName": "${MODULE_NAME}",
"version": "${VERSION}",
"main": "index.js",
"author": "${AUTHOR}",
"homepage": "${HOMEPAGE}",
"license": "MIT",
"scripts": {
"build": "rm -fr dist; tsc --sourceMap false --outDir dist; babel --config-file ./babel-nodejs.config.js dist --out-dir dist",
"build:dev": "webpack",
"build:prod": "NODE_ENV='production' webpack -p --env production",
"publish": "yarn build; npm publish",
"dev-server": "NODE_ENV='development' webpack-dev-server"
},
"files": [
"/dist",
"/docs",
"LICENSE",
"README.md"
],
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-loader": "^8.0.6",
"babel-plugin-add-module-exports": "^1.0.2",
"clean-webpack-plugin": "^3.0.0",
"html-webpack-harddisk-plugin": "^1.0.1",
"html-webpack-plugin": "^3.2.0",
"regenerator-runtime": "^0.13.3",
"terser-webpack-plugin": "^2.2.1",
"ts-loader": "^6.2.1",
"typescript": "^3.6.4",
"webpack": "^4.19.1",
"webpack-bundle-analyzer": "^3.0.2",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
},
"dependencies": {
"@aerisweather/javascript-sdk": "../aeris-js-core"
}
}
EOF
mkdir ./src
step "Creating module file at src/${MODULE_NAME}.ts..."
cat > "src/${MODULE_NAME}.ts" <<EOF
import MapSourceModule from '@aerisweather/javascript-sdk/dist/modules/MapSourceModule';
class ${MODULE_NAME} extends MapSourceModule {
public get id() {
return '${MODULE_ID}';
}
constructor(opts: any = null) {
super(opts);
// Perform additional custom setup required by the module.
}
source(): any {
// Setup and return the map content source that's used to load and render your module's
// data on the map
// re: https://www.aerisweather.com/docs/js/classes/tilesource.html
// re: https://www.aerisweather.com/docs/js/classes/vectorsource.html
return null;
}
controls(): any {
// Setup and return the layer button configuration for this module. If 'null' is returnd,
// then this module will not include a toggleable control within the map application.
// re: https://www.aerisweather.com/docs/js/globals.html#buttonoptions
return {
value: this.id,
title: '${MODULE_NAME}'
};
}
legend(): any {
// Create and return the legend configuration for this module. If 'null' is returned, then
// a legend will not be rendered when this module's map source is active.
// re: https://www.aerisweather.com/docs/js/globals.html#legendoptions
return null;
}
infopanel(): any {
// Create and return the info panel configuration to associate with data loaded and
// rendered by this module's map source. If a custom info panel view is not needed for this
// module, just return 'null'.
// re: https://www.aerisweather.com/support/docs/toolkits/aeris-js-sdk/interactive-map-app/info-panel/
// re: https://www.aerisweather.com/docs/js/globals.html#infopanelviewsection
return null;
}
onInit() {
// Perform custom actions when the module has been initialized with a map application
// instance.
}
onAdd() {
// Perform custom actions when the module's map source has been added to the map and is
// active.
}
onRemove() {
// Perform custom actions when the module's map source has been removed from the map and
// is no longer active.
}
onMarkerClick(marker: any, data: any) {
// Perform custom actions when a marker object associated with the module's map source was
// clicked on the map. You can use this method to perform additional actions or to display
// the info panel for the module with the marker's data, e.g.:
//
// this.showInfoPanel('Observation', data);
}
onShapeClick(shape: any, data: any) {
// Perform custom actions when a vector shape object associated with the module's map
// source was clicked on the map. You can use this method to perform additional actions or
// to display the info panel for the module with the shape's data, e.g.:
//
// this.showInfoPanel('Outlook', data);
}
}
export default ${MODULE_NAME};
EOF
if [[ "${HAS_GROUP}" = "Y" || "${HAS_GROUP}" = "y" ]]; then
step "Creating module group file at src/${GROUP_NAME}.ts..."
cat > "src/${GROUP_NAME}.ts" <<EOF
import ModuleGroup from '@aerisweather/javascript-sdk/dist/modules/ModuleGroup';
import { IMapSourceModule } from '@aerisweather/javascript-sdk/dist/modules/interfaces/IMapSourceModule';
import ${MODULE_NAME} from './${MODULE_NAME}';
class ${GROUP_NAME} extends ModuleGroup {
get id() {
return '${GROUP_ID}';
}
async load(): Promise<IMapSourceModule[]> {
return new Promise((resolve, reject) => {
this._modules = [new ${MODULE_NAME}()];
resolve(this._modules);
});
}
controls() {
return {
title: '${GROUP_NAME}',
buttons: this.modules ? this.modules.map((m) => m.controls()) : []
};
}
}
export default ${GROUP_NAME};
EOF
cat > src/index.ts <<EOF
import ${GROUP_NAME} from './${GROUP_NAME}';
export { default as ${MODULE_NAME} } from './${MODULE_NAME}';
export default ${GROUP_NAME};
EOF
else
cat > src/index.ts <<EOF
import ${MODULE_NAME} from './${MODULE_NAME}';
export default ${MODULE_NAME};
EOF
fi
mkdir -p ./test
mkdir -p ./public
cat > ./public/template.html <<EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>Aeris JS - ${MODULE_NAME} Module</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
}
#app {
height: 100%;
width: 100%;
}
</style>
<script src="https://cdn.aerisapi.com/sdk/js/1.3.0/aerisweather.min.js"></script>
<link rel="stylesheet" href="https://cdn.aerisapi.com/sdk/js/1.3.0/aerisweather.css">
</head>
<body>
<div id="app"></div>
<script>
window.addEventListener('load', () => {
// Update with your Aeris account access keys
const aeris = new AerisWeather('${AERIS_ID}', '${AERIS_SECRET}');
aeris.apps().then((apps) => {
const app = new apps.InteractiveMapApp('#app', {
map: {
map: {
zoom: 5
}
},
panels: {
layers: {
buttons: []
}
}
});
// Add an instance of your module to the map application
app.modules.add(new ${MODULE_NAME}());
});
});
</script>
</body>
</html>
EOF
yarn install
step "Done setting up your module project!"
read -p "Do you want to startup the development server (y/n)? [n]: " START_DEV_SERVER
if [[ "${START_DEV_SERVER}" = "Y" || "${START_DEV_SERVER}" = "y" ]]; then
yarn dev-server
fi