@vcmap/plugin-cli 3.1.2 → 4.0.0-rc.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcmap/plugin-cli",
3
- "version": "3.1.2",
3
+ "version": "4.0.0-rc.1",
4
4
  "description": "A CLI to help develop and build plugins for the VC Map",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -31,19 +31,19 @@
31
31
  "dependencies": {
32
32
  "@vcmap/rollup-plugin-vcs-ol": "^1.0.2",
33
33
  "@vcsuite/cli-logger": "^1.0.0",
34
- "@vitejs/plugin-vue2": "^2.2.0",
34
+ "@vitejs/plugin-vue": "^5.0.4",
35
35
  "commander": "^10.0.1",
36
36
  "express": "^4.18.2",
37
37
  "prompts": "^2.4.2",
38
- "sass": "1.32.13",
38
+ "sass": "^1.77.1",
39
39
  "semver": "^7.5.4",
40
40
  "tar": "^6.1.15",
41
- "vite": "^4.5.2",
41
+ "vite": "^5.2.11",
42
42
  "vue-template-compiler": "~2.7.14"
43
43
  },
44
44
  "peerDependencies": {
45
- "@vcmap/ui": "^5.2.0",
46
- "vue": "~2.7.14"
45
+ "@vcmap/ui": "^6.0.0-rc.1",
46
+ "vue": "~3.4.27"
47
47
  },
48
48
  "peerDependenciesMeta": {
49
49
  "@vcmap/ui": {
@@ -81,7 +81,7 @@
81
81
  },
82
82
  "prettier": "@vcsuite/eslint-config/prettier.js",
83
83
  "engines": {
84
- "node": ">=18.12.0",
85
- "npm": ">=9.0.0"
84
+ "node": ">=18.12.0 || >= 20.0.0",
85
+ "npm": ">=9.0.0 || 10.0.0"
86
86
  }
87
87
  }
package/src/build.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from 'path';
2
2
  import { rm, mkdir } from 'node:fs/promises';
3
3
  import fs from 'node:fs';
4
- import vue2 from '@vitejs/plugin-vue2';
4
+ import vue from '@vitejs/plugin-vue';
5
5
  import vcsOl from '@vcmap/rollup-plugin-vcs-ol';
6
6
  import { logger } from '@vcsuite/cli-logger';
7
7
  import { getEntry, getPluginName } from './packageJsonHelpers.js';
@@ -19,7 +19,7 @@ import { executeUiNpm, resolveMapUi } from './hostingHelpers.js';
19
19
  export function getDefaultConfig() {
20
20
  return {
21
21
  publicDir: false,
22
- plugins: [vue2(), vcsOl()],
22
+ plugins: [vue(), vcsOl()],
23
23
  };
24
24
  }
25
25
 
package/src/create.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import prompts from 'prompts';
4
- import { minVersion, parse, valid } from 'semver';
4
+ import { minVersion, parse, prerelease, valid } from 'semver';
5
5
  import tar from 'tar';
6
6
  import { logger } from '@vcsuite/cli-logger';
7
7
  import { LicenseType, writeLicense } from './licenses.js';
@@ -164,6 +164,11 @@ async function createPluginTemplate(options, pluginPath) {
164
164
  root: true,
165
165
  extends: '@vcsuite/eslint-config/vue',
166
166
  };
167
+ } else {
168
+ await fs.promises.copyFile(
169
+ path.join(getDirname(), '..', 'assets', 'eslintrc.cjs'),
170
+ path.join(pluginPath, '.eslintrc.cjs'),
171
+ );
167
172
  }
168
173
  packageJson.prettier = '@vcsuite/eslint-config/prettier.js';
169
174
  }
@@ -214,15 +219,15 @@ async function createPluginTemplate(options, pluginPath) {
214
219
  path.join(pluginPath, 'tests'),
215
220
  { recursive: true },
216
221
  );
222
+ await fs.promises.copyFile(
223
+ path.join(getDirname(), '..', 'assets', 'eslintrcTests.cjs'),
224
+ path.join(pluginPath, '.eslintrc.cjs'),
225
+ );
217
226
  }
218
227
  await fs.promises.copyFile(
219
228
  path.join(getDirname(), '..', 'assets', 'vitest.config.js'),
220
229
  path.join(pluginPath, 'vitest.config.js'),
221
230
  );
222
- await fs.promises.copyFile(
223
- path.join(getDirname(), '..', 'assets', 'eslintrcTests.cjs'),
224
- path.join(pluginPath, '.eslintrc.cjs'),
225
- );
226
231
  }
