@vcmap/plugin-cli 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # @vcmplugin/plugin-cli
2
- The `vcmplugin` cli helps develop and build plugins for the **vcMAP**.
1
+ # @vcmap/plugin-cli
2
+ The `vcmplugin` cli helps develop and build plugins for the **VC MAP**.
3
3
 
4
4
  For more information on plugin development refer to [map plugin examples](https://github.com/virtualcitySYSTEMS/map-plugin-examples),
5
5
  which provides documentations and a tutorial on plugin development.
@@ -33,7 +33,7 @@ To create a new plugin template, run the following within your projects root:
33
33
  ```
34
34
  vcmplugin create
35
35
  ```
36
- This will open a command prompt helping you to create the basic [structure of a plugin](https://github.com/virtualcitySYSTEMS/map-plugin-examples/doc/VCM_Plugin.md#2-structure-of-a-plugin).
36
+ This will open a command prompt helping you to create the basic [structure of a plugin](https://github.com/virtualcitySYSTEMS/map-plugin-examples/blob/main/doc/VCM_Plugin.md#2-structure-of-a-plugin).
37
37
 
38
38
 
39
39
  ### 2. Serving a plugin for development
@@ -81,7 +81,7 @@ the `package.json` and use `npm run` to execute:
81
81
  "serve": "vcmplugin serve --vcm ./vcm"
82
82
  },
83
83
  "devDependencies": {
84
- "vcmplugin-cli": "^0.1.1"
84
+ "@vcmap/plugin-cli": "^0.1.1"
85
85
  }
86
86
  }
87
87
  ```
package/cli.js CHANGED
@@ -8,12 +8,12 @@ program.version(version);
8
8
 
9
9
  program
10
10
  .command('create')
11
- .action(create);
11
+ .safeAction(create);
12
12
 
13
13
  program
14
14
  .command('pack')
15
15
  .defaultBuildOptions()
16
- .action(pack);
16
+ .safeAction(pack);
17
17
 
18
18
  program
19
19
  .command('serve')
@@ -30,13 +30,13 @@ program
30
30
  prev.push(val);
31
31
  return prev;
32
32
  }, [])
33
- .action(serve);
33
+ .safeAction(serve);
34
34
 
35
35
  program
36
36
  .command('build')
37
37
  .defaultBuildOptions()
38
38
  .option('--development', 'set mode to development')
39
39
  .option('--watch', 'watch file changes')
40
- .action(build);
40
+ .safeAction(build);
41
41
 
42
42
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcmap/plugin-cli",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "A CLI to help develop and build plugins for the virtualcityMAP",
5
5
  "main": "index.js",
6
6
  "bin": {
package/src/context.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const fs = require('fs');
2
3
 
3
4
  let context = null;
4
5
 
@@ -6,7 +7,10 @@ function setContext(c) {
6
7
  if (context) {
7
8
  throw new Error('cannot set context twice');
8
9
  }
9
- context = c;
10
+ if (!fs.existsSync(c) || !fs.statSync(c).isDirectory()) {
11
+ throw new Error('context must be an existing directory');
12
+ }
13
+ context = path.resolve(c);
10
14
  }
11
15
 
12
16
  function getContext() {
package/src/create.js CHANGED
@@ -6,6 +6,7 @@ const util = require('util');
6
6
  const childProcess = require('child_process');
7
7
  const { logger } = require('@vcsuite/cli-logger');
8
8
  const { version, name } = require('../package.json');
9
+ const { LicenseType, writeLicense } = require('./licenses');
9
10
 
10
11
  /**
11
12
  * @typedef {Object} PluginTemplateOptions
@@ -92,7 +93,13 @@ async function createPluginTemplate(options) {
92
93
  '};'].join('\n'),
93
94
  );
94
95
 
95
- await Promise.all([writePackagePromise, writeConfigPromise, writeReadmePromise, writeIndexPromise]);
96
+ await Promise.all([
97
+ writePackagePromise,
98
+ writeConfigPromise,
99
+ writeReadmePromise,
100
+ writeIndexPromise,
101
+ writeLicense(options.author, options.license, pluginPath),
102
+ ]);
96
103
 
97
104
  logger.spin('installing dependencies...');
98
105
  const exec = util.promisify(childProcess.exec);
@@ -162,10 +169,15 @@ async function create() {
162
169
  initial: 'author <email>',
163
170
  },
164
171
  {
165
- type: 'text',
172
+ type: 'select',
166
173
  name: 'license',
167
174
  message: 'License',
168
- initial: 'ISC',
175
+ initial: 0,
176
+ choices: Object.values(LicenseType)
177
+ .map(type => ({
178
+ title: type,
179
+ value: type,
180
+ })),
169
181
  },
170
182
  {
171
183
  type: 'text',
@@ -1,8 +1,14 @@
1
1
  const { Command } = require('commander');
2
+ const { logger } = require('@vcsuite/cli-logger');
3
+ const { setContext } = require('./context');
2
4
 
3
5
  Command.prototype.defaultOptions = function defaultOptions() {
4
6
  this
5
7
  .option('-n, --plugin-name [name]', 'a name override to use. extracts the name from the package.json by default')
8
+ .option('--context [path]', 'an optional context, default is cwd', (value) => {
9
+ setContext(value);
10
+ return value;
11
+ })
6
12
  .option('--no-condense-whitespace', 'do not condense white space')
7
13
  .option('-e, --entry <entry>', 'entrypoint override');
8
14
 
@@ -17,3 +23,17 @@ Command.prototype.defaultBuildOptions = function defaultBuildOptions() {
17
23
 
18
24
  return this;
19
25
  };
26
+
27
+ Command.prototype.safeAction = function safeAction(action) {
28
+ this.action(async (options) => {
29
+ try {
30
+ await action(options);
31
+ } catch (e) {
32
+ if (e) {
33
+ logger.error(e);
34
+ }
35
+ logger.stopSpinner();
36
+ process.exit(1);
37
+ }
38
+ });
39
+ };
@@ -0,0 +1,133 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * @param {string} user
6
+ * @param {number} year
7
+ * @returns {string}
8
+ */
9
+ function mit(user, year) {
10
+ return `
11
+ Copyright ${year} ${user}
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
14
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation
15
+ the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
16
+ and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
21
+ THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
22
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ `;
25
+ }
26
+
27
+ /**
28
+ * @param {string} user
29
+ * @param {number} year
30
+ * @returns {string}
31
+ */
32
+ function apache(user, year) {
33
+ return `
34
+ Copyright ${year} ${user}
35
+
36
+ Licensed under the Apache License, Version 2.0 (the "License");
37
+ you may not use this file except in compliance with the License.
38
+ You may obtain a copy of the License at
39
+
40
+ http://www.apache.org/licenses/LICENSE-2.0
41
+
42
+ Unless required by applicable law or agreed to in writing, software
43
+ distributed under the License is distributed on an "AS IS" BASIS,
44
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45
+ See the License for the specific language governing permissions and
46
+ limitations under the License.
47
+ `;
48
+ }
49
+
50
+ /**
51
+ * @param {string} user
52
+ * @param {number} year
53
+ * @returns {string}
54
+ */
55
+ function gpl3(user, year) {
56
+ return `
57
+ Copyright (C) ${year} ${user}
58
+
59
+ This program is free software: you can redistribute it and/or modify
60
+ it under the terms of the GNU General Public License as published by
61
+ the Free Software Foundation, either version 3 of the License, or
62
+ (at your option) any later version.
63
+
64
+ This program is distributed in the hope that it will be useful,
65
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
66
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67
+ GNU General Public License for more details.
68
+
69
+ You should have received a copy of the GNU General Public License
70
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
71
+ `;
72
+ }
73
+
74
+ /**
75
+ * @param {string} user
76
+ * @param {number} year
77
+ * @returns {string}
78
+ */
79
+ function isc(user, year) {
80
+ return `
81
+ Copyright (c) ${year}, ${user}
82
+
83
+ Permission to use, copy, modify, and/or distribute this software for any
84
+ purpose with or without fee is hereby granted, provided that the above
85
+ copyright notice and this permission notice appear in all copies.
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
88
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
89
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
90
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
91
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
92
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
93
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
94
+ `;
95
+ }
96
+
97
+ /**
98
+ * @enum {string}
99
+ */
100
+ const LicenseType = {
101
+ MIT: 'MIT',
102
+ ISC: 'ISC',
103
+ 'APACHE-2.0': 'APACHE-2.0',
104
+ 'GPL-3.0': 'GPL-3.0',
105
+ };
106
+
107
+ /**
108
+ * @type {Object<LicenseType, function(string, number):string>}
109
+ */
110
+ const LicenseTypeFunctions = {
111
+ [LicenseType.MIT]: mit,
112
+ [LicenseType['GPL-3.0']]: gpl3,
113
+ [LicenseType.ISC]: isc,
114
+ [LicenseType['APACHE-2.0']]: apache,
115
+ };
116
+
117
+ /**
118
+ * @param {string} user
119
+ * @param {LicenseType} type
120
+ * @param {string} pluginPath
121
+ * @returns {Promise<void>}
122
+ */
123
+ function writeLicense(user, type, pluginPath) {
124
+ const year = new Date().getFullYear();
125
+ const text = LicenseTypeFunctions[type](user, year);
126
+
127
+ return fs.promises.writeFile(path.join(pluginPath, 'LICENSE.md'), text);
128
+ }
129
+
130
+ module.exports = {
131
+ writeLicense,
132
+ LicenseType,
133
+ };
package/src/serve.js CHANGED
@@ -109,6 +109,7 @@ function getConfigJson(vcm, name, { auth, config: configFile }) {
109
109
 
110
110
  async function serve(options) {
111
111
  logger.spin('Starting development server...');
112
+ // eslint-disable-next-line prefer-const
112
113
  let { vcm, index } = options;
113
114
  const pluginName = options.pluginName || await getPluginName();
114
115
  const isWebVcm = /^https?:\/\//.test(vcm);
@@ -125,6 +126,7 @@ async function serve(options) {
125
126
  target: vcm,
126
127
  changeOrigin: true,
127
128
  auth: options.auth,
129
+ followRedirects: true,
128
130
  };
129
131
  });
130
132
  }