@shijiu/jsview 2.2.426-test.0 → 2.3.151-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.
@@ -240,6 +240,7 @@ function getOptions(framework)
240
240
  }
241
241
  }
242
242
  }
243
+ options.distJsvConfigFile = path.resolve(options.distDir, 'jsv-config.json');
243
244
  options.distJsvListFile = path.resolve(options.distDir, 'jsv-list.json');
244
245
  options.distJsvInfoFile = path.resolve(options.distDir, 'jsv-info.json');
245
246
  options.distJsIndexFile = path.resolve(options.distDir, 'index.html');
@@ -95,6 +95,7 @@ function updateOptions(options)
95
95
  options.appPrivKey = privKey;
96
96
  options.appPubKey = pubKey;
97
97
  options.appEntryMd5 = appEntryMd5;
98
+ options.appEntryFileName = `main.jsv.${options.appEntryMd5.slice(0, 8)}.js`;
98
99
  }
99
100
 
100
101
  function getOtherSignVerifyKeys(options)
@@ -156,7 +157,7 @@ async function prepareMainAppData(options)
156
157
  const encryptBase64 = getEncryptBase64(options.appPrivKey, options.appPubKey, options.appEntryMd5);
157
158
 
158
159
  // 获取 预加载的文件名
159
- const filterKeys = [
160
+ const chunkFilterKeys = [
160
161
  'domNativePath',
161
162
  'NativePlatformDomBridge',
162
163
  'ForgeExtension',
@@ -165,7 +166,7 @@ async function prepareMainAppData(options)
165
166
  'mount("#app")',
166
167
  ];
167
168
  const preloadChunks = [];
168
- const jsFileNames = fs.readdirSync(options.distJsDir);
169
+ let jsFileNames = fs.readdirSync(options.distJsDir);
169
170
  for(const fileName of jsFileNames) {
170
171
  if (!fileName.startsWith('chunk.jsv') || !fileName.endsWith('.js')) {
171
172
  continue;
@@ -173,17 +174,32 @@ async function prepareMainAppData(options)
173
174
 
174
175
  const filePath = path.resolve(options.distJsDir, fileName);
175
176
  const sourceContent = fs.readFileSync(filePath, 'utf8');
176
- if(filterKeys.some(it => sourceContent.includes(it)) == false) {
177
+ if(chunkFilterKeys.some(it => sourceContent.includes(it)) == false) {
177
178
  continue;
178
179
  }
179
180
 
180
181
  preloadChunks.push(fileName);
181
182
  }
182
183
 
184
+ const preloadBurdenResources = [];
185
+ const bunderBaseUrl = process.env['JSVIEW_BURDEN_LOCAL'] ? '' : getBunderBaseUrl();
186
+ const burdenFilePathList = getBurdenFilePathList(options);
187
+ for(const filePath of burdenFilePathList) {
188
+ let fileName = path.basename(filePath);
189
+ if(process.env['JSVIEW_BURDEN_LOCAL']) {
190
+ fileName = path.relative(options.distJsDir, filePath);
191
+ }
192
+ preloadBurdenResources.push(fileName);
193
+ }
194
+
183
195
  // 组装AppData
184
196
  appConfig.PublicKeys = publicKeys; // 使用签名数组,支持后续追加签名
185
197
  appConfig.EncryptCodes = [encryptBase64]; // 同样使用数组,支持后续追加
186
198
  appConfig.PreloadChunks = preloadChunks;
199
+ appConfig.PreloadBurdens = {
200
+ BaseUrl: bunderBaseUrl,
201
+ Resources: preloadBurdenResources,
202
+ };
187
203
 
188
204
  return JSON.stringify(appConfig);
189
205
  }
@@ -254,10 +270,10 @@ async function signApp(options)
254
270
  }
255
271
  }
256
272
 
257
- function redirectBurdenResource(options)
273
+ function getBunderBaseUrl()
258
274
  {
259
275
  if(process.env['JSVIEW_BURDEN_LOCAL']) {
260
- return;
276
+ return undefined;
261
277
  }
262
278
 
263
279
  let burdenBaseUrl = process.env['JSVIEW_BURDEN_BASEURL'];
@@ -268,27 +284,47 @@ function redirectBurdenResource(options)
268
284
  burdenBaseUrl += '/';
269
285
  }
