@shijiu/jsview 1.9.909 → 1.9.914
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-dom-browser.min.js +1 -1
- package/dom/bin/jsview-dom-native.min.js +1 -1
- package/dom/bin/jsview-engine-js-browser.min.js +1 -1
- package/package.json +1 -1
- package/tools/jsview-batch-upgrade.mjs +382 -0
- package/tools/jsview-common.mjs +11 -0
- package/tools/jsview-upgrade.mjs +0 -353
package/tools/jsview-upgrade.mjs
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import url from 'url';
|
|
7
|
-
import {
|
|
8
|
-
checkNodeVersion,
|
|
9
|
-
execCommand,
|
|
10
|
-
parseArguments
|
|
11
|
-
} from './jsview-common.mjs';
|
|
12
|
-
|
|
13
|
-
function askAndAnswer(question)
|
|
14
|
-
{
|
|
15
|
-
process.stdout.write(question)
|
|
16
|
-
let buffer = Buffer.alloc(100)
|
|
17
|
-
fs.readSync(0, buffer, 0, 100)
|
|
18
|
-
let answer = buffer.toString().toLowerCase().replace('\n', '');
|
|
19
|
-
answer = answer.substring(0, answer.indexOf('\0'));
|
|
20
|
-
return answer;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getArgument(argument, usage)
|
|
24
|
-
{
|
|
25
|
-
if (!argument) {
|
|
26
|
-
return argument;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (typeof (argument) != 'string') {
|
|
30
|
-
console.error('JsView Error: ' + usage + ' is not a valid path.');
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
const argumentPath = path.resolve(process.cwd(), argument);
|
|
34
|
-
if (fs.existsSync(argumentPath) == false) {
|
|
35
|
-
console.error('JsView Error: ' + argument + ' is not exists.');
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return argumentPath;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function getOptions(argv)
|
|
43
|
-
{
|
|
44
|
-
const options = {};
|
|
45
|
-
|
|
46
|
-
const scriptPath = path.resolve(process.cwd(), process.argv[1]);
|
|
47
|
-
options.rootDir = scriptPath.replaceAll(/node_modules\/@shijiu\/jsview.*/g, '');
|
|
48
|
-
|
|
49
|
-
options.jsviewVersion = argv.jsviewVersion;
|
|
50
|
-
|
|
51
|
-
options.stagePixel = getArgument(argv.stagePixel, '--stage-pixel');
|
|
52
|
-
options.stageAnimation = getArgument(argv.stageAnimation, '--stage-animation');
|
|
53
|
-
options.stagePkgJson = getArgument(argv.stagePkgJson, '--stage-pkg-json');
|
|
54
|
-
|
|
55
|
-
console.info();
|
|
56
|
-
console.info('Upgrade to JsView version: ' + options.jsviewVersion);
|
|
57
|
-
console.info(' Project folder: ' + options.rootDir);
|
|
58
|
-
console.info('=====================================');
|
|
59
|
-
console.info(' Stage pixel: ' + (options.stagePixel ?? false));
|
|
60
|
-
console.info(' Stage animation: ' + (options.stageAnimation ?? false));
|
|
61
|
-
console.info(' Stage package.json: ' + (options.stagePkgJson ?? false));
|
|
62
|
-
console.info('=====================================');
|
|
63
|
-
|
|
64
|
-
console.info();
|
|
65
|
-
console.info('Are you sure to upgrade it?');
|
|
66
|
-
const answer = askAndAnswer('(y/N) ');
|
|
67
|
-
if (answer.substring(0, 1) != 'y' && answer.substring(0, 3) != 'yes') {
|
|
68
|
-
console.error('JsView Info: User cancelled.')
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return options;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getFilesRecursive(dirPath) {
|
|
76
|
-
const ignoreFileList = [
|
|
77
|
-
'.git',
|
|
78
|
-
'.gitignore',
|
|
79
|
-
'node_modules',
|
|
80
|
-
'package.json',
|
|
81
|
-
'package-lock.json'
|
|
82
|
-
];
|
|
83
|
-
const fileExtList = [
|
|
84
|
-
'!.min.js',
|
|
85
|
-
'.css',
|
|
86
|
-
'.js',
|
|
87
|
-
'.json',
|
|
88
|
-
'.mjs',
|
|
89
|
-
'.vue',
|
|
90
|
-
];
|
|
91
|
-
|
|
92
|
-
let filePathList = [];
|
|
93
|
-
|
|
94
|
-
const fileNameList = fs.readdirSync(dirPath);
|
|
95
|
-
for (const fileName of fileNameList) {
|
|
96
|
-
if (ignoreFileList.includes(fileName)) {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const filePath = path.join(dirPath, fileName);
|
|
101
|
-
if (fs.statSync(filePath).isDirectory()) {
|
|
102
|
-
const subFilePathList = getFilesRecursive(filePath);
|
|
103
|
-
filePathList = [...filePathList, ...subFilePathList];
|
|
104
|
-
} else {
|
|
105
|
-
let needUpgrade = false;
|
|
106
|
-
for (let fileExtName of fileExtList) {
|
|
107
|
-
if (fileExtName.startsWith('!')) { // 强制忽略该文件
|
|
108
|
-
fileExtName = fileExtName.substring(1);
|
|
109
|
-
if (filePath.endsWith(fileExtName)) {
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
if (filePath.endsWith(fileExtName)) {
|
|
114
|
-
needUpgrade = true;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (needUpgrade == false) {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const fileExtName = path.extname(filePath);
|
|
124
|
-
if (fileExtList.includes(fileExtName) == false) {
|
|
125
|
-
continue;
|
|
126
|
-
} else if (fileExtList.includes('!' + fileExtName)) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
filePathList.push(filePath);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return filePathList;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function upgradeStagePixel(options) {
|
|
137
|
-
console.info('Upgrading stage pixel...');
|
|
138
|
-
|
|
139
|
-
const filePathList = getFilesRecursive(options.stagePixel);
|
|
140
|
-
|
|
141
|
-
for (const filePath of filePathList) {
|
|
142
|
-
try {
|
|
143
|
-
let content = fs.readFileSync(filePath, 'utf8');
|
|
144
|
-
|
|
145
|
-
content = content.replaceAll(/([0-9])px/g, '$1');
|
|
146
|
-
|
|
147
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
148
|
-
} catch (ex) {
|
|
149
|
-
console.error('JsView Error: Failed to update pixel for file: ' + filePath);
|
|
150
|
-
console.error(ex);
|
|
151
|
-
process.exit(1);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
console.info('Upgraded stage pixel...');
|
|
156
|
-
|
|
157
|
-
return 0;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function upgradeStageAnimation(options)
|
|
161
|
-
{
|
|
162
|
-
console.info('Upgrading stage animation...');
|
|
163
|
-
|
|
164
|
-
if (typeof (options.stageAnimation) != 'string'
|
|
165
|
-
|| fs.existsSync(options.stageAnimation) == false) {
|
|
166
|
-
console.error('JsView Error: --stage-animation is not a valid path.');
|
|
167
|
-
process.exit(1);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const filePathList = getFilesRecursive(options.stageAnimation);
|
|
171
|
-
|
|
172
|
-
for (const filePath of filePathList) {
|
|
173
|
-
try {
|
|
174
|
-
let content = fs.readFileSync(filePath, 'utf8');
|
|
175
|
-
|
|
176
|
-
content = content.replaceAll(':onAnimationEnd', '@animationend');
|
|
177
|
-
|
|
178
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
179
|
-
} catch (ex) {
|
|
180
|
-
console.error('JsView Error: Failed to update animation for file: ' + filePath);
|
|
181
|
-
console.error(ex);
|
|
182
|
-
process.exit(1);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
console.info('Upgraded stage animation...');
|
|
187
|
-
|
|
188
|
-
return 0;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function getFramework(pkgJsonFilePath)
|
|
192
|
-
{
|
|
193
|
-
if (fs.existsSync(pkgJsonFilePath) == false) {
|
|
194
|
-
console.error('JsView Error: Failed to find package.json: ' + pkgJsonFilePath);
|
|
195
|
-
process.exit(1);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
let framework = 'unknown';
|
|
199
|
-
|
|
200
|
-
const content = fs.readFileSync(pkgJsonFilePath, 'utf8');
|
|
201
|
-
const pkgObj = JSON.parse(content);
|
|
202
|
-
if (pkgObj.dependencies?.vue) {
|
|
203
|
-
framework = 'vue';
|
|
204
|
-
} else if (pkgObj.dependencies?.react) {
|
|
205
|
-
framework = 'react';
|
|
206
|
-
} else {
|
|
207
|
-
console.error('JsView Error: Failed to recognize framework.');
|
|
208
|
-
process.exit(1);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return framework;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function upgradeVueStagePackageJson(options)
|
|
215
|
-
{
|
|
216
|
-
console.info('Upgrading stage package.json...');
|
|
217
|
-
|
|
218
|
-
const needRemovePkgs = [
|
|
219
|
-
// dependencies
|
|
220
|
-
'@shijiu/jsview-vue',
|
|
221
|
-
'core-js',
|
|
222
|
-
'deepmerge',
|
|
223
|
-
'fork-ts-checker-webpack-plugin',
|
|
224
|
-
'gifuct-js',
|
|
225
|
-
'qr.js',
|
|
226
|
-
'vue',
|
|
227
|
-
'vue-router',
|
|
228
|
-
|
|
229
|
-
// devDependencies
|
|
230
|
-
'@typescript-eslint/eslint-plugin',
|
|
231
|
-
'@typescript-eslint/parser',
|
|
232
|
-
'@vue/cli-plugin-babel',
|
|
233
|
-
'@vue/cli-plugin-eslint',
|
|
234
|
-
'@vue/cli-plugin-typescript',
|
|
235
|
-
'@vue/cli-service',
|
|
236
|
-
'@vue/compiler-sfc',
|
|
237
|
-
'@vue/eslint-config-typescript',
|
|
238
|
-
'babel-eslint',
|
|
239
|
-
'cache-loader',
|
|
240
|
-
'cosmiconfig',
|
|
241
|
-
'eslint',
|
|
242
|
-
'eslint-plugin-node',
|
|
243
|
-
'eslint-plugin-promise',
|
|
244
|
-
'eslint-plugin-standard',
|
|
245
|
-
'eslint-plugin-vue',
|
|
246
|
-
'fork-ts-checker-webpack-plugin-v5',
|
|
247
|
-
'postcss-import-sync',
|
|
248
|
-
'postcss-js',
|
|
249
|
-
'typescript',
|
|
250
|
-
'vue-class-component',
|
|
251
|
-
'webpack',
|
|
252
|
-
];
|
|
253
|
-
|
|
254
|
-
const needAppendPkgs = {
|
|
255
|
-
'@shijiu/jsview': '1.9.888',
|
|
256
|
-
'@shijiu/jsview-vue': '1.9.888',
|
|
257
|
-
'vue': '3.2.45',
|
|
258
|
-
'vue-router': '4.1.6',
|
|
259
|
-
};
|
|
260
|
-
const needAppendDevPkgs = {
|
|
261
|
-
'@vitejs/plugin-vue': '4.0.0',
|
|
262
|
-
'typescript': '4.9.3',
|
|
263
|
-
'vite': '4.0.0',
|
|
264
|
-
'vue-tsc': '1.0.11',
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
if (typeof (options.stagePkgJson) != 'string'
|
|
268
|
-
|| fs.existsSync(options.stagePkgJson) == false) {
|
|
269
|
-
console.error('JsView Error: --stage-pkg-json is not a valid path.');
|
|
270
|
-
process.exit(1);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
try {
|
|
274
|
-
let content = fs.readFileSync(options.stagePkgJson, 'utf8');
|
|
275
|
-
const pkgObj = JSON.parse(content);
|
|
276
|
-
|
|
277
|
-
// 删除旧内容
|
|
278
|
-
delete pkgObj.main;
|
|
279
|
-
delete pkgObj.eslintConfig;
|
|
280
|
-
delete pkgObj.scripts.lint;
|
|
281
|
-
delete pkgObj.scripts.serve;
|
|
282
|
-
for (const removePkg of needRemovePkgs) {
|
|
283
|
-
delete pkgObj.dependencies[removePkg];
|
|
284
|
-
delete pkgObj.devDependencies[removePkg];
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// 添加新内容
|
|
288
|
-
pkgObj.type = 'module';
|
|
289
|
-
pkgObj.scripts.android = 'node node_modules/@shijiu/jsview/tools/jsview-run-android.mjs --framework=vue';
|
|
290
|
-
pkgObj.scripts.build = 'vue-tsc && vite build && node node_modules/@shijiu/jsview/tools/jsview-post-build.mjs --framework=vue';
|
|
291
|
-
pkgObj.scripts.dev = 'vite';
|
|
292
|
-
pkgObj.scripts.postinstall = 'node node_modules/@shijiu/jsview/tools/jsview-post-install.mjs --framework=vue';
|
|
293
|
-
pkgObj.scripts.preview = 'vite preview';
|
|
294
|
-
pkgObj.scripts.start = 'vite';
|
|
295
|
-
pkgObj.browserslist = ['chrome 102', 'not dead'];
|
|
296
|
-
|
|
297
|
-
for (const [key, value] of Object.entries(needAppendPkgs)) {
|
|
298
|
-
pkgObj.dependencies[key] = value;
|
|
299
|
-
}
|
|
300
|
-
for (const [key, value] of Object.entries(needAppendDevPkgs)) {
|
|
301
|
-
pkgObj.devDependencies[key] = value;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
content = JSON.stringify(pkgObj, null, 2);
|
|
305
|
-
fs.writeFileSync(options.stagePkgJson, content, 'utf8');
|
|
306
|
-
} catch (ex) {
|
|
307
|
-
console.error('JsView Error: Failed to update package.json: ' + options.stagePkgJson);
|
|
308
|
-
console.error(ex);
|
|
309
|
-
process.exit(1);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
execCommand('npm install');
|
|
313
|
-
|
|
314
|
-
console.info('Upgraded stage package.json...');
|
|
315
|
-
|
|
316
|
-
return 0;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
function main(argv)
|
|
320
|
-
{
|
|
321
|
-
checkNodeVersion();
|
|
322
|
-
|
|
323
|
-
const options = getOptions(argv);
|
|
324
|
-
|
|
325
|
-
if (options.stagePixel) {
|
|
326
|
-
upgradeStagePixel(options);
|
|
327
|
-
}
|
|
328
|
-
if (options.stageAnimation) {
|
|
329
|
-
upgradeStageAnimation(options);
|
|
330
|
-
}
|
|
331
|
-
if (options.stagePkgJson) {
|
|
332
|
-
const framework = getFramework(options.stagePkgJson);
|
|
333
|
-
if (framework == 'vue') {
|
|
334
|
-
upgradeVueStagePackageJson(options);
|
|
335
|
-
} else {
|
|
336
|
-
console.error('JsView Error: Upgrade ' + framework + ' package.json is not implementation.');
|
|
337
|
-
process.exit(1);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const requiredUsages = {
|
|
343
|
-
'--jsv | --jsview-version': 'The version of jsview that is expected to be upgraded.',
|
|
344
|
-
};
|
|
345
|
-
const optionalUsages = {
|
|
346
|
-
'--stage-animation': 'Fix animations, value is a directory.',
|
|
347
|
-
'--stage-app-config': 'Upgrade appConfig to new version.',
|
|
348
|
-
'--stage-main-js': 'Upgrade main.js to new version.',
|
|
349
|
-
'--stage-pixel': 'Fix pixels, value is a directory.',
|
|
350
|
-
'--stage-pkg-json': 'Upgrade package.json to new version.',
|
|
351
|
-
};
|
|
352
|
-
const argv = parseArguments(requiredUsages, optionalUsages, false);
|
|
353
|
-
main(argv)
|