@shijiu/jsview 1.9.778 → 1.9.780

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shijiu/jsview",
3
- "version": "1.9.778",
3
+ "version": "1.9.780",
4
4
  "bin": {
5
5
  "jsview-post-build": "./tools/jsview-post-build.js",
6
6
  "jsview-post-install": "./tools/jsview-post-install.js"
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
4
  const fs = require('fs');
4
5
  const path = require('path');
5
6
 
6
- function parseArguments(beginWithHyphen = true) {
7
+ function parseArguments(beginWithHyphen = true)
8
+ {
7
9
  let options = {
8
10
  unparsed: []
9
11
  };
@@ -11,8 +13,7 @@ function parseArguments(beginWithHyphen = true) {
11
13
  // arg0: node
12
14
  // arg1: script.js
13
15
  const arguList = process.argv.slice(2);
14
- const unparsed = [];
15
- for (argu of arguList) {
16
+ for (const argu of arguList) {
16
17
  let [key, value] = argu.split('=');
17
18
  if (argu.includes('=') == false) {
18
19
  value = true;
@@ -69,7 +70,8 @@ function parseArguments(beginWithHyphen = true) {
69
70
  * └── src
70
71
  *    └── appConfig
71
72
  **************************************************/
72
- function getOptions(framework) {
73
+ function getOptions(framework)
74
+ {
73
75
  const options = {};
74
76
 
75
77
  options.projectDir = process.cwd();
@@ -101,7 +103,20 @@ function getOptions(framework) {
101
103
  return options;
102
104
  }
103
105
 
104
- function cpSync(workDir, src, dest, ignore=[]) {
106
+ function getPackageObject(modulePath)
107
+ {
108
+ const pkgFullFile = path.resolve(modulePath, 'package.json');
109
+ if (!fs.existsSync(pkgFullFile)) {
110
+ console.error('Error: Failed to get ' + modulePath + ', file is not exists.');
111
+ process.exit(1);
112
+ }
113
+ const pkgObj = require(pkgFullFile);
114
+
115
+ return pkgObj;
116
+ }
117
+
118
+ function cpSync(workDir, src, dest, ignore=[])
119
+ {
105
120
  const exists = fs.existsSync(src);
106
121
  const stats = exists && fs.statSync(src);
107
122
  const isDirectory = exists && stats.isDirectory();
@@ -109,14 +124,15 @@ function cpSync(workDir, src, dest, ignore=[]) {
109
124
  if (fs.existsSync(dest) == false) {
110
125
  fs.mkdirSync(dest);
111
126
  }
112
- fs.readdirSync(src).forEach(function(childItemName) {
127
+ const childFileNames = fs.readdirSync(src);
128
+ for (const childName of childFileNames) {
113
129
  cpSync(
114
130
  workDir,
115
- path.join(src, childItemName),
116
- path.join(dest, childItemName),
131
+ path.join(src, childName),
132
+ path.join(dest, childName),
117
133
  ignore
118
134
  );
119
- });
135
+ };
120
136
  } else {
121
137
  const filename = path.basename(src);
122
138
  if (ignore && ignore.includes(filename)) {
@@ -129,11 +145,13 @@ function cpSync(workDir, src, dest, ignore=[]) {
129
145
  }
130
146
  }
131
147
 
132
- function rmSync(path) {
148
+ function rmSync(path)
149
+ {
133
150
  fs.rmSync(path, { recursive: true, force: true });
134
151
  }
135
152
 
136
- function symlinkSync(target, to) {
153
+ function symlinkSync(target, to)
154
+ {
137
155
  rmSync(to);
138
156
 
139
157
  const targetPath = path.relative(path.dirname(to), target);
@@ -144,6 +162,7 @@ function symlinkSync(target, to) {
144
162
  module.exports = {
145
163
  cpSync,
146
164
  getOptions,
165
+ getPackageObject,
147
166
  parseArguments,
148
167
  rmSync,
149
168
  symlinkSync,
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
4
  import fs from 'fs';
4
5
  import http from 'http';
@@ -12,7 +13,8 @@ const context = {
12
13
  needRedirect: false,
13
14
  }
14
15
 
15
- function requestListener(req, res) {
16
+ function requestListener(req, res)
17
+ {
16
18
  console.log('[request] ' + req.url);
17
19
 
18
20
  if (req.url.endsWith('.map') == false) { // 只处理 .map 文件
@@ -46,7 +48,8 @@ function requestListener(req, res) {
46
48
  return;
47
49
  }
48
50
 
49
- function convertMapBaseUrl(originUrl) {
51
+ function convertMapBaseUrl(originUrl)
52
+ {
50
53
  if (originUrl.startsWith('/map/')) {
51
54
  /* 去掉子目录/map/ */
52
55
  return originUrl.substr(5);
@@ -58,7 +61,8 @@ function convertMapBaseUrl(originUrl) {
58
61
  }
59
62
  }
60
63
 
61
- function getIPAddress() {
64
+ function getIPAddress()
65
+ {
62
66
  let ret = [];
63
67
 
64
68
  var interfaces = os.networkInterfaces();
@@ -74,7 +78,8 @@ function getIPAddress() {
74
78
  return ret;
75
79
  }
76
80
 
77
- function parseBaseUrl(context, argv) {
81
+ function parseBaseUrl(context, argv)
82
+ {
78
83
  context.baseUrl = context.scriptDir;
79
84
  if (argv.length < 3) {
80
85
  return;
@@ -97,21 +102,24 @@ function parseBaseUrl(context, argv) {
97
102
  return;
98
103
  }
99
104
 
100
- function main(argv) {
105
+ function main(argv)
106
+ {
101
107
  parseBaseUrl(context, argv);
102
108
 
103
109
  const server = http.createServer(requestListener);
104
110
  const port = 57245;
105
111
  server.listen(port, '0.0.0.0', () => {
112
+ const ipAddrs = getIPAddress();
113
+
106
114
  console.log('');
107
115
  console.log('SourceMap base url: ' + context.baseUrl)
108
116
  console.log('');
109
117
  console.log('JsView server running at:');
110
118
  console.log('');
111
119
  console.log(' - Local: http://localhost:' + port + '/');
112
- getIPAddress().forEach(ip => {
120
+ for(const ip of ipAddrs) {
113
121
  console.log(' - Network: http://' + ip + ':' + port + '/');
114
- });
122
+ }
115
123
  console.log('');
116
124
  });
117
125
  }
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
4
  const crypto = require('crypto');
4
5
  const fs = require('fs');
@@ -70,7 +71,7 @@ async function prepareMainAppData(options, fileMd5)
70
71
  }
71
72
  // const appConfigText = fs.readFileSync(appConfigFile);
72
73
  // const appDataOriginJson = JSON.parse(appConfigText);
73
- appDataOriginJson = await import(appConfigFile);
74
+ const appDataOriginJson = await import(appConfigFile);
74
75
 
75
76
  // 组装AppData
76
77
  let targetAppData = {};
@@ -157,15 +158,16 @@ function makeDebugMap(options)
157
158
  process.exit(1);
158
159
  }
159
160
 
160
- const to = path.resolve(options.debugDir, jsmapServeName);
161
+ const to = path.resolve(options.distDebugDir, jsmapServeName);
161
162
  console.log(' -> ' + path.relative(options.projectDir, to));
162
163
  fs.copyFileSync(jsmapServePath, to);
163
164
  }
164
165
 
165
- async function main() {
166
+ async function main()
167
+ {
166
168
  const options = getOptions();
167
169
 
168
- vueConfigFile = path.resolve(options.projectDir, 'vue.config.js');
170
+ const vueConfigFile = path.resolve(options.projectDir, 'vue.config.js');
169
171
  if (fs.existsSync(vueConfigFile)) {
170
172
  vueCfgObj = require(vueConfigFile);
171
173
  if(vueCfgObj.outputDir) {
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
4
  const fs = require('fs');
4
5
  const path = require('path');
@@ -6,12 +7,14 @@ const url = require('url');
6
7
  const {
7
8
  cpSync,
8
9
  getOptions,
10
+ getPackageObject,
9
11
  parseArguments,
10
12
  symlinkSync,
11
13
  rmSync
12
14
  } = require('./jsview-common');
13
15
 
14
- function checkNpmCommand() {
16
+ function checkNpmCommand()
17
+ {
15
18
  let command = process.env.npm_command;
16
19
  if(!command) {
17
20
  command = process.env.npm_config_refer; // for linux
@@ -26,10 +29,11 @@ function checkNpmCommand() {
26
29
  console.warn();
27
30
  }
28
31
 
29
- function checkNpmLinkForDebug(options, linkablePkgNames) {
30
- const pkgObj = getPackageObject(options, options.projectDir, '.');
32
+ function checkNpmLinkForDebug(options, linkablePkgNames)
33
+ {
34
+ const pkgObj = getPackageObject(options.projectDir);
31
35
 
32
- for (linkableName of linkablePkgNames) {
36
+ for (const linkableName of linkablePkgNames) {
33
37
  let linkableTarget = pkgObj.dependencies?.[linkableName];
34
38
  if (!linkableTarget || !linkableTarget.startsWith('file:')) {
35
39
  continue;
@@ -42,26 +46,17 @@ function checkNpmLinkForDebug(options, linkablePkgNames) {
42
46
  }
43
47
  }
44
48
 
45
- function getPackageObject(options, dir, name)
49
+ function checkPatches(options, pkgNeedPatch, skipCheckVersion)
46
50
  {
47
- const pkgFullFile = path.resolve(dir, name, 'package.json');
48
- if (!fs.existsSync(pkgFullFile)) {
49
- console.error('Error: Failed to get "' + path.relative(options.projectDir, pkgFullFile) + '" is not exists.');
50
- process.exit(1);
51
- }
52
- const pkgObj = require(pkgFullFile);
53
-
54
- return pkgObj;
55
- }
56
-
57
- function checkPatches(options, pkgNeedPatch, skipCheckVersion) {
58
51
  console.info('Checking package:');
59
- for (pkgName of pkgNeedPatch) {
52
+ for (const pkgName of pkgNeedPatch) {
60
53
  if (skipCheckVersion !== true) {
61
- const patchPkgObj = getPackageObject(options, options.jsviewPatchModulesDir, pkgName);
54
+ const patchPkgDir = path.resolve(options.jsviewPatchModulesDir, pkgName);
55
+ const patchPkgObj = getPackageObject(patchPkgDir);
62
56
  console.info(' ' + pkgName + ': ' + patchPkgObj.version);
63
57
 
64
- const modulePkgObj = getPackageObject(options, options.modulesDir, pkgName);
58
+ const modulePkgDir = path.resolve(options.modulesDir, pkgName);
59
+ const modulePkgObj = getPackageObject(modulePkgDir);
65
60
  if (modulePkgObj.version != patchPkgObj.version) {
66
61
  console.error('Error: ' + pkgName + '@' + modulePkgObj.version + ' is not supported, required version is ' + patchPkgObj.version);
67
62
  process.exit(1);
@@ -72,9 +67,10 @@ function checkPatches(options, pkgNeedPatch, skipCheckVersion) {
72
67
  }
73
68
  }
74
69
 
75
- function installPatches(options, pkgNeedPatch) {
70
+ function installPatches(options, pkgNeedPatch)
71
+ {
76
72
  console.info('\nPatching JsView:');
77
- for (pkgName of pkgNeedPatch) {
73
+ for (const pkgName of pkgNeedPatch) {
78
74
  const patchSrc = path.resolve(options.jsviewPatchModulesDir, pkgName);
79
75
  const patchDest = path.resolve(options.modulesDir, pkgName);
80
76
 
@@ -85,7 +81,8 @@ function installPatches(options, pkgNeedPatch) {
85
81
  rmSync(options.cacheDir);
86
82
  }
87
83
 
88
- async function printRevision(options) {
84
+ async function printRevision(options)
85
+ {
89
86
  const jsviewVersionURL = url.pathToFileURL(options.jsviewRevisionFile);
90
87
  const { default: jsviewTargetVersion } = await import(jsviewVersionURL);
91
88
 
@@ -100,8 +97,9 @@ async function printRevision(options) {
100
97
  {
101
98
  let pluginDirPath = path.resolve(options.jsviewFrameworkDir, 'utils', 'JsViewPlugin');
102
99
  if(fs.existsSync(pluginDirPath)) {
103
- fs.readdirSync(pluginDirPath).forEach((file) => {
104
- 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);
105
103
  if (fs.statSync(pathname).isDirectory()) {
106
104
  let versionFilePath = path.resolve(pathname, 'version.js');
107
105
  if (fs.existsSync(versionFilePath)) {
@@ -112,7 +110,7 @@ async function printRevision(options) {
112
110
  pluginCount++;
113
111
  }
114
112
  }
115
- })
113
+ }
116
114
  }
117
115
  }
118
116
  console.log(`* total:${pluginCount}`);
@@ -120,7 +118,8 @@ async function printRevision(options) {
120
118
  console.log('**************************************************');
121
119
  }
122
120
 
123
- function doPostInstall(framework, pkgNeedPatch, skipCheckVersion) {
121
+ function doPostInstall(framework, pkgNeedPatch, skipCheckVersion)
122
+ {
124
123
  const options = getOptions(framework);
125
124
  options.projectDir = process.cwd();
126
125
 
@@ -143,7 +142,8 @@ function doPostInstall(framework, pkgNeedPatch, skipCheckVersion) {
143
142
  printRevision(options);
144
143
  }
145
144
 
146
- function main(argv) {
145
+ function main(argv)
146
+ {
147
147
  let pkgNeedPatch;
148
148
 
149
149
  switch (argv.framework) {
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
4
  const childProcess = require('child_process');
4
5
  const path = require('path');
@@ -8,7 +9,8 @@ const {
8
9
  parseArguments
9
10
  } = require('./jsview-common');
10
11
 
11
- async function getExtraOptions(argv) {
12
+ async function getExtraOptions(argv)
13
+ {
12
14
  const options = getOptions(argv.framework);
13
15
  options.androidPackage = 'com.tvcode.sjcenter/com.tvcode.chmarket.MainActivity';
14
16
  options.jsviewCoreRevision = null;
@@ -36,7 +38,8 @@ async function getExtraOptions(argv) {
36
38
  return options;
37
39
  }
38
40
 
39
- function printRevision(options) {
41
+ function printRevision(options)
42
+ {
40
43
  console.log('**************************************************');
41
44
  console.log('* Android Package: ' + options.androidPackage);
42
45
  console.log('* Core: ' + options.jsviewCoreRevision);
@@ -45,7 +48,8 @@ function printRevision(options) {
45
48
  console.log('**************************************************');
46
49
  }
47
50
 
48
- function androidStartActivity(options) {
51
+ function androidStartActivity(options)
52
+ {
49
53
  let cmdline = 'adb shell am start';
50
54
  cmdline += ` -n ${options.androidPackage}`;
51
55
  cmdline += ` --es COREVERSIONRANGE "${options.jsviewCoreRevision}"`;
@@ -59,9 +63,9 @@ function androidStartActivity(options) {
59
63
  }
60
64
  }
61
65
 
62
-
63
66
  const argv = parseArguments(false);
64
- async function main(argv) {
67
+ async function main(argv)
68
+ {
65
69
  const options = await getExtraOptions(argv);
66
70
 
67
71
  printRevision(options);