@vcmap/plugin-cli 2.1.12 → 2.1.14
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 +1 -1
- package/assets/vitest.config.js +32 -0
- package/cli.js +19 -3
- package/package.json +4 -4
- package/src/create.js +27 -64
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ conflicts in the used API within a plugin. This means, that _all_ commands
|
|
|
44
44
|
plugin cli _within the plugin itself_ using npx. When using the `create`
|
|
45
45
|
command, the `@vcmap/plugin-cli` will automatically be installed as a devDependency in
|
|
46
46
|
its current major version. You can then use either the scripts defined
|
|
47
|
-
by the template in your package.json `npm start`, `npm run
|
|
47
|
+
by the template in your package.json `npm start`, `npm run bundle` etc. or `npx`
|
|
48
48
|
to execute CLI commands.
|
|
49
49
|
|
|
50
50
|
All commands have (optional) cli options. Run `vcmplugin --help` or `vcmplugin help [command]` for more information.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import commonViteConfig from '@vcmap/ui/build/commonViteConfig.js';
|
|
4
|
+
|
|
5
|
+
const configTest = defineConfig({
|
|
6
|
+
...commonViteConfig,
|
|
7
|
+
resolve: {
|
|
8
|
+
alias: {
|
|
9
|
+
vue: 'vue/dist/vue.esm.js',
|
|
10
|
+
tinyqueue: 'tinyqueue/tinyqueue.js',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
css: {
|
|
14
|
+
preprocessorOptions: {
|
|
15
|
+
sass: {
|
|
16
|
+
additionalData: "\n@import '@vcmap/ui/src/styles/variables.scss'\n",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
test: {
|
|
21
|
+
server: {
|
|
22
|
+
deps: {
|
|
23
|
+
inline: ['vuetify', '@vcmap/ui'],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
environment: 'jsdom',
|
|
27
|
+
setupFiles: ['tests/setup.js'],
|
|
28
|
+
isolate: false,
|
|
29
|
+
threads: false,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
export default configTest;
|
package/cli.js
CHANGED
|
@@ -8,12 +8,22 @@ import buildStagingApp from './src/buildStagingApp.js';
|
|
|
8
8
|
|
|
9
9
|
program.version(version);
|
|
10
10
|
|
|
11
|
-
program
|
|
11
|
+
program
|
|
12
|
+
.command('create')
|
|
13
|
+
.summary('create new plugin')
|
|
14
|
+
.defaultOptions()
|
|
15
|
+
.safeAction(create);
|
|
12
16
|
|
|
13
|
-
program
|
|
17
|
+
program
|
|
18
|
+
.command('bundle')
|
|
19
|
+
.summary('pack tar for production')
|
|
20
|
+
.defaultOptions()
|
|
21
|
+
.alias('pack')
|
|
22
|
+
.safeAction(pack);
|
|
14
23
|
|
|
15
24
|
program
|
|
16
25
|
.command('preview')
|
|
26
|
+
.summary('start preview server')
|
|
17
27
|
.defaultOptions()
|
|
18
28
|
.defaultServeOptions()
|
|
19
29
|
.option('--vcm [url]', 'URL to a virtualcityMAP application', (val) =>
|
|
@@ -23,6 +33,7 @@ program
|
|
|
23
33
|
|
|
24
34
|
program
|
|
25
35
|
.command('serve')
|
|
36
|
+
.summary('start dev server')
|
|
26
37
|
.defaultOptions()
|
|
27
38
|
.defaultServeOptions()
|
|
28
39
|
.option(
|
|
@@ -33,6 +44,7 @@ program
|
|
|
33
44
|
|
|
34
45
|
program
|
|
35
46
|
.command('build')
|
|
47
|
+
.description('builds plugin including assets using vite')
|
|
36
48
|
.defaultOptions()
|
|
37
49
|
.option('--development', 'set mode to development')
|
|
38
50
|
.option('--watch', 'watch file changes')
|
|
@@ -40,10 +52,14 @@ program
|
|
|
40
52
|
|
|
41
53
|
program.command('buildStagingApp').defaultOptions().safeAction(buildStagingApp);
|
|
42
54
|
|
|
43
|
-
program
|
|
55
|
+
program
|
|
56
|
+
.command('setup-map-ui')
|
|
57
|
+
.description('make other plugins of @vcmap/ui available in dev server')
|
|
58
|
+
.safeAction(setupMapUi);
|
|
44
59
|
|
|
45
60
|
program
|
|
46
61
|
.command('update')
|
|
62
|
+
.description('update to (latest) VC Map version')
|
|
47
63
|
.defaultOptions()
|
|
48
64
|
.option(
|
|
49
65
|
'--mapVersion [semver]',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vcmap/plugin-cli",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.14",
|
|
4
4
|
"description": "A CLI to help develop and build plugins for the VC Map",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"vue-template-compiler": "~2.7.14"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@vcmap/ui": "^5.0.
|
|
45
|
+
"@vcmap/ui": "^5.0.1",
|
|
46
46
|
"vue": "~2.7.14"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"prettier": "@vcsuite/eslint-config/prettier.js",
|
|
81
81
|
"engines": {
|
|
82
|
-
"node": "
|
|
83
|
-
"npm": "
|
|
82
|
+
"node": ">=18.12.0",
|
|
83
|
+
"npm": ">=9.0.0"
|
|
84
84
|
}
|
|
85
85
|
}
|
package/src/create.js
CHANGED
|
@@ -82,6 +82,7 @@ async function downloadAndExtractPluginTar(
|
|
|
82
82
|
file: tarPath,
|
|
83
83
|
cwd: pluginPath,
|
|
84
84
|
strip: 4,
|
|
85
|
+
keep: true,
|
|
85
86
|
};
|
|
86
87
|
if (filter) {
|
|
87
88
|
extractOptions.filter = (entryPath) =>
|
|
@@ -101,59 +102,19 @@ async function downloadAndExtractPluginTar(
|
|
|
101
102
|
*/
|
|
102
103
|
async function copyPluginTemplate(options, pluginPath) {
|
|
103
104
|
await downloadAndExtractPluginTar('@vcmap/ui', pluginPath, [
|
|
104
|
-
path.join('plugins', options.template),
|
|
105
|
+
path.posix.join('plugins', options.template), // tar x filter requires linux path
|
|
105
106
|
]);
|
|
106
107
|
|
|
107
|
-
const pluginPackageJson = JSON.parse(
|
|
108
|
-
(
|
|
109
|
-
await fs.promises.readFile(path.join(pluginPath, 'package.json'))
|
|
110
|
-
).toString(),
|
|
111
|
-
);
|
|
112
|
-
const userPackageJson = createPackageJson(options);
|
|
113
|
-
const packageJson = { ...pluginPackageJson, ...userPackageJson };
|
|
114
|
-
if (options.repository) {
|
|
115
|
-
packageJson.repository = {
|
|
116
|
-
url: options.repository,
|
|
117
|
-
};
|
|
118
|
-
} else {
|
|
119
|
-
delete options.repository;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const writePackagePromise = fs.promises.writeFile(
|
|
123
|
-
path.join(pluginPath, 'package.json'),
|
|
124
|
-
JSON.stringify(packageJson, null, 2),
|
|
125
|
-
);
|
|
126
|
-
|
|
127
108
|
const configPath = path.join(pluginPath, 'config.json');
|
|
128
109
|
const configJson = fs.existsSync(configPath)
|
|
129
110
|
? JSON.parse((await fs.promises.readFile(configPath)).toString())
|
|
130
111
|
: {};
|
|
131
112
|
configJson.name = options.name;
|
|
132
113
|
|
|
133
|
-
|
|
114
|
+
await fs.promises.writeFile(
|
|
134
115
|
path.join(pluginPath, 'config.json'),
|
|
135
116
|
JSON.stringify(configJson, null, 2),
|
|
136
117
|
);
|
|
137
|
-
|
|
138
|
-
await Promise.all([writePackagePromise, writeConfigPromise]);
|
|
139
|
-
logger.debug('created plugin template');
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
await updatePeerDependencies(packageJson.peerDependencies, pluginPath);
|
|
143
|
-
logger.spin('installing dependencies... (this may take a while)');
|
|
144
|
-
if (packageJson.dependencies) {
|
|
145
|
-
const deps = Object.entries(packageJson.dependencies).map(
|
|
146
|
-
([depName, depVersion]) => `${depName}@${depVersion}`,
|
|
147
|
-
);
|
|
148
|
-
await installDeps(deps, DepType.DEP, pluginPath);
|
|
149
|
-
}
|
|
150
|
-
await installDeps([`${name}@${version}`], DepType.DEV, pluginPath);
|
|
151
|
-
logger.success('Installed dependencies');
|
|
152
|
-
} catch (e) {
|
|
153
|
-
logger.error(e);
|
|
154
|
-
logger.failure('Failed installing dependencies');
|
|
155
|
-
}
|
|
156
|
-
logger.stopSpinner();
|
|
157
118
|
}
|
|
158
119
|
|
|
159
120
|
/**
|
|
@@ -188,7 +149,7 @@ async function createPluginTemplate(options, pluginPath) {
|
|
|
188
149
|
packageJson.prettier = '@vcsuite/eslint-config/prettier.js';
|
|
189
150
|
}
|
|
190
151
|
|
|
191
|
-
|
|
152
|
+
await fs.promises.writeFile(
|
|
192
153
|
path.join(pluginPath, 'package.json'),
|
|
193
154
|
JSON.stringify(packageJson, null, 2),
|
|
194
155
|
);
|
|
@@ -197,24 +158,25 @@ async function createPluginTemplate(options, pluginPath) {
|
|
|
197
158
|
name: options.name,
|
|
198
159
|
};
|
|
199
160
|
|
|
200
|
-
|
|
161
|
+
await fs.promises.writeFile(
|
|
201
162
|
path.join(pluginPath, 'config.json'),
|
|
202
163
|
JSON.stringify(configJson, null, 2),
|
|
203
164
|
);
|
|
204
165
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
166
|
+
if (options.template) {
|
|
167
|
+
await copyPluginTemplate(options, pluginPath);
|
|
168
|
+
} else {
|
|
169
|
+
const srcPath = path.join(pluginPath, 'src');
|
|
170
|
+
if (!fs.existsSync(srcPath)) {
|
|
171
|
+
await fs.promises.mkdir(srcPath);
|
|
172
|
+
logger.debug('created src directory');
|
|
173
|
+
}
|
|
212
174
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
175
|
+
await fs.promises.copyFile(
|
|
176
|
+
path.join(getDirname(), '..', 'assets', 'index.js'),
|
|
177
|
+
path.join(pluginPath, 'src', 'index.js'),
|
|
178
|
+
);
|
|
179
|
+
}
|
|
218
180
|
|
|
219
181
|
if (installVitest) {
|
|
220
182
|
logger.debug('setting up test environment');
|
|
@@ -223,6 +185,10 @@ async function createPluginTemplate(options, pluginPath) {
|
|
|
223
185
|
path.join(pluginPath, 'tests'),
|
|
224
186
|
{ recursive: true },
|
|
225
187
|
);
|
|
188
|
+
await fs.promises.copyFile(
|
|
189
|
+
path.join(getDirname(), '..', 'assets', 'vitest.config.js'),
|
|
190
|
+
path.join(pluginPath, 'vitest.config.js'),
|
|
191
|
+
);
|
|
226
192
|
}
|
|
227
193
|
|
|
228
194
|
try {
|
|
@@ -239,8 +205,9 @@ async function createPluginTemplate(options, pluginPath) {
|
|
|
239
205
|
if (installVitest) {
|
|
240
206
|
devDeps.push(
|
|
241
207
|
'vitest',
|
|
242
|
-
'@vitest/coverage-
|
|
208
|
+
'@vitest/coverage-v8',
|
|
243
209
|
'jest-canvas-mock',
|
|
210
|
+
'resize-observer-polyfill',
|
|
244
211
|
'jsdom',
|
|
245
212
|
);
|
|
246
213
|
}
|
|
@@ -324,11 +291,7 @@ async function createPlugin(options) {
|
|
|
324
291
|
);
|
|
325
292
|
}
|
|
326
293
|
|
|
327
|
-
|
|
328
|
-
await copyPluginTemplate(options, pluginPath);
|
|
329
|
-
} else {
|
|
330
|
-
await createPluginTemplate(options, pluginPath);
|
|
331
|
-
}
|
|
294
|
+
await createPluginTemplate(options, pluginPath);
|
|
332
295
|
await setVcMapVersion(pluginPath);
|
|
333
296
|
logger.success(`Created plugin ${options.name}`);
|
|
334
297
|
}
|
|
@@ -350,7 +313,7 @@ export default async function create() {
|
|
|
350
313
|
|
|
351
314
|
const scriptChoices = [
|
|
352
315
|
{ title: 'build', value: { build: 'vcmplugin build' }, selected: true },
|
|
353
|
-
{ title: '
|
|
316
|
+
{ title: 'bundle', value: { bundle: 'vcmplugin bundle' }, selected: true },
|
|
354
317
|
{ title: 'start', value: { start: 'vcmplugin serve' }, selected: true },
|
|
355
318
|
{
|
|
356
319
|
title: 'preview',
|
|
@@ -449,7 +412,7 @@ export default async function create() {
|
|
|
449
412
|
hint: '- Space to select. Enter to submit',
|
|
450
413
|
},
|
|
451
414
|
{
|
|
452
|
-
type:
|
|
415
|
+
type: 'multiselect',
|
|
453
416
|
name: 'peerDeps',
|
|
454
417
|
message: 'Add the following peer dependencies to the package.json.',
|
|
455
418
|
choices: peerDependencyChoices,
|