@shijiu/jsview 2.1.367-test.0 → 2.1.435

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.
@@ -8,43 +8,31 @@ import {
8
8
  parseArguments,
9
9
  Logger,
10
10
  execCommand,
11
- printArgumentsUsages,
12
11
  } from './jsview-common.mjs';
13
12
 
14
13
  async function getExtraOptions(argv)
15
14
  {
16
15
  const options = getOptions(argv.framework);
17
- options.argumentsLine = argv.argumentsLine;
18
- options.help = argv.help;
19
16
  options.jsviewCoreRevision = null;
20
17
  options.jsviewEngineUrl = null;
21
18
  options.entryUrl = argv.url;
22
19
 
23
20
  let commandCount = 0;
24
- commandCount += (argv.configApp ? 1 : 0);
25
21
  commandCount += (argv.genKeypair ? 1 : 0);
26
22
  commandCount += (argv.runonAndroid ? 1 : 0);
27
23
  commandCount += (argv.buildMinmap ? 1 : 0);
28
24
  commandCount += (argv.buildZip ? 1 : 0);
29
- commandCount += (argv.moduleFederation ? 1 : 0);
30
25
  if(commandCount == 0) {
31
- if(argv.help || argv.h) {
32
- printArgumentsUsages(requiredUsages, optionalUsages);
33
- process.exit(0);
34
- }
35
-
36
26
  const commandPrompt = [
37
27
  ' 1. runon-android',
38
- ' 2. config-app',
39
- ' 3. gen-keypair',
40
- ' 4. build-minmap',
41
- ' 5. build-offline',
42
- ' 6. module-federation',
28
+ ' 2. gen-keypair',
29
+ ' 3. build-minmap',
30
+ ' 4. build-offline',
43
31
  ];
44
32
 
45
33
  Logger.Info();
46
34
  Logger.Info('Please choice a command:');
47
- for(const key of commandPrompt) {
35
+ for(const key in commandPrompt) {
48
36
  Logger.Info(key);
49
37
  }
50
38
  const answer = askAndAnswer('Command Index: ');
@@ -53,30 +41,22 @@ async function getExtraOptions(argv)
53
41
  options.runonAndroid = true;
54
42
  break;
55
43
  case '2':
56
- options.configApp = true;
57
- break;
58
- case '3':
59
44
  options.genKeypair = true;
60
45
  break;
61
- case '4':
46
+ case '3':
62
47
  options.buildMinmap = true;
63
48
  break;
64
- case '5':
49
+ case '4':
65
50
  options.buildZip = true;
66
51
  break;
67
- case '6':
68
- options.moduleFederation = true;
69
- break;
70
52
  default:
71
53
  Logger.ErrorAndExitNoException("Unknown input: " + answer);
72
54
  }
73
55
  } else if(commandCount == 1) {
74
56
  options.runonAndroid = argv.runonAndroid;
75
- options.configApp = argv.configApp;
76
57
  options.genKeypair = argv.genKeypair;
77
58
  options.buildMinmap = argv.buildMinmap;
78
59
  options.buildZip = argv.buildZip;
79
- options.moduleFederation = argv.moduleFederation;
80
60
  } else if(commandCount > 1) {
81
61
  Logger.ErrorAndExitNoException("Only one command can be executed.");
82
62
  }
@@ -88,17 +68,6 @@ function doCommand(options) {
88
68
  let command;
89
69
  if(options.runonAndroid) {
90
70
  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;
102
71
  } else if(options.genKeypair) {
103
72
  command = 'node node_modules/@shijiu/jsview/tools/jsview-generate-keypair.mjs';
104
73
  } else if(options.buildMinmap) {
@@ -117,11 +86,6 @@ function doCommand(options) {
117
86
  }
118
87
 
119
88
  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;
125
89
  }
126
90
 
127
91
  execCommand(command);
@@ -141,11 +105,9 @@ const requiredUsages = {
141
105
  };
142
106
  const optionalUsages = {
143
107
  '-a | --runon-android': 'Run app on android devices.',
144
- '-c | --config-app': 'Config app, like: -c or --config-app=[AppName:AppTitle].',
145
108
  '-g | --gen-keypair': 'Generate sign keypair.',
146
109
  '-m | --build-minmap': 'Build target with filter map, like: -m or --build-minmap=[filter].',
147
110
  '-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.',
149
111
  };
150
- const argv = parseArguments(requiredUsages, optionalUsages, true, true, true);
112
+ const argv = parseArguments(requiredUsages, optionalUsages, false);
151
113
  main(argv)
@@ -1,70 +0,0 @@
1
- diff --git a/node_modules/@originjs/vite-plugin-federation/dist/index.js b/node_modules/@originjs/vite-plugin-federation/dist/index.js
2
- index 980b8e3..48baae5 100644
3
- --- a/node_modules/@originjs/vite-plugin-federation/dist/index.js
4
- +++ b/node_modules/@originjs/vite-plugin-federation/dist/index.js
5
- @@ -970,8 +970,11 @@ function prodExposePlugin(options) {
6
- const filepathMap = /* @__PURE__ */ new Map();
7
- const getFilename = (name) => path.parse(path.parse(name).name).name;
8
- const cssBundlesMap = Object.keys(bundle).filter((name) => path.extname(name) === ".css").reduce((res, name) => {
9
- - const filename = getFilename(name);
10
- - res.set(filename, bundle[name]);
11
- +// JsView Removed >>>
12
- +// JsView js代码中已内嵌css
13
- + //const filename = getFilename(name);
14
- + //res.set(filename, bundle[name]);
15
- +// JsView Removed <<<
16
- return res;
17
- }, /* @__PURE__ */ new Map());
18
- remoteEntryChunk.code = remoteEntryChunk.code.replace(
19
- @@ -1481,6 +1484,16 @@ function federation(options) {
20
- }
21
- builderInfo.builder = "vite";
22
- builderInfo.assetsDir = ((_b = config == null ? void 0 : config.build) == null ? void 0 : _b.assetsDir) ?? "assets";
23
- +// JsView Added >>>
24
- +// 根据chunkFile路径设置assetsDir
25
- + let chunkFileNames = config.build.rollupOptions.output.chunkFileNames;
26
- + if (typeof (chunkFileNames) === 'function') {
27
- + chunkFileNames = chunkFileNames({name: 'test.js'})
28
- + }
29
- + const jsDir = path.dirname(chunkFileNames);
30
- + builderInfo.assetsDir = jsDir;
31
- + console.log("builderInfo",builderInfo);
32
- +// JsView Added <<<
33
- },
34
- configureServer(server) {
35
- var _a;
36
- diff --git a/node_modules/@originjs/vite-plugin-federation/dist/index.mjs b/node_modules/@originjs/vite-plugin-federation/dist/index.mjs
37
- index 57bae8f..9320e8d 100644
38
- --- a/node_modules/@originjs/vite-plugin-federation/dist/index.mjs
39
- +++ b/node_modules/@originjs/vite-plugin-federation/dist/index.mjs
40
- @@ -953,8 +953,11 @@ function prodExposePlugin(options) {
41
- const filepathMap = /* @__PURE__ */ new Map();
42
- const getFilename = (name) => parse(parse(name).name).name;
43
- const cssBundlesMap = Object.keys(bundle).filter((name) => extname(name) === ".css").reduce((res, name) => {
44
- - const filename = getFilename(name);
45
- - res.set(filename, bundle[name]);
46
- +// JsView Removed >>>
47
- +// JsView js代码中已内嵌css
48
- + //const filename = getFilename(name);
49
- + //res.set(filename, bundle[name]);
50
- +// JsView Removed <<<
51
- return res;
52
- }, /* @__PURE__ */ new Map());
53
- remoteEntryChunk.code = remoteEntryChunk.code.replace(
54
- @@ -1464,6 +1467,16 @@ function federation(options) {
55
- }
56
- builderInfo.builder = "vite";
57
- builderInfo.assetsDir = ((_b = config == null ? void 0 : config.build) == null ? void 0 : _b.assetsDir) ?? "assets";
58
- +// JsView Added >>>
59
- +// 根据chunkFile路径设置assetsDir
60
- + let chunkFileNames = config.build.rollupOptions.output.chunkFileNames;
61
- + if (typeof (chunkFileNames) === 'function') {
62
- + chunkFileNames = chunkFileNames({name: 'test.js'})
63
- + }
64
- + const jsDir = path.dirname(chunkFileNames);
65
- + builderInfo.assetsDir = jsDir;
66
- + console.log("builderInfo",builderInfo);
67
- +// JsView Added <<<
68
- },
69
- configureServer(server) {
70
- var _a;
@@ -1,47 +0,0 @@
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
- getOptions,
9
- parseArguments,
10
- Logger,
11
- } from './jsview-common.mjs';
12
-
13
- function setAppConfig(options)
14
- {
15
- let appConfigContent = fs.readFileSync(options.appConfigFile, 'utf8');
16
-
17
- appConfigContent = appConfigContent.replace(/AppName: .*,/, 'AppName: "' + options.appName + '",');
18
- appConfigContent = appConfigContent.replace(/AppTitle: .*,/, 'AppTitle: "' + options.appTitle + '",');
19
-
20
- console.log(appConfigContent)
21
-
22
- fs.writeFileSync(options.appConfigFile, appConfigContent, 'utf8');
23
- }
24
-
25
- async function main(argv) {
26
- checkNodeVersion();
27
-
28
- const options = getOptions();
29
-
30
- options.appName = argv.appName ?? 'JsViewDemo';
31
- options.appTitle = argv.appTitle ?? 'JsView Demo';
32
-
33
- Logger.Info();
34
- Logger.Info('Setting config to app.config.mjs ...');
35
- setAppConfig(options);
36
- Logger.Info('Set config finish.');
37
- }
38
-
39
-
40
- const requiredUsages = {
41
- };
42
- const optionalUsages = {
43
- '--app-name': 'App name. default is: "JsViewDemo".',
44
- '--app-title': 'App title. default is: "JsView Demo".',
45
- };
46
- const argv = parseArguments(requiredUsages, optionalUsages, false);
47
- main(argv)
@@ -1,354 +0,0 @@
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
- execCommand,
9
- getOptions,
10
- parseArguments,
11
- Logger,
12
- } from './jsview-common.mjs';
13
- import { assert } from 'node:console';
14
-
15
- async function updateToFederationBase(options)
16
- {
17
- Logger.Info('Updating package.json...');
18
-
19
- const devDeps = '@originjs/vite-plugin-federation@1.3.4'
20
- Logger.Info('Installing ' + devDeps + ' ...');
21
- execCommand('npm install --save-dev ' + devDeps);
22
- execCommand('npm ci');
23
- }
24
-
25
- function genFederationUrl(options)
26
- {
27
- var content = '';
28
-
29
- if(options.mode == 'host') {
30
- content = `
31
- const remoteDomain = '${options.remoteDomain}' // 替换成你的 Remote 端 base url 或 ip:port;
32
- const remoteEntryUrl = remoteDomain + '/js/remoteEntry.js'`;
33
-
34
- if(options.jsviewMode == 'expose') {
35
- content += `
36
- const jsviewLoaderUrl = remoteDomain + '/js/JsViewLoader.js'`
37
- }
38
- }
39
-
40
- return content;
41
- }
42
-
43
- function genConfigFunction(options)
44
- {
45
- var content = '';
46
-
47
- if(options.mode == 'remote') {
48
- content = `
49
- function getRemoteConfig() {
50
- const config = {
51
- name: 'remote-lib',
52
- filename: 'remoteEntry.js',
53
- // 需要暴露的模块
54
- exposes: {`;
55
-
56
- if(options.jsviewMode == 'expose') {
57
- content += `
58
- // 必须模块,JsView 编译需要
59
- './JsViewLoader': 'node_modules/@shijiu/jsview/loader/jsview-loader.js',
60
- './JsViewVue': '/node_modules/@shijiu/jsview-vue/index.js',`;
61
- content += '\n'
62
- }
63
-
64
- content += `
65
- // 自定义模块,根据需要自行配置
66
- './App.vue': './src/App.vue',
67
- },`;
68
- } else if(options.mode == 'host') {
69
- content = `
70
- function getHostConfig() {
71
- const config = {
72
- name: 'host-app',
73
- remotes: {
74
- 'RemoteEntry': remoteEntryUrl,
75
- },`;
76
- }
77
-
78
- content += `
79
- shared: {`;
80
- if(options.jsviewMode == 'shared') {
81
- content += `
82
- '@shijiu/jsview-vue': {},
83
- jsview: { packagePath: '@shijiu/jsview-vue' },`;
84
- }
85
- content += `
86
- vue: {},
87
- 'vue-router': {},
88
- },
89
- }
90
-
91
- return config
92
- }`;
93
-
94
- return content;
95
- }
96
-
97
- function genChunkFileNameFunction(options)
98
- {
99
- var content = '';
100
-
101
- if(options.mode == 'remote') {
102
- if(options.jsviewMode == 'expose') {
103
- content = `
104
- function getChunkFileName(chunkInfo) {
105
- if(chunkInfo.name == '__federation_expose_JsViewLoader') {
106
- return 'js/JsViewLoader.js'
107
- }
108
- return (process.env['JSVIEW_KEEP_CHUNKNAME'] ? 'js/[name].[hash].js' : 'js/chunk.jsv.[hash].js')
109
- }`;
110
- }
111
- }
112
-
113
- return content;
114
- }
115
-
116
- function genFederationConfigFunction(options)
117
- {
118
- var content = '';
119
- if(options.mode == 'remote') {
120
- content += `
121
- function setFederationRemoteConfig(config, federation) {`;
122
- } else if(options.mode == 'host') {
123
- content += `
124
- function setFederationHostConfig(config, federation) {`;
125
- }
126
-
127
- content += `
128
- config.build = (config.build || {})
129
- config.build.rollupOptions = (config.build.rollupOptions || {})
130
- config.build.rollupOptions.output = (config.build.rollupOptions.output || {})
131
- config.build.rollupOptions.output.manualChunks = (config.build.rollupOptions.output.manualChunks || {})
132
- config.build.rollupOptions.output.manualChunks["__federation_fn_import"] = ["__federation_fn_import"]`;
133
-
134
- if(options.mode == 'remote') {
135
- if(options.jsviewMode == 'expose') {
136
- content += `
137
- config.build.rollupOptions.output.chunkFileNames = getChunkFileName`;
138
- }
139
- }
140
-
141
- content += '\n'
142
- if(options.mode == 'remote') {
143
- content += `
144
- const federationConfig = getRemoteConfig()`;
145
- } else if(options.mode == 'host') {
146
- content += `
147
- const federationConfig = getHostConfig()`;
148
- }
149
-
150
- content += `
151
- config.plugins.push(federation(federationConfig))
152
-
153
- }`;
154
-
155
- return content;
156
- }
157
-
158
- function createFederationRemoteConfigFile(options)
159
- {
160
- const federationConfigName = 'federation.remote.config.ts';
161
- Logger.Info('Creating ' + federationConfigName + ' ...');
162
-
163
- var federationConfigContent = `
164
- import federation from '@originjs/vite-plugin-federation'`;
165
-
166
- federationConfigContent += '\n';
167
- federationConfigContent += genConfigFunction(options);
168
- federationConfigContent += '\n';
169
- federationConfigContent += genChunkFileNameFunction(options);
170
- federationConfigContent += '\n';
171
- federationConfigContent += genFederationConfigFunction(options);
172
- federationConfigContent += '\n';
173
-
174
- federationConfigContent += `
175
- export {
176
- setFederationRemoteConfig,
177
- }`;
178
-
179
- fs.writeFileSync(path.resolve(options.projectDir, federationConfigName),
180
- federationConfigContent,
181
- 'utf-8');
182
- }
183
-
184
- function createFederationHostConfigFile(options)
185
- {
186
- const federationConfigName = 'federation.host.config.ts';
187
- Logger.Info('Creating ' + federationConfigName + ' ...');
188
-
189
- var federationConfigContent = '';
190
-
191
- federationConfigContent += '\n';
192
- federationConfigContent += genFederationUrl(options);
193
- federationConfigContent += '\n';
194
- federationConfigContent += genConfigFunction(options);
195
- federationConfigContent += '\n';
196
- federationConfigContent += genFederationConfigFunction(options);
197
- federationConfigContent += '\n';
198
-
199
- federationConfigContent += `
200
- export {
201
- setFederationHostConfig,`;
202
- if(options.jsviewMode == 'expose') {
203
- federationConfigContent += `
204
- jsviewLoaderUrl,`;
205
- }
206
- federationConfigContent += `
207
- }`;
208
-
209
- fs.writeFileSync(path.resolve(options.projectDir, federationConfigName),
210
- federationConfigContent,
211
- 'utf-8');
212
- }
213
-
214
- async function updateViteConfigFile(options)
215
- {
216
- const viteConfigName = 'vite.config.ts';
217
- Logger.Info('Updating ' + viteConfigName + ' ...');
218
-
219
- const viteConfigPath = path.resolve(options.projectDir, viteConfigName);
220
- var viteConfigContent = fs.readFileSync(viteConfigPath, 'utf-8');
221
-
222
- const regex = /export default defineConfig(?!\(viteConfig\))/;
223
- if(regex.test(viteConfigContent)) {
224
- viteConfigContent = viteConfigContent.replace(regex, 'const viteConfig = ');
225
-
226
- // 开头添加
227
- viteConfigContent = "import federation from '@originjs/vite-plugin-federation'\n" + viteConfigContent;
228
- if(options.mode == 'remote') {
229
- viteConfigContent = "import { setFederationRemoteConfig } from './federation.remote.config'\n" + viteConfigContent;
230
- } else if(options.mode == 'host') {
231
- viteConfigContent = "import { setFederationHostConfig } from './federation.host.config'\n" + viteConfigContent;
232
- }
233
-
234
- // 末尾添加
235
- viteConfigContent += '\n';
236
- if(options.mode == 'remote') {
237
- viteConfigContent += 'setFederationRemoteConfig(viteConfig, federation)\n';
238
- } else if(options.mode == 'host') {
239
- viteConfigContent += 'setFederationHostConfig(viteConfig, federation)\n';
240
- }
241
- viteConfigContent += '\n';
242
- viteConfigContent += 'export default defineConfig(viteConfig)\n';
243
- }
244
-
245
- fs.writeFileSync(viteConfigPath, viteConfigContent, 'utf-8');
246
-
247
- }
248
-
249
- function updateJsviewConfigFile(options)
250
- {
251
- const jsviewConfigName = path.basename(options.appJsviewConfigFile);
252
- Logger.Info('Updating ' + jsviewConfigName + ' ...');
253
-
254
- if(options.mode == 'host') {
255
- if(options.jsviewMode == 'expose') {
256
- var jsviewConfigContent = fs.readFileSync(options.appJsviewConfigFile, 'utf-8');
257
- const regex = /jsviewLoaderUrl/;
258
- if(regex.test(jsviewConfigContent) == false) {
259
- jsviewConfigContent = "import { jsviewLoaderUrl } from '../../federation.host.config'\n" + jsviewConfigContent;
260
- jsviewConfigContent = jsviewConfigContent.replace(/remoteLoader.*?,/, 'remoteLoader: jsviewLoaderUrl,');
261
- }
262
- fs.writeFileSync(options.appJsviewConfigFile, jsviewConfigContent, 'utf-8');
263
- }
264
- }
265
- }
266
-
267
- function updateTsConfigFile(options)
268
- {
269
- const tsConfigName = 'tsconfig.json';
270
- Logger.Info('Updating ' + tsConfigName + ' ...');
271
-
272
- if(options.mode == 'host') {
273
- if(options.jsviewMode == 'expose') {
274
- const tsConfigPath = path.resolve(options.projectDir, tsConfigName);
275
- var tsConfigContent = fs.readFileSync(tsConfigPath, 'utf-8');
276
- const regex = /RemoteEntry/;
277
- if(regex.test(tsConfigContent) == false) {
278
- tsConfigContent = tsConfigContent.replace(/"jsview"/, '"RemoteEntry/JsViewVue": [ "./node_modules/@shijiu/jsview-vue" ],\n $&');
279
- }
280
- fs.writeFileSync(tsConfigPath, tsConfigContent, 'utf-8');
281
- }
282
- }
283
- }
284
-
285
- function updateToFederationRemote(options)
286
- {
287
- createFederationRemoteConfigFile(options);
288
-
289
- updateViteConfigFile(options);
290
- }
291
-
292
- function updateToFederationHost(options)
293
- {
294
- createFederationHostConfigFile(options);
295
-
296
- updateViteConfigFile(options);
297
-
298
- updateJsviewConfigFile(options);
299
-
300
- updateTsConfigFile(options);
301
- }
302
-
303
-
304
- async function main(argv)
305
- {
306
- checkNodeVersion();
307
-
308
-
309
- const options = getOptions();
310
-
311
- if(argv.mode != 'remote' && argv.mode != 'host') {
312
- Logger.ErrorAndExit('Invalid --mode, its value can only be "remote" or "host".');
313
- }
314
- options.mode = argv.mode;
315
-
316
- if(argv.jsview != 'shared' && argv.jsview != 'expose') {
317
- Logger.ErrorAndExit('Invalid --jsview, its value can only be "shared" or "expose".');
318
- }
319
- options.jsviewMode = argv.jsview;
320
-
321
- if(argv.mode == 'host' && !argv.remoteDomain) {
322
- Logger.ErrorAndExit('--remote-domain is required for host mode.');
323
- }
324
- options.remoteDomain = argv.remoteDomain;
325
-
326
- Logger.Info();
327
- Logger.Info('Updating to module federation ' + options.mode + ' ...');
328
- await updateToFederationBase(options);
329
- if(options.mode == 'remote') {
330
- await updateToFederationRemote(options);
331
- } else if(options.mode == 'host') {
332
- await updateToFederationHost(options);
333
- } else {
334
- assert(0);
335
- }
336
- Logger.Info('Success to update project to module federation.');
337
- Logger.Info('Module federation info:');
338
- Logger.Info(' Mode: ' + options.mode);
339
- Logger.Info(' JsView: ' + options.jsviewMode);
340
- if(options.mode == 'host') {
341
- Logger.Info(' remote entry url: ' + options.remoteDomain + '/js/remoteEntry.js');
342
- }
343
- }
344
-
345
-
346
- const requiredUsages = {
347
- '--mode': 'Project mode. the value is "remote" or "host"',
348
- '--jsview': 'jsview mode. the value is "shared" or "expose"',
349
- };
350
- const optionalUsages = {
351
- '--remote-domain': 'remote domain. Host use this domain to access remote module.',
352
- };
353
- const argv = parseArguments(requiredUsages, optionalUsages);
354
- main(argv)