@vcmap/plugin-cli 2.1.3 → 2.1.5

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
@@ -136,7 +136,7 @@ in the VC Publishers `plugins` public directory.
136
136
  ## vcm config js
137
137
 
138
138
  The `@vcmap/plugin-cli` supports an optional configuration file, which can be used for the commands `serve` and `preview`.
139
- It's an alternative to providing cli parameters (which will still have precedence) and even has a few extra feature like proxy.
139
+ It's an alternative to providing cli parameters (which will still have precedence) and even has a few extra feature like proxy or inline config files.
140
140
  This can be helpful, if you want to share specific parameters valid for a specific plugin.
141
141
  In order to do so just save a `vcm.config.js` in your plugin's root directory.
142
142
  This file has to return a js object as default export.
@@ -155,14 +155,15 @@ export default {
155
155
 
156
156
  The following parameters are valid:
157
157
 
158
- | parameter | type | description |
159
- |-----------|---------|-----------------------------------------------------------------------------------------------|
160
- | config | string | an optional fileName to use for configuring the plugin |
161
- | port | number | optional alternative port (default 8008) |
162
- | https | boolean | wether to use http (default) or https |
163
- | mapConfig | string | a filename or URL to a map config (for `serve` command) |
164
- | vcm | string | a filename or URL to a map (for `preview` command) |
165
- | proxy | Object | a server proxy (see [vitejs.dev](https://vitejs.dev/config/server-options.html#server-proxy)) |
158
+ | parameter | type | description |
159
+ |-----------|--------------------|-----------------------------------------------------------------------------------------------|
160
+ | config | string|Object | an optional configObject or fileName to use for configuring the plugin |
161
+ | auth | string | potential auth string to download assets (index.html, config) with |
162
+ | port | number | optional alternative port (default 8008) |
163
+ | https | boolean | whether to use http (default) or https |
164
+ | mapConfig | string|Object | an optional configObject resp. fileName or URL to a map config (for `serve` command) |
165
+ | vcm | string | a filename or URL to a map (for `preview` command) |
166
+ | proxy | Object | a server proxy (see [vitejs.dev](https://vitejs.dev/config/server-options.html#server-proxy)) |
166
167
 
167
168
 
168
169
  ## About Peer Dependencies
@@ -147,8 +147,8 @@ version:
147
147
  - npm version patch -m "%s [skip-ci]"
148
148
  - TAG=`git describe --abbrev=0`
149
149
  - echo git push git@gitlab:vcsuite/"$CI_PROJECT_PATH".git
150
- - git push git@gitlab:vcsuite/"$CI_PROJECT_PATH".git $TAG
151
- - git push git@gitlab:vcsuite/"$CI_PROJECT_PATH".git HEAD:$CI_COMMIT_REF_NAME
150
+ - git push git@gitlab:"$CI_PROJECT_PATH".git $TAG
151
+ - git push git@gitlab:"$CI_PROJECT_PATH".git HEAD:$CI_COMMIT_REF_NAME
152
152
  before_script:
153
153
  - mkdir -p ~/.ssh
154
154
  - chmod 700 ~/.ssh
@@ -0,0 +1,2 @@
1
+ FROM httpd:2-buster
2
+ COPY * /usr/local/apache2/htdocs/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcmap/plugin-cli",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "A CLI to help develop and build plugins for the VC Map",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -40,7 +40,7 @@
40
40
  "vue-template-compiler": "~2.7.14"
41
41
  },
42
42
  "peerDependencies": {
43
- "@vcmap/ui": "^5.0.0-rc.21",
43
+ "@vcmap/ui": "^5.0.0-rc.22",
44
44
  "vue": "~2.7.14"
45
45
  },
46
46
  "peerDependenciesMeta": {
@@ -7,6 +7,7 @@ import { getConfigJson, 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
+ import { getVcmConfigJs } from './pluginCliHelper.js';
10
11
 
11
12
 
12
13
  /**
@@ -44,7 +45,8 @@ export default async function buildStagingApp() {
44
45
  path.join(getContext(), 'node_modules', '@vcmap', 'ui', 'dist', 'index.html'),
45
46
  path.join(distPath, 'index.html'),
46
47
  );
47
- const config = await getConfigJson();
48
+ const { default: vcmConfigJs } = await getVcmConfigJs();
49
+ const config = await getConfigJson(vcmConfigJs.mapConfig, vcmConfigJs.auth, false, vcmConfigJs.config);
48
50
  // update Entry
49
51
  const pluginConfig = config.plugins.find(p => p.name === pluginName);
50
52
  if (pluginConfig) {
package/src/create.js CHANGED
@@ -211,7 +211,7 @@ async function createPluginTemplate(options, pluginPath) {
211
211
  devDeps.push('@vcsuite/eslint-config');
212
212
  }
213
213
  if (installVitest) {
214
- devDeps.push('vite', 'vitest', '@vitest/coverage-c8', 'jest-canvas-mock', 'jsdom');
214
+ devDeps.push('vitest', '@vitest/coverage-c8', 'jest-canvas-mock', 'jsdom');
215
215
  }
216
216
  await installDeps(devDeps, DepType.DEV, pluginPath);
217
217
  logger.success('Installed dependencies');
@@ -279,6 +279,11 @@ async function createPlugin(options) {
279
279
  path.join(getDirname(), '..', 'assets', '.gitlab-ci.yml'),
280
280
  path.join(pluginPath, '.gitlab-ci.yml'),
281
281
  );
282
+ await fs.promises.cp(
283
+ path.join(getDirname(), '..', 'assets', 'build'),
284
+ path.join(pluginPath, 'build'),
285
+ { recursive: true },
286
+ );
282
287
  }
283
288
 
284
289
  if (options.template) {
@@ -10,7 +10,7 @@ import { promiseExec, getDirname } from './pluginCliHelper.js';
10
10
 
11
11
  /**
12
12
  * @typedef {Object} HostingOptions
13
- * @property {string} [config] - an optional fileName to use for configuring the plugin
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
16
  * @property {boolean} [https]
@@ -71,6 +71,18 @@ export async function readConfigJson(fileName) {
71
71
  return config;
72
72
  }
73
73
 
74
+ /**
75
+ * @param {string} pluginConfig
76
+ * @returns {Promise<Object>}
77
+ */
78
+ export async function getPluginConfig(pluginConfig) {
79
+ const isObject = typeof pluginConfig === 'object' && pluginConfig !== null;
80
+ if (isObject) {
81
+ return pluginConfig;
82
+ }
83
+ return readConfigJson(pluginConfig);
84
+ }
85
+
74
86
  const configMap = new Map();
75
87
 
76
88
  /**
@@ -117,8 +129,20 @@ export function getConfigJson(mapConfig, auth, production, configFile) {
117
129
  if (configMap.has('map.config.json')) {
118
130
  return Promise.resolve(configMap.get('map.config.json'));
119
131
  }
120
- const isWebVcm = /^https?:\/\//.test(usedConfig);
132
+ const isObject = typeof mapConfig === 'object' && mapConfig !== null;
133
+ const isWebVcm = !isObject && /^https?:\/\//.test(usedConfig);
121
134
  return new Promise((resolve, reject) => {
135
+ async function handleConfig(data) {
136
+ try {
137
+ const configJson = JSON.parse(data);
138
+ configMap.set('map.config.json', configJson);
139
+ const pluginConfig = await getPluginConfig(configFile);
140
+ await reWriteConfig(configJson, pluginConfig, production);
141
+ resolve(configJson);
142
+ } catch (e) {
143
+ reject(e);
144
+ }
145
+ }
122
146
  function handleStream(stream) {
123
147
  let data = '';
124
148
  stream.on('data', (chunk) => {
@@ -126,18 +150,12 @@ export function getConfigJson(mapConfig, auth, production, configFile) {
126
150
  });
127
151
 
128
152
  stream.on('close', async () => {
129
- try {
130
- const configJson = JSON.parse(data);
131
- configMap.set('map.config.json', configJson);
132
- const pluginConfig = await readConfigJson(configFile);
133
- await reWriteConfig(configJson, pluginConfig, production);
134
- resolve(configJson);
135
- } catch (e) {
136
- reject(e);
137
- }
153
+ await handleConfig(data);
138
154
  });
139
155
  }
140
- if (isWebVcm) {
156
+ if (isObject) {
157
+ handleConfig(JSON.stringify(mapConfig));
158
+ } else if (isWebVcm) {
141
159
  httpGet(usedConfig, auth, (res) => {
142
160
  if (res.statusCode < 400) {
143
161
  handleStream(res);
@@ -213,7 +231,7 @@ export function addMapConfigRoute(app, mapConfig, auth, configFile, production)
213
231
  */
214
232
  export async function addConfigRoute(app, auth, configFileName, production) { // IDEA pass in available plugins and strip unavailable ones?
215
233
  const mapUiDir = resolveMapUi();
216
- const pluginConfig = await readConfigJson(configFileName);
234
+ const pluginConfig = await getPluginConfig(configFileName);
217
235
 
218
236
  app.get('/config*', async (req, res) => {
219
237
  const { url } = req;
@@ -24,6 +24,14 @@ export const { version, name } = JSON.parse(fs.readFileSync(path.join(getDirname
24
24
  */
25
25
  export const promiseExec = util.promisify(childProcess.exec);
26
26
 
27
+ /**
28
+ * @typedef {ServeOptions} VcmConfigJs
29
+ * @property {Object} proxy - see https://vitejs.dev/config/server-options.html#server-proxy
30
+ */
31
+
32
+ /**
33
+ * @returns {Promise<VcmConfigJs>}
34
+ */
27
35
  export async function getVcmConfigJs() {
28
36
  let vcmConfigJs = {};
29
37
  const vcmConfigJsPath = path.resolve(getContext(), 'vcm.config.js');
package/src/preview.js CHANGED
@@ -42,7 +42,9 @@ async function getServerOptions(hostedVcm, https) {
42
42
  let proxy;
43
43
  const normalLibraries = await getLibraryPaths('normal');
44
44
  const scopedLibraries = await getLibraryPaths('@scoped/plugin');
45
- const alias = {};
45
+ const alias = {
46
+ '@cesium/engine': '@vcmap-cesium/engine',
47
+ };
46
48
  setAliases(alias, normalLibraries);
47
49
  setAliases(alias, scopedLibraries);
48
50
 
package/src/serve.js CHANGED
@@ -20,7 +20,7 @@ import { buildMapUI } from './build.js';
20
20
 
21
21
  /**
22
22
  * @typedef {HostingOptions} ServeOptions
23
- * @property {string} [mapConfig] - a filename or URL to a map config
23
+ * @property {string|Object} [mapConfig] - an optional configObject resp. fileName or URL to a map config
24
24
  */
25
25
 
26
26
  async function getProxy(protocol, port) {
@@ -91,6 +91,11 @@ export default async function serve(options) {
91
91
  const server = await createServer({
92
92
  root: getContext(),
93
93
  publicDir: false,
94
+ resolve: {
95
+ alias: {
96
+ '@cesium/engine': '@vcmap-cesium/engine',
97
+ },
98
+ },
94
99
  optimizeDeps: {
95
100
  exclude: [
96
101
  '@vcmap/ui',