270
286
 
287
+ return burdenBaseUrl;
288
+ }
289
+
290
+ function getBurdenFilePathList(options)
291
+ {
292
+ const burdenFilterSuffixes = [
293
+ '.wasm',
294
+ '.ttf',
295
+ ];
271
296
  const burdenFilePathList = [];
272
297
 
273
298
  const assetFileNames = fs.readdirSync(options.distAssetsDir);
274
299
  for(const fileName of assetFileNames) {
275
- if (!fileName.endsWith('.ttf')) {
300
+ const fileExt = path.extname(fileName);
301
+ if (!burdenFilterSuffixes.includes(fileExt)) {
276
302
  continue;
277
303
  }
278
304
  burdenFilePathList.push(path.resolve(options.distAssetsDir, fileName));
279
305
  }
280
306
  const jsFileNames = fs.readdirSync(options.distJsDir);
281
307
  for(const fileName of jsFileNames) {
282
- if (!fileName.endsWith('.wasm')) {
308
+ const fileExt = path.extname(fileName);
309
+ if (!burdenFilterSuffixes.includes(fileExt)) {
283
310
  continue;
284
311
  }
285
312
  burdenFilePathList.push(path.resolve(options.distJsDir, fileName));
286
313
  }
287
- for(const filePath of burdenFilePathList) {
288
- fs.rmSync(filePath);
289
- Logger.Info('Config burden file: ' + path.relative(options.projectDir, filePath));
314
+
315
+ return burdenFilePathList;
316
+ }
317
+
318
+ function redirectBurdenResource(options)
319
+ {
320
+ let burdenBaseUrl = getBunderBaseUrl();
321
+ if(!burdenBaseUrl) { // use local
322
+ return;
290
323
  }
324
+
325
+ const burdenFilePathList = getBurdenFilePathList(options);
291
326
 
327
+ const jsFileNames = fs.readdirSync(options.distJsDir);
292
328
  for(const fileName of jsFileNames) {
293
329
  if (!fileName.endsWith('.js') && !fileName.endsWith('.js.map')) {
294
330
  continue;
@@ -298,7 +334,8 @@ function redirectBurdenResource(options)
298
334
  let sourceContent = fs.readFileSync(filePath, 'utf8');
299
335
 
300
336
  for(const burdenFilePath of burdenFilePathList) {
301
- const relativeBurdenFilePath = path.relative(options.distJsDir, burdenFilePath);
337
+ let relativeBurdenFilePath = path.relative(options.distJsDir, burdenFilePath);
338
+ relativeBurdenFilePath = relativeBurdenFilePath.replaceAll('\\', '/'); // 更正windows分隔符
302
339
  if(!sourceContent.includes(relativeBurdenFilePath)) {
303
340
  continue;
304
341
  }
@@ -306,13 +343,27 @@ function redirectBurdenResource(options)
306
343
  const burdenFileUrl = burdenBaseUrl + path.basename(burdenFilePath);
307
344
 
308
345
  sourceContent = sourceContent.replaceAll(relativeBurdenFilePath, burdenFileUrl);
309
- Logger.Info('Burdenting ' + path.relative(options.projectDir, filePath) + ' for [' + relativeBurdenFilePath + ']');
346
+ Logger.Info('Burdening ' + path.relative(options.projectDir, filePath) + ' for [' + relativeBurdenFilePath + ']');
310
347
  }
311
348
 
312
349
  fs.writeFileSync(filePath, sourceContent, 'utf8');
313
350
  };
314
351
  }
315
352
 
353
+ function cleanupBurdenResource(options)
354
+ {
355
+ let burdenBaseUrl = getBunderBaseUrl();
356
+ if(!burdenBaseUrl) { // 本地用不要清除
357
+ return;
358
+ }
359
+
360
+ const burdenFilePathList = getBurdenFilePathList(options);
361
+ for(const filePath of burdenFilePathList) {
362
+ fs.rmSync(filePath);
363
+ Logger.Info('Cleanup burden file: ' + path.relative(options.projectDir, filePath));
364
+ }
365
+ }
366
+
316
367
  function redirectSourceMappingURL(options)
317
368
  {
318
369
  const jsFileNames = fs.readdirSync(options.distJsDir);
@@ -346,14 +397,13 @@ function makeMainJsvMjs(options, framework)
346
397
 
347
398
  // 更新entry hash
348
399
  const jsEntryFilePath = getEntryFilePath(options);
349
- const newEntryFileName = `main.jsv.${options.appEntryMd5.slice(0, 8)}.js`;
350
- const newEntryFilePath = path.resolve(path.dirname(jsEntryFilePath), newEntryFileName);
400
+ const newEntryFilePath = path.resolve(options.distJsDir, options.appEntryFileName);
351
401
  Logger.Info(' -> ' + path.relative(options.projectDir, newEntryFilePath));
352
402
  fs.renameSync(jsEntryFilePath, newEntryFilePath);
353
403
 
354
404
  // 更新index.html hash
355
405
  var indexContent = fs.readFileSync(options.distJsIndexFile, 'utf8');
356
- indexContent = indexContent.replace(path.basename(jsEntryFilePath), newEntryFileName);
406
+ indexContent = indexContent.replace(path.basename(jsEntryFilePath), options.appEntryFileName);
357
407
  Logger.Info(' -> ' + path.relative(options.projectDir, options.distJsIndexFile));
358
408
  fs.writeFileSync(options.distJsIndexFile, indexContent, 'utf8');
359
409
 
@@ -429,6 +479,25 @@ function makeDebugMap(options, framework)
429
479
  fs.copyFileSync(jsmapServePath, to);
430
480
  }
431
481
 
482
+ async function makeJsvConfig(options)
483
+ {
484
+ const jsviewVersionURL = url.pathToFileURL(options.jsviewDomRevisionFile);
485
+ const { default: jsviewTargetVersion } = await import(jsviewVersionURL);
486
+ const appEntryFilePath = path.resolve(options.distJsDir, options.appEntryFileName);
487
+ let appEntryFileName = `./${path.relative(options.distDir, appEntryFilePath)}`;
488
+ // appEntryFileName = appEntryFileName.replace(/\.js$/, '.mjs'); // deprecated
489
+ appEntryFileName = appEntryFileName.replaceAll('\\', '/'); // windows平台适配
490
+
491
+ const jsvConfig = {
492
+ "COREVERSIONRANGE": jsviewTargetVersion.CoreRevisionAndBranch,
493
+ "ENGINE": jsviewTargetVersion.JseUrl,
494
+ "URL": appEntryFileName,
495
+ };
496
+
497
+ const content = JSON.stringify(jsvConfig, null, 2);
498
+ fs.writeFileSync(options.distJsvConfigFile, content, 'utf8');
499
+ }
500
+
432
501
  function makeJsvList(options)
433
502
  {
434
503
  let jsvList = makeFileListRecusive(options.distDir);
@@ -502,6 +571,10 @@ async function main(argv)
502
571
  await checkDomDebugDisabled(options);
503
572
 
504
573
  Logger.Info();
574
+ const jsviewPkgJson = loadPackageObject(options.jsviewDir);
575
+ Logger.Info(`JsView version: ${jsviewPkgJson.version}`);
576
+ Logger.Info();
577
+
505
578
  Logger.Info('Redirecting JsView burden resource...');
506
579
  redirectBurdenResource(options)
507
580
  Logger.Info('Redirected JsView burden resource...');
@@ -529,7 +602,12 @@ async function main(argv)
529
602
  makeDebugMap(options, argv.framework);
530
603
  Logger.Info('Made JsView Debug map.');
531
604
 
605
+ Logger.Info('Cleaning JsView Burden Resource...');
606
+ cleanupBurdenResource(options);
607
+ Logger.Info('Cleaned JsView Burden Resource...');
608
+
532
609
  Logger.Info('Making JsView info...');
610
+ await makeJsvConfig(options);
533
611
  makeJsvList(options);
534
612
  await makeJsvInfo(options);
535
613
  Logger.Info('Made JsView info...');
@@ -250,6 +250,11 @@ function doPostInstall(framework, pkgNeedPatch, skipCheckVersion, skipCheckNpmcm
250
250
  const options = getOptions(framework);
251
251
  options.projectDir = process.cwd();
252
252
 
253
+ Logger.Info();
254
+ const jsviewPkgJson = loadPackageObject(options.jsviewDir);
255
+ Logger.Info(`JsView version: ${jsviewPkgJson.version}`);
256
+ Logger.Info();
257
+
253
258
  const linkablePkgNames = [
254
259
  '@shijiu/jsview',
255
260
  '@shijiu/jsview-vue',
@@ -24,17 +24,19 @@ async function getExtraOptions(argv)
24
24
  options.entryUrl = argv.url;
25
25
 
26
26
  let commandCount = 0;
27
- commandCount += (argv.httpServer ? 1 : 0);
28
- commandCount += (argv.httpsServer ? 1 : 0);
29
- commandCount += (argv.httpVite ? 1 : 0);
30
- commandCount += (argv.httpsVite ? 1 : 0);
31
27
  commandCount += (argv.configApp ? 1 : 0);
32
28
  commandCount += (argv.genKeypair ? 1 : 0);
33
29
  commandCount += (argv.runonAndroid ? 1 : 0);
34
30
  commandCount += (argv.buildMinifyExclude ? 1 : 0);
35
31
  commandCount += (argv.buildZip ? 1 : 0);
36
32
  commandCount += (argv.buildBurdenLocal ? 1 : 0);
33
+ commandCount += (argv.buildBurdenBaseurl ? 1 : 0);
37
34
  commandCount += (argv.moduleFederation ? 1 : 0);
35
+ commandCount += (argv.httpServer ? 1 : 0);
36
+ commandCount += (argv.httpsServer ? 1 : 0);
37
+ commandCount += (argv.httpVite ? 1 : 0);
38
+ commandCount += (argv.httpsVite ? 1 : 0);
39
+ commandCount += (argv.fowardArkweb ? 1 : 0);
38
40
  commandCount += (argv.vueDevtools ? 1 : 0);
39
41
  if(commandCount == 0) {
40
42
  if(argv.help || argv.h) {
@@ -43,17 +45,19 @@ async function getExtraOptions(argv)
43
45
  }
44
46
 
45
47
  const commandPrompt = [
46
- 'httpServer',
47
- 'httpsServer',
48
- 'httpVite',
49
- 'httpsVite',
50
48
  'runonAndroid',
51
49
  'configApp',
52
50
  'genKeypair',
53
51
  'buildMinifyExclude',
54
52
  'buildZip',
55
53
  'buildBurdenLocal',
54
+ 'buildBurdenBaseurl',
56
55
  'vueDevtools',
56
+ 'httpServer',
57
+ 'httpsServer',
58
+ 'httpVite',
59
+ 'httpsVite',
60
+ 'fowardArkweb',
57
61
  'moduleFederation',
58
62
  ];
59
63
 
@@ -70,17 +74,19 @@ async function getExtraOptions(argv)
70
74
  Logger.Info('command:', command);
71
75
  options[command] = true
72
76
  } else if(commandCount == 1) {
73
- options.httpServer = argv.httpServer;
74
- options.httpsServer = argv.httpsServer;
75
- options.httpsVite = argv.httpsVite;
76
- options.httpVite = argv.httpVite;
77
77
  options.runonAndroid = argv.runonAndroid;
78
78
  options.configApp = argv.configApp;
79
79
  options.genKeypair = argv.genKeypair;
80
80
  options.buildMinifyExclude = argv.buildMinifyExclude;
81
81
  options.buildZip = argv.buildZip;
82
82
  options.buildBurdenLocal = argv.buildBurdenLocal;
83
+ options.buildBurdenBaseurl = argv.buildBurdenBaseurl;
83
84
  options.vueDevtools = argv.vueDevtools;
85
+ options.httpServer = argv.httpServer;
86
+ options.httpsServer = argv.httpsServer;
87
+ options.httpsVite = argv.httpsVite;
88
+ options.httpVite = argv.httpVite;
89
+ options.fowardArkweb = argv.fowardArkweb;
84
90
  options.moduleFederation = argv.moduleFederation;
85
91
  } else if(commandCount > 1) {
86
92
  Logger.ErrorAndExitNoException("Only one command can be executed.");
@@ -110,13 +116,13 @@ function doCommand(options, argv) {
110
116
  let filter = options.buildMinifyExclude;
111
117
  if(typeof(filter) !== 'string') {
112
118
  filter = 'jsview-';
113
- Logger.Warn('Minify filter is not set, use default value: ' + filter);
119
+ Logger.Warn(`Minify filter is not set, use default value: ${filter}`);
114
120
  }
115
121
 
116
122
  let script = argv.s ?? argv.script;
117
123
  if(typeof(script) !== 'string') {
118
124
  script = 'build';
119
- Logger.Warn('Build script is not set, use default value: ' + script);
125
+ Logger.Warn(`Build script is not set, use default value: ${script}`);
120
126
  }
121
127
 
122
128
  command = 'node node_modules/@shijiu/jsview/tools/jsview-build-minify-exclude.mjs --filter=' + filter + ' --script=' + script;
@@ -124,28 +130,33 @@ function doCommand(options, argv) {
124
130
  const defaultPassword = 'jsview.shijiu.com';
125
131
  const password = (typeof(options.buildZip) === 'string' ? options.buildZip : defaultPassword);
126
132
  if(password !== options.buildZip) {
127
- Logger.Warn('Zip password is not set, use default value: ' + defaultPassword);
133
+ Logger.Warn(`Zip password is not set, use default value: ${defaultPassword}`);
128
134
  }
129
135
 
130
- command = 'node node_modules/@shijiu/jsview/tools/jsview-build-zip.mjs --password=' + password;
136
+ command = `node node_modules/@shijiu/jsview/tools/jsview-build-zip.mjs --password=${password}`;
131
137
  } else if(options.buildBurdenLocal) {
132
138
  command = 'JSVIEW_BURDEN_LOCAL=true npm run build';
139
+ } else if(options.buildBurdenBaseurl) {
140
+ if(typeof options.buildBurdenBaseurl != 'string') {
141
+ Logger.ErrorAndExitNoException("Bad build burden base url, please set valid url such as: https://example.com/burden-dir.");
142
+ }
143
+ command = `JSVIEW_BURDEN_BASEURL=${options.buildBurdenBaseurl} npm run build`;
133
144
  } else if(options.vueDevtools) {
134
145
  var defaultPort = 8098;
135
146
  const port = (typeof(options.vueDevtools) === 'string' ? options.vueDevtools : defaultPort);
136
147
  if(port !== options.vueDevtools) {
137
- Logger.Warn('Vue Devtools server port is not set, use default value: ' + defaultPort);
148
+ Logger.Warn(`Vue Devtools server port is not set, use default value: ${port}`);
138
149
  }
139
150
 
140
- command = 'node node_modules/@shijiu/jsview/tools/jsview-vue-devtools.mjs --port=' + port;
151
+ command = `node node_modules/@shijiu/jsview/tools/jsview-vue-devtools.mjs --port=${port}`;
141
152
  } else if(options.moduleFederation) {
142
153
  var argumentsLine = options.argumentsLine.replace(/ --framework.*? /, ' ');
143
154
  argumentsLine = argumentsLine.replace(' -f ', ' ').replace(' --module-federation ', ' ');
144
155
 
145
- command = 'node node_modules/@shijiu/jsview/tools/jsview-module-federation.mjs' + argumentsLine;
156
+ command = `node node_modules/@shijiu/jsview/tools/jsview-module-federation.mjs ${argumentsLine}`;
146
157
  } else if(options.httpServer) {
147
158
  if(isCommandAvailable('serve') == false) {
148
- Logger.ErrorAndExitNoException("Command `serve` is not found, please install it first by `npm install -g serve`.");
159
+ Logger.ErrorAndExitNoException("Command 'serve' is not found, please install it first by 'npm install -g serve'.");
149
160
  }
150
161
  if(typeof options.httpServer !== 'string') {
151
162
  Logger.ErrorAndExitNoException("Dir path is not found, please set dir by [-t|--http-server]=[DirPath].");
@@ -153,7 +164,7 @@ function doCommand(options, argv) {
153
164
  command = `serve -p 8080 --cors ${options.httpServer}`;
154
165
  } else if(options.httpsServer) {
155
166
  if(isCommandAvailable('serve') == false) {
156
- Logger.ErrorAndExitNoException("Command `serve` is not found, please install it first by `npm install -g serve`.");
167
+ Logger.ErrorAndExitNoException("Command 'serve' is not found, please install it first by 'npm install -g serve'.");
157
168
  }
158
169
  if(typeof options.httpsServer !== 'string') {
159
170
  Logger.ErrorAndExitNoException("Dir path is not found, please set dir by [-s|--https-server]=[DirPath].");
@@ -169,6 +180,21 @@ function doCommand(options, argv) {
169
180
  } else if(options.httpsVite) {
170
181
  const exportPrefix = getExportPrefix();
171
182
  command = `${exportPrefix} JSVIEW_ENABLE_HTTPS=true && npm start`;
183
+ } else if(options.fowardArkweb) {
184
+ var defaultPort = 9220;
185
+ const port = (typeof(options.fowardArkweb) === 'string' ? options.fowardArkweb : defaultPort);
186
+ if(port !== options.fowardArkweb) {
187
+ Logger.Warn(`Foward webview port is not set, use default value: ${port}`);
188
+ }
189
+
190
+ command = `hdc shell cat /proc/net/unix | grep devtools`;
191
+ const output = execCommand(command, true);
192
+ if(output.includes('@webview_devtools_remote_') == false) {
193
+ Logger.ErrorAndThrow(`Failed to find foward webview process.`);
194
+ }
195
+ const webviewPid = output.substring(output.indexOf('@') + 1).trim();
196
+
197
+ command = `hdc fport tcp:${port} localabstract:${webviewPid}`;
172
198
  }
173
199
 
174
200
  execCommand(command);
@@ -187,17 +213,19 @@ const requiredUsages = {
187
213
  '--framework': 'Select from [vue|react]',
188
214
  };
189
215
  const optionalUsages = {
190
- '-t | --http-server': '=[DirPath]. Start http server for debug, port is 8080.',
191
- '-s | --https-server': '=[DirPath]. Start https server for debug, port is 8080.',
192
- '-v | --http-vite': 'Start vite https server for debug, same as `npm start`',
193
- '-i | --https-vite': 'Start vite https server for debug.',
194
216
  '-a | --runon-android': 'Run app on android devices.',
195
217
  '-c | --config-app': 'Config app, like: -c or --config-app=[AppName:AppTitle].',
196
218
  '-g | --gen-keypair': 'Generate sign keypair.',
197
219
  '-m | --build-minify-exclude': 'Build target with minify-exclude filter, like: -m or --build-minify-exclude=[filter], additional options: -s or --script=build:dev.',
198
220
  '-z | --build-zip': 'Build target to offline zip package, like: -z or --build-zip=[password].',
199
- '-b | --build-burden-local': 'Build target with local burden files.',
221
+ '-l | --build-burden-local': 'Build target with local burden files.',
222
+ '-b | --build-burden-baseurl': 'Build target with custom burden base url.',
200
223
  '-d | --vue-devtools': 'Start vue dev server and vue-devtools standalone, like: -d or --vue-devtools=[port].',
224
+ '-t | --http-server': '=[DirPath]. Start http server for debug, port is 8080.',
225
+ '-s | --https-server': '=[DirPath]. Start https server for debug, port is 8080.',
226
+ '-v | --http-vite': 'Start vite https server for debug, same as `npm start`',
227
+ '-i | --https-vite': 'Start vite https server for debug.',
228
+ '-p | --foward-arkweb': 'Foward port to openharmony webview devtools, like -p or --foward-arkweb=[port].',
201
229
  '-f | --module-federation': 'Make project to module federation, use --module-federation --help for details.',
202
230
  };
203
231
  const argv = parseArguments(requiredUsages, optionalUsages, true, true, true);
Binary file