@shijiu/jsview 1.9.760 → 1.9.779

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.
Files changed (34) hide show
  1. package/dom/bin/jsview-browser-debug-dom.min.js +1 -1
  2. package/dom/bin/jsview-dom.min.js +1 -1
  3. package/dom/bin/jsview-engine-js-browser.min.js +1 -1
  4. package/dom/jsv-dom.js +3 -1
  5. package/loader/loader.js +3 -3
  6. package/package.json +7 -8
  7. package/patches/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +3085 -2968
  8. package/patches/node_modules/@vue/compiler-sfc/package.json +6 -6
  9. package/patches/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js +8123 -8038
  10. package/patches/node_modules/@vue/runtime-core/package.json +3 -3
  11. package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +1681 -1663
  12. package/patches/node_modules/@vue/runtime-dom/package.json +3 -3
  13. package/patches/node_modules/react-dom/cjs/react-dom.development.js +29868 -0
  14. package/patches/node_modules/react-dom/cjs/react-dom.production.min.js +323 -0
  15. package/patches/node_modules/react-dom/package.json +62 -0
  16. package/patches/node_modules/react-scripts/config/paths.js +4 -1
  17. package/patches/node_modules/react-scripts/config/webpack.config.js +3 -3
  18. package/patches/node_modules/vite/dist/node/chunks/{dep-0fc8e132.js → dep-ed9cb113.js} +46837 -46866
  19. package/patches/node_modules/vite/dist/node/jsview-vite-extension.js +155 -0
  20. package/patches/node_modules/vite/package.json +48 -39
  21. package/patches/node_modules/vue-router/dist/vue-router.mjs +22 -5
  22. package/patches/node_modules/vue-router/package.json +12 -12
  23. package/tools/jsview-common.js +169 -0
  24. package/tools/jsview-jsmap-serve.mjs +127 -0
  25. package/tools/jsview-post-build.js +63 -55
  26. package/tools/jsview-post-install.js +92 -42
  27. package/tools/jsview-run-android.js +46 -38
  28. package/patches/node_modules/vite/dist/node/jsview-react.vite.config.js +0 -7
  29. package/patches/node_modules/vite/dist/node/jsview-vue.vite.config.js +0 -7
  30. package/patches/node_modules/vite/dist/node/jsview.vite.config.js +0 -64
  31. package/tools/common.js +0 -63
  32. package/tools/jsview-jsmap-serve.js +0 -105
  33. package/tools/jsview-post-install-react.js +0 -15
  34. package/tools/jsview-post-install-vue.js +0 -20
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ import fs from 'fs';
5
+ import http from 'http';
6
+ import os from 'os';
7
+ import path from 'path';
8
+ import url from 'url';
9
+
10
+ const context = {
11
+ scriptDir: path.dirname(url.fileURLToPath(import.meta.url)),
12
+ baseUrl: null,
13
+ needRedirect: false,
14
+ }
15
+
16
+ function requestListener(req, res)
17
+ {
18
+ console.log('[request] ' + req.url);
19
+
20
+ if (req.url.endsWith('.map') == false) { // 只处理 .map 文件
21
+ console.log('JsView Error: Failed to process ' + req.url);
22
+ res.writeHead(404);
23
+ res.end();
24
+ return;
25
+ }
26
+
27
+ // 解决 devtools://devtools 引起的 CORS 问题。
28
+ res.setHeader('Access-Control-Allow-Origin', '*');
29
+ res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
30
+
31
+ if (context.needRedirect) {
32
+ // redirect with 302 HTTP code in response
33
+ let redirectTarget = context.baseUrl + convertMapBaseUrl(req.url)
34
+ console.log(`redirect ${req.url} -> ${redirectTarget}`)
35
+ res.writeHead(302, { 'Location': redirectTarget });
36
+ return res.end();
37
+ }
38
+
39
+ try {
40
+ const fileContent = fs.readFileSync(context.baseUrl + '/' + req.url);
41
+ res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
42
+ res.write(fileContent);
43
+ } catch (ex) {
44
+ console.log('JsView Error: Failed to process ' + req.url + '\nException: ' + ex);
45
+ res.writeHead(404);
46
+ }
47
+ res.end();
48
+ return;
49
+ }
50
+
51
+ function convertMapBaseUrl(originUrl)
52
+ {
53
+ if (originUrl.startsWith('/map/')) {
54
+ /* 去掉子目录/map/ */
55
+ return originUrl.substr(5);
56
+ } else if (originUrl.startsWith('/')) {
57
+ /* 去掉'/' */
58
+ return originUrl.substring(1, originUrl.length);
59
+ } else {
60
+ return originUrl;
61
+ }
62
+ }
63
+
64
+ function getIPAddress()
65
+ {
66
+ let ret = [];
67
+
68
+ var interfaces = os.networkInterfaces();
69
+ for (var devname in interfaces) {
70
+ var iface = interfaces[devname];
71
+
72
+ for (var i = 0; i < iface.length; i++) {
73
+ var alias = iface[i];
74
+ if (alias.family === 'IPv4' && !alias.internal)
75
+ ret.push(alias.address);
76
+ }
77
+ }
78
+ return ret;
79
+ }
80
+
81
+ function parseBaseUrl(context, argv)
82
+ {
83
+ context.baseUrl = context.scriptDir;
84
+ if (argv.length < 3) {
85
+ return;
86
+ }
87
+
88
+ const redirectPath = argv[2];
89
+ const regex = /^(http|https):\/\//i;
90
+ if (regex.test(redirectPath)) {
91
+ context.baseUrl = redirectPath;
92
+ context.needRedirect = true;
93
+ } else if (redirectPath.startsWith('file://')) {
94
+ context.baseUrl = url.fileURLToPath(redirectPath)
95
+ } else {
96
+ context.baseUrl = path.resolve(process.cwd(), redirectPath);
97
+ }
98
+ if (context.baseUrl.endsWith('/') == false) {
99
+ context.baseUrl += '/';
100
+ }
101
+
102
+ return;
103
+ }
104
+
105
+ function main(argv)
106
+ {
107
+ parseBaseUrl(context, argv);
108
+
109
+ const server = http.createServer(requestListener);
110
+ const port = 57245;
111
+ server.listen(port, '0.0.0.0', () => {
112
+ const ipAddrs = getIPAddress();
113
+
114
+ console.log('');
115
+ console.log('SourceMap base url: ' + context.baseUrl)
116
+ console.log('');
117
+ console.log('JsView server running at:');
118
+ console.log('');
119
+ console.log(' - Local: http://localhost:' + port + '/');
120
+ for(const ip of ipAddrs) {
121
+ console.log(' - Network: http://' + ip + ':' + port + '/');
122
+ }
123
+ console.log('');
124
+ });
125
+ }
126
+
127
+ main(process.argv);
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
4
  const crypto = require('crypto');
