@shijiu/jsview 2.1.341-test.0 → 2.1.362-test.0
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/dom/bin/jsview-dom-browser.min.js +1 -1
- package/dom/bin/jsview-dom-native.min.js +1 -1
- package/dom/bin/jsview-engine-js-browser.min.js +1 -1
- package/dom/target_core_revision.mjs +2 -2
- package/package.json +1 -1
- package/patches/node_modules/@vitejs/plugin-vue/dist/index.mjs +123 -337
- package/patches/node_modules/@vitejs/plugin-vue/package.json +18 -16
- package/patches/node_modules/vite/dist/node/chunks/{dep-V3BH7oO1.js → dep-ed9cb113.js} +45353 -50657
- package/patches/node_modules/vite/dist/node/constants.js +1 -7
- package/patches/node_modules/vite/dist/node/jsview-vite-extension.js +2 -1
- package/patches/node_modules/vite/package.json +64 -86
- package/tools/jsview-common.mjs +84 -9
- package/tools/jsview-config-app.mjs +47 -0
- package/tools/jsview-module-federation.mjs +365 -0
- package/tools/jsview-post-build.mjs +2 -2
- package/tools/jsview-post-install.mjs +6 -6
- package/tools/jsview-run-tool.mjs +45 -7
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
checkNodeVersion,
|
|
8
|
+
downloadFileAsync,
|
|
9
|
+
execCommand,
|
|
10
|
+
getOptions,
|
|
11
|
+
loadPackageObject,
|
|
12
|
+
parseArguments,
|
|
13
|
+
savePackageObject,
|
|
14
|
+
Logger,
|
|
15
|
+
unzipFile,
|
|
16
|
+
} from './jsview-common.mjs';
|
|
17
|
+
import { assert } from 'node:console';
|
|
18
|
+
|
|
19
|
+
async function updateToFederationBase(options)
|
|
20
|
+
{
|
|
21
|
+
Logger.Info('Updating package.json...');
|
|
22
|
+
const pkgObj = loadPackageObject(options.projectDir);
|
|
23
|
+
if(!pkgObj.scripts) {
|
|
24
|
+
pkgObj.scripts = {};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var postInstall = pkgObj.scripts.postinstall ?? '';
|
|
28
|
+
if(postInstall.includes('npx patch-package') == false) {
|
|
29
|
+
if(postInstall) {
|
|
30
|
+
postInstall += ' && '
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
postInstall += 'npx patch-package'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
pkgObj.scripts.postinstall = postInstall;
|
|
37
|
+
|
|
38
|
+
savePackageObject(options.projectDir, pkgObj);
|
|
39
|
+
|
|
40
|
+
Logger.Info('Downloading patches ...');
|
|
41
|
+
const url = 'https://gitlab.cluster.qcast.cn/mirror/jsview-module-federation-demo/-/raw/main/patches.zip';
|
|
42
|
+
const filePath = path.resolve(options.projectDir, 'patches.zip');
|
|
43
|
+
await downloadFileAsync(url, filePath, options.projectDir)
|
|
44
|
+
|
|
45
|
+
unzipFile(filePath, options.projectDir, options.projectDir);
|
|
46
|
+
|
|
47
|
+
const devDeps = '@originjs/vite-plugin-federation@1.3.4'
|
|
48
|
+
Logger.Info('Installing ' + devDeps + ' ...');
|
|
49
|
+
execCommand('npm install --save-dev ' + devDeps);
|
|
50
|
+
execCommand('npm ci');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getRemoteEntryUrl(options)
|
|
54
|
+
{
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function genFederationUrl(options)
|
|
58
|
+
{
|
|
59
|
+
var content = '';
|
|
60
|
+
|
|
61
|
+
if(options.mode == 'host') {
|
|
62
|
+
content = `
|
|
63
|
+
const remoteDomain = '${options.remoteDomain}' // 替换成你的 Remote 端 base url 或 ip:port;
|
|
64
|
+
const remoteEntryUrl = remoteDomain + '/js/remoteEntry.js'`;
|
|
65
|
+
|
|
66
|
+
if(options.jsviewMode == 'expose') {
|
|
67
|
+
content += `
|
|
68
|
+
const jsviewLoaderUrl = remoteDomain + '/js/JsViewLoader.js'`
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return content
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function genConfigFunction(options)
|
|
76
|
+
{
|
|
77
|
+
var content = '';
|
|
78
|
+
|
|
79
|
+
if(options.mode == 'remote') {
|
|
80
|
+
content = `
|
|
81
|
+
function getRemoteConfig()
|
|
82
|
+
{
|
|
83
|
+
const config = {
|
|
84
|
+
name: 'remote-lib',
|
|
85
|
+
filename: 'remoteEntry.js',
|
|
86
|
+
// 需要暴露的模块
|
|
87
|
+
exposes: {`;
|
|
88
|
+
|
|
89
|
+
if(options.jsviewMode == 'expose') {
|
|
90
|
+
content += `
|
|
91
|
+
// 必须模块,JsView 编译需要
|
|
92
|
+
'./JsViewLoader': 'node_modules/@shijiu/jsview/loader/jsview-loader.js',
|
|
93
|
+
'./JsViewVue': '/node_modules/@shijiu/jsview-vue/index.js',`;
|
|
94
|
+
content += '\n'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
content += `
|
|
98
|
+
// 自定义模块,根据需要自行配置
|
|
99
|
+
// './HelloWorld.vue': './src/components/HelloWorld.vue',
|
|
100
|
+
},`;
|
|
101
|
+
} else if(options.mode == 'host') {
|
|
102
|
+
content = `
|
|
103
|
+
function getHostConfig()
|
|
104
|
+
{
|
|
105
|
+
const config = {
|
|
106
|
+
name: 'host-app',
|
|
107
|
+
remotes: {
|
|
108
|
+
'RemoteEntry': remoteEntryUrl,
|
|
109
|
+
},`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
content += `
|
|
113
|
+
shared: [`;
|
|
114
|
+
if(options.jsviewMode == 'share') {
|
|
115
|
+
content += `
|
|
116
|
+
'jsview',`;
|
|
117
|
+
}
|
|
118
|
+
content += `
|
|
119
|
+
'vue',
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return config
|
|
124
|
+
}`;
|
|
125
|
+
|
|
126
|
+
return content;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function genChunkFileNameFunction(options)
|
|
130
|
+
{
|
|
131
|
+
var content = '';
|
|
132
|
+
|
|
133
|
+
if(options.mode == 'remote') {
|
|
134
|
+
if(options.jsviewMode == 'expose') {
|
|
135
|
+
content = `
|
|
136
|
+
function getChunkFileName(chunkInfo) {
|
|
137
|
+
if(chunkInfo.name == '__federation_expose_JsViewLoader') {
|
|
138
|
+
return 'js/JsViewLoader.js'
|
|
139
|
+
}
|
|
140
|
+
return 'js/chunk.jsv.[hash].js'
|
|
141
|
+
}`;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return content;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function genFederationConfigFunction(options)
|
|
149
|
+
{
|
|
150
|
+
var content = '';
|
|
151
|
+
if(options.mode == 'remote') {
|
|
152
|
+
content += `
|
|
153
|
+
function setFederationRemoteConfig(config) {`;
|
|
154
|
+
} else if(options.mode == 'host') {
|
|
155
|
+
content += `
|
|
156
|
+
function setFederationHostConfig(config) {`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if(options.mode == 'remote') {
|
|
160
|
+
if(options.jsviewMode == 'expose') {
|
|
161
|
+
content += `
|
|
162
|
+
config.build = (config.build || {})
|
|
163
|
+
config.build.rollupOptions = (config.build.rollupOptions || {})
|
|
164
|
+
config.build.rollupOptions.output = (config.build.rollupOptions.output || {})
|
|
165
|
+
config.build.rollupOptions.output.manualChunks = (config.build.rollupOptions.output.manualChunks || {})
|
|
166
|
+
|
|
167
|
+
config.build.rollupOptions.output.chunkFileNames = getChunkFileName
|
|
168
|
+
config.build.rollupOptions.output.manualChunks["__federation_fn_import"] = ["__federation_fn_import"]`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
content += '\n'
|
|
173
|
+
if(options.mode == 'remote') {
|
|
174
|
+
content += `
|
|
175
|
+
const config = getRemoteConfig()`;
|
|
176
|
+
} else if(options.mode == 'host') {
|
|
177
|
+
content += `
|
|
178
|
+
const config = getHostConfig()`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
content += `
|
|
182
|
+
config.plugins.push(federation(config))
|
|
183
|
+
|
|
184
|
+
}`;
|
|
185
|
+
|
|
186
|
+
return content;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function createFederationRemoteConfigFile(options)
|
|
190
|
+
{
|
|
191
|
+
const federationConfigName = 'federation.remote.config.ts';
|
|
192
|
+
Logger.Info('Creating ' + federationConfigName + ' ...');
|
|
193
|
+
|
|
194
|
+
var federationConfigContent = `
|
|
195
|
+
import federation from '@originjs/vite-plugin-federation'`;
|
|
196
|
+
|
|
197
|
+
federationConfigContent += '\n';
|
|
198
|
+
federationConfigContent += genConfigFunction(options);
|
|
199
|
+
federationConfigContent += '\n';
|
|
200
|
+
federationConfigContent += genChunkFileNameFunction(options);
|
|
201
|
+
federationConfigContent += '\n';
|
|
202
|
+
federationConfigContent += genFederationConfigFunction(options);
|
|
203
|
+
federationConfigContent += '\n';
|
|
204
|
+
|
|
205
|
+
federationConfigContent += `
|
|
206
|
+
export {
|
|
207
|
+
setFederationHostConfig,
|
|
208
|
+
}`;
|
|
209
|
+
|
|
210
|
+
fs.writeFileSync(path.resolve(options.projectDir, federationConfigName),
|
|
211
|
+
federationConfigContent,
|
|
212
|
+
'utf-8');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function createFederationHostConfigFile(options)
|
|
216
|
+
{
|
|
217
|
+
const federationConfigName = 'federation.host.config.ts';
|
|
218
|
+
Logger.Info('Creating ' + federationConfigName + ' ...');
|
|
219
|
+
|
|
220
|
+
var federationConfigContent = `
|
|
221
|
+
import federation from '@originjs/vite-plugin-federation'`;
|
|
222
|
+
|
|
223
|
+
federationConfigContent += '\n';
|
|
224
|
+
federationConfigContent += genFederationUrl(options);
|
|
225
|
+
federationConfigContent += '\n';
|
|
226
|
+
federationConfigContent += genConfigFunction(options);
|
|
227
|
+
federationConfigContent += '\n';
|
|
228
|
+
federationConfigContent += genFederationConfigFunction(options);
|
|
229
|
+
federationConfigContent += '\n';
|
|
230
|
+
|
|
231
|
+
federationConfigContent += `
|
|
232
|
+
export {
|
|
233
|
+
setFederationHostConfig,`;
|
|
234
|
+
if(options.jsviewMode == 'expose') {
|
|
235
|
+
federationConfigContent += `
|
|
236
|
+
jsviewLoaderUrl,`;
|
|
237
|
+
}
|
|
238
|
+
federationConfigContent += `
|
|
239
|
+
}`;
|
|
240
|
+
|
|
241
|
+
fs.writeFileSync(path.resolve(options.projectDir, federationConfigName),
|
|
242
|
+
federationConfigContent,
|
|
243
|
+
'utf-8');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async function updateViteConfigFile(options)
|
|
247
|
+
{
|
|
248
|
+
const viteConfigName = 'vite.config.ts';
|
|
249
|
+
Logger.Info('Updating ' + viteConfigName + ' ...');
|
|
250
|
+
|
|
251
|
+
const viteConfigPath = path.resolve(options.projectDir, viteConfigName);
|
|
252
|
+
var viteConfigContent = fs.readFileSync(viteConfigPath, 'utf-8');
|
|
253
|
+
|
|
254
|
+
const regex = /export default defineConfig(?!\(viteConfig\))/;
|
|
255
|
+
if(regex.test(viteConfigContent)) {
|
|
256
|
+
viteConfigContent = viteConfigContent.replace(regex, 'const viteConfig = ');
|
|
257
|
+
|
|
258
|
+
// 开头添加
|
|
259
|
+
if(options.mode == 'remote') {
|
|
260
|
+
viteConfigContent = "import { setFederationRemoteConfig } from './federation.remote.config'\n" + viteConfigContent;
|
|
261
|
+
} else if(options.mode == 'host') {
|
|
262
|
+
viteConfigContent = "import { setFederationHostConfig } from './federation.host.config'\n" + viteConfigContent;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// 末尾添加
|
|
266
|
+
viteConfigContent += '\n';
|
|
267
|
+
if(options.mode == 'remote') {
|
|
268
|
+
viteConfigContent += 'setFederationRemoteConfig(viteConfig)\n';
|
|
269
|
+
} else if(options.mode == 'host') {
|
|
270
|
+
viteConfigContent += 'setFederationHostConfig(viteConfig)\n';
|
|
271
|
+
}
|
|
272
|
+
viteConfigContent += '\n';
|
|
273
|
+
viteConfigContent += 'export default defineConfig(viteConfig)\n';
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
fs.writeFileSync(viteConfigPath, viteConfigContent, 'utf-8');
|
|
277
|
+
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function updateJsviewConfigFile(options)
|
|
281
|
+
{
|
|
282
|
+
const jsviewConfigName = path.basename(options.appJsviewConfigFile);
|
|
283
|
+
Logger.Info('Updating ' + jsviewConfigName + ' ...');
|
|
284
|
+
|
|
285
|
+
if(options.mode == 'host') {
|
|
286
|
+
if(options.jsviewMode == 'expose') {
|
|
287
|
+
var jsviewConfigContent = fs.readFileSync(options.appJsviewConfigFile, 'utf-8');
|
|
288
|
+
const regex = /jsviewLoaderUrl/;
|
|
289
|
+
if(regex.test(jsviewConfigContent) == false) {
|
|
290
|
+
jsviewConfigContent = "import { jsviewLoaderUrl } from '../../federation.host.config'\n" + jsviewConfigContent;
|
|
291
|
+
jsviewConfigContent = jsviewConfigContent.replace(/remoteLoader.*?,/, 'remoteLoader: jsviewLoaderUrl,');
|
|
292
|
+
}
|
|
293
|
+
fs.writeFileSync(options.appJsviewConfigFile, jsviewConfigContent, 'utf-8');
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function updateToFederationRemote(options)
|
|
299
|
+
{
|
|
300
|
+
createFederationRemoteConfigFile(options);
|
|
301
|
+
|
|
302
|
+
updateViteConfigFile(options);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function updateToFederationHost(options)
|
|
306
|
+
{
|
|
307
|
+
createFederationHostConfigFile(options);
|
|
308
|
+
|
|
309
|
+
updateViteConfigFile(options);
|
|
310
|
+
|
|
311
|
+
updateJsviewConfigFile(options);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
async function main(argv)
|
|
316
|
+
{
|
|
317
|
+
checkNodeVersion();
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
const options = getOptions();
|
|
321
|
+
|
|
322
|
+
if(argv.mode != 'remote' && argv.mode != 'host') {
|
|
323
|
+
Logger.ErrorAndExit('Invalid --mode, its value can only be "remote" or "host".');
|
|
324
|
+
}
|
|
325
|
+
options.mode = argv.mode;
|
|
326
|
+
|
|
327
|
+
if(argv.jsview != 'share' && argv.jsview != 'expose') {
|
|
328
|
+
Logger.ErrorAndExit('Invalid --jsview, its value can only be "share" or "expose".');
|
|
329
|
+
}
|
|
330
|
+
options.jsviewMode = argv.jsview;
|
|
331
|
+
|
|
332
|
+
if(argv.mode == 'host' && !argv.remoteDomain) {
|
|
333
|
+
Logger.ErrorAndExit('--remote-domain is required for host mode.');
|
|
334
|
+
}
|
|
335
|
+
options.remoteDomain = argv.remoteDomain;
|
|
336
|
+
|
|
337
|
+
Logger.Info();
|
|
338
|
+
Logger.Info('Updating to module federation ' + options.mode + ' ...');
|
|
339
|
+
await updateToFederationBase(options);
|
|
340
|
+
if(options.mode == 'remote') {
|
|
341
|
+
await updateToFederationRemote(options);
|
|
342
|
+
} else if(options.mode == 'host') {
|
|
343
|
+
await updateToFederationHost(options);
|
|
344
|
+
} else {
|
|
345
|
+
assert(0);
|
|
346
|
+
}
|
|
347
|
+
Logger.Info('Success to update project to module federation.');
|
|
348
|
+
Logger.Info('Module federation info:');
|
|
349
|
+
Logger.Info(' mode: ' + options.mode);
|
|
350
|
+
Logger.Info(' jsview: ' + options.jsviewMode);
|
|
351
|
+
if(options.mode == 'host') {
|
|
352
|
+
Logger.Info(' remote entry url: ' + options.remoteDomain + '/js/remoteEntry.js');
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
const requiredUsages = {
|
|
358
|
+
'--mode': 'Project mode. the value is "remote" or "host"',
|
|
359
|
+
'--jsview': 'jsview mode. the value is "share" or "expose"',
|
|
360
|
+
};
|
|
361
|
+
const optionalUsages = {
|
|
362
|
+
'--remote-domain': 'remote domain. Host use this domain to access remote module.',
|
|
363
|
+
};
|
|
364
|
+
const argv = parseArguments(requiredUsages, optionalUsages);
|
|
365
|
+
main(argv)
|
|
@@ -8,7 +8,7 @@ import url from 'node:url'
|
|
|
8
8
|
import {
|
|
9
9
|
checkNodeVersion,
|
|
10
10
|
getOptions,
|
|
11
|
-
|
|
11
|
+
loadPackageObject,
|
|
12
12
|
parseArguments,
|
|
13
13
|
Logger,
|
|
14
14
|
} from './jsview-common.mjs';
|
|
@@ -241,7 +241,7 @@ function makeJsvList(options)
|
|
|
241
241
|
|
|
242
242
|
async function makeJsvInfo(options)
|
|
243
243
|
{
|
|
244
|
-
const jsviewPkgJson =
|
|
244
|
+
const jsviewPkgJson = loadPackageObject(options.jsviewDir);
|
|
245
245
|
|
|
246
246
|
const jsviewVersionURL = url.pathToFileURL(options.jsviewDomRevisionFile);
|
|
247
247
|
const { default: jsviewTargetVersion } = await import(jsviewVersionURL);
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
cpSync,
|
|
10
10
|
execCommand,
|
|
11
11
|
getOptions,
|
|
12
|
-
|
|
12
|
+
loadPackageObject,
|
|
13
13
|
isSymlinkSync,
|
|
14
14
|
parseArguments,
|
|
15
15
|
symlinkSync,
|
|
@@ -33,7 +33,7 @@ function checkNpmCommand()
|
|
|
33
33
|
|
|
34
34
|
function checkNpmLinkForDebug(options, linkablePkgNames)
|
|
35
35
|
{
|
|
36
|
-
const pkgObj =
|
|
36
|
+
const pkgObj = loadPackageObject(options.projectDir);
|
|
37
37
|
|
|
38
38
|
// node 16 不会安装本地包的二次依赖, 需要手动安装。
|
|
39
39
|
let missingDepPkgs = '';
|
|
@@ -46,7 +46,7 @@ function checkNpmLinkForDebug(options, linkablePkgNames)
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const linkablePath = path.resolve(options.modulesDir, linkableName);
|
|
49
|
-
const linkablePkgObj =
|
|
49
|
+
const linkablePkgObj = loadPackageObject(linkablePath);
|
|
50
50
|
|
|
51
51
|
for (const dep in linkablePkgObj.dependencies ?? {}) {
|
|
52
52
|
const depPath = path.resolve(options.modulesDir, dep);
|
|
@@ -70,7 +70,7 @@ function checkNpmLinkForDebug(options, linkablePkgNames)
|
|
|
70
70
|
}
|
|
71
71
|
if (missingDepPkgs !== '') {
|
|
72
72
|
Logger.Info('Install missing dependencies')
|
|
73
|
-
execCommand('npm install --no-save ' + missingDepPkgs);
|
|
73
|
+
execCommand('npm install --force --no-save ' + missingDepPkgs);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// node 18 不会将本地依赖安装成链接,需要手动改成链接。
|
|
@@ -98,11 +98,11 @@ function checkPatches(options, pkgNeedPatch, skipCheckVersion)
|
|
|
98
98
|
for (const pkgName of pkgNeedPatch) {
|
|
99
99
|
if (skipCheckVersion !== true) {
|
|
100
100
|
const patchPkgDir = path.resolve(options.jsviewPatchModulesDir, pkgName);
|
|
101
|
-
const patchPkgObj =
|
|
101
|
+
const patchPkgObj = loadPackageObject(patchPkgDir);
|
|
102
102
|
Logger.Info(' ' + pkgName + ': ' + patchPkgObj.version);
|
|
103
103
|
|
|
104
104
|
const modulePkgDir = path.resolve(options.modulesDir, pkgName);
|
|
105
|
-
const modulePkgObj =
|
|
105
|
+
const modulePkgObj = loadPackageObject(modulePkgDir);
|
|
106
106
|
if (modulePkgObj.version != patchPkgObj.version) {
|
|
107
107
|
Logger.ErrorAndExit(pkgName + '@' + modulePkgObj.version + ' is not supported, required version is ' + patchPkgObj.version);
|
|
108
108
|
}
|
|
@@ -8,31 +8,43 @@ import {
|
|
|
8
8
|
parseArguments,
|
|
9
9
|
Logger,
|
|
10
10
|
execCommand,
|
|
11
|
+
printArgumentsUsages,
|
|
11
12
|
} from './jsview-common.mjs';
|
|
12
13
|
|
|
13
14
|
async function getExtraOptions(argv)
|
|
14
15
|
{
|
|
15
16
|
const options = getOptions(argv.framework);
|
|
17
|
+
options.argumentsLine = argv.argumentsLine;
|
|
18
|
+
options.help = argv.help;
|
|
16
19
|
options.jsviewCoreRevision = null;
|
|
17
20
|
options.jsviewEngineUrl = null;
|
|
18
21
|
options.entryUrl = argv.url;
|
|
19
22
|
|
|
20
23
|
let commandCount = 0;
|
|
24
|
+
commandCount += (argv.configApp ? 1 : 0);
|
|
21
25
|
commandCount += (argv.genKeypair ? 1 : 0);
|
|
22
26
|
commandCount += (argv.runonAndroid ? 1 : 0);
|
|
23
27
|
commandCount += (argv.buildMinmap ? 1 : 0);
|
|
24
28
|
commandCount += (argv.buildZip ? 1 : 0);
|
|
29
|
+
commandCount += (argv.moduleFederation ? 1 : 0);
|
|
25
30
|
if(commandCount == 0) {
|
|
31
|
+
if(argv.help || argv.h) {
|
|
32
|
+
printArgumentsUsages(requiredUsages, optionalUsages);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
const commandPrompt = [
|
|
27
37
|
' 1. runon-android',
|
|
28
|
-
' 2.
|
|
29
|
-
' 3.
|
|
30
|
-
' 4. build-
|
|
38
|
+
' 2. config-app',
|
|
39
|
+
' 3. gen-keypair',
|
|
40
|
+
' 4. build-minmap',
|
|
41
|
+
' 5. build-offline',
|
|
42
|
+
' 6. module-federation',
|
|
31
43
|
];
|
|
32
44
|
|
|
33
45
|
Logger.Info();
|
|
34
46
|
Logger.Info('Please choice a command:');
|
|
35
|
-
for(const key
|
|
47
|
+
for(const key of commandPrompt) {
|
|
36
48
|
Logger.Info(key);
|
|
37
49
|
}
|
|
38
50
|
const answer = askAndAnswer('Command Index: ');
|
|
@@ -41,22 +53,30 @@ async function getExtraOptions(argv)
|
|
|
41
53
|
options.runonAndroid = true;
|
|
42
54
|
break;
|
|
43
55
|
case '2':
|
|
44
|
-
options.
|
|
56
|
+
options.configApp = true;
|
|
45
57
|
break;
|
|
46
58
|
case '3':
|
|
47
|
-
options.
|
|
59
|
+
options.genKeypair = true;
|
|
48
60
|
break;
|
|
49
61
|
case '4':
|
|
62
|
+
options.buildMinmap = true;
|
|
63
|
+
break;
|
|
64
|
+
case '5':
|
|
50
65
|
options.buildZip = true;
|
|
51
66
|
break;
|
|
67
|
+
case '6':
|
|
68
|
+
options.moduleFederation = true;
|
|
69
|
+
break;
|
|
52
70
|
default:
|
|
53
71
|
Logger.ErrorAndExitNoException("Unknown input: " + answer);
|
|
54
72
|
}
|
|
55
73
|
} else if(commandCount == 1) {
|
|
56
74
|
options.runonAndroid = argv.runonAndroid;
|
|
75
|
+
options.configApp = argv.configApp;
|
|
57
76
|
options.genKeypair = argv.genKeypair;
|
|
58
77
|
options.buildMinmap = argv.buildMinmap;
|
|
59
78
|
options.buildZip = argv.buildZip;
|
|
79
|
+
options.moduleFederation = argv.moduleFederation;
|
|
60
80
|
} else if(commandCount > 1) {
|
|
61
81
|
Logger.ErrorAndExitNoException("Only one command can be executed.");
|
|
62
82
|
}
|
|
@@ -68,6 +88,17 @@ function doCommand(options) {
|
|
|
68
88
|
let command;
|
|
69
89
|
if(options.runonAndroid) {
|
|
70
90
|
command = 'node node_modules/@shijiu/jsview/tools/jsview-run-android.mjs --framework=vue';
|
|
91
|
+
} else if(options.configApp) {
|
|
92
|
+
const defaultConfig = 'JsViewDemo:JsView示例';
|
|
93
|
+
const config = (typeof(options.configApp) === 'string' ? options.configApp : defaultConfig);
|
|
94
|
+
if(config !== options.configApp) {
|
|
95
|
+
Logger.Warn('App config is not set, use default value: ' + defaultConfig);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const configArray = config.split(':');
|
|
99
|
+
const appName = configArray[0];
|
|
100
|
+
const appTitle = configArray[1] ?? appName;
|
|
101
|
+
command = 'node node_modules/@shijiu/jsview/tools/jsview-config-app.mjs --app-name=' + appName + ' --app-title=' + appTitle;
|
|
71
102
|
} else if(options.genKeypair) {
|
|
72
103
|
command = 'node node_modules/@shijiu/jsview/tools/jsview-generate-keypair.mjs';
|
|
73
104
|
} else if(options.buildMinmap) {
|
|
@@ -86,6 +117,11 @@ function doCommand(options) {
|
|
|
86
117
|
}
|
|
87
118
|
|
|
88
119
|
command = 'node node_modules/@shijiu/jsview/tools/jsview-build-zip.mjs --password=' + password;
|
|
120
|
+
} else if(options.moduleFederation) {
|
|
121
|
+
var argumentsLine = options.argumentsLine.replace(/ --framework.*? /, ' ');
|
|
122
|
+
argumentsLine = argumentsLine.replace(' -f ', ' ').replace(' --module-federation ', ' ');
|
|
123
|
+
|
|
124
|
+
command = 'node node_modules/@shijiu/jsview/tools/jsview-module-federation.mjs' + argumentsLine;
|
|
89
125
|
}
|
|
90
126
|
|
|
91
127
|
execCommand(command);
|
|
@@ -105,9 +141,11 @@ const requiredUsages = {
|
|
|
105
141
|
};
|
|
106
142
|
const optionalUsages = {
|
|
107
143
|
'-a | --runon-android': 'Run app on android devices.',
|
|
144
|
+
'-c | --config-app': 'Config app, like: -c or --config-app=[AppName:AppTitle].',
|
|
108
145
|
'-g | --gen-keypair': 'Generate sign keypair.',
|
|
109
146
|
'-m | --build-minmap': 'Build target with filter map, like: -m or --build-minmap=[filter].',
|
|
110
147
|
'-z | --build-zip': 'Build target to offline zip package, like: -z or --build-zip=[password].',
|
|
148
|
+
'-f | --module-federation': 'Make project to module federation, use --module-federation --help for details.',
|
|
111
149
|
};
|
|
112
|
-
const argv = parseArguments(requiredUsages, optionalUsages,
|
|
150
|
+
const argv = parseArguments(requiredUsages, optionalUsages, true, true, true);
|
|
113
151
|
main(argv)
|