@vcmap/plugin-cli 3.0.0 → 3.0.2
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/assets/.gitlab-ci.yml +9 -0
- package/assets/eslintrcTests.cjs +25 -0
- package/assets/index.html +6 -2
- package/assets/tests/vcsPluginInterface.spec.js +135 -0
- package/assets/testsTypescript/tsconfig.json +32 -0
- package/assets/testsTypescript/vcsPluginInterface.spec.ts +150 -0
- package/package.json +2 -1
- package/src/build.js +1 -1
- package/src/create.js +14 -0
- package/src/hostingHelpers.js +6 -3
- package/src/packageJsonHelpers.js +12 -4
- package/src/serve.js +9 -1
- package/assets/tests/sample.spec.js +0 -15
package/assets/.gitlab-ci.yml
CHANGED
|
@@ -72,6 +72,15 @@ buildPreview:
|
|
|
72
72
|
stage: bundle
|
|
73
73
|
script:
|
|
74
74
|
- npm run buildStagingApp
|
|
75
|
+
before_script:
|
|
76
|
+
- mkdir -p ~/.ssh
|
|
77
|
+
- chmod 700 ~/.ssh
|
|
78
|
+
- echo "$SSH_RUNNER_KEY" | tr -d '\r' > ~/.ssh/id_rsa
|
|
79
|
+
- chmod 600 ~/.ssh/id_rsa
|
|
80
|
+
- ssh-keyscan gitlab.virtualcitysystems.de >> ~/.ssh/known_hosts
|
|
81
|
+
- chmod 644 ~/.ssh/known_hosts
|
|
82
|
+
- git config user.name "Gitlab Runner"
|
|
83
|
+
- git config user.email "gitlab-runner@vc.systems"
|
|
75
84
|
|
|
76
85
|
bundle:
|
|
77
86
|
<<: *after_build_definition
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
// const sharedLib = require('eslint-config-airbnb-typescript/lib/shared.js');
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
root: true,
|
|
6
|
+
extends: ['@vcsuite/eslint-config/vue-ts'],
|
|
7
|
+
env: {
|
|
8
|
+
node: true,
|
|
9
|
+
},
|
|
10
|
+
rules: {
|
|
11
|
+
'no-restricted-syntax': 'off',
|
|
12
|
+
},
|
|
13
|
+
overrides: [
|
|
14
|
+
{
|
|
15
|
+
files: ['*.ts', '*.vue'],
|
|
16
|
+
parserOptions: {
|
|
17
|
+
project: ['./tsconfig.json', './tests/tsconfig.json'],
|
|
18
|
+
},
|
|
19
|
+
rules: {
|
|
20
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
ignorePatterns: ['dist/', 'node_modules/'],
|
|
25
|
+
};
|
package/assets/index.html
CHANGED
|
@@ -5,30 +5,34 @@
|
|
|
5
5
|
<meta charset="utf-8">
|
|
6
6
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
7
7
|
<link
|
|
8
|
+
class="vcs-favicon"
|
|
8
9
|
rel="icon"
|
|
9
10
|
type="image/png"
|
|
10
11
|
href="./assets/favicon-32.png"
|
|
11
12
|
sizes="32x32"
|
|
12
13
|
>
|
|
13
14
|
<link
|
|
15
|
+
class="vcs-favicon"
|
|
14
16
|
rel="icon"
|
|
15
17
|
type="image/png"
|
|
16
18
|
href="./assets/favicon-128.png"
|
|
17
19
|
sizes="128x128"
|
|
18
20
|
>
|
|
19
21
|
<link
|
|
22
|
+
class="vcs-favicon"
|
|
20
23
|
rel="icon"
|
|
21
24
|
type="image/png"
|
|
22
25
|
href="./assets/favicon-180.png"
|
|
23
26
|
sizes="180x180"
|
|
24
27
|
>
|
|
25
28
|
<link
|
|
29
|
+
class="vcs-favicon"
|
|
26
30
|
rel="icon"
|
|
27
31
|
type="image/png"
|
|
28
32
|
href="./assets/favicon-192.png"
|
|
29
33
|
sizes="192x192"
|
|
30
34
|
>
|
|
31
|
-
<link rel="icon" type="image/svg+xml" href="./assets/favicon.svg">
|
|
35
|
+
<link class="vcs-favicon" rel="icon" type="image/svg+xml" href="./assets/favicon.svg">
|
|
32
36
|
<link
|
|
33
37
|
rel="stylesheet"
|
|
34
38
|
href="./assets/@mdi/font/css/materialdesignicons.min.css"
|
|
@@ -92,7 +96,7 @@
|
|
|
92
96
|
}
|
|
93
97
|
</style>
|
|
94
98
|
</head>
|
|
95
|
-
<body style="height: 100vh">
|
|
99
|
+
<body style="height: 100vh; margin: 0;">
|
|
96
100
|
<noscript>
|
|
97
101
|
<strong>...</strong>
|
|
98
102
|
</noscript>
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
+
import { VcsUiApp, loadPlugin } from '@vcmap/ui';
|
|
3
|
+
import plugin from '../src/index.js';
|
|
4
|
+
import packageJSON from '../package.json';
|
|
5
|
+
|
|
6
|
+
function sleep(ms = 0) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
setTimeout(resolve, ms);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
window.VcsPluginLoaderFunction = (name, module) => ({
|
|
13
|
+
default: () => plugin({ name }, module),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const testPropSymbol = Symbol('testProp');
|
|
17
|
+
|
|
18
|
+
describe('VcsPlugin Interface test', () => {
|
|
19
|
+
let pluginInstance;
|
|
20
|
+
|
|
21
|
+
beforeAll(async () => {
|
|
22
|
+
pluginInstance = await loadPlugin(packageJSON.name, {
|
|
23
|
+
name: packageJSON.name,
|
|
24
|
+
entry: '_dev',
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterAll(() => {
|
|
29
|
+
pluginInstance?.destroy?.();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('name, version, mapVersion', () => {
|
|
33
|
+
it('should return the plugin name from the package.json', () => {
|
|
34
|
+
expect(pluginInstance).to.have.property('name', packageJSON.name);
|
|
35
|
+
});
|
|
36
|
+
it('should return the plugin version from the package.json', () => {
|
|
37
|
+
expect(pluginInstance).to.have.property('version', packageJSON.version);
|
|
38
|
+
});
|
|
39
|
+
it('should return the plugin mapVersion from the package.json', () => {
|
|
40
|
+
expect(pluginInstance).to.have.property(
|
|
41
|
+
'mapVersion',
|
|
42
|
+
packageJSON.mapVersion,
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('internationalization', () => {
|
|
48
|
+
it('may provide an i18n object and should provide at least en as fallback language', () => {
|
|
49
|
+
if (pluginInstance?.i18n) {
|
|
50
|
+
expect(pluginInstance?.i18n).to.be.a('object').with.property('en');
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
it('should use unscoped, camel-case plugin name as namespace for plugin specific i18n entries', () => {
|
|
54
|
+
if (pluginInstance?.i18n) {
|
|
55
|
+
expect(pluginInstance.i18n).to.be.a('object');
|
|
56
|
+
const [scope, name] = packageJSON.name.split('/');
|
|
57
|
+
const unscopedName = name || scope;
|
|
58
|
+
const camelCaseName = unscopedName.replace(/-./g, (x) =>
|
|
59
|
+
x[1].toUpperCase(),
|
|
60
|
+
);
|
|
61
|
+
Object.values(pluginInstance.i18n).forEach((locale) => {
|
|
62
|
+
expect(locale).to.have.property(camelCaseName);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('plugin hooks', () => {
|
|
69
|
+
it('may implement initialize', () => {
|
|
70
|
+
if (pluginInstance?.initialize) {
|
|
71
|
+
expect(pluginInstance.initialize).to.be.a('function');
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
it('should implement destroy', () => {
|
|
75
|
+
if (pluginInstance?.destroy) {
|
|
76
|
+
expect(pluginInstance.destroy).to.be.a('function');
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('options & serialization', () => {
|
|
82
|
+
it('may return default options', () => {
|
|
83
|
+
if (pluginInstance?.getDefaultOptions) {
|
|
84
|
+
expect(pluginInstance.getDefaultOptions()).to.be.a('object');
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
it('may implement toJSON returning the plugin config', () => {
|
|
88
|
+
if (pluginInstance?.toJSON) {
|
|
89
|
+
expect(pluginInstance.toJSON()).to.be.a('object');
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('shadowing a plugin', () => {
|
|
95
|
+
let app;
|
|
96
|
+
let pluginInstance2;
|
|
97
|
+
|
|
98
|
+
beforeAll(async () => {
|
|
99
|
+
app = new VcsUiApp();
|
|
100
|
+
app.plugins.add(pluginInstance);
|
|
101
|
+
pluginInstance2 = await loadPlugin(packageJSON.name, {
|
|
102
|
+
name: packageJSON.name,
|
|
103
|
+
version: '2.0.0',
|
|
104
|
+
entry: '_dev',
|
|
105
|
+
});
|
|
106
|
+
if (pluginInstance2) {
|
|
107
|
+
pluginInstance2[testPropSymbol] = 'test';
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
afterAll(() => {
|
|
112
|
+
pluginInstance2?.destroy?.();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should override the plugin correctly', () => {
|
|
116
|
+
expect(() => app.plugins.override(pluginInstance2)).to.not.throw;
|
|
117
|
+
app.plugins.override(pluginInstance2);
|
|
118
|
+
expect(app.plugins.getByKey(packageJSON.name)).to.have.property(
|
|
119
|
+
testPropSymbol,
|
|
120
|
+
'test',
|
|
121
|
+
);
|
|
122
|
+
expect(app.plugins.getByKey(packageJSON.name)).to.equal(pluginInstance2);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should reincarnate the plugin correctly', async () => {
|
|
126
|
+
expect(() => app.plugins.remove(pluginInstance2)).to.not.throw;
|
|
127
|
+
app.plugins.remove(pluginInstance2);
|
|
128
|
+
await sleep(0);
|
|
129
|
+
expect(app.plugins.getByKey(packageJSON.name)).not.to.have.property(
|
|
130
|
+
testPropSymbol,
|
|
131
|
+
'test',
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2022",
|
|
4
|
+
"module": "node16",
|
|
5
|
+
"incremental": true,
|
|
6
|
+
"lib": ["esnext", "dom"],
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"checkJs": false,
|
|
9
|
+
"jsx": "preserve",
|
|
10
|
+
"outDir": "../.tests",
|
|
11
|
+
"rootDir": "..",
|
|
12
|
+
/* Strict Type-Checking Options */
|
|
13
|
+
"strict": true,
|
|
14
|
+
"noImplicitAny": true,
|
|
15
|
+
"strictNullChecks": true,
|
|
16
|
+
|
|
17
|
+
/* Additional Checks */
|
|
18
|
+
"noImplicitReturns": false,
|
|
19
|
+
"noFallthroughCasesInSwitch": false,
|
|
20
|
+
|
|
21
|
+
/* Module Resolution Options */
|
|
22
|
+
"baseUrl": ".",
|
|
23
|
+
"moduleResolution": "node16",
|
|
24
|
+
"resolveJsonModule": true,
|
|
25
|
+
"esModuleInterop": true,
|
|
26
|
+
"preserveSymlinks": true,
|
|
27
|
+
"allowSyntheticDefaultImports": true,
|
|
28
|
+
"types": ["mocha", "node"]
|
|
29
|
+
},
|
|
30
|
+
"include": ["../types/", "../src/", "../index.ts", "."],
|
|
31
|
+
"exclude": ["../dist", "../.tests", "../build"]
|
|
32
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
+
import { VcsUiApp, loadPlugin, VcsPlugin } from '@vcmap/ui';
|
|
3
|
+
import plugin from '../src/index.js';
|
|
4
|
+
import packageJSON from '../package.json';
|
|
5
|
+
|
|
6
|
+
function sleep(ms = 0): Promise<void> {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
setTimeout(resolve, ms);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type TestPluginInstance = VcsPlugin<Record<never, never>, Record<never, never>>;
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
window.VcsPluginLoaderFunction = (
|
|
17
|
+
name: string,
|
|
18
|
+
module: string,
|
|
19
|
+
): {
|
|
20
|
+
default: () => TestPluginInstance;
|
|
21
|
+
} => ({
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
default: () => plugin({ name }, module),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const testPropSymbol = Symbol('testProp');
|
|
28
|
+
|
|
29
|
+
describe('VcsPlugin Interface test', () => {
|
|
30
|
+
let pluginInstance: TestPluginInstance | null;
|
|
31
|
+
|
|
32
|
+
beforeAll(async () => {
|
|
33
|
+
pluginInstance = await loadPlugin(packageJSON.name, {
|
|
34
|
+
name: packageJSON.name,
|
|
35
|
+
entry: '_dev',
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
pluginInstance?.destroy?.();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('name, version, mapVersion', () => {
|
|
44
|
+
it('should return the plugin name from the package.json', () => {
|
|
45
|
+
expect(pluginInstance).to.have.property('name', packageJSON.name);
|
|
46
|
+
});
|
|
47
|
+
it('should return the plugin version from the package.json', () => {
|
|
48
|
+
expect(pluginInstance).to.have.property('version', packageJSON.version);
|
|
49
|
+
});
|
|
50
|
+
it('should return the plugin mapVersion from the package.json', () => {
|
|
51
|
+
expect(pluginInstance).to.have.property(
|
|
52
|
+
'mapVersion',
|
|
53
|
+
packageJSON.mapVersion,
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('internationalization', () => {
|
|
59
|
+
it('may provide an i18n object and should provide at least en as fallback language', () => {
|
|
60
|
+
if (pluginInstance?.i18n) {
|
|
61
|
+
expect(pluginInstance?.i18n)
|
|
62
|
+
.to.be.a('object')
|
|
63
|
+
.with.property('en');
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
it('should use unscoped, camel-case plugin name as namespace for plugin specific i18n entries', () => {
|
|
67
|
+
if (pluginInstance?.i18n) {
|
|
68
|
+
expect(pluginInstance.i18n).to.be.a('object');
|
|
69
|
+
const [scope, name] = packageJSON.name.split('/');
|
|
70
|
+
const unscopedName = name || scope;
|
|
71
|
+
const camelCaseName = unscopedName.replace(/-./g, (x: string) =>
|
|
72
|
+
x[1].toUpperCase(),
|
|
73
|
+
);
|
|
74
|
+
Object.values(pluginInstance.i18n).forEach((locale) => {
|
|
75
|
+
expect(locale).to.have.property(camelCaseName);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('plugin hooks', () => {
|
|
82
|
+
it('may implement initialize', () => {
|
|
83
|
+
if (pluginInstance?.initialize) {
|
|
84
|
+
expect(pluginInstance.initialize).to.be.a('function');
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
it('should implement destroy', () => {
|
|
88
|
+
if (pluginInstance?.destroy) {
|
|
89
|
+
expect(pluginInstance.destroy).to.be.a('function');
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('options & serialization', () => {
|
|
95
|
+
it('may return default options', () => {
|
|
96
|
+
if (pluginInstance?.getDefaultOptions) {
|
|
97
|
+
expect(pluginInstance.getDefaultOptions()).to.be.a('object');
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
it('may implement toJSON returning the plugin config', () => {
|
|
101
|
+
if (pluginInstance?.toJSON) {
|
|
102
|
+
expect(pluginInstance.toJSON()).to.be.a('object');
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('shadowing a plugin', () => {
|
|
108
|
+
let app: VcsUiApp;
|
|
109
|
+
let pluginInstance2:
|
|
110
|
+
| (TestPluginInstance & { [testPropSymbol]?: string })
|
|
111
|
+
| null;
|
|
112
|
+
|
|
113
|
+
beforeAll(async () => {
|
|
114
|
+
app = new VcsUiApp();
|
|
115
|
+
app.plugins.add(pluginInstance!);
|
|
116
|
+
pluginInstance2 = await loadPlugin(packageJSON.name, {
|
|
117
|
+
name: packageJSON.name,
|
|
118
|
+
version: '2.0.0',
|
|
119
|
+
entry: '_dev',
|
|
120
|
+
});
|
|
121
|
+
if (pluginInstance2) {
|
|
122
|
+
pluginInstance2[testPropSymbol] = 'test';
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
afterAll(() => {
|
|
127
|
+
pluginInstance2?.destroy?.();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should override the plugin correctly', () => {
|
|
131
|
+
expect(() => app.plugins.override(pluginInstance2!)).to.not.throw;
|
|
132
|
+
app.plugins.override(pluginInstance2!);
|
|
133
|
+
expect(app.plugins.getByKey(packageJSON.name)).to.have.property(
|
|
134
|
+
testPropSymbol,
|
|
135
|
+
'test',
|
|
136
|
+
);
|
|
137
|
+
expect(app.plugins.getByKey(packageJSON.name)).to.equal(pluginInstance2);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should reincarnate the plugin correctly', async () => {
|
|
141
|
+
expect(() => app.plugins.remove(pluginInstance2!)).to.not.throw;
|
|
142
|
+
app.plugins.remove(pluginInstance2!);
|
|
143
|
+
await sleep(0);
|
|
144
|
+
expect(app.plugins.getByKey(packageJSON.name)).not.to.have.property(
|
|
145
|
+
testPropSymbol,
|
|
146
|
+
'test',
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vcmap/plugin-cli",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "A CLI to help develop and build plugins for the VC Map",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"eslintIgnore": [
|
|
61
61
|
"node_modules",
|
|
62
62
|
"assets/tests",
|
|
63
|
+
"assets/testsTypescript",
|
|
63
64
|
"assets/index.ts"
|
|
64
65
|
],
|
|
65
66
|
"eslintConfig": {
|
package/src/build.js
CHANGED
|
@@ -44,7 +44,7 @@ export async function getLibraryPaths(pluginName) {
|
|
|
44
44
|
* @returns {Promise<void>}
|
|
45
45
|
*/
|
|
46
46
|
export default async function buildModule(options) {
|
|
47
|
-
const entry =
|
|
47
|
+
const entry = getEntry();
|
|
48
48
|
const pluginName = await getPluginName();
|
|
49
49
|
const libraryPaths = await getLibraryPaths(pluginName);
|
|
50
50
|
const distPath = path.join(getContext(), 'dist');
|
package/src/create.js
CHANGED
|
@@ -205,10 +205,24 @@ async function createPluginTemplate(options, pluginPath) {
|
|
|
205
205
|
path.join(pluginPath, 'tests'),
|
|
206
206
|
{ recursive: true },
|
|
207
207
|
);
|
|
208
|
+
if (options.typescript) {
|
|
209
|
+
await fs.promises.rm(
|
|
210
|
+
path.join(pluginPath, 'tests', 'vcsPluginInterface.spec.js'),
|
|
211
|
+
);
|
|
212
|
+
await fs.promises.cp(
|
|
213
|
+
path.join(getDirname(), '..', 'assets', 'testsTypescript'),
|
|
214
|
+
path.join(pluginPath, 'tests'),
|
|
215
|
+
{ recursive: true },
|
|
216
|
+
);
|
|
217
|
+
}
|
|
208
218
|
await fs.promises.copyFile(
|
|
209
219
|
path.join(getDirname(), '..', 'assets', 'vitest.config.js'),
|
|
210
220
|
path.join(pluginPath, 'vitest.config.js'),
|
|
211
221
|
);
|
|
222
|
+
await fs.promises.copyFile(
|
|
223
|
+
path.join(getDirname(), '..', 'assets', 'eslintrcTests.cjs'),
|
|
224
|
+
path.join(pluginPath, '.eslintrc.cjs'),
|
|
225
|
+
);
|
|
212
226
|
}
|
|
213
227
|
|
|
214
228
|
try {
|
package/src/hostingHelpers.js
CHANGED
|
@@ -5,7 +5,7 @@ import fs from 'fs';
|
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { logger } from '@vcsuite/cli-logger';
|
|
7
7
|
import { getContext, resolveContext } from './context.js';
|
|
8
|
-
import { getPluginName
|
|
8
|
+
import { getPluginName } from './packageJsonHelpers.js';
|
|
9
9
|
import { promiseExec, getDirname } from './pluginCliHelper.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -119,14 +119,17 @@ export async function printVcmapUiVersion() {
|
|
|
119
119
|
export async function reWriteAppConfig(appConfig, pluginConfig, production) {
|
|
120
120
|
const name = await getPluginName();
|
|
121
121
|
pluginConfig.name = name;
|
|
122
|
-
pluginConfig.entry = production ? 'dist/index.js' :
|
|
122
|
+
pluginConfig.entry = production ? 'dist/index.js' : 'src/index.js';
|
|
123
123
|
appConfig.modules = appConfig.modules ?? [];
|
|
124
124
|
appConfig.modules.forEach((config) => {
|
|
125
125
|
if (Array.isArray(config.plugins)) {
|
|
126
126
|
config.plugins = config.plugins.filter((p) => p.name !== name);
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
|
-
appConfig.modules
|
|
129
|
+
appConfig.modules = [
|
|
130
|
+
{ _id: 'plugin-cli-module', plugins: [pluginConfig] },
|
|
131
|
+
...appConfig.modules,
|
|
132
|
+
];
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
/**
|
|
@@ -41,13 +41,21 @@ export async function getPluginName() {
|
|
|
41
41
|
return name;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Whether this is considered a TS plugin or not
|
|
46
|
+
* @returns {boolean}
|
|
47
|
+
*/
|
|
48
|
+
export function isTS() {
|
|
49
|
+
const indexTs = resolveContext('src', 'index.ts');
|
|
50
|
+
return existsSync(indexTs);
|
|
51
|
+
}
|
|
52
|
+
|
|
44
53
|
/**
|
|
45
54
|
* Gets the entry of the package
|
|
46
|
-
* @returns {
|
|
55
|
+
* @returns {string}
|
|
47
56
|
*/
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
-
if (existsSync(isTS)) {
|
|
57
|
+
export function getEntry() {
|
|
58
|
+
if (isTS()) {
|
|
51
59
|
return 'src/index.ts';
|
|
52
60
|
}
|
|
53
61
|
return 'src/index.js';
|
package/src/serve.js
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
printVcmapUiVersion,
|
|
17
17
|
resolveMapUi,
|
|
18
18
|
} from './hostingHelpers.js';
|
|
19
|
-
import { getPackageJson, getPluginName } from './packageJsonHelpers.js';
|
|
19
|
+
import { getPackageJson, getPluginName, isTS } from './packageJsonHelpers.js';
|
|
20
20
|
import { getVcmConfigJs } from './pluginCliHelper.js';
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -65,6 +65,13 @@ async function getProxy(protocol, port) {
|
|
|
65
65
|
delete proxy[hasThisPlugin];
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
if (isTS()) {
|
|
69
|
+
proxy['/src/index.js'] = {
|
|
70
|
+
target: `http://localhost:${port}`,
|
|
71
|
+
rewrite: () => '/src/index.ts',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
68
75
|
// exampleData is not part of the @vcmap/ui package and must be proxied therefore
|
|
69
76
|
proxy['^/exampleData'] = {
|
|
70
77
|
target: 'https://raw.githubusercontent.com/virtualcitySYSTEMS/map-ui/main',
|
|
@@ -107,6 +114,7 @@ export default async function serve(options) {
|
|
|
107
114
|
|
|
108
115
|
logger.info('Starting development server...');
|
|
109
116
|
const proxy = await getProxy('http', port);
|
|
117
|
+
|
|
110
118
|
const { peerDependencies } = await getPackageJson();
|
|
111
119
|
|
|
112
120
|
const optimizationIncludes = [
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll } from 'vitest';
|
|
2
|
-
import plugin from '../src/index.js';
|
|
3
|
-
import { name } from '../package.json';
|
|
4
|
-
|
|
5
|
-
describe('sample test spec', () => {
|
|
6
|
-
describe('plugin name', () => {
|
|
7
|
-
let pluginInstance;
|
|
8
|
-
beforeAll(() => {
|
|
9
|
-
pluginInstance = plugin({}, 'localhost');
|
|
10
|
-
});
|
|
11
|
-
it('should return the plugin name from the package.json', () => {
|
|
12
|
-
expect(pluginInstance.name).to.equal(name);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
});
|