@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.
@@ -8,7 +8,7 @@ import url from 'node:url'
8
8
  import {
9
9
  checkNodeVersion,
10
10
  getOptions,
11
- getPackageObject,
11
+ loadPackageObject,
12
12
  parseArguments,
13
13
  Logger,
14
14
  } from './jsview-common.mjs';
@@ -183,8 +183,8 @@ function makeMainJsvMjs(options, framework)
183
183
 
184
184
  const sourceContent = fs.readFileSync(jsEntryFilePath, 'utf8');
185
185
  const hash = sourceContent.replace(/\n/g, '').replace(/.*\/\*jsvmd5:([a-fA-F0-9]{8})[a-fA-F0-9]*\*\/.*/, '$1');
186
- const newEntryFileName = `main.jsv.${hash}.mjs`;
187
- const newEntryFilePath = path.resolve(path.dirname(jsEntryFilePath), `main.jsv.${hash}.mjs`);
186
+ const newEntryFileName = `main.jsv.${hash}.js`;
187
+ const newEntryFilePath = path.resolve(path.dirname(jsEntryFilePath), newEntryFileName);
188
188
  Logger.Info(' -> ' + path.relative(options.projectDir, newEntryFilePath));
189
189
  fs.renameSync(jsEntryFilePath, newEntryFilePath);
190
190
 
@@ -192,6 +192,9 @@ function makeMainJsvMjs(options, framework)
192
192
  indexContent = indexContent.replace(path.basename(jsEntryFilePath), newEntryFileName);
193
193
  Logger.Info(' -> ' + path.relative(options.projectDir, options.distJsIndexFile));
194
194
  fs.writeFileSync(options.distJsIndexFile, indexContent, 'utf8');
195
+
196
+ const moduleEntryFilePath = newEntryFilePath.replace(/\.js$/, '.mjs');
197
+ fs.copyFileSync(newEntryFilePath, moduleEntryFilePath);
195
198
  }
196
199
 
197
200
  function makeDebugMap(options, framework)
@@ -249,7 +252,7 @@ function makeJsvList(options)
249
252
 
250
253
  async function makeJsvInfo(options)
