@vcmap/plugin-cli 2.1.4 → 2.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcmap/plugin-cli",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "description": "A CLI to help develop and build plugins for the VC Map",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -8,7 +8,10 @@
8
8
  "vcmplugin": "cli.js"
9
9
  },
10
10
  "scripts": {
11
- "lint": "eslint . --env node",
11
+ "lint:js": "eslint . --ext .vue,.js,.cjs,.mjs,.ts,.cts,.mts",
12
+ "lint:prettier": "prettier --check .",
13
+ "lint": "npm run lint:js && npm run lint:prettier",
14
+ "format": "prettier --write --list-different . && npm run lint:js -- --fix",
12
15
  "test": "echo \"Error: no test specified\" && exit 1"
13
16
  },
14
17
  "repository": {
@@ -40,7 +43,7 @@
40
43
  "vue-template-compiler": "~2.7.14"
41
44
  },
42
45
  "peerDependencies": {
43
- "@vcmap/ui": "^5.0.0-rc.22",
46
+ "@vcmap/ui": "^5.0.0-rc.23",
44
47
  "vue": "~2.7.14"
45
48
  },
46
49
  "peerDependenciesMeta": {
@@ -52,8 +55,8 @@
52
55
  }
53
56
  },
54
57
  "devDependencies": {
55
- "@vcsuite/eslint-config": "^2.1.1",
56
- "eslint": "^8.9.0"
58
+ "@vcsuite/eslint-config": "^3.0.3",
59
+ "eslint": "^8.38.0"
57
60
  },
58
61
  "eslintIgnore": [
59
62
  "node_modules"
@@ -74,6 +77,7 @@
74
77
  ]
75
78
  }
76
79
  },