4
5
  const fs = require('fs');
5
6
  const path = require('path');
7
+ const { getOptions } = require('./jsview-common');
6
8
 
7
9
  // main.js处理AppData信息
8
10
  async function prepareMainAppData(options, fileMd5)
@@ -69,7 +71,7 @@ async function prepareMainAppData(options, fileMd5)
69
71
  }
70
72
  // const appConfigText = fs.readFileSync(appConfigFile);
71
73
  // const appDataOriginJson = JSON.parse(appConfigText);
72
- appDataOriginJson = await import(appConfigFile);
74
+ const appDataOriginJson = await import(appConfigFile);
73
75
 
74
76
  // 组装AppData
75
77
  let targetAppData = {};
@@ -80,31 +82,24 @@ async function prepareMainAppData(options, fileMd5)
80
82
  return JSON.stringify(targetAppData);
81
83
  }
82
84
 
83
- function signApp(options)
85
+ async function signApp(options)
84
86
  {
85
- const jsDir = path.resolve(options.distDir, 'js');
86
- const jsFiles = fs.readdirSync(jsDir);
87
- jsFiles.forEach(async (file, index) => {
88
- if (!file.endsWith('.js')) {
89
- return;
87
+ const jsFileNames = fs.readdirSync(options.distJsDir);
88
+ for(const fileName of jsFileNames) {
89
+ if (!fileName.endsWith('.js')) {
90
+ continue;
90
91
  }
91
92
 
92
- const jsFile = path.resolve(jsDir, file);
93
- console.log('Updating ' + path.relative(options.projectDir, jsFile));
93
+ const filePath = path.resolve(options.distJsDir, fileName);
94
+ // console.log(' -> ' + path.relative(options.projectDir, filePath));
94
95
 
95
- var jsvAppContents = fs.readFileSync(jsFile);
96
- jsvAppContents = jsvAppContents.toString();
96
+ var sourceContent = fs.readFileSync(filePath, 'utf8');
97
97
 
98
- let mapOffset = jsvAppContents.lastIndexOf('# sourceMappingURL='); // 避免代码中间位置的sourceMappingUrl内容被替换
99
- let mapStr = (jsvAppContents.substring(mapOffset, jsvAppContents.length)).replace(
100
- '# sourceMappingURL=', '# sourceMappingURL=http://localhost:57245/map/');
101
- jsvAppContents = jsvAppContents.substring(0, mapOffset) + mapStr;
102
-
103
- jsvAppContents += '\n'; // 把\n归入算进md5计算中
98
+ sourceContent += '\n'; // 把\n归入算进md5计算中
104
99
 
105
- const jsvAppMd5 = crypto.createHash('md5').update(jsvAppContents).digest('hex');
100
+ const jsvAppMd5 = crypto.createHash('md5').update(sourceContent).digest('hex');
106
101
  let appDataInfo = '';
107
- if (jsFile.indexOf('main.jsv.') > 0) {
102
+ if (fileName.indexOf('main.jsv.') >= 0) {
108
103
  // 对main文件加入应用头信息
109
104
  appDataInfo = await prepareMainAppData(options, jsvAppMd5);
110
105
 
@@ -113,54 +108,66 @@ function signApp(options)
113
108
  const infoLen = new TextEncoder().encode(appDataInfo).length;
114
109
  appDataInfo = '/*jsvapp:' + infoLen + ':' + appDataInfo + ':' + infoLen + ':jsvapp*/';
115
110
  }
116
- jsvAppContents = jsvAppContents + appDataInfo + '/*jsvmd5:' + jsvAppMd5 + '*/';
117
- fs.writeFileSync(jsFile, jsvAppContents);
118
- });
111
+ sourceContent = sourceContent + appDataInfo + '/*jsvmd5:' + jsvAppMd5 + '*/';
112
+ fs.writeFileSync(filePath, sourceContent, 'utf8');
113
+ }
114
+ }
115
+
116
+ function redirectSourceMappingURL(options)
117
+ {
118
+ const jsFileNames = fs.readdirSync(options.distJsDir);
119
+ for(const fileName of jsFileNames) {
120
+ if (!fileName.endsWith('.js')) {
121
+ continue;
122
+ }
123
+
124
+ const filePath = path.resolve(options.distJsDir, fileName);
125
+ // console.log(' -> ' + path.relative(options.projectDir, filePath));
126
+
127
+ let sourceContent = fs.readFileSync(filePath, 'utf8');
128
+
129
+ let mapUrlOffset = sourceContent.lastIndexOf('# sourceMappingURL='); // 避免代码中间位置的sourceMappingUrl内容被替换
130
+ let mapUrlStr = (sourceContent.substring(mapUrlOffset, sourceContent.length)).replace(
131
+ '# sourceMappingURL=', '# sourceMappingURL=http://localhost:57245/map/');
132
+ sourceContent = sourceContent.substring(0, mapUrlOffset) + mapUrlStr;
133
+
134
+ fs.writeFileSync(filePath, sourceContent, 'utf8');
135
+ };
119
136
  }
120
137
 
121
138
  function makeDebugMap(options)
122
139
  {
123
- fs.mkdirSync(options.mapDir, { recursive: true });
140
+ fs.mkdirSync(options.distDebugMapDir, { recursive: true });
124
141
 
125
- const jsDir = path.resolve(options.distDir, 'js');
126
- const jsFiles = fs.readdirSync(jsDir);
127
- jsFiles.forEach((file, index) => {
128
- if (!file.endsWith('.map')) {
129
- return;
142
+ const jsFileNames = fs.readdirSync(options.distJsDir);
143
+ for(const fileName of jsFileNames) {
144
+ if (!fileName.endsWith('.map')) {
145
+ continue;
130
146
  }
131
147
 
132
- const from = path.resolve(jsDir, file);
133
- const to = path.resolve(options.mapDir, file);
134
- console.log("Moving " + path.relative(options.projectDir, to));
148
+ const from = path.resolve(options.distJsDir, fileName);
149
+ const to = path.resolve(options.distDebugMapDir, fileName);
150
+ // console.log(' -> ' + path.relative(options.projectDir, to));
135
151
  fs.renameSync(from, to);
136
- });
152
+ };
137
153
 
138
- const jsmapServeName = "jsview-jsmap-serve.js";
139
- const jsmapServePath = path.resolve(options.toolsDir, jsmapServeName);
154
+ const jsmapServeName = 'jsview-jsmap-serve.mjs';
155
+ const jsmapServePath = path.resolve(options.jsviewToolsDir, jsmapServeName);
140
156
  if (!fs.existsSync(jsmapServePath)) {
141
- console.error("Failed to copy " + jsmapServePath + ", file not exists.");
157
+ console.error('JsView Error: Failed to copy ' + jsmapServePath + ', file not exists.');
142
158
  process.exit(1);
143
159
  }
144
160
 
145
- const to = path.resolve(options.debugDir, jsmapServeName);
146
- console.log("Making " + path.relative(options.projectDir, to));
161
+ const to = path.resolve(options.distDebugDir, jsmapServeName);
162
+ console.log(' -> ' + path.relative(options.projectDir, to));
147
163
  fs.copyFileSync(jsmapServePath, to);
148
164
  }
149
165
 
150
- function main() {
151
- const options = {};
152
- options.projectDir = process.cwd();
153
- options.modulesDir = path.resolve(options.projectDir, "node_modules");
154
- options.jsviewDir = path.resolve(options.modulesDir, "@shijiu", "jsview");
155
- options.patchesDir = path.resolve(options.jsviewDir, "patches");
156
- options.toolsDir = path.resolve(options.jsviewDir, "tools");
157
- options.distDir = path.resolve(options.projectDir, "dist");
158
- options.appConfigDir = path.resolve(options.projectDir, "src", "appConfig");
159
- options.debugDir = path.resolve(options.distDir, "debug");
160
- options.mapDir = path.resolve(options.debugDir, "map");
161
-
166
+ async function main()
167
+ {
168
+ const options = getOptions();
162
169
 
163
- vueConfigFile = path.resolve(options.projectDir, 'vue.config.js');
170
+ const vueConfigFile = path.resolve(options.projectDir, 'vue.config.js');
164
171
  if (fs.existsSync(vueConfigFile)) {
165
172
  vueCfgObj = require(vueConfigFile);
166
173
  if(vueCfgObj.outputDir) {
@@ -168,16 +175,17 @@ function main() {
168
175
  }
169
176
  }
170
177
 
171
- console.info('Signing JsView App...');
172
- console.info();
173
- signApp(options);
174
178
  console.info();
179
+ console.info('Redirecting JsView source map...');
180
+ redirectSourceMappingURL(options)
181
+ console.info('Redirected JsView source map...');
182
+
183
+ console.info('Signing JsView App...');
184
+ await signApp(options);
175
185
  console.info('Signed JsView App.');
176
186
 
177
187
  console.info('Making JsView Debug map...');
178
- console.info();
179
188
  makeDebugMap(options);
180
- console.info();
181
189
  console.info('Made JsView Debug map.');
182
190
  }
183
191
 
@@ -1,11 +1,20 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
4
  const fs = require('fs');
4
5
  const path = require('path');
5
- const { pathToFileURL } = require('url');
6
- const { cpSync, rmSync } = require('./common');
7
-
8
- function checkNpmCommand() {
6
+ const url = require('url');
7
+ const {
8
+ cpSync,
9
+ getOptions,
10
+ getPackageObject,
11
+ parseArguments,
12
+ symlinkSync,
13
+ rmSync
14
+ } = require('./jsview-common');
15
+
16
+ function checkNpmCommand()
17
+ {
9
18
  let command = process.env.npm_command;
10
19
  if(!command) {
11
20
  command = process.env.npm_config_refer; // for linux
@@ -20,54 +29,61 @@ function checkNpmCommand() {
20
29
  console.warn();
21
30
  }
22
31
 
23
- function getPackageObject(options, dir, name)
32
+ function checkNpmLinkForDebug(options, linkablePkgNames)
24
33
  {
25
- const pkgFullFile = path.resolve(dir, name, 'package.json');
26
- if (!fs.existsSync(pkgFullFile)) {
27
- console.error('Error: Failed to install jsview patches, "' + path.relative(options.projectDir, pkgFullFile) + '" is not exists.');
28
- process.exit(1);
29
- }
30
- const pkgObj = require(pkgFullFile);
34
+ const pkgObj = getPackageObject(options.projectDir);
31
35
 
32
- return pkgObj;
33
- }
36
+ for (const linkableName of linkablePkgNames) {
37
+ let linkableTarget = pkgObj.dependencies?.[linkableName];
38
+ if (!linkableTarget || !linkableTarget.startsWith('file:')) {
39
+ continue;
40
+ }
34
41
 
35
- function checkPatches(options, pkgNeedPatch, skipCheckVersion) {
36
- console.info("Checking package:");
37
- for (pkgName of pkgNeedPatch) {
38
- if (skipCheckVersion == false) {
39
- const patchPkgObj = getPackageObject(options, path.resolve(options.patchesDir, 'node_modules'), pkgName);
40
- console.info(" " + pkgName + ": " + patchPkgObj.version);
42
+ linkableTarget = linkableTarget.replace('file:', '');
43
+ const linkableTargetPath = path.resolve(options.projectDir, linkableTarget);
44
+ const linkablePath = path.resolve(options.modulesDir, linkableName);
45
+ symlinkSync(linkableTargetPath, linkablePath);
46
+ }
47
+ }
41
48
 
42
- const modulePkgObj = getPackageObject(options, options.modulesDir, pkgName);
49
+ function checkPatches(options, pkgNeedPatch, skipCheckVersion)
50
+ {
51
+ console.info('Checking package:');
52
+ for (const pkgName of pkgNeedPatch) {
53
+ if (skipCheckVersion !== true) {
54
+ const patchPkgDir = path.resolve(options.jsviewPatchModulesDir, pkgName);
55
+ const patchPkgObj = getPackageObject(options, patchPkgDir);
56
+ console.info(' ' + pkgName + ': ' + patchPkgObj.version);
57
+
58
+ const modulePkgDir = path.resolve(options.modulesDir, pkgName);
59
+ const modulePkgObj = getPackageObject(modulePkgDir);
43
60
  if (modulePkgObj.version != patchPkgObj.version) {
44
61
  console.error('Error: ' + pkgName + '@' + modulePkgObj.version + ' is not supported, required version is ' + patchPkgObj.version);
45
62
  process.exit(1);
46
63
  }
47
64
  } else {
48
- console.info(" Skip ", pkgName);
65
+ console.info(' Skip ', pkgName);
49
66
  }
50
67
  }
51
68
  }
52
69
 
53
- function installPatches(options, pkgNeedPatch) {
70
+ function installPatches(options, pkgNeedPatch)
71
+ {
54
72
  console.info('\nPatching JsView:');
55
- for (pkgName of pkgNeedPatch) {
56
- const patchSrc = path.resolve(options.patchesDir, 'node_modules', pkgName);
73
+ for (const pkgName of pkgNeedPatch) {
74
+ const patchSrc = path.resolve(options.jsviewPatchModulesDir, pkgName);
57
75
  const patchDest = path.resolve(options.modulesDir, pkgName);
58
76
 
59
77
  cpSync(options.projectDir, patchSrc, patchDest, ['package.json']);
60
78
  }
61
79
 
62
80
  console.info('\nCleanup node_modules cache... ');
63
- const nodeModuleCacheDir = path.resolve(options.modulesDir, '.cache');
64
- rmSync(nodeModuleCacheDir);
81
+ rmSync(options.cacheDir);
65
82
  }
66
83
 
67
- async function printRevision(options) {
68
- const jsviewVersionFile = path.resolve(options.jsviewDir, 'dom', 'target_core_revision.mjs');
69
-
70
- const jsviewVersionURL = pathToFileURL(jsviewVersionFile);
84
+ async function printRevision(options)
85
+ {
86
+ const jsviewVersionURL = url.pathToFileURL(options.jsviewRevisionFile);
71
87
  const { default: jsviewTargetVersion } = await import(jsviewVersionURL);
72
88
 
73
89
  console.log('**************************************************');
@@ -81,8 +97,9 @@ async function printRevision(options) {
81
97
  {
82
98
  let pluginDirPath = path.resolve(options.jsviewFrameworkDir, 'utils', 'JsViewPlugin');
83
99
  if(fs.existsSync(pluginDirPath)) {
84
- fs.readdirSync(pluginDirPath).forEach((file) => {
85
- var pathname = path.resolve(pluginDirPath, file);
100
+ const pluginFileNames = fs.readdirSync(pluginDirPath);
101
+ for(const fileName of pluginFileNames) {
102
+ var pathname = path.resolve(pluginDirPath, fileName);
86
103
  if (fs.statSync(pathname).isDirectory()) {
87
104
  let versionFilePath = path.resolve(pathname, 'version.js');
88
105
  if (fs.existsSync(versionFilePath)) {
@@ -101,17 +118,23 @@ async function printRevision(options) {
101
118
  console.log('**************************************************');
102
119
  }
103
120
 
104
- function doPostInstall(framework, pkgNeedPatch, skipCheckVersion) {
105
- const options = {};
121
+ function doPostInstall(framework, pkgNeedPatch, skipCheckVersion)
122
+ {
123
+ const options = getOptions(framework);
106
124
  options.projectDir = process.cwd();
107
- options.modulesDir = path.resolve(options.projectDir, 'node_modules');
108
- options.jsviewDir = path.resolve(options.modulesDir, '@shijiu', 'jsview');
109
- options.jsviewFrameworkDir = path.resolve(options.modulesDir, '@shijiu', 'jsview-' + framework);
110
- options.patchesDir = path.resolve(options.jsviewDir, 'patches');
111
- options.distDir = path.resolve(options.projectDir, 'dist');
125
+
126
+ const linkablePkgNames = [
127
+ '@shijiu/jsview',
128
+ '@shijiu/jsview-vue',
129
+ '@shijiu/jsview-vue-samples',
130
+ '@shijiu/jsview-react',
131
+ '@shijiu/jsview-react-samples',
132
+ ]
112
133
 
113
134
  checkNpmCommand();
114
135
 
136
+ checkNpmLinkForDebug(options, linkablePkgNames);
137
+
115
138
  checkPatches(options, pkgNeedPatch, skipCheckVersion);
116
139
 
117
140
  installPatches(options, pkgNeedPatch);
@@ -119,6 +142,33 @@ function doPostInstall(framework, pkgNeedPatch, skipCheckVersion) {
119
142
  printRevision(options);
120
143
  }
121
144
 
122
- module.exports = {
123
- doPostInstall
124
- };
145
+ function main(argv)
146
+ {
147
+ let pkgNeedPatch;
148
+
149
+ switch (argv.framework) {
150
+ case 'vue':
151
+ pkgNeedPatch = [
152
+ '@vue/compiler-sfc',
153
+ '@vue/runtime-core',
154
+ '@vue/runtime-dom',
155
+ 'postcss-js',
156
+ 'vite',
157
+ 'vue-router',
158
+ ];
159
+ break;
160
+ case 'react':
161
+ pkgNeedPatch = [
162
+ 'react-dom',
163
+ 'react-scripts',
164
+ ];
165
+ break;
166
+ default:
167
+ throw new Error('JsView Error: Failed to support framework: ' + framework);
168
+ }
169
+
170
+ doPostInstall(argv.framework, pkgNeedPatch, argv.skipCheckVersion);
171
+ }
172
+
173
+ const argv = parseArguments();
174
+ main(argv);
@@ -1,53 +1,60 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
4
  const childProcess = require('child_process');
4
5
  const path = require('path');
5
- const { pathToFileURL } = require('url');
6
+ const url = require('url');
7
+ const {
8
+ getOptions,
9
+ parseArguments
10
+ } = require('./jsview-common');
6
11
 
7
- async function getOptions() {
8
- const options = {
9
- androidPackage: "com.qcode.jsview.sample_demo/com.qcode.jsview.sample.SingleActivity",
10
- coreRevision: null,
11
- jseUrl: null,
12
- homepageUrl: null,
13
- }
12
+ async function getExtraOptions(argv)
13
+ {
14
+ const options = getOptions(argv.framework);
15
+ options.androidPackage = 'com.tvcode.sjcenter/com.tvcode.chmarket.MainActivity';
16
+ options.jsviewCoreRevision = null;
17
+ options.jsviewEngineUrl = null;
18
+ options.entryUrl = null;
14
19
 
15
- if (process.argv.length >= 3) {
16
- options.androidPackage = process.argv[2];
20
+ if (argv.unparsed.length > 0) {
21
+ options.androidPackage = argv.unparsed[0];
17
22
  }
18
23
 
19
- const projectDir = process.cwd();
20
- const modulesDir = path.resolve(projectDir, 'node_modules');
21
- const jsviewDir = path.resolve(modulesDir, '@shijiu', 'jsview');
22
- const jsviewVersionFile = path.resolve(jsviewDir, 'dom', 'target_core_revision.mjs');
23
- const jsviewVersionURL = pathToFileURL(jsviewVersionFile);
24
- const { default: jsviewTargetVersion } = await import(jsviewVersionURL);
25
- options.coreRevision = jsviewTargetVersion.CoreRevision;
26
- options.jseUrl = jsviewTargetVersion.JseUrl;
24
+ const jsviewRevisionFile = url.pathToFileURL(options.jsviewRevisionFile);
25
+ const { default: jsviewTargetRevision } = await import(jsviewRevisionFile);
26
+ options.jsviewCoreRevision = jsviewTargetRevision.CoreRevision;
27
+ options.jsviewEngineUrl = jsviewTargetRevision.JseUrl;
28
+
29
+ const baseUrlFile = url.pathToFileURL(options.baseUrlFile);
30
+ let { default: baseUrl } = await import(baseUrlFile);
31
+ baseUrl = baseUrl.replace(/\u001b\[.*?m/g, '')
32
+ options.entryUrl = baseUrl + 'js/main.jsv.js';
27
33
 
28
- const homepageUrlFile = path.resolve(modulesDir, '.vite', 'jsview', 'network.mjs');
29
- let { default: homepageDomain } = await import(homepageUrlFile);
30
- homepageDomain = homepageDomain.replace(/\u001b\[.*?m/g, '')
31
- options.homepageUrl = homepageDomain + "js/main.jsv.js?module=true";
34
+ if (argv.framework === 'vue') {
35
+ options.entryUrl += '?module=true';
36
+ }
32
37
 
33
38
  return options;
34
39
  }
35
40
 
36
- function printRevision(options) {
37
- console.log("**************************************************");
38
- console.log("* Android Package: " + options.androidPackage);
39
- console.log("* Core: " + options.coreRevision);
40
- console.log("* Engine JS url: " + options.jseUrl);
41
- console.log("* Homepage url: " + options.homepageUrl);
42
- console.log("**************************************************");
41
+ function printRevision(options)
42
+ {
43
+ console.log('**************************************************');
44
+ console.log('* Android Package: ' + options.androidPackage);
45
+ console.log('* Core: ' + options.jsviewCoreRevision);
46
+ console.log('* Engine JS url: ' + options.jsviewEngineUrl);
47
+ console.log('* Homepage url: ' + options.entryUrl);
48
+ console.log('**************************************************');
43
49
  }
44
50
 
45
- function androidStartActivity(options) {
46
- let cmdline = "adb shell am start";
51
+ function androidStartActivity(options)
52
+ {
53
+ let cmdline = 'adb shell am start';
47
54
  cmdline += ` -n ${options.androidPackage}`;
48
- cmdline += ` --es COREVERSIONRANGE "${options.coreRevision}"`;
49
- cmdline += ` --es ENGINE "${options.jseUrl}"`;
50
- cmdline += ` --es URL "${options.homepageUrl}"`;
55
+ cmdline += ` --es COREVERSIONRANGE "${options.jsviewCoreRevision}"`;
56
+ cmdline += ` --es ENGINE "${options.jsviewEngineUrl}"`;
57
+ cmdline += ` --es URL "${options.entryUrl}"`;
51
58
  console.log(`Run command: ${cmdline}\n`);
52
59
  try {
53
60
  childProcess.execSync(cmdline, {stdio: [0, 1, 2]});
@@ -56,12 +63,13 @@ function androidStartActivity(options) {
56
63
  }
57
64
  }
58
65
 
59
-
60
- async function main() {
61
- const options = await getOptions();
66
+ const argv = parseArguments(false);
67
+ async function main(argv)
68
+ {
69
+ const options = await getExtraOptions(argv);
62
70
 
63
71
  printRevision(options);
64
72
 
65
73
  androidStartActivity(options);
66
74
  }
67
- main()
75
+ main(argv)
@@ -1,7 +0,0 @@
1
- import path from 'path'
2
- import jsviewViteConfig from './jsview.vite.config.js'
3
-
4
- jsviewViteConfig.resolve.alias['jsview']
5
- = path.resolve(process.cwd(), 'node_modules/@shijiu/jsview-react');
6
-
7
- export default jsviewViteConfig;
@@ -1,7 +0,0 @@
1
- import path from 'path'
2
- import jsviewViteConfig from './jsview.vite.config.js'
3
-
4
- jsviewViteConfig.resolve.alias['jsview']
5
- = path.resolve(process.cwd(), 'node_modules/@shijiu/jsview-vue');
6
-
7
- export default jsviewViteConfig;