@shijiu/jsview 2.1.428 → 2.1.448-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-engine-js-browser.min.js +1 -1
- package/dom/target_core_revision.mjs +2 -2
- package/package.json +1 -1
- package/patches/node_modules/@originjs/vite-plugin-federation/1.3.4/@originjs+vite-plugin-federation+1.3.4.patch +70 -0
- package/tools/jsview-common.mjs +78 -8
- package/tools/jsview-config-app.mjs +47 -0
- package/tools/jsview-module-federation.mjs +354 -0
- package/tools/jsview-post-build.mjs +7 -4
- package/tools/jsview-post-install.mjs +88 -6
- package/tools/jsview-run-tool.mjs +45 -7
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const TargetRevision = {
|
|
6
|
-
"CoreRevision":
|
|
7
|
-
"CoreRevisionAndBranch": "
|
|
6
|
+
"CoreRevision": 1021746,
|
|
7
|
+
"CoreRevisionAndBranch": "1021746",
|
|
8
8
|
"JseRevision": "1.0.950",
|
|
9
9
|
"JseUrl":
|
|
10
10
|
"http://cdn.release.qcast.cn/forge_js/master/JsViewES6_js2c_r950.jsv.33b8f0af.js",
|
package/package.json
CHANGED
|
@@ -0,0 +1,70 @@
|
|
|
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;
|
package/tools/jsview-common.mjs
CHANGED
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
|
|
4
4
|
import childProcess from 'node:child_process';
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
+
import https from 'node:https';
|
|
6
7
|
import os from 'node:os';
|
|
7
8
|
import path from 'node:path';
|
|
8
9
|
import { Logger } from "./jsview-logger.js";
|
|
9
10
|
|
|
10
11
|
function printArgumentsUsages(requiredUsages, optionalUsages, helpUsages)
|
|
11
12
|
{
|
|
13
|
+
if(!helpUsages) {
|
|
14
|
+
helpUsages = {
|
|
15
|
+
'-h | --help': 'Print help usages.',
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
let maxLength = 0;
|
|
13
20
|
for (const usage in requiredUsages) {
|
|
14
21
|
maxLength = (maxLength > usage.length ? maxLength : usage.length);
|
|
@@ -41,7 +48,9 @@ function printArgumentsUsages(requiredUsages, optionalUsages, helpUsages)
|
|
|
41
48
|
|
|
42
49
|
function parseArguments(requiredUsages = {},
|
|
43
50
|
optionalUsages = {},
|
|
44
|
-
withoutUnparsed = true
|
|
51
|
+
withoutUnparsed = true,
|
|
52
|
+
ignoreUnknown = false,
|
|
53
|
+
ignoreHelpUsage = false)
|
|
45
54
|
{
|
|
46
55
|
const keySeparator = '|';
|
|
47
56
|
const formatKey = (key) => {
|
|
@@ -110,7 +119,8 @@ function parseArguments(requiredUsages = {},
|
|
|
110
119
|
}
|
|
111
120
|
|
|
112
121
|
let options = {
|
|
113
|
-
unparsed: []
|
|
122
|
+
unparsed: [],
|
|
123
|
+
argumentsLine: '',
|
|
114
124
|
};
|
|
115
125
|
|
|
116
126
|
// arg0: node
|
|
@@ -130,7 +140,8 @@ function parseArguments(requiredUsages = {},
|
|
|
130
140
|
}
|
|
131
141
|
}
|
|
132
142
|
|
|
133
|
-
if (
|
|
143
|
+
if (ignoreUnknown == false
|
|
144
|
+
&& hasKey(helpUsages, key) == false
|
|
134
145
|
&& hasKey(requiredUsages, key) == false
|
|
135
146
|
&& hasKey(optionalUsages, key) == false) {
|
|
136
147
|
Logger.ErrorAndExitNoException('Failed to parse usage: ' + argu);
|
|
@@ -139,11 +150,13 @@ function parseArguments(requiredUsages = {},
|
|
|
139
150
|
let formattedKey = formatKey(key);
|
|
140
151
|
let formattedValue = formatValue(value);
|
|
141
152
|
options[formattedKey] = formattedValue;
|
|
153
|
+
|
|
154
|
+
options.argumentsLine += ' ' + argu;
|
|
142
155
|
}
|
|
143
156
|
|
|
144
157
|
for (const checker in helpUsages) {
|
|
145
158
|
const aliasedOptions = checkAliases(checker, options);
|
|
146
|
-
if (aliasedOptions) {
|
|
159
|
+
if (aliasedOptions && ignoreHelpUsage == false) {
|
|
147
160
|
printArgumentsUsages(requiredUsages, optionalUsages, helpUsages);
|
|
148
161
|
process.exit(0);
|
|
149
162
|
}
|
|
@@ -208,6 +221,8 @@ function getOptions(framework)
|
|
|
208
221
|
}
|
|
209
222
|
|
|
210
223
|
options.appConfigDir = path.resolve(options.projectDir, 'src', 'appConfig');
|
|
224
|
+
options.appConfigFile = path.resolve(options.appConfigDir, 'app.config.mjs');
|
|
225
|
+
options.appJsviewConfigFile = path.resolve(options.appConfigDir, 'jsview.config.mjs');
|
|
211
226
|
options.appPrivKeyFile = path.resolve(options.appConfigDir, 'app_sign_private_key.crt');
|
|
212
227
|
options.appPubKeyFile = path.resolve(options.appConfigDir, 'app_sign_public_key.pem');
|
|
213
228
|
|
|
@@ -231,12 +246,13 @@ function getOptions(framework)
|
|
|
231
246
|
|
|
232
247
|
const cacheName = (framework == 'vue' ? '.vite' : '.cache');
|
|
233
248
|
options.cacheDir = path.resolve(options.modulesDir, cacheName);
|
|
234
|
-
options.
|
|
249
|
+
options.cacheJsViewDir = path.resolve(options.cacheDir, 'jsview');
|
|
250
|
+
options.baseUrlFile = path.resolve(options.cacheJsViewDir, 'network.mjs');
|
|
235
251
|
|
|
236
252
|
return options;
|
|
237
253
|
}
|
|
238
254
|
|
|
239
|
-
function
|
|
255
|
+
function loadPackageObject(modulePath)
|
|
240
256
|
{
|
|
241
257
|
const pkgFullFile = path.resolve(modulePath, 'package.json');
|
|
242
258
|
if (!fs.existsSync(pkgFullFile)) {
|
|
@@ -248,6 +264,16 @@ function getPackageObject(modulePath)
|
|
|
248
264
|
return pkgObj;
|
|
249
265
|
}
|
|
250
266
|
|
|
267
|
+
function savePackageObject(modulePath, pkgObj)
|
|
268
|
+
{
|
|
269
|
+
const pkgFullFile = path.resolve(modulePath, 'package.json');
|
|
270
|
+
const pkgContent = JSON.stringify(pkgObj, null, 2);
|
|
271
|
+
|
|
272
|
+
fs.writeFileSync(pkgFullFile, pkgContent, 'utf8');
|
|
273
|
+
|
|
274
|
+
return pkgObj;
|
|
275
|
+
}
|
|
276
|
+
|
|
251
277
|
function cpSync(workDir, srcPath, destPath, ignore=[])
|
|
252
278
|
{
|
|
253
279
|
const exists = fs.existsSync(srcPath);
|
|
@@ -395,6 +421,46 @@ function convertHomeDirectory(filePath)
|
|
|
395
421
|
return filePath.replace(/^~\//, homeDir + '/');
|
|
396
422
|
}
|
|
397
423
|
|
|
424
|
+
function downloadFileAsync(url, localPath, workDir)
|
|
425
|
+
{
|
|
426
|
+
const relativePath = path.relative(workDir, localPath);
|
|
427
|
+
Logger.Info('Downloading ' + url + ' => ' + relativePath);
|
|
428
|
+
|
|
429
|
+
const file = fs.createWriteStream(localPath);
|
|
430
|
+
|
|
431
|
+
return new Promise((resolve, reject) => {
|
|
432
|
+
const request = https.get(url, (response) => {
|
|
433
|
+
response.pipe(file);
|
|
434
|
+
|
|
435
|
+
file.on('finish', () => {
|
|
436
|
+
file.close(() => {
|
|
437
|
+
Logger.Info('Success to download file to ' + relativePath);
|
|
438
|
+
resolve();
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
request.on('error', (err) => {
|
|
444
|
+
fs.unlink(localPath, () => {
|
|
445
|
+
Logger.ErrorAndExit('Failed to download file from ' + url);
|
|
446
|
+
reject(err);
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function unzipFile(zipFilePath, toDir, workDir)
|
|
453
|
+
{
|
|
454
|
+
var relativePath = path.relative(workDir, toDir);
|
|
455
|
+
if(!relativePath) {
|
|
456
|
+
relativePath = './'
|
|
457
|
+
}
|
|
458
|
+
Logger.Info('Unzipping ' + zipFilePath + ' => ' + relativePath);
|
|
459
|
+
|
|
460
|
+
const cmdline = 'npx -y extract-zip ' + zipFilePath + ' ' + toDir;
|
|
461
|
+
execCommand(cmdline);
|
|
462
|
+
}
|
|
463
|
+
|
|
398
464
|
function getNpmRegistry()
|
|
399
465
|
{
|
|
400
466
|
return 'https://nexus.cluster.qcast.cn/repository/npm-public';
|
|
@@ -405,15 +471,19 @@ export {
|
|
|
405
471
|
checkNodeVersion,
|
|
406
472
|
convertHomeDirectory,
|
|
407
473
|
cpSync,
|
|
474
|
+
downloadFileAsync,
|
|
408
475
|
execCommand,
|
|
409
476
|
getOptions,
|
|
410
|
-
getPackageObject,
|
|
411
477
|
getNpmRegistry,
|
|
412
478
|
isSymlinkSync,
|
|
479
|
+
loadPackageObject,
|
|
413
480
|
makeZip,
|
|
414
481
|
parseArguments,
|
|
482
|
+
printArgumentsUsages,
|
|
415
483
|
readJsonFile,
|
|
416
484
|
rmSync,
|
|
485
|
+
savePackageObject,
|
|
417
486
|
symlinkSync,
|
|
487
|
+
unzipFile,
|
|
418
488
|
Logger,
|
|
419
|
-
}
|
|
489
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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)
|
|
@@ -0,0 +1,354 @@
|
|
|
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)
|