@shijiu/jsview 1.9.992 → 2.0.1002
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.
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const TargetRevision = {
|
|
6
|
-
"CoreRevision":
|
|
7
|
-
"CoreRevisionAndBranch": "
|
|
6
|
+
"CoreRevision": 1021330,
|
|
7
|
+
"CoreRevisionAndBranch": "1021330",
|
|
8
8
|
"JseRevision": "1.0.881",
|
|
9
9
|
"JseUrl":
|
|
10
10
|
"http://cdn.release.qcast.cn/forge_js/master/JsViewES6_js2c_r881.jsv.bf42e49e.js"
|
package/loader/jsview-main.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import AppData from '/src/appConfig/app.config'
|
|
2
|
-
import JsViewVendorConfig from "/src/appConfig/jsview.config"
|
|
1
|
+
import AppData from '/src/appConfig/app.config.mjs'
|
|
2
|
+
import JsViewVendorConfig from "/src/appConfig/jsview.config.mjs"
|
|
3
3
|
|
|
4
4
|
async function main() {
|
|
5
5
|
let JsViewLoader = null;
|
package/package.json
CHANGED
|
@@ -3,34 +3,92 @@
|
|
|
3
3
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import url from 'url';
|
|
7
6
|
import {
|
|
8
7
|
askAndAnswer,
|
|
9
8
|
checkNodeVersion,
|
|
10
|
-
execCommand,
|
|
11
9
|
parseArguments
|
|
12
10
|
} from './jsview-common.mjs';
|
|
13
11
|
|
|
12
|
+
function main(argv)
|
|
13
|
+
{
|
|
14
|
+
checkNodeVersion();
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const options = getOptions(argv);
|
|
18
|
+
|
|
19
|
+
// Stage 1
|
|
20
|
+
if (options.stages.includes(options.stageAlias)) {
|
|
21
|
+
upgradeStageAlias(options);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Stage 2
|
|
25
|
+
if (options.stages.includes(options.stageImportPostfix)) {
|
|
26
|
+
upgradeStageImportPostfix(options);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Stage 3
|
|
30
|
+
if (options.stages.includes(options.stageCommonJS)) {
|
|
31
|
+
upgradeStageCommonJS(options);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Stage 4
|
|
35
|
+
if (options.stages.includes(options.stageHashHistory)) {
|
|
36
|
+
upgradeStageHashHistory(options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Stage 5
|
|
40
|
+
if (options.stages.includes(options.stageAnimation)) {
|
|
41
|
+
upgradeStageAnimation(options);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Stage 6
|
|
45
|
+
if (options.stages.includes(options.stagePixels)) {
|
|
46
|
+
upgradeStagePixel(options);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Stage 7
|
|
50
|
+
if (options.stages.includes(options.stageAudiotrack)) {
|
|
51
|
+
upgradeStageAudiotrack(options);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Stage 8
|
|
55
|
+
if (options.stages.includes(options.stageAppConfig)) {
|
|
56
|
+
upgradeStageAppConfig(options);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Stage 9
|
|
60
|
+
if (options.stages.includes(options.stageMainEntry)) {
|
|
61
|
+
upgradeStageMainEntry(options);
|
|
62
|
+
}
|
|
63
|
+
} catch (ex) {
|
|
64
|
+
console.error('JsView Error: Failed to update jsview source!');
|
|
65
|
+
console.error(ex);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.error('JsView Info: Done!');
|
|
70
|
+
}
|
|
71
|
+
|
|
14
72
|
function getOptions(argv)
|
|
15
73
|
{
|
|
16
74
|
const options = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
75
|
+
stageAlias: '1',
|
|
76
|
+
stageImportPostfix: '2',
|
|
77
|
+
stageCommonJS: '3',
|
|
78
|
+
stageHashHistory: '4',
|
|
79
|
+
stageAnimation: '5',
|
|
80
|
+
stagePixels: '6',
|
|
81
|
+
stageAudiotrack: '7',
|
|
82
|
+
stageAppConfig: '8',
|
|
83
|
+
stageMainEntry: '9',
|
|
24
84
|
};
|
|
25
85
|
|
|
26
|
-
|
|
27
|
-
options.rootDir = scriptPath.replaceAll(/node_modules\/@shijiu\/jsview.*/g, '');
|
|
28
|
-
options.rootDir = options.rootDir.replaceAll(/node_modules\\@shijiu\\jsview.*/g, ''); // for windows
|
|
86
|
+
options.projectDir = process.cwd();
|
|
29
87
|
|
|
30
88
|
options.stages = argv.stages?.split(',') ?? [];
|
|
31
89
|
|
|
32
|
-
const defaultUpgradeDir =
|
|
33
|
-
options.upgradeDir = path.resolve(
|
|
90
|
+
const defaultUpgradeDir = 'src';
|
|
91
|
+
options.upgradeDir = path.resolve(options.projectDir, argv.dir ?? defaultUpgradeDir);
|
|
34
92
|
if (fs.existsSync(options.upgradeDir) == false) {
|
|
35
93
|
console.error('JsView Error: Upgrade dir [' + options.upgradeDir + '] is not exists.');
|
|
36
94
|
process.exit(1);
|
|
@@ -38,9 +96,9 @@ function getOptions(argv)
|
|
|
38
96
|
|
|
39
97
|
console.info();
|
|
40
98
|
console.info('Upgrade JsView source: ');
|
|
41
|
-
console.info(' Project folder: ' + options.
|
|
99
|
+
console.info(' Project folder: ' + options.projectDir);
|
|
42
100
|
console.info('=====================================');
|
|
43
|
-
console.info(' Upgrade folder: ' + path.relative(options.
|
|
101
|
+
console.info(' Upgrade folder: ' + path.relative(options.projectDir, options.upgradeDir));
|
|
44
102
|
console.info(' Stages: [ ' + options.stages.join(', ') + ' ]');
|
|
45
103
|
console.info('=====================================');
|
|
46
104
|
|
|
@@ -57,118 +115,129 @@ function getOptions(argv)
|
|
|
57
115
|
return options;
|
|
58
116
|
}
|
|
59
117
|
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
'node_modules',
|
|
65
|
-
'package.json',
|
|
66
|
-
'package-lock.json'
|
|
67
|
-
];
|
|
68
|
-
const fileExtList = [
|
|
69
|
-
'!.d.ts',
|
|
70
|
-
'!.min.js',
|
|
71
|
-
'.css',
|
|
72
|
-
'.js',
|
|
73
|
-
'.json',
|
|
74
|
-
'.mjs',
|
|
75
|
-
'.ts',
|
|
76
|
-
'.tsx',
|
|
77
|
-
'.vue',
|
|
78
|
-
];
|
|
118
|
+
function upgradeStageAlias(options)
|
|
119
|
+
{
|
|
120
|
+
const msgPrefix = 'Stage ' + options.stageAlias;
|
|
121
|
+
console.info(msgPrefix + ': upgrading alias @ => /src ...');
|
|
79
122
|
|
|
80
|
-
|
|
123
|
+
const amendImportAlias = function(content) {
|
|
124
|
+
if (isImportSyntax(content) == false) {
|
|
125
|
+
return content;
|
|
126
|
+
}
|
|
81
127
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
continue;
|
|
128
|
+
let filePath = getImportFilePath(content);
|
|
129
|
+
if (!filePath || filePath.startsWith('@/') == false) {
|
|
130
|
+
return content;
|
|
86
131
|
}
|
|
87
132
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const subFilePathList = getFilesRecursive(filePath);
|
|
91
|
-
filePathList = [...filePathList, ...subFilePathList];
|
|
92
|
-
} else {
|
|
93
|
-
let needUpgrade = false;
|
|
94
|
-
for (let fileExtName of fileExtList) {
|
|
95
|
-
if (fileExtName.startsWith('!')) { // 强制忽略该文件
|
|
96
|
-
fileExtName = fileExtName.substring(1);
|
|
97
|
-
if (filePath.endsWith(fileExtName)) {
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
if (filePath.endsWith(fileExtName)) {
|
|
102
|
-
needUpgrade = true;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (needUpgrade == false) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
133
|
+
let fixedFilePath = filePath.replace(/^@\//, '/src/');
|
|
134
|
+
const fixedContent = content.replace(filePath, fixedFilePath);
|
|
110
135
|
|
|
111
|
-
|
|
112
|
-
if (fileExtList.includes(fileExtName) == false) {
|
|
113
|
-
continue;
|
|
114
|
-
} else if (fileExtList.includes('!' + fileExtName)) {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
filePathList.push(filePath);
|
|
118
|
-
}
|
|
136
|
+
return fixedContent;
|
|
119
137
|
}
|
|
120
138
|
|
|
121
|
-
|
|
139
|
+
processSourceLineByLine(options, options.sourcePathList, msgPrefix, amendImportAlias);
|
|
140
|
+
|
|
141
|
+
return;
|
|
122
142
|
}
|
|
123
143
|
|
|
124
|
-
function
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
144
|
+
function upgradeStageImportPostfix(options)
|
|
145
|
+
{
|
|
146
|
+
const msgPrefix = 'Stage ' + options.stageImportPostfix;
|
|
147
|
+
console.info(msgPrefix + ': upgrading import postfix...');
|
|
128
148
|
|
|
129
|
-
|
|
130
|
-
if (
|
|
131
|
-
|
|
149
|
+
const amendImportPostfix = function (content, sourceDir) {
|
|
150
|
+
if (isImportSyntax(content) == false) {
|
|
151
|
+
return content;
|
|
132
152
|
}
|
|
133
153
|
|
|
134
|
-
|
|
135
|
-
|
|
154
|
+
let filePath = getImportFilePath(content);
|
|
155
|
+
if (!filePath) {
|
|
156
|
+
return content;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let fixedFilePath = null;
|
|
160
|
+
if (filePath.startsWith('/')) {
|
|
161
|
+
fixedFilePath = path.resolve(options.projectDir, filePath.replace('/', ''));
|
|
162
|
+
} else if (filePath.startsWith('@/')) {
|
|
163
|
+
fixedFilePath = path.resolve(options.projectDir, 'src', filePath.replace('@/', ''));
|
|
164
|
+
} else {
|
|
165
|
+
fixedFilePath = path.resolve(sourceDir, filePath);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 执行到此处,则需要给给import的文件加上尾缀。
|
|
169
|
+
// 当同时存在.js和.vue时,.js优先。
|
|
170
|
+
let fixedContent = content;
|
|
171
|
+
if (fs.existsSync(fixedFilePath + '.js')) {
|
|
172
|
+
fixedContent = content.replace(filePath, filePath + '.js');
|
|
173
|
+
} else if (fs.existsSync(fixedFilePath + '/index.js')) {
|
|
174
|
+
fixedContent = content.replace(filePath, filePath + '/index.js');
|
|
175
|
+
} else if (fs.existsSync(fixedFilePath + '.vue')) {
|
|
176
|
+
fixedContent = content.replace(filePath, filePath + '.vue');
|
|
177
|
+
} else if (fs.existsSync(fixedFilePath + '/index.vue')) {
|
|
178
|
+
fixedContent = content.replace(filePath, filePath + '/index.vue');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return fixedContent;
|
|
136
182
|
}
|
|
137
183
|
|
|
184
|
+
processSourceLineByLine(options, options.sourcePathList, msgPrefix, amendImportPostfix);
|
|
185
|
+
|
|
138
186
|
return;
|
|
139
187
|
}
|
|
140
188
|
|
|
141
|
-
function
|
|
142
|
-
fromExtNameList, toExtName)
|
|
189
|
+
function upgradeStageCommonJS(options)
|
|
143
190
|
{
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
for (const extName of fromExtNameList) {
|
|
147
|
-
if (filePath.endsWith(extName)) {
|
|
148
|
-
fromExtName = extName;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (fromExtName == null) {
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
191
|
+
const msgPrefix = 'Stage ' + options.stageCommonJS;
|
|
192
|
+
console.info(msgPrefix + ': upgrading commonjs ...');
|
|
155
193
|
|
|
156
|
-
|
|
157
|
-
|
|
194
|
+
const amendCommonJS = function(content) {
|
|
195
|
+
let fixedContent = content;
|
|
158
196
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
197
|
+
if (content.includes('module.exports')) {
|
|
198
|
+
let replaceTo = 'export default';
|
|
199
|
+
if (content.includes('{')) {
|
|
200
|
+
replaceTo = 'export ';
|
|
201
|
+
}
|
|
202
|
+
fixedContent = content.replace(/module.exports.*=/, replaceTo);
|
|
203
|
+
} else if (content.match(/=.*require.*\(.*\)/)) {
|
|
204
|
+
let name = content.replace(/(.*)=.*require.*/, '$1').trim();
|
|
205
|
+
name = name.replace(/.* /, '');
|
|
206
|
+
const filePath = content.replace(/.*=.*require.*\((.*)\)/, '$1').trim();
|
|
207
|
+
|
|
208
|
+
fixedContent = `import ${name} from ${filePath}`
|
|
164
209
|
}
|
|
165
210
|
|
|
166
|
-
|
|
211
|
+
return fixedContent;
|
|
167
212
|
}
|
|
168
213
|
|
|
214
|
+
processSourceLineByLine(options, options.sourcePathList, msgPrefix, amendCommonJS);
|
|
215
|
+
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function upgradeStageHashHistory(options)
|
|
220
|
+
{
|
|
221
|
+
const msgPrefix = 'Stage ' + options.stageHashHistory;
|
|
222
|
+
console.info(msgPrefix + ': Upgrading hash history...');
|
|
223
|
+
|
|
224
|
+
replaceStageContent(options, options.sourcePathList, msgPrefix,
|
|
225
|
+
'createJsvHashHistory', 'jsvCreateHashHistory');
|
|
226
|
+
|
|
169
227
|
return;
|
|
170
228
|
}
|
|
171
229
|
|
|
230
|
+
function upgradeStageAnimation(options)
|
|
231
|
+
{
|
|
232
|
+
const msgPrefix = 'Stage ' + options.stageAnimation;
|
|
233
|
+
console.info(msgPrefix + ': Upgrading animation...');
|
|
234
|
+
|
|
235
|
+
const ret = replaceStageContent(options, options.sourcePathList, msgPrefix,
|
|
236
|
+
':onAnimationEnd', '@animationend');
|
|
237
|
+
|
|
238
|
+
return ret;
|
|
239
|
+
}
|
|
240
|
+
|
|
172
241
|
function upgradeStagePixel(options) {
|
|
173
242
|
const msgPrefix = 'Stage ' + options.stagePixels;
|
|
174
243
|
console.info(msgPrefix + ': Upgrading pixels...');
|
|
@@ -219,28 +288,6 @@ function upgradeStagePixel(options) {
|
|
|
219
288
|
return;
|
|
220
289
|
}
|
|
221
290
|
|
|
222
|
-
function upgradeStageAnimation(options)
|
|
223
|
-
{
|
|
224
|
-
const msgPrefix = 'Stage ' + options.stageAnimation;
|
|
225
|
-
console.info(msgPrefix + ': Upgrading animation...');
|
|
226
|
-
|
|
227
|
-
const ret = replaceStageContent(options, options.sourcePathList, msgPrefix,
|
|
228
|
-
':onAnimationEnd', '@animationend');
|
|
229
|
-
|
|
230
|
-
return ret;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function upgradeStageHashHistory(options)
|
|
234
|
-
{
|
|
235
|
-
const msgPrefix = 'Stage ' + options.stageHashHistory;
|
|
236
|
-
console.info(msgPrefix + ': Upgrading hash history...');
|
|
237
|
-
|
|
238
|
-
replaceStageContent(options, options.sourcePathList, msgPrefix,
|
|
239
|
-
'createJsvHashHistory', 'jsvCreateHashHistory');
|
|
240
|
-
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
291
|
function upgradeStageAudiotrack(options)
|
|
245
292
|
{
|
|
246
293
|
const msgPrefix = 'Stage ' + options.stageAudiotrack;
|
|
@@ -252,66 +299,6 @@ function upgradeStageAudiotrack(options)
|
|
|
252
299
|
return;
|
|
253
300
|
}
|
|
254
301
|
|
|
255
|
-
function upgradeStageImportPostfix(options)
|
|
256
|
-
{
|
|
257
|
-
const msgPrefix = 'Stage ' + options.stageImportPostfix;
|
|
258
|
-
console.info(msgPrefix + ': upgrading import postfix...');
|
|
259
|
-
|
|
260
|
-
const amendImportPostfix = function(currentDir, content) {
|
|
261
|
-
if (content.trim().startsWith('import') == false) {
|
|
262
|
-
return content;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
let importFromFile = content.replaceAll(/.*'(.*)'.*/g, '$1');
|
|
266
|
-
if (importFromFile === content) {
|
|
267
|
-
importFromFile = content.replaceAll(/.*"\(\)".*/g, "$1");
|
|
268
|
-
}
|
|
269
|
-
if (importFromFile === content) {
|
|
270
|
-
return content;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
let fixedContent = content;
|
|
274
|
-
|
|
275
|
-
let importFilePath = null;
|
|
276
|
-
if (importFromFile.startsWith('@')) {
|
|
277
|
-
importFilePath = path.resolve(options.rootDir, 'src', importFromFile.replace('@/', ''));
|
|
278
|
-
} else {
|
|
279
|
-
importFilePath = path.resolve(currentDir, importFromFile);
|
|
280
|
-
}
|
|
281
|
-
if (fs.existsSync(importFilePath + '.js')) {
|
|
282
|
-
// 执行到此处,则需要给给import的文件加上js尾缀。当同时存在.js和.vue时,.js优先。
|
|
283
|
-
fixedContent = content.replace(importFromFile, importFromFile + '.js');
|
|
284
|
-
} else if (fs.existsSync(importFilePath + '.vue')) {
|
|
285
|
-
// 执行到此处,则需要给给import的文件加上vue尾缀。
|
|
286
|
-
fixedContent = content.replace(importFromFile, importFromFile + '.vue');
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return fixedContent;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
for (const filePath of options.sourcePathList) {
|
|
293
|
-
const currentDir = path.dirname(filePath);
|
|
294
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
295
|
-
|
|
296
|
-
const lineContentList = content.split('\n');
|
|
297
|
-
for (let idx = 0; idx < lineContentList.length; idx++) {
|
|
298
|
-
let lineContent = lineContentList[idx];
|
|
299
|
-
lineContent = amendImportPostfix(currentDir, lineContent);
|
|
300
|
-
lineContentList[idx] = lineContent;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const fixedContent = lineContentList.join('\n');
|
|
304
|
-
if (fixedContent == content) {
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
fs.writeFileSync(filePath, fixedContent, 'utf8');
|
|
309
|
-
console.info(msgPrefix + ': Upgraded ' + path.relative(options.rootDir, filePath));
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
302
|
function upgradeStageAppConfig(options)
|
|
316
303
|
{
|
|
317
304
|
const msgPrefix = 'Stage ' + options.stageAppConfig;
|
|
@@ -358,65 +345,205 @@ function upgradeStageMainEntry(options)
|
|
|
358
345
|
return;
|
|
359
346
|
}
|
|
360
347
|
|
|
361
|
-
function
|
|
362
|
-
|
|
363
|
-
|
|
348
|
+
function getFilesRecursive(dirPath) {
|
|
349
|
+
const ignoreFileList = [
|
|
350
|
+
'.git',
|
|
351
|
+
'.gitignore',
|
|
352
|
+
'node_modules',
|
|
353
|
+
'package.json',
|
|
354
|
+
'package-lock.json'
|
|
355
|
+
];
|
|
356
|
+
const fileExtList = [
|
|
357
|
+
'!.d.ts',
|
|
358
|
+
'!.min.js',
|
|
359
|
+
'.css',
|
|
360
|
+
'.js',
|
|
361
|
+
'.json',
|
|
362
|
+
'.mjs',
|
|
363
|
+
'.ts',
|
|
364
|
+
'.tsx',
|
|
365
|
+
'.vue',
|
|
366
|
+
];
|
|
364
367
|
|
|
365
|
-
|
|
366
|
-
const options = getOptions(argv);
|
|
368
|
+
let filePathList = [];
|
|
367
369
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
370
|
+
const fileNameList = fs.readdirSync(dirPath);
|
|
371
|
+
for (const fileName of fileNameList) {
|
|
372
|
+
if (ignoreFileList.includes(fileName)) {
|
|
373
|
+
continue;
|
|
371
374
|
}
|
|
372
375
|
|
|
373
|
-
|
|
374
|
-
if (
|
|
375
|
-
|
|
376
|
+
const filePath = path.join(dirPath, fileName);
|
|
377
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
378
|
+
const subFilePathList = getFilesRecursive(filePath);
|
|
379
|
+
filePathList = [...filePathList, ...subFilePathList];
|
|
380
|
+
} else {
|
|
381
|
+
let needUpgrade = false;
|
|
382
|
+
for (let fileExtName of fileExtList) {
|
|
383
|
+
if (fileExtName.startsWith('!')) { // 强制忽略该文件
|
|
384
|
+
fileExtName = fileExtName.substring(1);
|
|
385
|
+
if (filePath.endsWith(fileExtName)) {
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
if (filePath.endsWith(fileExtName)) {
|
|
390
|
+
needUpgrade = true;
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (needUpgrade == false) {
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const fileExtName = path.extname(filePath);
|
|
400
|
+
if (fileExtList.includes(fileExtName) == false) {
|
|
401
|
+
continue;
|
|
402
|
+
} else if (fileExtList.includes('!' + fileExtName)) {
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
filePathList.push(filePath);
|
|
376
406
|
}
|
|
407
|
+
}
|
|
377
408
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
409
|
+
return filePathList;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function replaceStageContent(options, sourcePathList, msgPrefix,
|
|
413
|
+
repleceRegExp, replaceto) {
|
|
414
|
+
for (const filePath of sourcePathList) {
|
|
415
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
416
|
+
|
|
417
|
+
const fixedContent = content.replaceAll(repleceRegExp, replaceto);
|
|
418
|
+
if (fixedContent === content) {
|
|
419
|
+
continue;
|
|
381
420
|
}
|
|
382
421
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
422
|
+
fs.writeFileSync(filePath, fixedContent, 'utf8');
|
|
423
|
+
console.info(msgPrefix + ': Upgraded ' + path.relative(options.projectDir, filePath));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function removeStageFile(options, sourcePathList, msgPrefix,
|
|
430
|
+
fromExtNameList, toExtName)
|
|
431
|
+
{
|
|
432
|
+
for (const filePath of sourcePathList) {
|
|
433
|
+
let fromExtName = null;
|
|
434
|
+
for (const extName of fromExtNameList) {
|
|
435
|
+
if (filePath.endsWith(extName)) {
|
|
436
|
+
fromExtName = extName;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (fromExtName == null) {
|
|
441
|
+
continue;
|
|
386
442
|
}
|
|
387
443
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
444
|
+
const toFilePath = filePath.replace(new RegExp(fromExtName + '$'), toExtName);
|
|
445
|
+
fs.renameSync(filePath, toFilePath)
|
|
446
|
+
|
|
447
|
+
// json => mjs
|
|
448
|
+
if (fromExtName == '.json') {
|
|
449
|
+
const content = fs.readFileSync(toFilePath, 'utf8');
|
|
450
|
+
const fixedContent = 'export default ' + content;
|
|
451
|
+
fs.writeFileSync(toFilePath, fixedContent, 'utf8');
|
|
391
452
|
}
|
|
392
453
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
454
|
+
console.info(msgPrefix + ': Upgraded ' + path.relative(options.projectDir, filePath));
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function getImportFilePath(content)
|
|
461
|
+
{
|
|
462
|
+
if (isImportSyntax(content) == false) {
|
|
463
|
+
return content;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
let filePath = content.replace(/import .* from/, ''); // import xxx from 'xxx.js'; => 'xxx.js';
|
|
467
|
+
filePath = filePath.replace(/.*import.*\((.*)\)/, '$1'); // xxx = import ('xxx.js'); => 'xxx.js';
|
|
468
|
+
filePath = filePath.replace(/import /, ''); // import 'xxx.js'; => 'xxx.js';
|
|
469
|
+
filePath = filePath.replaceAll('{', ''); // import { => ''
|
|
470
|
+
filePath = filePath.replaceAll(';', '');
|
|
471
|
+
filePath = filePath.replaceAll(',', '');
|
|
472
|
+
filePath = filePath.replaceAll('"', '');
|
|
473
|
+
filePath = filePath.replaceAll('\'', '');
|
|
474
|
+
filePath = filePath.trim();
|
|
475
|
+
|
|
476
|
+
return filePath;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function isImportSyntax(content)
|
|
480
|
+
{
|
|
481
|
+
if (content.trim().match(/^import|import.*\(.*\)/)) { // import,和import()
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function processSourceLineByLine(options, sourcePathList, msgPrefix, processor)
|
|
489
|
+
{
|
|
490
|
+
for (const filePath of sourcePathList) {
|
|
491
|
+
const sourceDir = path.dirname(filePath);
|
|
492
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
493
|
+
|
|
494
|
+
const lineContentList = content.split('\n');
|
|
495
|
+
for (let idx = 0; idx < lineContentList.length; idx++) {
|
|
496
|
+
let lineContent = lineContentList[idx];
|
|
497
|
+
lineContent = processor(lineContent, sourceDir);
|
|
498
|
+
lineContentList[idx] = lineContent;
|
|
396
499
|
}
|
|
397
500
|
|
|
398
|
-
|
|
399
|
-
if (
|
|
400
|
-
|
|
501
|
+
const fixedContent = lineContentList.join('\n');
|
|
502
|
+
if (fixedContent == content) {
|
|
503
|
+
continue;
|
|
401
504
|
}
|
|
402
|
-
} catch (ex) {
|
|
403
|
-
console.error('JsView Error: Failed to update jsview source!');
|
|
404
|
-
console.error(ex);
|
|
405
|
-
process.exit(1);
|
|
406
|
-
}
|
|
407
505
|
|
|
408
|
-
|
|
506
|
+
fs.writeFileSync(filePath, fixedContent, 'utf8');
|
|
507
|
+
console.info(msgPrefix + ': Upgraded ' + path.relative(options.projectDir, filePath));
|
|
508
|
+
}
|
|
409
509
|
}
|
|
410
510
|
|
|
511
|
+
|
|
411
512
|
const requiredUsages = {
|
|
412
513
|
'--stages': `Upgrade stages, separate by comma(,). The value means the following:
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
514
|
+
|
|
515
|
+
1. Fix alias: @. * import App from '@/App'
|
|
516
|
+
=> import App from '/src/App'
|
|
517
|
+
|
|
518
|
+
2. Fix import postfix. * import somemodule from 'somemodule'
|
|
519
|
+
=> import somemodule from 'somemodule[.js|.vue|/index.js|/index.vue]',
|
|
520
|
+
* import('somemodule')
|
|
521
|
+
=> import('somemodule[.js|.vue|/index.js|/index.vue]')
|
|
522
|
+
|
|
523
|
+
3. Fix commonjs. * const somemodule = require('somemodule')
|
|
524
|
+
=> import somemodule from 'somemodule',
|
|
525
|
+
* module.exports = somemodule
|
|
526
|
+
=> export default somemodule
|
|
527
|
+
* module.exports = {}
|
|
528
|
+
=> export {}
|
|
529
|
+
|
|
530
|
+
4. Fix hash history. * createJsvHashHistory
|
|
531
|
+
=> jsvCreateHashHistory
|
|
532
|
+
|
|
533
|
+
5. Fix animation. * :onAnimationEnd
|
|
534
|
+
=> @animationend
|
|
535
|
+
|
|
536
|
+
6. Fix pixels. * [0-9]px
|
|
537
|
+
=> [0-9], delete (+ \`px\`),(+ 'px'),(+ "px")
|
|
538
|
+
|
|
539
|
+
7. Fix audiotrack. * <audiotrack
|
|
540
|
+
=> <jsv-audiotrack
|
|
541
|
+
|
|
542
|
+
8. Fix appConfig. * xxx.config.js
|
|
543
|
+
=> xxx.config.mjs
|
|
544
|
+
|
|
545
|
+
9. Fix main.ts. * main.ts
|
|
546
|
+
=> main.tsx`,
|
|
420
547
|
};
|
|
421
548
|
const optionalUsages = {
|
|
422
549
|
'--dir': 'Upgrade directory, default is [src].',
|
package/tools/jsview-common.mjs
CHANGED
|
@@ -211,6 +211,7 @@ function getOptions(framework)
|
|
|
211
211
|
options.appConfigDir = path.resolve(options.projectDir, 'src', 'appConfig');
|
|
212
212
|
|
|
213
213
|
options.distDir = path.resolve(options.projectDir, 'dist');
|
|
214
|
+
options.distJsvListFile = path.resolve(options.distDir, 'jsv-list.json');
|
|
214
215
|
options.distJsDir = path.resolve(options.distDir, 'js');
|
|
215
216
|
options.distDebugDir = path.resolve(options.distDir, 'debug');
|
|
216
217
|
options.distDebugMapDir = path.resolve(options.distDebugDir, 'map');
|
|
@@ -217,6 +217,41 @@ function makeDebugMap(options, framework)
|
|
|
217
217
|
fs.copyFileSync(jsmapServePath, to);
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
function makeJsvList(options)
|
|
221
|
+
{
|
|
222
|
+
let jsvList = makeFileListRecusive(options.distDir);
|
|
223
|
+
|
|
224
|
+
for (let idx = 0; idx < jsvList.length; idx++) {
|
|
225
|
+
jsvList[idx] = path.relative(options.distDir, jsvList[idx]);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const content = JSON.stringify(jsvList, null, 2);
|
|
229
|
+
fs.writeFileSync(options.distJsvListFile, content, 'utf8');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function makeFileListRecusive(dir)
|
|
233
|
+
{
|
|
234
|
+
let fileList = [];
|
|
235
|
+
|
|
236
|
+
const fileNameArray = fs.readdirSync(dir);
|
|
237
|
+
for(const fileName of fileNameArray) {
|
|
238
|
+
if (fileName.endsWith('debug')) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const filePath = path.resolve(dir, fileName);
|
|
243
|
+
const stat = fs.statSync(filePath);
|
|
244
|
+
if (stat.isDirectory()) {
|
|
245
|
+
const subFileList = makeFileListRecusive(filePath);
|
|
246
|
+
fileList = [...fileList, ...subFileList];
|
|
247
|
+
} else {
|
|
248
|
+
fileList.push(filePath);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return fileList;
|
|
253
|
+
}
|
|
254
|
+
|
|
220
255
|
async function main(argv)
|
|
221
256
|
{
|
|
222
257
|
checkNodeVersion();
|
|
@@ -250,6 +285,10 @@ async function main(argv)
|
|
|
250
285
|
console.info('Making JsView Debug map...');
|
|
251
286
|
makeDebugMap(options, argv.framework);
|
|
252
287
|
console.info('Made JsView Debug map.');
|
|
288
|
+
|
|
289
|
+
console.info('Making JsView list...');
|
|
290
|
+
makeJsvList(options);
|
|
291
|
+
console.info('Made JsView list...');
|
|
253
292
|
}
|
|
254
293
|
|
|
255
294
|
const requiredUsages = {
|