251
254
  {
252
- const jsviewPkgJson = getPackageObject(options.jsviewDir);
255
+ const jsviewPkgJson = loadPackageObject(options.jsviewDir);
253
256
 
254
257
  const jsviewVersionURL = url.pathToFileURL(options.jsviewDomRevisionFile);
255
258
  const { default: jsviewTargetVersion } = await import(jsviewVersionURL);
@@ -9,7 +9,7 @@ import {
9
9
  cpSync,
10
10
  execCommand,
11
11
  getOptions,
12
- getPackageObject,
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 = getPackageObject(options.projectDir);
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 = getPackageObject(linkablePath);
49
+ const linkablePkgObj = loadPackageObject(linkablePath);
50
50
 
51
51
  for (const dep in linkablePkgObj.dependencies ?? {}) {
52
52
  const depPath = path.resolve(options.modulesDir, dep);
@@ -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 = getPackageObject(patchPkgDir);
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 = getPackageObject(modulePkgDir);
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
  }
@@ -114,7 +114,7 @@ function checkPatches(options, pkgNeedPatch, skipCheckVersion)
114
114
 
115
115
  function installPatches(options, pkgNeedPatch)
116
116
  {
117
- Logger.Info('Patching JsView:');
117
+ Logger.Info('Stage 1: Installing patches for JsView:');
118
118
  for (const pkgName of pkgNeedPatch) {
119
119
  const patchSrc = path.resolve(options.jsviewPatchModulesDir, pkgName);
120
120
  const patchDest = path.resolve(options.modulesDir, pkgName);
@@ -126,6 +126,86 @@ function installPatches(options, pkgNeedPatch)
126
126
  rmSync(options.projectDir, options.cacheDir);
127
127
  }
128
128
 
129
+ function getPatchListRecursive(patchDir)
130
+ {
131
+ var patchList = [];
132
+
133
+ const pkgNameArray = fs.readdirSync(patchDir);
134
+ for (const pkgName of pkgNameArray) {
135
+ const pkgFullPath = path.resolve(patchDir, pkgName);
136
+
137
+ const isDirectory = fs.statSync(pkgFullPath).isDirectory();
138
+ if(isDirectory) {
139
+ const subPatchList = getPatchListRecursive(pkgFullPath);
140
+ patchList = [...patchList, ...subPatchList];
141
+ } else {
142
+ if(pkgFullPath.endsWith('.patch') == false) {
143
+ continue;
144
+ }
145
+
146
+ patchList.push(pkgFullPath);
147
+ }
148
+ }
149
+
150
+ return patchList;
151
+ }
152
+
153
+ function autoPatchPackages(options)
154
+ {
155
+ Logger.Info('Stage 2: Auto patching packages:');
156
+
157
+ const patchCacheDir = path.resolve(options.cacheJsViewDir, 'patches');
158
+ fs.mkdirSync(patchCacheDir, { recursive: true, force: true });
159
+
160
+ const patchInfo = {};
161
+ const patchList = getPatchListRecursive(options.jsviewPatchModulesDir);
162
+ for (const patchFullPath of patchList) {
163
+ const patchRelativePath = path.relative(options.jsviewPatchModulesDir, patchFullPath);
164
+ const patchNameAndVersion = path.dirname(patchRelativePath);
165
+ const patchVersion = path.basename(patchNameAndVersion);
166
+ const patchName = path.dirname(patchNameAndVersion);
167
+
168
+ if(!patchInfo[patchName]) {
169
+ patchInfo[patchName] = [];
170
+ }
171
+ patchInfo[patchName].push(patchVersion);
172
+ }
173
+
174
+ for(const [patchName, patchVersions] of Object.entries(patchInfo)) {
175
+ const pkgFullDir = path.resolve(options.modulesDir, patchName);
176
+ const pkgJsonFullPath = path.resolve(pkgFullDir, 'package.json');
177
+ if(fs.existsSync(pkgJsonFullPath) == false) {
178
+ continue;
179
+ }
180
+
181
+ const pkgObj = loadPackageObject(pkgFullDir);
182
+ const pkgVersion = pkgObj.version;
183
+ if(patchVersions.includes(pkgVersion) == false) {
184
+ Logger.Warn(' Patch file for ' + patchName + '@' + pkgVersion + ' is not found.');
185
+ continue;
186
+ }
187
+
188
+ const patchFullDir = path.resolve(options.jsviewPatchModulesDir, patchName, pkgVersion);
189
+ const patchFiles = fs.readdirSync(patchFullDir);
190
+ for (const file of patchFiles) {
191
+ if(file.endsWith('.patch') == false) {
192
+ continue;
193
+ }
194
+
195
+ const copyFromPath = path.resolve(patchFullDir, file);
196
+ const copyToPath = path.resolve(patchCacheDir, file);
197
+ cpSync(options.projectDir, copyFromPath, copyToPath);
198
+ }
199
+ }
200
+
201
+ const hasPatches = fs.readdirSync(patchCacheDir);
202
+ if(hasPatches && hasPatches.length > 0) {
203
+ execCommand('npx patch-package --patch-dir ' + path.relative(options.projectDir, patchCacheDir));
204
+ } else {
205
+ Logger.Info(' No patch files found.');
206
+ }
207
+ }
208
+
129
209
  async function printRevision(options)
130
210
  {
131
211
  const jsviewVersionURL = url.pathToFileURL(options.jsviewDomRevisionFile);
@@ -188,6 +268,8 @@ function doPostInstall(framework, pkgNeedPatch, skipCheckVersion)
188
268
 
189
269
  installPatches(options, pkgNeedPatch);
190
270
 
271
+ autoPatchPackages(options);
272
+
191
273
  printRevision(options);
192
274
  }
193
275
 
@@ -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. gen-keypair',
29
- ' 3. build-minmap',
30
- ' 4. build-offline',
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 in commandPrompt) {
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.genKeypair = true;
56
+ options.configApp = true;
45
57
  break;
46
58
  case '3':
47
- options.buildMinmap = true;
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, false);
150
+ const argv = parseArguments(requiredUsages, optionalUsages, true, true, true);
113
151
  main(argv)