80
+ "prettier": "@vcsuite/eslint-config/prettier.js",
77
81
  "engines": {
78
82
  "node": "^16.14.0",
79
83
  "npm": "^8.3.0"
package/src/build.js CHANGED
@@ -19,10 +19,7 @@ import { executeUiNpm, resolveMapUi } from './hostingHelpers.js';
19
19
  export function getDefaultConfig() {
20
20
  return {
21
21
  publicDir: false,
22
- plugins: [
23
- createVuePlugin(),
24
- vcsOl(),
25
- ],
22
+ plugins: [createVuePlugin(), vcsOl()],
26
23
  };
27
24
  }
28
25
 
@@ -50,7 +47,9 @@ export default async function buildModule(options) {
50
47
  const entry = await getPluginEntry();
51
48
  if (path.relative('src', entry).startsWith('.')) {
52
49
  logger.warning(`detected irregular entry ${entry}`);
53
- logger.warning('vuetify component resolution expects source files to be within "src"');
50
+ logger.warning(
51
+ 'vuetify component resolution expects source files to be within "src"',
52
+ );
54
53
  }
55
54
 
56
55
  const pluginName = await getPluginName();
@@ -78,14 +77,17 @@ export default async function buildModule(options) {
78
77
  external,
79
78
  output: {
80
79
  paths: libraryPaths,
81
- manualChunks() { // ensure only one chunk will be created
80
+ manualChunks() {
81
+ // ensure only one chunk will be created
82
82
  return 'index';
83
83
  },
84
84
  },
85
85
  },
86
- watch: options.watch ? {
87
- skipWrite: true,
88
- } : null,
86
+ watch: options.watch
87
+ ? {
88
+ skipWrite: true,
89
+ }
90
+ : null,
89
91
  },
90
92
  };
91
93
  const { buildLibrary } = await import('@vcmap/ui/build/buildHelpers.js');
@@ -3,14 +3,14 @@ import path from 'path';
3
3
  import fs from 'fs';
4
4
  import { logger } from '@vcsuite/cli-logger';
5
5
  import { getContext, resolveContext } from './context.js';
6
- import { getConfigJson, resolveMapUi } from './hostingHelpers.js';
6
+ import { getAppConfigJson, resolveMapUi } from './hostingHelpers.js';
7
7
  import { getPluginName } from './packageJsonHelpers.js';
8
8
  import buildModule, { buildMapUI, getDefaultConfig } from './build.js';
9
9
  import setupMapUi from './setupMapUi.js';
10
-
10
+ import { getVcmConfigJs } from './pluginCliHelper.js';
11
11
 
12
12
  /**
13
- * creates production preview application in the dist folder based on the @vcmap/ui default map configuration.
13
+ * creates production preview application in the dist folder based on the @vcmap/ui default configuration.
14
14
  * @returns {Promise<void>}
15
15
  */
16
16
  export default async function buildStagingApp() {
@@ -20,11 +20,16 @@ export default async function buildStagingApp() {
20
20
  await rm(distPath, { recursive: true, force: true });
21
21
  await mkdir(distPath);
22
22
  await setupMapUi();
23
- const { buildPluginsForPreview } = await import('@vcmap/ui/build/buildHelpers.js');
23
+ const { buildPluginsForPreview } = await import(
24
+ '@vcmap/ui/build/buildHelpers.js'
25
+ );
24
26
  await buildPluginsForPreview(getDefaultConfig(), true);
25
27
  await mkdir(path.join(distPath, 'plugins', pluginName), { recursive: true });
26
28
 
27
- await buildModule({ outputPath: `plugins/${pluginName}`, keepDistFolder: true });
29
+ await buildModule({
30
+ outputPath: `plugins/${pluginName}`,
31
+ keepDistFolder: true,
32
+ });
28
33
 
29
34
  // copy assets folder if exists
30
35
  if (fs.existsSync(resolveContext('plugin-assets'))) {
@@ -41,16 +46,34 @@ export default async function buildStagingApp() {
41
46
  }
42
47
 
43
48
  await copyFile(
44
- path.join(getContext(), 'node_modules', '@vcmap', 'ui', 'dist', 'index.html'),
49
+ path.join(
50
+ getContext(),
51
+ 'node_modules',
52
+ '@vcmap',
53
+ 'ui',
54
+ 'dist',
55
+ 'index.html',
56
+ ),
45
57
  path.join(distPath, 'index.html'),
46
58
  );
47
- const config = await getConfigJson();
59
+ const vcmConfigJs = await getVcmConfigJs();
60
+ const appConfig = await getAppConfigJson(
61
+ vcmConfigJs.appConfig,
62
+ vcmConfigJs.auth,
63
+ false,
64
+ vcmConfigJs.config,
65
+ );
48
66
  // update Entry
49
- const pluginConfig = config.plugins.find(p => p.name === pluginName);
67
+ const pluginConfig = appConfig.modules
68
+ .at(-1)
69
+ .plugins.find((p) => p.name === pluginName);
50
70
  if (pluginConfig) {
51
71
  pluginConfig.entry = `plugins/${pluginName}/index.js`;
52
72
  }
53
- await writeFile(path.join(distPath, 'map.config.json'), JSON.stringify(config, null, 2));
73
+ await writeFile(
74
+ path.join(distPath, 'app.config.json'),
75
+ JSON.stringify(appConfig, null, 2),
76
+ );
54
77
  await cp(
55
78
  path.join(getContext(), 'node_modules', '@vcmap', 'ui', 'dist', 'assets'),
56
79
  path.join(distPath, 'assets'),
package/src/create.js CHANGED
@@ -28,10 +28,17 @@ import { name, version, promiseExec, getDirname } from './pluginCliHelper.js';
28
28
  * @param {string} pluginPath
29
29
  * @param {string[]} filter - files or dirs to be extracted
30
30
  */
31
- async function downloadAndExtractPluginTar(pluginName, pluginPath, filter = undefined) {
31
+ async function downloadAndExtractPluginTar(
32
+ pluginName,
33
+ pluginPath,
34
+ filter = undefined,
35
+ ) {
32
36
  const logMsg = filter ? filter.join(', ') : pluginName;
33
37
  logger.spin(`Downloading and extracting ${logMsg}`);
34
- const { stdout: packOut, stderr: packErr } = await promiseExec(`npm pack ${pluginName} --quiet`, { cwd: pluginPath });
38
+ const { stdout: packOut, stderr: packErr } = await promiseExec(
39
+ `npm pack ${pluginName} --quiet`,
40
+ { cwd: pluginPath },
41
+ );
35
42
  logger.error(packErr);
36
43
 
37
44
  const tarName = packOut.trim();
@@ -42,7 +49,8 @@ async function downloadAndExtractPluginTar(pluginName, pluginPath, filter = unde
42
49
  strip: 1,
43
50
  };
44
51
  if (filter) {
45
- extractOptions.filter = entryPath => filter.some(f => entryPath.includes(f));
52
+ extractOptions.filter = (entryPath) =>
53
+ filter.some((f) => entryPath.includes(f));
46
54
  }
47
55
  await tar.x(extractOptions);
48
56
  await fs.promises.rm(tarPath);
@@ -59,7 +67,11 @@ async function downloadAndExtractPluginTar(pluginName, pluginPath, filter = unde
59
67
  async function copyPluginTemplate(options, pluginPath) {
60
68
  await downloadAndExtractPluginTar(options.template, pluginPath);
61
69
 
62
- const pluginPackageJson = JSON.parse((await fs.promises.readFile(path.join(pluginPath, 'package.json'))).toString());
70
+ const pluginPackageJson = JSON.parse(
71
+ (
72
+ await fs.promises.readFile(path.join(pluginPath, 'package.json'))
73
+ ).toString(),
74
+ );
63
75
  const userPackageJson = {
64
76
  name: options.name,
65
77
  version: options.version,
@@ -81,7 +93,11 @@ async function copyPluginTemplate(options, pluginPath) {
81
93
  JSON.stringify(packageJson, null, 2),
82
94
  );
83
95
 
84
- const configJson = JSON.parse((await fs.promises.readFile(path.join(pluginPath, 'config.json'))).toString());
96
+ const configJson = JSON.parse(
97
+ (
98
+ await fs.promises.readFile(path.join(pluginPath, 'config.json'))
99
+ ).toString(),
100
+ );
85
101
  configJson.name = options.name;
86
102
 
87
103
  const writeConfigPromise = fs.promises.writeFile(
@@ -89,18 +105,16 @@ async function copyPluginTemplate(options, pluginPath) {
89
105
  JSON.stringify(configJson, null, 2),
90
106
  );
91
107
 
92
- await Promise.all([
93
- writePackagePromise,
94
- writeConfigPromise,
95
- ]);
108
+ await Promise.all([writePackagePromise, writeConfigPromise]);
96
109
  logger.debug('created plugin template');
97
110
 
98
111
  try {
99
112
  await updatePeerDependencies(packageJson.peerDependencies, pluginPath);
100
113
  logger.spin('installing dependencies... (this may take a while)');
101
114
  if (packageJson.dependencies) {
102
- const deps = Object.entries(packageJson.dependencies)
103
- .map(([depName, depVersion]) => `${depName}@${depVersion}`);
115
+ const deps = Object.entries(packageJson.dependencies).map(
116
+ ([depName, depVersion]) => `${depName}@${depVersion}`,
117
+ );
104
118
  await installDeps(deps, DepType.DEP, pluginPath);
105
119
  }
106
120
  await installDeps([`${name}@${version}`], DepType.DEV, pluginPath);
@@ -118,13 +132,12 @@ async function copyPluginTemplate(options, pluginPath) {
118
132
  * @param {string} pluginPath
119
133
  */
120
134
  async function createPluginTemplate(options, pluginPath) {
121
- const installVitest = options.scripts && options.scripts.find(script => script.test);
135
+ const installVitest =
136
+ options.scripts && options.scripts.find((script) => script.test);
122
137
  if (!installVitest) {
123
138
  options.scripts.push({ test: 'echo "Error: no test specified" && exit 1' });
124
139
  } else {
125
- options.scripts.push(
126
- { coverage: 'vitest run --coverage' },
127
- );
140
+ options.scripts.push({ coverage: 'vitest run --coverage' });
128
141
  }
129
142
 
130
143
  const packageJson = {
@@ -133,21 +146,15 @@ async function createPluginTemplate(options, pluginPath) {
133
146
  description: options.description,
134
147
  type: 'module',
135
148
  main: 'src/index.js',
136
- scripts: Object.assign({ prepublishOnly: 'vcmplugin build' }, ...options.scripts),
149
+ scripts: Object.assign(
150
+ { prepublishOnly: 'vcmplugin build' },
151
+ ...options.scripts,
152
+ ),
137
153
  author: options.author,
138
154
  license: options.license,
139
155
  dependencies: {},
140
- keywords: [
141
- 'vcmap',
142
- 'plugin',
143
- ],
144
- files: [
145
- 'src/',
146
- 'dist/',
147
- 'plugin-assets/',
148
- 'LICENSE.md',
149
- 'README.md',
150
- ],
156
+ keywords: ['vcmap', 'plugin'],
157
+ files: ['src/', 'dist/', 'plugin-assets/', 'LICENSE.md', 'README.md'],
151
158
  exports: {
152
159
  '.': './src/index.js',
153
160
  './dist': './dist/index.js',
@@ -160,13 +167,14 @@ async function createPluginTemplate(options, pluginPath) {
160
167
  };
161
168
  }
162
169
 
163
- const installEsLint = options.scripts.find(script => script.lint);
170
+ const installEsLint = options.scripts.find((script) => script.lint);
164
171
  if (installEsLint) {
165
172
  packageJson.eslintIgnore = ['node_modules'];
166
173
  packageJson.eslintConfig = {
167
174
  root: true,
168
175
  extends: '@vcsuite/eslint-config/vue',
169
176
  };
177
+ packageJson.prettier = '@vcsuite/eslint-config/prettier.js';
170
178
  }
171
179
 
172
180
  const writePackagePromise = fs.promises.writeFile(
@@ -199,11 +207,17 @@ async function createPluginTemplate(options, pluginPath) {
199
207
 
200
208
  if (installVitest) {
201
209
  logger.debug('setting up test environment');
202
- await downloadAndExtractPluginTar('@vcmap/hello-world', pluginPath, ['tests', 'vitest.config.js']);
210
+ await downloadAndExtractPluginTar('@vcmap/hello-world', pluginPath, [
211
+ 'tests',
212
+ 'vitest.config.js',
213
+ ]);
203
214
  }
204
215
 
205
216
  try {
206
- const peerDependencies = options.peerDeps.reduce((obj, key) => ({ ...obj, [key]: 'latest' }), {});
217
+ const peerDependencies = options.peerDeps.reduce(
218
+ (obj, key) => ({ ...obj, [key]: 'latest' }),
219
+ {},
220
+ );
207
221
  await updatePeerDependencies(peerDependencies, pluginPath);
208
222
  logger.spin('installing dependencies... (this may take a while)');
209
223
  const devDeps = [`${name}@${version}`];
@@ -211,7 +225,12 @@ async function createPluginTemplate(options, pluginPath) {
211
225
  devDeps.push('@vcsuite/eslint-config');
212
226
  }
213
227
  if (installVitest) {
214
- devDeps.push('vitest', '@vitest/coverage-c8', 'jest-canvas-mock', 'jsdom');
228
+ devDeps.push(
229
+ 'vitest',
230
+ '@vitest/coverage-c8',
231
+ 'jest-canvas-mock',
232
+ 'jsdom',
233
+ );
215
234
  }
216
235
  await installDeps(devDeps, DepType.DEV, pluginPath);
217
236
  logger.success('Installed dependencies');
@@ -250,10 +269,7 @@ async function createPlugin(options) {
250
269
 
251
270
  const writeReadmePromise = fs.promises.writeFile(
252
271
  path.join(pluginPath, 'README.md'),
253
- [
254
- `# ${options.name}`,
255
- 'describe your plugin',
256
- ].join('\n'),
272
+ [`# ${options.name}`, 'describe your plugin'].join('\n'),
257
273
  );
258
274
 
259
275
  const writeChangesPromise = fs.promises.writeFile(
@@ -308,9 +324,27 @@ export default async function create() {
308
324
  { title: 'build', value: { build: 'vcmplugin build' }, selected: true },
309
325
  { title: 'pack', value: { pack: 'vcmplugin pack' }, selected: true },
310
326
  { title: 'start', value: { start: 'vcmplugin serve' }, selected: true },
311
- { title: 'preview', value: { preview: 'vcmplugin preview' }, selected: true },
312
- { title: 'buildStagingApp', value: { buildStagingApp: 'vcmplugin buildStagingApp' }, selected: true },
313
- { title: 'lint', value: { lint: 'eslint "{src,tests}/**/*.{js,vue}"' }, selected: true },
327
+ {
328
+ title: 'preview',
329
+ value: { preview: 'vcmplugin preview' },
330
+ selected: true,
331
+ },
332
+ {
333
+ title: 'buildStagingApp',
334
+ value: { buildStagingApp: 'vcmplugin buildStagingApp' },
335
+ selected: true,
336
+ },
337
+ {
338
+ title: 'lint',
339
+ value: {
340
+ 'lint:js': 'eslint . --ext .vue,.js,.cjs,.mjs,.ts,.cts,.mts',
341
+ 'lint:prettier': 'prettier --check .',
342
+ lint: 'npm run lint:js && npm run lint:prettier',
343
+ format:
344
+ 'prettier --write --list-different . && npm run lint:js -- --fix',
345
+ },
346
+ selected: true,
347
+ },
314
348
  { title: 'test', value: { test: 'vitest' }, selected: true },
315
349
  ];
316
350
 
@@ -342,7 +376,7 @@ export default async function create() {
342
376
  name: 'version',
343
377
  message: 'Version',
344
378
  initial: '1.0.0',
345
- validate: value => !!semver.valid(value),
379
+ validate: (value) => !!semver.valid(value),
346
380
  },
347
381
  {
348
382
  type: 'text',
@@ -367,11 +401,10 @@ export default async function create() {
367
401
  name: 'license',
368
402
  message: 'License',
369
403
  initial: 0,
370
- choices: Object.values(LicenseType)
371
- .map(type => ({
372
- title: type,
373
- value: type,
374
- })),
404
+ choices: Object.values(LicenseType).map((type) => ({
405
+ title: type,
406
+ value: type,
407
+ })),
375
408
  },
376
409
  {
377
410
  type: 'select',
@@ -404,7 +437,11 @@ export default async function create() {
404
437
  },
405
438
  ];
406
439
 
407
- const answers = await prompts(questions, { onCancel() { process.exit(0); } });
440
+ const answers = await prompts(questions, {
441
+ onCancel() {
442
+ process.exit(0);
443
+ },
444
+ });
408
445
 
409
446
  await createPlugin(answers);
410
447
  }
@@ -3,20 +3,28 @@ import { logger } from '@vcsuite/cli-logger';
3
3
  import { setContext } from './context.js';
4
4
 
5
5
  Command.prototype.defaultOptions = function defaultOptions() {
6
- this
7
- .option('--context [path]', 'an optional context, default is cwd', (value) => {
6
+ this.option(
7
+ '--context [path]',
8
+ 'an optional context, default is cwd',
9
+ (value) => {
8
10
  setContext(value);
9
11
  return value;
10
- });
12
+ },
13
+ );
11
14
 
12
15
  return this;
13
16
  };
14
17
 
15
18
  Command.prototype.defaultServeOptions = function defaultServeOptions() {
16
- this
17
- .option('-p, --port [port]', 'the port to listen on', /\d+/)
18
- .option('--auth <user:password>', 'an optional auth to append to proxy requests')
19
- .option('-c, --config <config>', 'a config override to not use the default plugin config')
19
+ this.option('-p, --port [port]', 'the port to listen on', /\d+/)
20
+ .option(
21
+ '--auth <user:password>',
22
+ 'an optional auth to append to proxy requests',
23
+ )
24
+ .option(
25
+ '-c, --config <config>',
26
+ 'a config override to not use the default plugin config',
27
+ )
20
28
  .option('--https', 'use https for serving');
21
29
 
22
30
  return this;