227
232
 
228
233
  try {
@@ -230,11 +235,30 @@ async function createPluginTemplate(options, pluginPath) {
230
235
  (obj, key) => ({ ...obj, [key]: 'latest' }),
231
236
  {},
232
237
  );
233
- const { major, minor } = parse(
234
- minVersion(cliPeerDependencies['@vcmap/ui']),
235
- );
236
- const mapVersion = `^${major}.${minor}`;
237
- await updatePeerDependencies(peerDependencies, pluginPath, { mapVersion });
238
+
239
+ if (cliPeerDependencies['@vcmap/ui'].startsWith('git')) {
240
+ logger.warning('installing git ui peer dependency');
241
+ const peerDeps = [
242
+ cliPeerDependencies['@vcmap/ui'],
243
+ ...Object.keys(peerDependencies),
244
+ ];
245
+ await installDeps(peerDeps, DepType.PEER, pluginPath);
246
+ } else {
247
+ let mapVersion;
248
+ const mapSemver = parse(minVersion(cliPeerDependencies['@vcmap/ui']));
249
+ if (prerelease(mapSemver)) {
250
+ const { major, minor, patch } = mapSemver;
251
+ mapVersion = `^${major}.${minor}.${patch}-rc`;
252
+ } else {
253
+ const { major, minor } = mapSemver;
254
+ mapVersion = `^${major}.${minor}`;
255
+ }
256
+
257
+ await updatePeerDependencies(peerDependencies, pluginPath, {
258
+ mapVersion,
259
+ });
260
+ }
261
+
238
262
  logger.spin('installing dependencies... (this may take a while)');
239
263
  const devDeps = [`${name}@${version}`];
240
264
  if (installEsLint) {
@@ -74,9 +74,10 @@ export const DepType = {
74
74
  * @param {Array<string>} deps
75
75
  * @param {DepType} type
76
76
  * @param {string} pluginPath
77
+ * @param {boolean} [force=false]
77
78
  * @returns {Promise<void>}
78
79
  */
79
- export async function installDeps(deps, type, pluginPath) {
80
+ export async function installDeps(deps, type, pluginPath, force = false) {
80
81
  if (deps.length < 1) {
81
82
  return;
82
83
  }
@@ -86,6 +87,11 @@ export async function installDeps(deps, type, pluginPath) {
86
87
  } else if (type === DepType.DEV) {
87
88
  save = '--save-dev';
88
89
  }
90
+
91
+ if (force) {
92
+ save = `${save} --force`;
93
+ }
94
+
89
95
  const installCmd = `npm i ${save} ${deps.map((d) => `"${d}"`).join(' ')}`; // wrap deps with "" for windows
90
96
  logger.debug(installCmd);
91
97
  const { stdout, stderr } = await promiseExec(installCmd, { cwd: pluginPath });
package/src/preview.js CHANGED
@@ -13,11 +13,7 @@ import {
13
13
  printVcmapUiVersion,
14
14
  resolveMapUi,
15
15
  } from './hostingHelpers.js';
16
- import build, {
17
- buildMapUI,
18
- getDefaultConfig,
19
- getLibraryPaths,
20
- } from './build.js';
16
+ import build, { buildMapUI, getDefaultConfig } from './build.js';
21
17
  import { getContext } from './context.js';
22
18
  import setupMapUi from './setupMapUi.js';
23
19
  import { getVcmConfigJs } from './pluginCliHelper.js';
@@ -27,29 +23,12 @@ import { getVcmConfigJs } from './pluginCliHelper.js';
27
23
  * @property {string} [vcm] - an optional URL to a VC Map application
28
24
  */
29
25
 
30
- /**
31
- * @param {Object<string, string>} alias
32
- * @param {Object<string, string>} libraryPaths
33
- */
34
- function setAliases(alias, libraryPaths) {
35
- Object.values(libraryPaths).forEach((entry) => {
36
- alias[entry] = entry.replace(/(..\/)*assets/, '/assets');
37
- });
38
- }
39
-
40
26
  /**
41
27
  * @param {VcmConfigJs} options
42
28
  * @returns {Promise<import("vite").InlineConfig>}
43
29
  */
44
30
  async function getServerOptions(options) {
45
31
  let proxy = options.proxy || {};
46
- const normalLibraries = await getLibraryPaths('normal');
47
- const scopedLibraries = await getLibraryPaths('@scoped/plugin');
48
- const alias = {
49
- '@cesium/engine': '@vcmap-cesium/engine',
50
- };
51
- setAliases(alias, normalLibraries);
52
- setAliases(alias, scopedLibraries);
53
32
 
54
33
  if (options.vcm) {
55
34
  const proxyOptions = {
@@ -75,13 +54,30 @@ async function getServerOptions(options) {
75
54
  return {
76
55
  publicDir: false,
77
56
  plugins: [createConfigJsonReloadPlugin()],
57
+
78
58
  resolve: {
79
- alias,
59
+ alias: [
60
+ {
61
+ find: /(\.\.\/)+assets(.*)/,
62
+ replacement: '/assets$2',
63
+ customResolver: {
64
+ resolveId(source) {
65
+ return source;
66
+ },
67
+ },
68
+ },
69
+ {
70
+ find: '@cesium/engine',
71
+ replacement: '@vcmap-cesium/engine',
72
+ },
73
+ ],
80
74
  },
81
75
  server: {
76
+ preTransformRequests: false,
82
77
  middlewareMode: true,
83
78
  proxy,
84
79
  },
80
+ appType: 'custom',
85
81
  };
86
82
  }
87
83
 
package/src/serve.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import { readFile } from 'fs/promises';
3
3
  import { createServer } from 'vite';
4
- import vue2 from '@vitejs/plugin-vue2';
4
+ import vue from '@vitejs/plugin-vue';
5
5
  import express from 'express';
6
6
  import { logger } from '@vcsuite/cli-logger';
7
7
  import path from 'path';
@@ -158,7 +158,7 @@ export default async function serve(options) {
158
158
  ],
159
159
  include: optimizationIncludes,
160
160
  },
161
- plugins: [vue2(), createConfigJsonReloadPlugin()],
161
+ plugins: [vue(), createConfigJsonReloadPlugin()],
162
162
  server: {
163
163
  middlewareMode: true,
164
164
  proxy: { ...mergedOptions.proxy, ...proxy },
package/src/update.js CHANGED
@@ -1,17 +1,18 @@
1
1
  import { logger } from '@vcsuite/cli-logger';
2
- import { validRange } from 'semver';
2
+ import { validRange, prerelease } from 'semver';
3
3
  import {
4
4
  checkVcMapVersion,
5
5
  DepType,
6
6
  getPackageJson,
7
7
  installDeps,
8
8
  } from './packageJsonHelpers.js';
9
- import { name, promiseExec } from './pluginCliHelper.js';
9
+ import { name, version, promiseExec } from './pluginCliHelper.js';
10
10
  import { getContext } from './context.js';
11
11
 
12
12
  /**
13
13
  * @typedef {Object} UpdateOptions
14
14
  * @property {string} [mapVersion] - Optional version of @vcmap/ui to update to. Default is latest
15
+ * @property {boolean} [force] - Force install
15
16
  */
16
17
 
17
18
  /**
@@ -46,7 +47,7 @@ export async function updatePeerDependencies(
46
47
  peerDeps.push(...pluginPeerDeps);
47
48
  }
48
49
  logger.spin('Updating peer dependencies');
49
- await installDeps(peerDeps, DepType.PEER, pluginPath);
50
+ await installDeps(peerDeps, DepType.PEER, pluginPath, options.force);
50
51
  logger.stopSpinner();
51
52
  logger.success('Updated peer dependencies');
52
53
  }
@@ -58,7 +59,11 @@ export async function updatePeerDependencies(
58
59
  */
59
60
  async function updateCli(pluginPath) {
60
61
  logger.spin(`Updating ${name}`);
61
- await installDeps([`${name}@latest`], DepType.DEV, pluginPath);
62
+ let versionToUse = 'latest';
63
+ if (prerelease(version)) {
64
+ versionToUse = `^${version}`;
65
+ }
66
+ await installDeps([`${name}@${versionToUse}`], DepType.DEV, pluginPath, true);
62
67
  logger.stopSpinner();
63
68
  logger.success(`Updated ${name}`);
64
69
  }
@@ -72,8 +77,11 @@ async function updateCli(pluginPath) {
72
77
  export default async function update(options) {
73
78
  const packageJson = await getPackageJson();
74
79
  const context = getContext();
75
- await updatePeerDependencies(packageJson.peerDependencies, context, options);
76
- await checkVcMapVersion(context);
77
80
  await updateCli(context);
81
+ await updatePeerDependencies(packageJson.peerDependencies, context, {
82
+ force: true,
83
+ ...options,
84
+ });
85
+ await checkVcMapVersion(context);
78
86
  logger.success(`Updated plugin ${packageJson.name}`);
79
87
  }