@vcmap/plugin-cli 2.1.16 → 2.1.18
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 +30 -9
- package/cli.js +1 -1
- package/package.json +1 -1
- package/src/defaultCommand.js +1 -2
- package/src/hostingHelpers.js +12 -3
- package/src/pluginCliHelper.js +1 -1
- package/src/preview.js +29 -15
- package/src/serve.js +7 -3
package/README.md
CHANGED
|
@@ -173,15 +173,18 @@ export default {
|
|
|
173
173
|
|
|
174
174
|
The following parameters are valid:
|
|
175
175
|
|
|
176
|
-
| parameter | type | description
|
|
177
|
-
| --------- | ------------------ |
|
|
178
|
-
| config | string|Object |
|
|
179
|
-
| auth | string |
|
|
180
|
-
| port | number |
|
|
181
|
-
|
|
|
182
|
-
|
|
|
183
|
-
|
|
|
184
|
-
|
|
176
|
+
| parameter | type | description |
|
|
177
|
+
| --------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------- |
|
|
178
|
+
| config | string|Object | An optional configObject or fileName to use for configuring the plugin |
|
|
179
|
+
| auth | string | Potential auth string to download assets (index.html, config) with |
|
|
180
|
+
| port | number | Optional alternative port (default 8008) |
|
|
181
|
+
| appConfig | string|Object | An optional configObject resp. fileName or URL to an app config |
|
|
182
|
+
| vcm | string | A filename or URL to a VC Map application. Only works for `preview` command! Takes precedence over `appConfig` parameter. |
|
|
183
|
+
| proxy | Object | A server proxy (see [vitejs.dev](https://vitejs.dev/config/server-options.html#server-proxy)) |
|
|
184
|
+
|
|
185
|
+
> The `vcm` parameter uses a hosted map application to preview the plugin. The plugin is bundled and added to the application. This parameter is only working for `preview` mode.
|
|
186
|
+
|
|
187
|
+
> For the `appConfig` option, map and plugin are bundled to create a preview environment. Here only the configuration is loaded from the provided url or object. This parameter is working for both `preview` and `serve` mode.
|
|
185
188
|
|
|
186
189
|
## About Peer Dependencies
|
|
187
190
|
|
|
@@ -229,6 +232,24 @@ should be rewritten to:
|
|
|
229
232
|
import { Cartesian3 } from '@vcmap-cesium/engine';
|
|
230
233
|
```
|
|
231
234
|
|
|
235
|
+
### Overwriting Peer Dependencies
|
|
236
|
+
|
|
237
|
+
If you want to work with a release candidate or a specific branch of @vcmap/core or @vcmap/ui you need to define [overrides](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides) within your plugin's `package.json`.
|
|
238
|
+
This will replace the package(s) in your dependency tree with the corresponding version.
|
|
239
|
+
|
|
240
|
+
```json
|
|
241
|
+
{
|
|
242
|
+
"peerDependencies": {
|
|
243
|
+
"@vcmap/core": "5.1.0-rc.3",
|
|
244
|
+
"@vcmap/ui": "5.1.0-rc.3"
|
|
245
|
+
},
|
|
246
|
+
"overrides": {
|
|
247
|
+
"@vcmap/core": "5.1.0-rc.3",
|
|
248
|
+
"@vcmap/ui": "5.1.0-rc.3"
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
232
253
|
### What about openlayers?
|
|
233
254
|
|
|
234
255
|
openlayers provides a special case, since its modules do not provide a _flat_ namespace.
|
package/cli.js
CHANGED
|
@@ -26,7 +26,7 @@ program
|
|
|
26
26
|
.summary('start preview server')
|
|
27
27
|
.defaultOptions()
|
|
28
28
|
.defaultServeOptions()
|
|
29
|
-
.option('--vcm [url]', 'URL to a
|
|
29
|
+
.option('--vcm [url]', 'URL to a VC MAP application', (val) =>
|
|
30
30
|
val.replace(/\/$/, ''),
|
|
31
31
|
)
|
|
32
32
|
.safeAction(preview);
|
package/package.json
CHANGED
package/src/defaultCommand.js
CHANGED
package/src/hostingHelpers.js
CHANGED
|
@@ -13,7 +13,6 @@ import { promiseExec, getDirname } from './pluginCliHelper.js';
|
|
|
13
13
|
* @property {string|Object} [config] - an optional configObject or fileName to use for configuring the plugin
|
|
14
14
|
* @property {string} [auth] - potential auth string to download assets (index.html, config) with
|
|
15
15
|
* @property {number} [port]
|
|
16
|
-
* @property {boolean} [https]
|
|
17
16
|
*/
|
|
18
17
|
|
|
19
18
|
/**
|
|
@@ -127,7 +126,7 @@ export async function reWriteAppConfig(appConfig, pluginConfig, production) {
|
|
|
127
126
|
config.plugins = config.plugins.filter((p) => p.name !== name);
|
|
128
127
|
}
|
|
129
128
|
});
|
|
130
|
-
appConfig.modules.push({ plugins: [pluginConfig] });
|
|
129
|
+
appConfig.modules.push({ _id: 'plugin-cli-module', plugins: [pluginConfig] });
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
/**
|
|
@@ -143,7 +142,8 @@ export function getAppConfigJson(appConfig, auth, production, configFile) {
|
|
|
143
142
|
return Promise.resolve(configMap.get('app.config.json'));
|
|
144
143
|
}
|
|
145
144
|
const isObject = typeof appConfig === 'object' && appConfig !== null;
|
|
146
|
-
const
|
|
145
|
+
const isURL = (url) => /^https?:\/\//.test(url);
|
|
146
|
+
const isWebVcm = !isObject && isURL(usedConfig);
|
|
147
147
|
return new Promise((resolve, reject) => {
|
|
148
148
|
async function handleAppConfig(data) {
|
|
149
149
|
try {
|
|
@@ -151,6 +151,15 @@ export function getAppConfigJson(appConfig, auth, production, configFile) {
|
|
|
151
151
|
configMap.set('app.config.json', appConfigJson);
|
|
152
152
|
const pluginConfig = await getPluginConfig(configFile);
|
|
153
153
|
await reWriteAppConfig(appConfigJson, pluginConfig, production);
|
|
154
|
+
if (isWebVcm) {
|
|
155
|
+
// replace relative URLs by absolute ones
|
|
156
|
+
appConfigJson.modules = appConfigJson.modules.map((m) => {
|
|
157
|
+
if (typeof m === 'string' && !isURL(m)) {
|
|
158
|
+
return new URL(m, usedConfig).toString();
|
|
159
|
+
}
|
|
160
|
+
return m;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
154
163
|
resolve(appConfigJson);
|
|
155
164
|
} catch (e) {
|
|
156
165
|
reject(e);
|
package/src/pluginCliHelper.js
CHANGED
|
@@ -27,7 +27,7 @@ export const { version, name } = JSON.parse(
|
|
|
27
27
|
export const promiseExec = util.promisify(childProcess.exec);
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* @typedef {
|
|
30
|
+
* @typedef {PreviewOptions} VcmConfigJs
|
|
31
31
|
* @property {Object} proxy - see https://vitejs.dev/config/server-options.html#server-proxy
|
|
32
32
|
*/
|
|
33
33
|
|
package/src/preview.js
CHANGED
|
@@ -23,8 +23,8 @@ import setupMapUi from './setupMapUi.js';
|
|
|
23
23
|
import { getVcmConfigJs } from './pluginCliHelper.js';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* @typedef {
|
|
27
|
-
* @property {string} [vcm]
|
|
26
|
+
* @typedef {ServeOptions} PreviewOptions
|
|
27
|
+
* @property {string} [vcm] - an optional URL to a VC Map application
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -38,12 +38,11 @@ function setAliases(alias, libraryPaths) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* @param {
|
|
42
|
-
* @param {boolean} [https]
|
|
41
|
+
* @param {VcmConfigJs} options
|
|
43
42
|
* @returns {Promise<import("vite").InlineConfig>}
|
|
44
43
|
*/
|
|
45
|
-
async function getServerOptions(
|
|
46
|
-
let proxy;
|
|
44
|
+
async function getServerOptions(options) {
|
|
45
|
+
let proxy = options.proxy || {};
|
|
47
46
|
const normalLibraries = await getLibraryPaths('normal');
|
|
48
47
|
const scopedLibraries = await getLibraryPaths('@scoped/plugin');
|
|
49
48
|
const alias = {
|
|
@@ -52,11 +51,24 @@ async function getServerOptions(hostedVcm, https) {
|
|
|
52
51
|
setAliases(alias, normalLibraries);
|
|
53
52
|
setAliases(alias, scopedLibraries);
|
|
54
53
|
|
|
55
|
-
if (
|
|
54
|
+
if (options.vcm) {
|
|
55
|
+
const proxyOptions = {
|
|
56
|
+
target: options.vcm,
|
|
57
|
+
changeOrigin: true,
|
|
58
|
+
secure: false,
|
|
59
|
+
configure(httpProxy) {
|
|
60
|
+
httpProxy.on('proxyRes', (proxyRes) => {
|
|
61
|
+
delete proxyRes.headers['Content-Security-Policy'];
|
|
62
|
+
delete proxyRes.headers['content-security-policy'];
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
56
67
|
proxy = {
|
|
57
|
-
|
|
58
|
-
'^/
|
|
59
|
-
'^/
|
|
68
|
+
...proxy,
|
|
69
|
+
'^/style.css': proxyOptions,
|
|
70
|
+
'^/assets': proxyOptions,
|
|
71
|
+
'^/plugins': proxyOptions,
|
|
60
72
|
};
|
|
61
73
|
}
|
|
62
74
|
|
|
@@ -69,7 +81,6 @@ async function getServerOptions(hostedVcm, https) {
|
|
|
69
81
|
server: {
|
|
70
82
|
middlewareMode: true,
|
|
71
83
|
proxy,
|
|
72
|
-
https,
|
|
73
84
|
},
|
|
74
85
|
};
|
|
75
86
|
}
|
|
@@ -87,18 +98,21 @@ export default async function preview(options) {
|
|
|
87
98
|
if (!fs.existsSync(resolveMapUi('dist'))) {
|
|
88
99
|
await buildMapUI();
|
|
89
100
|
}
|
|
101
|
+
} else {
|
|
102
|
+
logger.info(`Using hosted VC Map application ${mergedOptions.vcm}`);
|
|
90
103
|
}
|
|
91
104
|
checkReservedDirectories();
|
|
92
105
|
await build({ development: false, watch: true });
|
|
93
106
|
const app = express();
|
|
94
107
|
logger.info('Starting preview server...');
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
);
|
|
108
|
+
const inlineConfig = await getServerOptions(mergedOptions);
|
|
109
|
+
const server = await createServer(inlineConfig);
|
|
98
110
|
|
|
99
111
|
addAppConfigRoute(
|
|
100
112
|
app,
|
|
101
|
-
mergedOptions.vcm
|
|
113
|
+
mergedOptions.vcm
|
|
114
|
+
? `${mergedOptions.vcm}/app.config.json`
|
|
115
|
+
: mergedOptions.appConfig,
|
|
102
116
|
mergedOptions.auth,
|
|
103
117
|
mergedOptions.config,
|
|
104
118
|
true,
|
package/src/serve.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
2
3
|
import { createServer } from 'vite';
|
|
3
4
|
import vue2 from '@vitejs/plugin-vue2';
|
|
4
5
|
import express from 'express';
|
|
@@ -91,6 +92,7 @@ export default async function serve(options) {
|
|
|
91
92
|
}
|
|
92
93
|
const vcmConfigJs = await getVcmConfigJs();
|
|
93
94
|
const mergedOptions = { ...vcmConfigJs, ...options };
|
|
95
|
+
|
|
94
96
|
await printVcmapUiVersion();
|
|
95
97
|
/*
|
|
96
98
|
// In case @vcmap/ui is linked via git+ssh, dist folder is not available and must be built first
|
|
@@ -104,7 +106,7 @@ export default async function serve(options) {
|
|
|
104
106
|
const port = mergedOptions.port || 8008;
|
|
105
107
|
|
|
106
108
|
logger.info('Starting development server...');
|
|
107
|
-
const proxy = await getProxy(
|
|
109
|
+
const proxy = await getProxy('http', port);
|
|
108
110
|
const { peerDependencies } = await getPackageJson();
|
|
109
111
|
|
|
110
112
|
const optimizationIncludes = [
|
|
@@ -119,7 +121,10 @@ export default async function serve(options) {
|
|
|
119
121
|
|
|
120
122
|
// We exclude ui dependencies from optimization, to allow plugins to use another version of the same plugin.
|
|
121
123
|
// vitejs seems to have a problem with optimized deps in different versions.
|
|
122
|
-
const
|
|
124
|
+
const uiPackageJsonPath = path.join(resolveMapUi(), 'package.json');
|
|
125
|
+
const { dependencies } = JSON.parse(
|
|
126
|
+
(await readFile(uiPackageJsonPath)).toString(),
|
|
127
|
+
);
|
|
123
128
|
|
|
124
129
|
const excludedOptimizations = Object.keys(dependencies).filter(
|
|
125
130
|
(name) => !optimizationIncludes.includes(name),
|
|
@@ -148,7 +153,6 @@ export default async function serve(options) {
|
|
|
148
153
|
plugins: [vue2(), createConfigJsonReloadPlugin()],
|
|
149
154
|
server: {
|
|
150
155
|
middlewareMode: true,
|
|
151
|
-
https: mergedOptions.https,
|
|
152
156
|
proxy: { ...mergedOptions.proxy, ...proxy },
|
|
153
157
|
},
|
|
154
158
|
css: {
|