@tmsfe/tmskit 0.0.52 → 0.0.54
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/dist/index.cjs.js +456 -871
- package/package.json +1 -1
- package/src/core/buildAppJson.js +1 -3
- package/src/core/handleAgentConfig.js +4 -29
- package/CHANGELOG.md +0 -65
package/dist/index.cjs.js
CHANGED
|
@@ -31,7 +31,7 @@ var require$$4$2 = require('ansi-colors');
|
|
|
31
31
|
var require$$5 = require('chokidar');
|
|
32
32
|
var require$$6 = require('readable-stream');
|
|
33
33
|
var require$$7 = require('vinyl-file');
|
|
34
|
-
var require$$8
|
|
34
|
+
var require$$8 = require('vinyl');
|
|
35
35
|
var require$$9 = require('anymatch');
|
|
36
36
|
var require$$11 = require('glob-parent');
|
|
37
37
|
var require$$2$1 = require('plugin-error');
|
|
@@ -72,7 +72,7 @@ var require$$4__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$4$2);
|
|
|
72
72
|
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
73
73
|
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
74
74
|
var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
|
|
75
|
-
var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8
|
|
75
|
+
var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
|
|
76
76
|
var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
|
|
77
77
|
var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
|
|
78
78
|
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
@@ -80,29 +80,14 @@ var require$$10__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$10$1);
|
|
|
80
80
|
var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12$1);
|
|
81
81
|
var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
|
|
82
82
|
|
|
83
|
-
function getAugmentedNamespace(n) {
|
|
84
|
-
if (n.__esModule) return n;
|
|
85
|
-
var a = Object.defineProperty({}, '__esModule', {value: true});
|
|
86
|
-
Object.keys(n).forEach(function (k) {
|
|
87
|
-
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
88
|
-
Object.defineProperty(a, k, d.get ? d : {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
get: function () {
|
|
91
|
-
return n[k];
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
return a;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
83
|
var src$3 = {};
|
|
99
84
|
|
|
100
85
|
const chalk$5 = require$$3__default;
|
|
101
86
|
const moment$1 = require$$1__default;
|
|
87
|
+
|
|
102
88
|
/**
|
|
103
89
|
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
104
90
|
*/
|
|
105
|
-
|
|
106
91
|
const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按,用来还原属性
|
|
107
92
|
|
|
108
93
|
/**
|
|
@@ -110,43 +95,33 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
|
|
|
110
95
|
* @param {String} message 需要打印的文字信息
|
|
111
96
|
* @returns {undefined} 无
|
|
112
97
|
*/
|
|
113
|
-
|
|
114
98
|
const fail$a = (message = '') => {
|
|
115
99
|
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
116
|
-
|
|
117
100
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
118
|
-
|
|
119
101
|
console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
120
102
|
};
|
|
103
|
+
|
|
121
104
|
/**
|
|
122
105
|
* 打印绿底黑字格式的文字
|
|
123
106
|
* @param {String} message 需要打印的文字信息
|
|
124
107
|
* @returns {undefined} 无
|
|
125
108
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
109
|
const succeed$2 = (message = '') => {
|
|
129
110
|
const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
|
|
130
|
-
|
|
131
111
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
132
|
-
|
|
133
112
|
console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
134
113
|
};
|
|
114
|
+
|
|
135
115
|
/**
|
|
136
116
|
* 打印warn提示
|
|
137
117
|
* @param {String} message 需要打印的文字信息
|
|
138
118
|
* @returns {undefined} 无
|
|
139
119
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
120
|
const warn$2 = message => {
|
|
143
121
|
console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, chalk$5.yellow(message));
|
|
144
122
|
};
|
|
145
|
-
|
|
146
123
|
const info$l = (...args) => console.log(`${moment$1().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
147
|
-
|
|
148
124
|
const infoNoTime$1 = (...args) => console.log(...args);
|
|
149
|
-
|
|
150
125
|
var log$1 = {
|
|
151
126
|
fail: fail$a,
|
|
152
127
|
succeed: succeed$2,
|
|
@@ -157,7 +132,7 @@ var log$1 = {
|
|
|
157
132
|
|
|
158
133
|
const ora$2 = require$$0__default;
|
|
159
134
|
const path$h = require$$1__default$1;
|
|
160
|
-
const fs$
|
|
135
|
+
const fs$j = require$$0__default$1;
|
|
161
136
|
const shelljs$7 = require$$0__default$2;
|
|
162
137
|
const glob = require$$4__default;
|
|
163
138
|
const {
|
|
@@ -166,32 +141,32 @@ const {
|
|
|
166
141
|
const shelljsOptions = {
|
|
167
142
|
slient: true,
|
|
168
143
|
async: false
|
|
169
|
-
};
|
|
144
|
+
};
|
|
170
145
|
|
|
146
|
+
// 获取当前目录
|
|
171
147
|
const cwd = process.cwd();
|
|
172
|
-
|
|
173
148
|
function resolve$l(...args) {
|
|
174
149
|
return path$h.resolve(cwd, ...args);
|
|
175
150
|
}
|
|
151
|
+
|
|
176
152
|
/**
|
|
177
153
|
* 判断变量是否是一个数组
|
|
178
154
|
* @param { unknown } obj 变量
|
|
179
155
|
* @returns { boolean } 是否是一个数组
|
|
180
156
|
*/
|
|
181
|
-
|
|
182
157
|
function isObject(obj) {
|
|
183
158
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
184
159
|
}
|
|
160
|
+
|
|
185
161
|
/**
|
|
186
162
|
* 判断变量是否是一个对象
|
|
187
163
|
* @param { unknown } obj 变量
|
|
188
164
|
* @returns { boolean } 是否是一个对象
|
|
189
165
|
*/
|
|
190
|
-
|
|
191
|
-
|
|
192
166
|
function isArray(obj) {
|
|
193
167
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
194
168
|
}
|
|
169
|
+
|
|
195
170
|
/**
|
|
196
171
|
* 下载模块代码
|
|
197
172
|
* @param { string } url 模块地址
|
|
@@ -199,16 +174,13 @@ function isArray(obj) {
|
|
|
199
174
|
* @param { string } branch 分支名
|
|
200
175
|
* @returns { undefined } no return
|
|
201
176
|
*/
|
|
202
|
-
|
|
203
|
-
|
|
204
177
|
function downloadRepoForGit$1(url, dest, branch) {
|
|
205
178
|
const cwd = process.cwd();
|
|
206
179
|
return new Promise((resolve, reject) => {
|
|
207
180
|
// 如果目标目录不存在
|
|
208
|
-
if (fs$
|
|
181
|
+
if (fs$j.existsSync(dest)) {
|
|
209
182
|
shelljs$7.rm('-rf', path$h.join(dest));
|
|
210
183
|
}
|
|
211
|
-
|
|
212
184
|
shelljs$7.mkdir('-p', dest);
|
|
213
185
|
shelljs$7.cd(dest);
|
|
214
186
|
shelljs$7.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
|
|
@@ -217,20 +189,18 @@ function downloadRepoForGit$1(url, dest, branch) {
|
|
|
217
189
|
if (code !== 0) {
|
|
218
190
|
reject(stderr);
|
|
219
191
|
}
|
|
220
|
-
|
|
221
192
|
shelljs$7.cd(cwd);
|
|
222
193
|
resolve();
|
|
223
194
|
});
|
|
224
195
|
});
|
|
225
196
|
}
|
|
197
|
+
|
|
226
198
|
/**
|
|
227
199
|
* pull模块代码
|
|
228
200
|
* @param { string } dest 下载代码的路径
|
|
229
201
|
* @param { string } branch 分支名
|
|
230
202
|
* @returns { undefined } no return
|
|
231
203
|
*/
|
|
232
|
-
|
|
233
|
-
|
|
234
204
|
function pullRepoForGit$1(dest, branch) {
|
|
235
205
|
const cwd = process.cwd();
|
|
236
206
|
return new Promise((resolve, reject) => {
|
|
@@ -242,20 +212,18 @@ function pullRepoForGit$1(dest, branch) {
|
|
|
242
212
|
if (code !== 0) {
|
|
243
213
|
reject(stderr);
|
|
244
214
|
}
|
|
245
|
-
|
|
246
215
|
shelljs$7.cd(cwd);
|
|
247
216
|
resolve();
|
|
248
217
|
});
|
|
249
218
|
});
|
|
250
219
|
}
|
|
220
|
+
|
|
251
221
|
/**
|
|
252
222
|
* npm 下载依赖
|
|
253
223
|
* @param {string} dir 下载npm的目录
|
|
254
224
|
* @param {object} npm npm的配置 (见下获取npm源入参)
|
|
255
225
|
* @returns
|
|
256
226
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
259
227
|
function npmInstall$3(dir, npmConfig) {
|
|
260
228
|
return new Promise((resolve, reject) => {
|
|
261
229
|
const registry = getNpmRegistry(npmConfig);
|
|
@@ -266,11 +234,12 @@ function npmInstall$3(dir, npmConfig) {
|
|
|
266
234
|
if (code !== 0) {
|
|
267
235
|
reject(stderr);
|
|
268
236
|
}
|
|
269
|
-
|
|
270
237
|
resolve();
|
|
271
238
|
});
|
|
272
239
|
});
|
|
273
|
-
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 获取npm源
|
|
274
243
|
// 入参:{
|
|
275
244
|
// registry: "https://registry.npmjs.org/",
|
|
276
245
|
// scope: {
|
|
@@ -278,31 +247,26 @@ function npmInstall$3(dir, npmConfig) {
|
|
|
278
247
|
// }
|
|
279
248
|
// }
|
|
280
249
|
// 出参: --@tencent:registry=http://mirrors.tencent.com/npm/ --registry=https://registry.npmjs.org/
|
|
281
|
-
|
|
282
|
-
|
|
283
250
|
function getNpmRegistry(npmConfig = {}) {
|
|
284
251
|
let resRegistry = '';
|
|
285
|
-
|
|
286
252
|
if (npmConfig.registry) {
|
|
287
253
|
resRegistry = ` --registry=${npmConfig.registry}`;
|
|
288
254
|
}
|
|
289
|
-
|
|
290
255
|
if (isObject(npmConfig.scope)) {
|
|
291
256
|
Object.keys(npmConfig.scope).forEach(key => {
|
|
292
257
|
resRegistry += ` --${key}:registry=${npmConfig.scope[key]}`;
|
|
293
258
|
});
|
|
294
259
|
}
|
|
295
|
-
|
|
296
260
|
return resRegistry;
|
|
297
261
|
}
|
|
262
|
+
|
|
298
263
|
/**
|
|
299
264
|
* 计算各项任务耗时
|
|
300
265
|
* @param {Number} start 任务开始时间
|
|
301
266
|
* @returns {Undefined} 无需返回值
|
|
302
267
|
*/
|
|
303
|
-
|
|
304
|
-
|
|
305
268
|
const cost = start => Date.now() - start;
|
|
269
|
+
|
|
306
270
|
/**
|
|
307
271
|
* 创建构建子任务
|
|
308
272
|
* @param {Function} task 子任务执行函数
|
|
@@ -310,8 +274,6 @@ const cost = start => Date.now() - start;
|
|
|
310
274
|
* @param {String} endText 任务结束后提示语
|
|
311
275
|
* @returns {Undefined} 无需返回值
|
|
312
276
|
*/
|
|
313
|
-
|
|
314
|
-
|
|
315
277
|
function createTask$7(task, startText, endText) {
|
|
316
278
|
return async (...args) => {
|
|
317
279
|
const start = Date.now();
|
|
@@ -324,35 +286,32 @@ function createTask$7(task, startText, endText) {
|
|
|
324
286
|
return result;
|
|
325
287
|
};
|
|
326
288
|
}
|
|
289
|
+
|
|
327
290
|
/**
|
|
328
291
|
* 字符串驼峰化处理
|
|
329
292
|
* @param {String} str 需要处理的字符串
|
|
330
293
|
* @returns {String} 经过驼峰处理的字符串
|
|
331
294
|
*/
|
|
332
|
-
|
|
333
295
|
const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
|
|
334
|
-
|
|
335
296
|
const mergeMap$1 = function (obj, src) {
|
|
336
297
|
for (const [k, v] of src) {
|
|
337
298
|
obj.set(k, v);
|
|
338
299
|
}
|
|
339
|
-
|
|
340
300
|
return obj;
|
|
341
301
|
};
|
|
342
|
-
|
|
343
302
|
const relativeCwdPath$1 = function (file) {
|
|
344
303
|
return path$h.relative(process.cwd(), file);
|
|
345
304
|
};
|
|
305
|
+
|
|
346
306
|
/**
|
|
347
307
|
* 从一个对象中,检索出去几个字段
|
|
348
308
|
* @param {*} obj
|
|
349
309
|
* @param {*} name
|
|
350
310
|
* @returns
|
|
351
311
|
*/
|
|
352
|
-
|
|
353
|
-
|
|
354
312
|
const filterField$8 = (obj, filterNames = []) => {
|
|
355
|
-
const newObj = {
|
|
313
|
+
const newObj = {
|
|
314
|
+
...obj
|
|
356
315
|
};
|
|
357
316
|
filterNames.forEach(name => {
|
|
358
317
|
if (newObj[name]) {
|
|
@@ -360,50 +319,46 @@ const filterField$8 = (obj, filterNames = []) => {
|
|
|
360
319
|
}
|
|
361
320
|
});
|
|
362
321
|
return newObj;
|
|
363
|
-
};
|
|
364
|
-
|
|
322
|
+
};
|
|
365
323
|
|
|
324
|
+
// 检索出文件列表
|
|
366
325
|
function findFiles(globPath, filter = []) {
|
|
367
326
|
return new Promise((resolve, reject) => {
|
|
368
327
|
glob(globPath, filter, (err, files) => {
|
|
369
328
|
if (err) {
|
|
370
329
|
reject(err);
|
|
371
330
|
}
|
|
372
|
-
|
|
373
331
|
resolve(files);
|
|
374
332
|
});
|
|
375
333
|
});
|
|
376
|
-
}
|
|
377
|
-
|
|
334
|
+
}
|
|
378
335
|
|
|
336
|
+
// 获取绝对路径
|
|
379
337
|
function getAbsolutePath$6(pathDir, cwd = '') {
|
|
380
338
|
let newPath = pathDir;
|
|
381
339
|
newPath = newPath.startsWith('/') ? newPath : resolve$l(cwd, newPath);
|
|
382
340
|
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
383
341
|
return newPath;
|
|
384
|
-
}
|
|
385
|
-
|
|
342
|
+
}
|
|
386
343
|
|
|
344
|
+
// 版本比较 => 1(大于), 0(等于), -1(小于)
|
|
387
345
|
function versionCompare(v1, v2) {
|
|
388
346
|
// 将两个版本号拆成数组
|
|
389
347
|
const arr1 = v1.split('.');
|
|
390
348
|
const arr2 = v2.split('.');
|
|
391
|
-
const minLength = Math.min(arr1.length, arr2.length);
|
|
392
|
-
|
|
349
|
+
const minLength = Math.min(arr1.length, arr2.length);
|
|
350
|
+
// 依次比较版本号每一位大小
|
|
393
351
|
for (let i = 0; i < minLength; i++) {
|
|
394
352
|
if (parseInt(arr1[i], 10) !== parseInt(arr2[i], 10)) {
|
|
395
353
|
return parseInt(arr1[i], 10) > parseInt(arr2[i], 10) ? 1 : -1;
|
|
396
354
|
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
355
|
+
}
|
|
356
|
+
// 若前几位分隔相同,则按分隔数比较。
|
|
400
357
|
if (arr1.length === arr2.length) {
|
|
401
358
|
return 0;
|
|
402
359
|
}
|
|
403
|
-
|
|
404
360
|
return arr1.length > arr2.length ? 1 : -1;
|
|
405
361
|
}
|
|
406
|
-
|
|
407
362
|
function getGitUser$2() {
|
|
408
363
|
const res = shelljs$7.exec('git config user.name', {
|
|
409
364
|
async: false,
|
|
@@ -411,7 +366,6 @@ function getGitUser$2() {
|
|
|
411
366
|
});
|
|
412
367
|
return res.stdout;
|
|
413
368
|
}
|
|
414
|
-
|
|
415
369
|
var widgets = {
|
|
416
370
|
resolve: resolve$l,
|
|
417
371
|
isObject,
|
|
@@ -434,45 +388,63 @@ var widgets = {
|
|
|
434
388
|
var tmsMpconfig = {exports: {}};
|
|
435
389
|
|
|
436
390
|
const path$g = require$$1__default$1;
|
|
437
|
-
const os = require$$1__default$2;
|
|
391
|
+
const os = require$$1__default$2;
|
|
438
392
|
|
|
439
|
-
|
|
393
|
+
// 用户目录
|
|
394
|
+
const HOME_DIR = os.homedir();
|
|
440
395
|
|
|
441
|
-
|
|
396
|
+
// 所有文件的缓存目录
|
|
397
|
+
const CACHE_DIR = path$g.resolve(HOME_DIR, '.tmskit');
|
|
442
398
|
|
|
443
|
-
|
|
399
|
+
// 版本管理的CDN地址
|
|
400
|
+
const VERSION_URL = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json';
|
|
444
401
|
|
|
445
|
-
|
|
402
|
+
// version缓存文件
|
|
403
|
+
const VERSION_CACHE_FILE = path$g.resolve(CACHE_DIR, 'version_cache_file.json');
|
|
446
404
|
|
|
447
|
-
|
|
405
|
+
// npm缓存文件
|
|
406
|
+
const NPM_CACHE_FILE$1 = path$g.resolve(CACHE_DIR, 'npm_cache_file.json');
|
|
448
407
|
|
|
449
|
-
|
|
408
|
+
// 脚手架模板代码所在目录
|
|
409
|
+
const TEMPLATE_DIR$1 = path$g.resolve(CACHE_DIR, 'template');
|
|
450
410
|
|
|
451
|
-
|
|
411
|
+
// 第三方模块源码存放的临时缓存目录
|
|
412
|
+
const MODULE_CODE_DIR$2 = path$g.resolve(CACHE_DIR, 'modules_code');
|
|
452
413
|
|
|
453
|
-
|
|
414
|
+
// 缓存分包node_modules的目录
|
|
415
|
+
const NODE_MODULES_DIR$2 = path$g.resolve(CACHE_DIR, 'node_modules');
|
|
454
416
|
|
|
455
|
-
|
|
417
|
+
// 扩展命令源码的存放处
|
|
418
|
+
const EXTEND_CMD$1 = path$g.resolve(CACHE_DIR, 'cmd');
|
|
456
419
|
|
|
457
|
-
|
|
420
|
+
// 创建模板的名称
|
|
421
|
+
const TEMPLATE_NAME$1 = 'tmskit-template';
|
|
458
422
|
|
|
459
|
-
|
|
423
|
+
// 脚手架模板的远程地址
|
|
424
|
+
const TEMPLATE_URL$1 = 'http://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip';
|
|
460
425
|
|
|
461
|
-
|
|
426
|
+
// 脚手架的名称
|
|
427
|
+
const TMS_NAME$1 = 'tmskit';
|
|
462
428
|
|
|
429
|
+
// 脚手架的配置名称
|
|
463
430
|
const TMS_CONFIG_FILENAME = 'tms.config.js';
|
|
464
|
-
const TMS_PRIVATE_FILENAME = 'tms.private.config.js';
|
|
431
|
+
const TMS_PRIVATE_FILENAME = 'tms.private.config.js';
|
|
465
432
|
|
|
466
|
-
|
|
433
|
+
// 模块代码的默认在modules子目录
|
|
434
|
+
const DEFAULT_MODULE_DIR = 'modules';
|
|
467
435
|
|
|
468
|
-
|
|
436
|
+
// 模块代码的默认在modules子目录
|
|
437
|
+
const DEFAULT_CLOUD_MODULE_DIR = './cloud';
|
|
469
438
|
|
|
470
|
-
|
|
439
|
+
// 模块的配置文件的名称
|
|
440
|
+
const MODULE_CONFIG_FILENAME = 'module.config.json';
|
|
471
441
|
|
|
442
|
+
// 默认的webpack entry
|
|
472
443
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
473
444
|
app: path$g.resolve(process.cwd(), 'app')
|
|
474
|
-
};
|
|
445
|
+
};
|
|
475
446
|
|
|
447
|
+
// 默认从源码拷贝到编译后的配置
|
|
476
448
|
const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json', 'project.config.json'];
|
|
477
449
|
const ENV = {
|
|
478
450
|
dev: 'development',
|
|
@@ -522,6 +494,7 @@ var constant = {
|
|
|
522
494
|
VERSION_URL
|
|
523
495
|
};
|
|
524
496
|
|
|
497
|
+
// tmsConfig默认配置项
|
|
525
498
|
var defaultTmsConfig = {
|
|
526
499
|
// 全局的环境配置项
|
|
527
500
|
envData: {},
|
|
@@ -530,22 +503,16 @@ var defaultTmsConfig = {
|
|
|
530
503
|
cloudDir: 'cloud',
|
|
531
504
|
// 第三方依赖代码需要拷贝到本项目的
|
|
532
505
|
dependencies: {},
|
|
533
|
-
|
|
534
506
|
/** 编译输出文件夹位置 */
|
|
535
507
|
outputDir: 'dist',
|
|
536
|
-
|
|
537
508
|
/** 是否在编译前清空输出目录 */
|
|
538
509
|
cleanOutputDirBeforeCompile: true,
|
|
539
|
-
|
|
540
510
|
/** 源码监听路径 */
|
|
541
511
|
sourceDir: './',
|
|
542
|
-
|
|
543
512
|
/** 静态资源目录 */
|
|
544
513
|
static: [],
|
|
545
|
-
|
|
546
514
|
/** 监听扩展文件 */
|
|
547
515
|
watchExtendFiles: [],
|
|
548
|
-
|
|
549
516
|
/** 上传是的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E7%BC%96%E8%AF%91%E8%AE%BE%E7%BD%AE */
|
|
550
517
|
upload: {
|
|
551
518
|
setting: {
|
|
@@ -558,7 +525,6 @@ var defaultTmsConfig = {
|
|
|
558
525
|
autoPrefixWXSS: true
|
|
559
526
|
}
|
|
560
527
|
},
|
|
561
|
-
|
|
562
528
|
/** 预览的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88 */
|
|
563
529
|
preview: {
|
|
564
530
|
setting: {
|
|
@@ -578,7 +544,6 @@ var defaultTmsConfig = {
|
|
|
578
544
|
|
|
579
545
|
const global$c = {
|
|
580
546
|
data: {},
|
|
581
|
-
|
|
582
547
|
setData(...args) {
|
|
583
548
|
if (args.length === 1) {
|
|
584
549
|
Object.keys(args[0]).forEach(k => {
|
|
@@ -591,11 +556,9 @@ const global$c = {
|
|
|
591
556
|
this.data[name] = value;
|
|
592
557
|
}
|
|
593
558
|
},
|
|
594
|
-
|
|
595
559
|
getData(name) {
|
|
596
560
|
return this.data[name];
|
|
597
561
|
}
|
|
598
|
-
|
|
599
562
|
};
|
|
600
563
|
var global_1 = {
|
|
601
564
|
global: global$c
|
|
@@ -604,7 +567,6 @@ var global_1 = {
|
|
|
604
567
|
/**
|
|
605
568
|
* 用来读取处理tms.config.js与module.config.json字段
|
|
606
569
|
*/
|
|
607
|
-
|
|
608
570
|
(function (module) {
|
|
609
571
|
/* eslint-disable no-param-reassign, no-nested-ternary */
|
|
610
572
|
const loadash = require$$0__default$3;
|
|
@@ -630,85 +592,75 @@ var global_1 = {
|
|
|
630
592
|
const {
|
|
631
593
|
fail
|
|
632
594
|
} = log$1;
|
|
595
|
+
|
|
633
596
|
/**
|
|
634
597
|
* 读取tms.config.js
|
|
635
598
|
* @param {string} configPath tms.config.js的路径
|
|
636
599
|
*/
|
|
637
|
-
|
|
638
600
|
const readTmsConfig = function (configPath) {
|
|
639
601
|
const tmsConfigPath = configPath ? `${configPath}/${TMS_CONFIG_FILENAME}` : resolve(TMS_CONFIG_FILENAME);
|
|
640
|
-
|
|
641
602
|
if (!fs.existsSync(tmsConfigPath)) {
|
|
642
603
|
fail(`${path.dirname(tmsConfigPath)}没有找到tms.config.js,请进行配置`);
|
|
643
604
|
process.exit(1);
|
|
644
605
|
}
|
|
645
|
-
|
|
646
606
|
const env = global.getData('commandName');
|
|
647
|
-
|
|
648
607
|
const tmsConfigFn = require(tmsConfigPath);
|
|
649
|
-
|
|
650
608
|
const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn({
|
|
651
609
|
env
|
|
652
|
-
}) : tmsConfigFn;
|
|
610
|
+
}) : tmsConfigFn;
|
|
653
611
|
|
|
612
|
+
// 合并默认值
|
|
654
613
|
return loadash.mergeWith({}, defaultTmsConfig$1, tmsConfig);
|
|
655
614
|
};
|
|
615
|
+
|
|
656
616
|
/**
|
|
657
617
|
* 读取tms.private.config.js
|
|
658
618
|
* @param {string} configPath tms.private.config.js的路径
|
|
659
619
|
*/
|
|
660
|
-
|
|
661
|
-
|
|
662
620
|
const readTmsPrivateCf = function (configPath) {
|
|
663
621
|
let tmsPrivateCf = {};
|
|
664
622
|
const tmsPrivatePath = configPath ? `${configPath}/${TMS_PRIVATE_FILENAME}` : resolve(TMS_PRIVATE_FILENAME);
|
|
665
|
-
|
|
666
623
|
if (fs.existsSync(tmsPrivatePath)) {
|
|
667
624
|
const env = global.getData('commandName');
|
|
668
|
-
|
|
669
625
|
const tmsPrivateFn = require(tmsPrivatePath);
|
|
670
|
-
|
|
671
626
|
tmsPrivateCf = typeof tmsPrivateFn === 'function' ? tmsPrivateFn({
|
|
672
627
|
env
|
|
673
628
|
}) : tmsPrivateFn;
|
|
674
629
|
}
|
|
675
|
-
|
|
676
630
|
return tmsPrivateCf;
|
|
677
631
|
};
|
|
632
|
+
|
|
678
633
|
/**
|
|
679
634
|
* 获取tms.config.js, tms.private.config.js的配置项
|
|
680
635
|
* @param {string} configPath config.js的路径
|
|
681
636
|
* @returns
|
|
682
637
|
*/
|
|
683
|
-
|
|
684
|
-
|
|
685
638
|
const getTmsConfig = configPath => {
|
|
686
639
|
const tmsPrivateCf = readTmsPrivateCf(configPath);
|
|
687
640
|
const tmsConfig = readTmsConfig(configPath);
|
|
688
641
|
const modules = {};
|
|
689
|
-
|
|
690
642
|
if (Array.isArray(tmsConfig.modules)) {
|
|
691
643
|
modules.all = tmsConfig.modules;
|
|
692
644
|
tmsConfig.modules = modules;
|
|
693
|
-
}
|
|
645
|
+
}
|
|
646
|
+
// 使用自定义的合并策略:
|
|
694
647
|
// 1. 对 templateVars 字段做浅合并(即把 tms.config.js 中的和 tms.private.config.js 中的对象合并,
|
|
695
648
|
// 如果存在同名字段则以 tms.private.config.js 中的为准)。
|
|
696
649
|
// 2. 对数组(并且数组元素为对象的情况)执行拼接
|
|
697
|
-
|
|
698
|
-
|
|
699
650
|
const res = loadash.mergeWith({}, tmsConfig, tmsPrivateCf, (objValue, srcValue, key) => {
|
|
700
651
|
if (key === 'templateVars') {
|
|
701
|
-
return {
|
|
652
|
+
return {
|
|
653
|
+
...(objValue || {}),
|
|
702
654
|
...(srcValue || {})
|
|
703
655
|
};
|
|
704
656
|
}
|
|
705
|
-
|
|
706
657
|
if (Array.isArray(objValue) && objValue[0] && isObject(objValue[0])) {
|
|
707
658
|
return objValue.concat(srcValue);
|
|
708
659
|
}
|
|
709
660
|
});
|
|
710
661
|
return res;
|
|
711
662
|
};
|
|
663
|
+
|
|
712
664
|
/**
|
|
713
665
|
* 根据moduleNames获取modules
|
|
714
666
|
* @param { object } tmsConfig
|
|
@@ -716,48 +668,39 @@ var global_1 = {
|
|
|
716
668
|
* @param {boolean} errorIsQuit 找不到配置文件是否退出
|
|
717
669
|
* @returns
|
|
718
670
|
*/
|
|
719
|
-
|
|
720
|
-
|
|
721
671
|
const getModulesByModuleNames = function (tmsConfig, moduleNames = []) {
|
|
722
672
|
const targetModules = [];
|
|
723
673
|
moduleNames.forEach(moduleName => {
|
|
724
674
|
const module = tmsConfig.modules.all.find(module => module.moduleName === moduleName);
|
|
725
|
-
|
|
726
675
|
if (!module) {
|
|
727
676
|
throw new Error(`你启动的模块${moduleName}在tms.config.js的modules.all中没有注册`);
|
|
728
677
|
}
|
|
729
|
-
|
|
730
678
|
targetModules.push(module);
|
|
731
679
|
});
|
|
732
680
|
return targetModules;
|
|
733
681
|
};
|
|
682
|
+
|
|
734
683
|
/**
|
|
735
684
|
* 适配处理module.config.json的字段
|
|
736
685
|
* @param { object } fileContent module.config.json的内容
|
|
737
686
|
* @param { string } appName 小程序的名称
|
|
738
687
|
*/
|
|
739
|
-
|
|
740
|
-
|
|
741
688
|
function adaptMpCgContent(fileContent, appName) {
|
|
742
689
|
const handleContent = function (appName, current) {
|
|
743
690
|
let res = current;
|
|
744
|
-
|
|
745
691
|
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
746
|
-
res = {
|
|
692
|
+
res = {
|
|
693
|
+
...current,
|
|
747
694
|
...current.mpConfig[appName]
|
|
748
695
|
};
|
|
749
696
|
}
|
|
750
|
-
|
|
751
697
|
delete res.mpConfig;
|
|
752
698
|
delete res.isSubpackages;
|
|
753
699
|
return res;
|
|
754
700
|
};
|
|
755
|
-
|
|
756
701
|
let content = fileContent;
|
|
757
|
-
|
|
758
702
|
if (isArray(content)) {
|
|
759
703
|
let i = content.length - 1;
|
|
760
|
-
|
|
761
704
|
while (i >= 0) {
|
|
762
705
|
content[i] = handleContent(appName, content[i]);
|
|
763
706
|
i--; // eslint-disable-line
|
|
@@ -765,23 +708,20 @@ var global_1 = {
|
|
|
765
708
|
} else {
|
|
766
709
|
content = handleContent(appName, content);
|
|
767
710
|
}
|
|
768
|
-
|
|
769
711
|
return content;
|
|
770
712
|
}
|
|
771
|
-
|
|
772
713
|
const adaptSubPackages = function (moduleConfig, appName) {
|
|
773
714
|
const {
|
|
774
715
|
subPackages
|
|
775
716
|
} = moduleConfig;
|
|
776
717
|
return adaptMpCgContent(subPackages, appName);
|
|
777
718
|
};
|
|
719
|
+
|
|
778
720
|
/**
|
|
779
721
|
* 获取模块module.config.json中的配置信息
|
|
780
722
|
* @param {array} modules 用户要编译的模块列表
|
|
781
723
|
* @param { string } appName 小程序的名称
|
|
782
724
|
*/
|
|
783
|
-
|
|
784
|
-
|
|
785
725
|
function getModulesConfig(modules = [], tmsConfig) {
|
|
786
726
|
const {
|
|
787
727
|
appName
|
|
@@ -790,57 +730,56 @@ var global_1 = {
|
|
|
790
730
|
modules.forEach(moduleItem => {
|
|
791
731
|
const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
|
|
792
732
|
let moduleConfig;
|
|
793
|
-
|
|
794
733
|
try {
|
|
795
734
|
// 模板渲染:先将 module.config.json 转为字符串,然后通过 preprocess 渲染
|
|
796
735
|
const moduleConfigJsonStr = fs.readFileSync(moduleConfigPath, 'utf-8');
|
|
797
|
-
const preprocessedStr = pp.preprocess(moduleConfigJsonStr, tmsConfig.templateVars || {}, 'json');
|
|
798
|
-
|
|
736
|
+
const preprocessedStr = pp.preprocess(moduleConfigJsonStr, tmsConfig.templateVars || {}, 'json');
|
|
737
|
+
// fs.writeFileSync(resolve(moduleConfigPath), moduleConfigJsonStr, 'utf8');
|
|
799
738
|
moduleConfig = JSON5.parse(preprocessedStr);
|
|
800
739
|
} catch (e) {
|
|
801
740
|
throw new Error(`${moduleConfigPath}json解析报错: ${e}`);
|
|
802
|
-
}
|
|
803
|
-
|
|
741
|
+
}
|
|
804
742
|
|
|
743
|
+
// 兼容历史逻辑,后续可删除--- start
|
|
805
744
|
const subPackages = adaptSubPackages(moduleConfig, appName);
|
|
806
|
-
moduleConfig = {
|
|
745
|
+
moduleConfig = {
|
|
746
|
+
...(isObject(moduleConfig) ? moduleConfig : {}),
|
|
807
747
|
subPackages
|
|
808
|
-
};
|
|
809
|
-
|
|
748
|
+
};
|
|
749
|
+
// 兼容逻辑--- end
|
|
810
750
|
modulesConfig.push(moduleConfig);
|
|
811
751
|
});
|
|
812
752
|
return modulesConfig;
|
|
813
753
|
}
|
|
754
|
+
|
|
814
755
|
/**
|
|
815
756
|
* 获取分包内容 (读取module.config.json的配置项)
|
|
816
757
|
* @param {array} modules
|
|
817
758
|
* @returns
|
|
818
759
|
*/
|
|
819
|
-
|
|
820
|
-
|
|
821
760
|
const getSubPackages = modules => {
|
|
822
761
|
const newSubPackages = [];
|
|
823
762
|
modules.forEach(module => {
|
|
824
763
|
(module.subPackages || []).forEach(subPackage => {
|
|
825
|
-
newSubPackages.push({
|
|
764
|
+
newSubPackages.push({
|
|
765
|
+
...subPackage
|
|
826
766
|
});
|
|
827
767
|
});
|
|
828
768
|
});
|
|
829
769
|
return newSubPackages;
|
|
830
770
|
};
|
|
771
|
+
|
|
831
772
|
/**
|
|
832
773
|
* 获取分包的root字段
|
|
833
774
|
* @param {*} modulePath 模块的编译路径
|
|
834
775
|
* @param {*} root 分包的root字段
|
|
835
776
|
* @returns
|
|
836
777
|
*/
|
|
837
|
-
|
|
838
|
-
|
|
839
778
|
const getSubPackageRoot = function (modulePath, root) {
|
|
840
779
|
return root.startsWith(modulePath) ? root : `${modulePath}/${root}`;
|
|
841
|
-
};
|
|
842
|
-
|
|
780
|
+
};
|
|
843
781
|
|
|
782
|
+
// 获取分包的源码路径
|
|
844
783
|
const getSubPackageSrcPath = function (tmsConfig, module, subPackage) {
|
|
845
784
|
const srcModulePath = getAbsolutePath(module.path);
|
|
846
785
|
const buildModulePath = resolve(tmsConfig.outputDir, module.modulePath);
|
|
@@ -850,39 +789,37 @@ var global_1 = {
|
|
|
850
789
|
const srcSubPackagePath = path.join(srcModulePath, subPackageRelativeModule);
|
|
851
790
|
return srcSubPackagePath;
|
|
852
791
|
};
|
|
853
|
-
|
|
854
792
|
const checkModuleItem = (tmsConfig, tmsModuleItem, moduleConfig) => {
|
|
855
|
-
const newModuleItem = {
|
|
793
|
+
const newModuleItem = {
|
|
794
|
+
...tmsModuleItem,
|
|
856
795
|
...moduleConfig
|
|
857
|
-
};
|
|
796
|
+
};
|
|
858
797
|
|
|
798
|
+
// 参数校验-模块源码路径
|
|
859
799
|
if (!newModuleItem.path) {
|
|
860
800
|
throw new Error(`${newModuleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
|
|
861
|
-
}
|
|
862
|
-
|
|
801
|
+
}
|
|
863
802
|
|
|
803
|
+
// 参数校验-模块编译路径
|
|
864
804
|
if (!newModuleItem.modulePath) {
|
|
865
805
|
throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到modulePath字段`);
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
|
|
806
|
+
}
|
|
807
|
+
// 参数校验-分包校验
|
|
869
808
|
for (const subPackage of newModuleItem.subPackages) {
|
|
870
809
|
if (!subPackage.root) {
|
|
871
810
|
throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到${subPackage.name}分包的root字段`);
|
|
872
|
-
}
|
|
873
|
-
|
|
811
|
+
}
|
|
874
812
|
|
|
813
|
+
// 参数校验-判断分包源码目录是否存在
|
|
875
814
|
const subPackageSrcPath = getSubPackageSrcPath(tmsConfig, newModuleItem, subPackage);
|
|
876
|
-
|
|
877
815
|
if (!subPackageSrcPath || !fs.existsSync(subPackageSrcPath)) {
|
|
878
816
|
throw new Error(`没有找到${newModuleItem.moduleName}模块的${subPackage.name}分包源码:${subPackageSrcPath}`);
|
|
879
817
|
}
|
|
880
|
-
|
|
881
818
|
subPackage.path = subPackageSrcPath;
|
|
882
819
|
}
|
|
883
|
-
|
|
884
820
|
return newModuleItem;
|
|
885
821
|
};
|
|
822
|
+
|
|
886
823
|
/**
|
|
887
824
|
* 获取所有的模块,合并模块的依赖模块
|
|
888
825
|
* @param { object } tmsConfig
|
|
@@ -890,54 +827,40 @@ var global_1 = {
|
|
|
890
827
|
* @param {boolean} errorIsQuit 找不到配置文件是否退出
|
|
891
828
|
* @returns
|
|
892
829
|
*/
|
|
893
|
-
|
|
894
|
-
|
|
895
830
|
const getModulesByMergeDepModules = (tmsConfig, modules, errorIsQuit = false) => {
|
|
896
831
|
const allModules = new Map();
|
|
897
|
-
|
|
898
832
|
function dfs(tmsConfig, modules) {
|
|
899
833
|
modules.forEach(moduleItem => {
|
|
900
834
|
if (!moduleItem.path) {
|
|
901
835
|
throw new Error(`${moduleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
|
|
902
836
|
}
|
|
903
|
-
|
|
904
837
|
const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
|
|
905
|
-
|
|
906
838
|
if (!fs.existsSync(moduleConfigPath)) {
|
|
907
839
|
if (!allModules.has(moduleItem.moduleName)) {
|
|
908
840
|
allModules.set(moduleItem.moduleName, moduleItem);
|
|
909
841
|
}
|
|
910
|
-
|
|
911
842
|
if (errorIsQuit) {
|
|
912
843
|
throw new Error(`${moduleItem.moduleName}模块的配置文件module.config.json在${moduleItem.path}目录下没有找到 ${moduleConfigPath}`);
|
|
913
844
|
}
|
|
914
|
-
|
|
915
845
|
return;
|
|
916
846
|
}
|
|
917
|
-
|
|
918
847
|
const [moduleConfig = {}] = getModulesConfig([moduleItem], tmsConfig);
|
|
919
|
-
|
|
920
848
|
if (!allModules.has(moduleItem.moduleName)) {
|
|
921
849
|
allModules.set(moduleItem.moduleName, checkModuleItem(tmsConfig, moduleItem, moduleConfig));
|
|
922
850
|
const dependenciesModules = getModulesByModuleNames(tmsConfig, moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.dependencies);
|
|
923
|
-
|
|
924
851
|
if (dependenciesModules.length) {
|
|
925
852
|
dfs(tmsConfig, dependenciesModules);
|
|
926
853
|
}
|
|
927
854
|
}
|
|
928
855
|
});
|
|
929
856
|
}
|
|
930
|
-
|
|
931
857
|
dfs(tmsConfig, modules);
|
|
932
858
|
const modulesArr = [];
|
|
933
|
-
|
|
934
859
|
for (const module of allModules.values()) {
|
|
935
860
|
modulesArr.push(module);
|
|
936
861
|
}
|
|
937
|
-
|
|
938
862
|
return modulesArr;
|
|
939
863
|
};
|
|
940
|
-
|
|
941
864
|
module.exports = {
|
|
942
865
|
readTmsConfig,
|
|
943
866
|
readTmsPrivateCf,
|
|
@@ -949,7 +872,7 @@ var global_1 = {
|
|
|
949
872
|
};
|
|
950
873
|
})(tmsMpconfig);
|
|
951
874
|
|
|
952
|
-
const fs$
|
|
875
|
+
const fs$i = require$$0__default$1;
|
|
953
876
|
const path$f = require$$1__default$1;
|
|
954
877
|
const {
|
|
955
878
|
info: info$j
|
|
@@ -962,49 +885,45 @@ const {
|
|
|
962
885
|
* @param {string} dirname 目录名
|
|
963
886
|
* @returns
|
|
964
887
|
*/
|
|
888
|
+
const isDirEmpty = dirname => fs$i.promises.readdir(dirname).then(files => files.length === 0);
|
|
965
889
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
890
|
+
// 判断是否是文件
|
|
969
891
|
const isFile = pathName => {
|
|
970
892
|
try {
|
|
971
|
-
const stat = fs$
|
|
893
|
+
const stat = fs$i.lstatSync(pathName);
|
|
972
894
|
return stat.isFile();
|
|
973
895
|
} catch {
|
|
974
896
|
return false;
|
|
975
897
|
}
|
|
976
898
|
};
|
|
899
|
+
|
|
977
900
|
/**
|
|
978
901
|
* 确保目录存在,不存在就创建一个
|
|
979
902
|
* @param {*} dirname 目录名
|
|
980
903
|
*/
|
|
981
|
-
|
|
982
|
-
|
|
983
904
|
const ensureDirExist$6 = dirname => {
|
|
984
|
-
if (!fs$
|
|
985
|
-
fs$
|
|
905
|
+
if (!fs$i.existsSync(dirname)) {
|
|
906
|
+
fs$i.mkdirSync(dirname, {
|
|
986
907
|
recursive: true
|
|
987
908
|
});
|
|
988
909
|
}
|
|
989
|
-
};
|
|
990
|
-
|
|
910
|
+
};
|
|
991
911
|
|
|
912
|
+
// 复制文件
|
|
992
913
|
const copyFile = function (src, dest) {
|
|
993
|
-
if (fs$
|
|
994
|
-
fs$
|
|
914
|
+
if (fs$i.existsSync(dest)) {
|
|
915
|
+
fs$i.unlinkSync(dest);
|
|
995
916
|
}
|
|
996
|
-
|
|
997
917
|
const dir = path$f.dirname(dest);
|
|
998
918
|
ensureDirExist$6(dir);
|
|
999
|
-
fs$
|
|
1000
|
-
};
|
|
1001
|
-
|
|
919
|
+
fs$i.copyFileSync(src, dest);
|
|
920
|
+
};
|
|
1002
921
|
|
|
922
|
+
// 判断文件内容是否一致,不一致再进行拷贝
|
|
1003
923
|
function diffContentCopyFile(originFile, destFile) {
|
|
1004
|
-
if (fs$
|
|
1005
|
-
const depDestContent = fs$
|
|
1006
|
-
const depOriginContent = fs$
|
|
1007
|
-
|
|
924
|
+
if (fs$i.existsSync(destFile)) {
|
|
925
|
+
const depDestContent = fs$i.readFileSync(destFile, 'utf8');
|
|
926
|
+
const depOriginContent = fs$i.readFileSync(originFile, 'utf8');
|
|
1008
927
|
if (depDestContent !== depOriginContent) {
|
|
1009
928
|
info$j(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
1010
929
|
copyFile(originFile, destFile);
|
|
@@ -1013,26 +932,23 @@ function diffContentCopyFile(originFile, destFile) {
|
|
|
1013
932
|
info$j(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
1014
933
|
copyFile(originFile, destFile);
|
|
1015
934
|
}
|
|
1016
|
-
}
|
|
1017
|
-
|
|
935
|
+
}
|
|
1018
936
|
|
|
937
|
+
// 添加后缀
|
|
1019
938
|
function ext(filePath, extensions) {
|
|
1020
939
|
let newFilePath = filePath;
|
|
1021
|
-
let extPath = '';
|
|
1022
|
-
|
|
940
|
+
let extPath = '';
|
|
941
|
+
// try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
1023
942
|
try {
|
|
1024
|
-
const stat = fs$
|
|
1025
|
-
|
|
943
|
+
const stat = fs$i.lstatSync(newFilePath);
|
|
1026
944
|
if (stat.isDirectory()) {
|
|
1027
945
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
1028
946
|
newFilePath += extPath;
|
|
1029
947
|
}
|
|
1030
948
|
} catch (e) {}
|
|
1031
|
-
|
|
1032
949
|
for (const ext of extensions) {
|
|
1033
950
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
1034
|
-
|
|
1035
|
-
if (fs$j.existsSync(file)) {
|
|
951
|
+
if (fs$i.existsSync(file)) {
|
|
1036
952
|
return {
|
|
1037
953
|
ext,
|
|
1038
954
|
extPath: extPath + ext,
|
|
@@ -1040,38 +956,31 @@ function ext(filePath, extensions) {
|
|
|
1040
956
|
};
|
|
1041
957
|
}
|
|
1042
958
|
}
|
|
1043
|
-
|
|
1044
959
|
return {
|
|
1045
960
|
ext: '',
|
|
1046
961
|
extPath,
|
|
1047
962
|
file: filePath
|
|
1048
963
|
};
|
|
1049
|
-
}
|
|
1050
|
-
|
|
964
|
+
}
|
|
1051
965
|
|
|
966
|
+
// 判断文件是否在某个目录
|
|
1052
967
|
const fileInDir = (dir, file) => {
|
|
1053
|
-
if (!fs$
|
|
968
|
+
if (!fs$i.existsSync(dir) || !fs$i.existsSync(file)) {
|
|
1054
969
|
return false;
|
|
1055
970
|
}
|
|
1056
|
-
|
|
1057
971
|
const relativePath = path$f.relative(dir, file);
|
|
1058
|
-
|
|
1059
972
|
if (relativePath.startsWith('..')) {
|
|
1060
973
|
return false;
|
|
1061
974
|
}
|
|
1062
|
-
|
|
1063
975
|
return true;
|
|
1064
976
|
};
|
|
1065
|
-
|
|
1066
977
|
function findAllFilesOfDir(dir) {
|
|
1067
978
|
const list = [];
|
|
1068
|
-
|
|
1069
979
|
function listFile(dir) {
|
|
1070
|
-
const arr = fs$
|
|
980
|
+
const arr = fs$i.readdirSync(dir);
|
|
1071
981
|
arr.forEach(item => {
|
|
1072
982
|
const fullPath = path$f.join(dir, item);
|
|
1073
|
-
const stats = fs$
|
|
1074
|
-
|
|
983
|
+
const stats = fs$i.statSync(fullPath);
|
|
1075
984
|
if (stats.isDirectory()) {
|
|
1076
985
|
listFile(fullPath);
|
|
1077
986
|
} else {
|
|
@@ -1080,11 +989,9 @@ function findAllFilesOfDir(dir) {
|
|
|
1080
989
|
});
|
|
1081
990
|
return list;
|
|
1082
991
|
}
|
|
1083
|
-
|
|
1084
992
|
listFile(dir);
|
|
1085
993
|
return list;
|
|
1086
994
|
}
|
|
1087
|
-
|
|
1088
995
|
var io$3 = {
|
|
1089
996
|
isDirEmpty,
|
|
1090
997
|
copyFile,
|
|
@@ -1098,25 +1005,21 @@ var io$3 = {
|
|
|
1098
1005
|
|
|
1099
1006
|
const async = require$$0__default$4;
|
|
1100
1007
|
const ejs = require$$1__default$4;
|
|
1101
|
-
|
|
1102
1008
|
const render$1 = (files, metalsmith, next) => {
|
|
1103
1009
|
const keys = Object.keys(files);
|
|
1104
1010
|
const metadata = metalsmith.metadata();
|
|
1105
|
-
|
|
1106
1011
|
const run = (file, next) => {
|
|
1107
1012
|
const str = files[file].contents.toString();
|
|
1108
|
-
const newStr = ejs.render(str, metadata);
|
|
1109
|
-
|
|
1013
|
+
const newStr = ejs.render(str, metadata);
|
|
1014
|
+
// eslint-disable-next-line
|
|
1110
1015
|
files[file].contents = Buffer.from(newStr);
|
|
1111
1016
|
next();
|
|
1112
1017
|
};
|
|
1113
|
-
|
|
1114
1018
|
async.each(keys, run, next);
|
|
1115
1019
|
};
|
|
1116
|
-
|
|
1117
1020
|
var render_1 = render$1;
|
|
1118
1021
|
|
|
1119
|
-
const fs$
|
|
1022
|
+
const fs$h = require$$0__default$1;
|
|
1120
1023
|
const inquirer$1 = require$$1__default$5;
|
|
1121
1024
|
const {
|
|
1122
1025
|
resolve: resolve$k
|
|
@@ -1129,17 +1032,13 @@ const {
|
|
|
1129
1032
|
* @param {string} dir questions.json所在的目录
|
|
1130
1033
|
* @returns {Array} inquirer 问题数组
|
|
1131
1034
|
*/
|
|
1132
|
-
|
|
1133
1035
|
const parseTemplateQuestions = dir => {
|
|
1134
1036
|
let prompts = [];
|
|
1135
|
-
|
|
1136
|
-
if (!fs$i.existsSync(`${dir}/questions.json`)) {
|
|
1037
|
+
if (!fs$h.existsSync(`${dir}/questions.json`)) {
|
|
1137
1038
|
return prompts;
|
|
1138
1039
|
}
|
|
1139
|
-
|
|
1140
1040
|
try {
|
|
1141
|
-
const json = JSON.parse(fs$
|
|
1142
|
-
|
|
1041
|
+
const json = JSON.parse(fs$h.readFileSync(`${dir}/questions.json`));
|
|
1143
1042
|
if (Array.isArray(json) && json.length > 0) {
|
|
1144
1043
|
json.forEach((item, index) => {
|
|
1145
1044
|
if (!isQuestionType(item)) {
|
|
@@ -1149,27 +1048,21 @@ const parseTemplateQuestions = dir => {
|
|
|
1149
1048
|
} else {
|
|
1150
1049
|
throw new Error('问题文件只能是数组');
|
|
1151
1050
|
}
|
|
1152
|
-
|
|
1153
1051
|
prompts = json;
|
|
1154
1052
|
} catch (err) {
|
|
1155
1053
|
throw new Error(`模板异常,${err.message}`);
|
|
1156
1054
|
}
|
|
1157
|
-
|
|
1158
1055
|
return prompts;
|
|
1159
1056
|
};
|
|
1160
|
-
|
|
1161
1057
|
const isQuestionType = result => {
|
|
1162
1058
|
if (!('message' in result)) {
|
|
1163
1059
|
return false;
|
|
1164
1060
|
}
|
|
1165
|
-
|
|
1166
1061
|
if (!('name' in result)) {
|
|
1167
1062
|
return false;
|
|
1168
1063
|
}
|
|
1169
|
-
|
|
1170
1064
|
return true;
|
|
1171
1065
|
};
|
|
1172
|
-
|
|
1173
1066
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
1174
1067
|
const prompts = parseTemplateQuestions(resolve$k(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
1175
1068
|
const metadata = metalsmith.metadata();
|
|
@@ -1177,22 +1070,20 @@ const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
|
1177
1070
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
1178
1071
|
return false;
|
|
1179
1072
|
}
|
|
1180
|
-
|
|
1181
1073
|
return true;
|
|
1182
1074
|
});
|
|
1183
1075
|
inquirer$1.prompt(filteredPrompts).then(res => {
|
|
1184
1076
|
for (const prompt of filteredPrompts) {
|
|
1185
1077
|
metadata[prompt.name] = res[prompt.name];
|
|
1186
1078
|
}
|
|
1187
|
-
|
|
1188
1079
|
next();
|
|
1189
1080
|
}).catch(err => {
|
|
1190
1081
|
next(err);
|
|
1191
1082
|
});
|
|
1192
1083
|
};
|
|
1193
|
-
|
|
1194
1084
|
var ask_1 = ask$1;
|
|
1195
1085
|
|
|
1086
|
+
// 在metal smith遍历时需要忽略的文件,这些文件会引起metalsmith的parse error
|
|
1196
1087
|
const FILES_TO_IGNORE$1 = ['node_modules'];
|
|
1197
1088
|
var ignoreFiles = FILES_TO_IGNORE$1;
|
|
1198
1089
|
|
|
@@ -1200,7 +1091,6 @@ const Metalsmith = require$$0__default$5;
|
|
|
1200
1091
|
const render = render_1;
|
|
1201
1092
|
const ask = ask_1;
|
|
1202
1093
|
const FILES_TO_IGNORE = ignoreFiles;
|
|
1203
|
-
|
|
1204
1094
|
const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolve, reject) => {
|
|
1205
1095
|
Metalsmith(buildDir).metadata(preMetadata).ignore(FILES_TO_IGNORE).clean(false).use(ask(buildDir)).source('./').destination(distDir).use(render).build(err => {
|
|
1206
1096
|
if (err) {
|
|
@@ -1210,7 +1100,6 @@ const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolv
|
|
|
1210
1100
|
}
|
|
1211
1101
|
});
|
|
1212
1102
|
});
|
|
1213
|
-
|
|
1214
1103
|
var generator_1 = generator$1;
|
|
1215
1104
|
|
|
1216
1105
|
const request$1 = require$$0__default$6;
|
|
@@ -1218,7 +1107,6 @@ const {
|
|
|
1218
1107
|
getGitUser: getGitUser$1
|
|
1219
1108
|
} = widgets;
|
|
1220
1109
|
const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
|
|
1221
|
-
|
|
1222
1110
|
const report$b = (name, attrs = {}) => {
|
|
1223
1111
|
try {
|
|
1224
1112
|
const param = [];
|
|
@@ -1226,27 +1114,25 @@ const report$b = (name, attrs = {}) => {
|
|
|
1226
1114
|
param[28] = 'tmskit';
|
|
1227
1115
|
param[29] = getGitUser$1();
|
|
1228
1116
|
param[30] = JSON.stringify(attrs);
|
|
1229
|
-
|
|
1230
1117
|
for (let i = 0; i < 40; i++) {
|
|
1231
1118
|
if (!param[i]) param[i] = null;
|
|
1232
1119
|
}
|
|
1233
|
-
|
|
1234
1120
|
;
|
|
1235
1121
|
request$1.post({
|
|
1236
1122
|
url: apiUrl,
|
|
1237
1123
|
json: {
|
|
1238
1124
|
param
|
|
1239
1125
|
}
|
|
1240
|
-
}, () => {});
|
|
1126
|
+
}, () => {});
|
|
1127
|
+
// (error, response, body) => {
|
|
1241
1128
|
// console.log('body:', body);
|
|
1242
1129
|
// }
|
|
1243
1130
|
} catch (e) {}
|
|
1244
1131
|
};
|
|
1245
|
-
|
|
1246
1132
|
var report_1 = report$b;
|
|
1247
1133
|
|
|
1248
1134
|
const path$e = require$$1__default$1;
|
|
1249
|
-
const fs$
|
|
1135
|
+
const fs$g = require$$0__default$1;
|
|
1250
1136
|
const shelljs$6 = require$$0__default$2;
|
|
1251
1137
|
const inquirer = require$$1__default$5;
|
|
1252
1138
|
const {
|
|
@@ -1269,15 +1155,15 @@ const generator = generator_1;
|
|
|
1269
1155
|
const request = require$$0__default$6;
|
|
1270
1156
|
const unzip = require$$10__default;
|
|
1271
1157
|
const report$a = report_1;
|
|
1158
|
+
|
|
1272
1159
|
/**
|
|
1273
1160
|
* 如果该目录下面存在文件,换个名字
|
|
1274
1161
|
* @param { string } targetDir 当前文件夹
|
|
1275
1162
|
* @returns { undefined }
|
|
1276
1163
|
*/
|
|
1277
|
-
|
|
1278
1164
|
async function createProjectDir(targetDir) {
|
|
1279
1165
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
1280
|
-
if (fs$
|
|
1166
|
+
if (fs$g.existsSync(targetDir)) {
|
|
1281
1167
|
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
1282
1168
|
fail$9('该目录名已经存在,换个项目名字吧~');
|
|
1283
1169
|
process.exit(1);
|
|
@@ -1286,6 +1172,7 @@ async function createProjectDir(targetDir) {
|
|
|
1286
1172
|
shelljs$6.mkdir('-p', targetDir);
|
|
1287
1173
|
}
|
|
1288
1174
|
}
|
|
1175
|
+
|
|
1289
1176
|
/**
|
|
1290
1177
|
* 下载和解压远程的小程序模板
|
|
1291
1178
|
* @param {string} templateDir
|
|
@@ -1293,38 +1180,33 @@ async function createProjectDir(targetDir) {
|
|
|
1293
1180
|
* @param {string} templateName
|
|
1294
1181
|
* @returns
|
|
1295
1182
|
*/
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
1183
|
function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
|
|
1299
1184
|
return new Promise((resolve, reject) => {
|
|
1300
1185
|
const localZipPath = `${templateDir}/${templateName}.zip`;
|
|
1301
|
-
const stream = fs$
|
|
1186
|
+
const stream = fs$g.createWriteStream(localZipPath);
|
|
1302
1187
|
request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
|
|
1303
1188
|
if (err) {
|
|
1304
1189
|
reject(err);
|
|
1305
1190
|
return;
|
|
1306
1191
|
}
|
|
1307
|
-
|
|
1308
|
-
fs$h.createReadStream(localZipPath).pipe(unzip.Extract({
|
|
1192
|
+
fs$g.createReadStream(localZipPath).pipe(unzip.Extract({
|
|
1309
1193
|
path: templateDir
|
|
1310
1194
|
})).on('close', err => {
|
|
1311
1195
|
if (err) {
|
|
1312
1196
|
reject(err);
|
|
1313
1197
|
return;
|
|
1314
1198
|
}
|
|
1315
|
-
|
|
1316
1199
|
resolve();
|
|
1317
1200
|
});
|
|
1318
1201
|
});
|
|
1319
1202
|
});
|
|
1320
1203
|
}
|
|
1204
|
+
|
|
1321
1205
|
/**
|
|
1322
1206
|
* 创建本地小程序运行环境
|
|
1323
1207
|
* @param { string } projectType 项目类型
|
|
1324
1208
|
* @param { string } projectName 项目名称
|
|
1325
1209
|
*/
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
1210
|
async function create(projectName) {
|
|
1329
1211
|
const cwd = process.cwd();
|
|
1330
1212
|
const targetDir = path$e.resolve(cwd, projectName);
|
|
@@ -1333,27 +1215,28 @@ async function create(projectName) {
|
|
|
1333
1215
|
} = await inquirer.prompt(CREATE_TEMPLATE_QUESTION);
|
|
1334
1216
|
report$a('create-start', {
|
|
1335
1217
|
projectType
|
|
1336
|
-
});
|
|
1218
|
+
});
|
|
1337
1219
|
|
|
1338
|
-
|
|
1220
|
+
// 创建项目目录
|
|
1221
|
+
await createProjectDir(targetDir);
|
|
1339
1222
|
|
|
1340
|
-
|
|
1223
|
+
// 新创建缓存目录
|
|
1224
|
+
if (fs$g.existsSync(TEMPLATE_DIR)) {
|
|
1341
1225
|
shelljs$6.rm('-rf', TEMPLATE_DIR);
|
|
1342
1226
|
}
|
|
1343
|
-
|
|
1344
|
-
fs$h.mkdirSync(TEMPLATE_DIR, {
|
|
1227
|
+
fs$g.mkdirSync(TEMPLATE_DIR, {
|
|
1345
1228
|
recursive: true
|
|
1346
|
-
});
|
|
1229
|
+
});
|
|
1347
1230
|
|
|
1348
|
-
|
|
1231
|
+
// 下载和解压模板
|
|
1232
|
+
await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME);
|
|
1349
1233
|
|
|
1234
|
+
// 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
1350
1235
|
generator(path$e.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
|
|
1351
1236
|
shelljs$6.cd(projectName);
|
|
1352
1237
|
const hookFilePath = resolve$j(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
|
|
1353
|
-
|
|
1354
|
-
if (fs$h.existsSync(hookFilePath)) {
|
|
1238
|
+
if (fs$g.existsSync(hookFilePath)) {
|
|
1355
1239
|
const hooks = require(hookFilePath);
|
|
1356
|
-
|
|
1357
1240
|
if (hooks.afterCreate) {
|
|
1358
1241
|
hooks.afterCreate.forEach(item => {
|
|
1359
1242
|
if (typeof item === 'function') {
|
|
@@ -1365,10 +1248,8 @@ async function create(projectName) {
|
|
|
1365
1248
|
}
|
|
1366
1249
|
});
|
|
1367
1250
|
}
|
|
1368
|
-
|
|
1369
1251
|
shelljs$6.rm('-rf', resolve$j(projectName, TEMPLATE_TKIT_DIR));
|
|
1370
1252
|
}
|
|
1371
|
-
|
|
1372
1253
|
report$a('create-success', {
|
|
1373
1254
|
projectType
|
|
1374
1255
|
});
|
|
@@ -1378,10 +1259,9 @@ async function create(projectName) {
|
|
|
1378
1259
|
info$i('详细的错误信息:', err);
|
|
1379
1260
|
});
|
|
1380
1261
|
}
|
|
1381
|
-
|
|
1382
1262
|
var create_1 = create;
|
|
1383
1263
|
|
|
1384
|
-
const fs$
|
|
1264
|
+
const fs$f = require$$0__default$1;
|
|
1385
1265
|
const path$d = require$$1__default$1;
|
|
1386
1266
|
const shellJs$3 = require$$0__default$2;
|
|
1387
1267
|
const {
|
|
@@ -1397,23 +1277,21 @@ const {
|
|
|
1397
1277
|
info: info$h,
|
|
1398
1278
|
fail: fail$8
|
|
1399
1279
|
} = log$1;
|
|
1280
|
+
|
|
1400
1281
|
/**
|
|
1401
1282
|
* 下载扩展命令的npm包
|
|
1402
1283
|
* @param {string} npmName npm包名
|
|
1403
1284
|
* @param {object} cmd {registry: 'http://mirrors.tencent.com/npm/'} 用户输入执行install-cmd的参数
|
|
1404
1285
|
*/
|
|
1405
|
-
|
|
1406
1286
|
async function installCmd(npmName, cmd) {
|
|
1407
1287
|
try {
|
|
1408
1288
|
const cmdPackageJson = `${EXTEND_CMD}/package.json`;
|
|
1409
|
-
|
|
1410
|
-
if (!fs$g.existsSync(cmdPackageJson)) {
|
|
1289
|
+
if (!fs$f.existsSync(cmdPackageJson)) {
|
|
1411
1290
|
ensureDirExist$5(EXTEND_CMD);
|
|
1412
|
-
fs$
|
|
1291
|
+
fs$f.writeFileSync(cmdPackageJson, JSON.stringify({
|
|
1413
1292
|
dependencies: {}
|
|
1414
1293
|
}, null, 2));
|
|
1415
1294
|
}
|
|
1416
|
-
|
|
1417
1295
|
shellJs$3.cd(EXTEND_CMD);
|
|
1418
1296
|
await createTask$6(npmName => new Promise((resolve, reject) => {
|
|
1419
1297
|
const registry = cmd.registry ? `--registry=${cmd.registry}` : '';
|
|
@@ -1424,7 +1302,6 @@ async function installCmd(npmName, cmd) {
|
|
|
1424
1302
|
if (code !== 0) {
|
|
1425
1303
|
reject(stderr);
|
|
1426
1304
|
}
|
|
1427
|
-
|
|
1428
1305
|
resolve();
|
|
1429
1306
|
});
|
|
1430
1307
|
}), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
|
|
@@ -1434,18 +1311,16 @@ async function installCmd(npmName, cmd) {
|
|
|
1434
1311
|
process.exit(1);
|
|
1435
1312
|
}
|
|
1436
1313
|
}
|
|
1314
|
+
|
|
1437
1315
|
/**
|
|
1438
1316
|
* 加载扩展命令的npm包
|
|
1439
1317
|
* @returns
|
|
1440
1318
|
*/
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
1319
|
function loadExtendCmd$1() {
|
|
1444
1320
|
const cmdPackageJson = `${EXTEND_CMD}/package.json`;
|
|
1445
1321
|
const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
const content = fs$g.readFileSync(cmdPackageJson, 'utf8');
|
|
1322
|
+
if (fs$f.existsSync(cmdPackageJson)) {
|
|
1323
|
+
const content = fs$f.readFileSync(cmdPackageJson, 'utf8');
|
|
1449
1324
|
const json = JSON.parse(content);
|
|
1450
1325
|
const deps = json.dependencies || {};
|
|
1451
1326
|
const cmdConfigs = [];
|
|
@@ -1453,17 +1328,14 @@ function loadExtendCmd$1() {
|
|
|
1453
1328
|
// 检索cmd的npm包
|
|
1454
1329
|
if (!/^tmskit-cmd-|^@[^/]+\/tmskit-cmd-/.test(name)) return false;
|
|
1455
1330
|
const cmdConfig = path$d.join(cmdNpmDir, name, 'tms.config.js');
|
|
1456
|
-
|
|
1457
|
-
if (fs$g.existsSync(cmdConfig)) {
|
|
1331
|
+
if (fs$f.existsSync(cmdConfig)) {
|
|
1458
1332
|
cmdConfigs.push(cmdConfig);
|
|
1459
1333
|
}
|
|
1460
1334
|
});
|
|
1461
1335
|
return cmdConfigs;
|
|
1462
1336
|
}
|
|
1463
|
-
|
|
1464
1337
|
return [];
|
|
1465
1338
|
}
|
|
1466
|
-
|
|
1467
1339
|
var extendCmd = {
|
|
1468
1340
|
installCmd,
|
|
1469
1341
|
loadExtendCmd: loadExtendCmd$1
|
|
@@ -1475,17 +1347,13 @@ const {
|
|
|
1475
1347
|
const {
|
|
1476
1348
|
global: global$b
|
|
1477
1349
|
} = global_1;
|
|
1478
|
-
|
|
1479
1350
|
function handleError$9(error, isQuit = false) {
|
|
1480
1351
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1481
|
-
|
|
1482
1352
|
if (isQuit) {
|
|
1483
1353
|
fail$7(errMsg);
|
|
1484
1354
|
process.exit(1);
|
|
1485
1355
|
}
|
|
1486
|
-
|
|
1487
1356
|
const isDev = global$b.getData('isDev');
|
|
1488
|
-
|
|
1489
1357
|
if (isDev) {
|
|
1490
1358
|
fail$7(errMsg);
|
|
1491
1359
|
} else {
|
|
@@ -1493,42 +1361,34 @@ function handleError$9(error, isQuit = false) {
|
|
|
1493
1361
|
process.exit(1);
|
|
1494
1362
|
}
|
|
1495
1363
|
}
|
|
1496
|
-
|
|
1497
1364
|
var handleError_1 = {
|
|
1498
1365
|
handleError: handleError$9
|
|
1499
1366
|
};
|
|
1500
1367
|
|
|
1501
1368
|
const {
|
|
1502
1369
|
resolve: resolve$i
|
|
1503
|
-
} =
|
|
1504
|
-
|
|
1370
|
+
} = widgets;
|
|
1505
1371
|
const {
|
|
1506
1372
|
info: info$g
|
|
1507
|
-
} =
|
|
1373
|
+
} = log$1;
|
|
1508
1374
|
|
|
1509
|
-
const fs$f = require('fs');
|
|
1510
1375
|
/* eslint-disable no-param-reassign */
|
|
1511
|
-
|
|
1512
1376
|
/**
|
|
1513
1377
|
* 检查是否包含 meta-services 分包
|
|
1514
1378
|
* @param {Object} appJson app.json配置对象
|
|
1515
1379
|
* @returns {boolean}
|
|
1516
1380
|
*/
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
1381
|
function hasMetaServicesSubpackage(appJson) {
|
|
1520
1382
|
return appJson.subpackages.some(s => s.root === 'modules/meta-services' || s.name === 'meta-services');
|
|
1521
1383
|
}
|
|
1384
|
+
|
|
1522
1385
|
/**
|
|
1523
1386
|
* 处理 agent 配置:根据是否包含 meta-services 分包来添加或删除 agent 配置
|
|
1524
1387
|
* @param {Object} appJson app.json配置对象
|
|
1525
1388
|
*/
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
1389
|
function handleAgentConfig$1(appJson) {
|
|
1529
1390
|
const hasMetaServices = hasMetaServicesSubpackage(appJson);
|
|
1530
1391
|
console.log('🔍', hasMetaServices ? '包含' : '不包含', 'meta-services 分包');
|
|
1531
|
-
|
|
1532
1392
|
if (hasMetaServices) {
|
|
1533
1393
|
if (!appJson.agent) {
|
|
1534
1394
|
try {
|
|
@@ -1544,50 +1404,15 @@ function handleAgentConfig$1(appJson) {
|
|
|
1544
1404
|
info$g('已移除 agent 配置');
|
|
1545
1405
|
}
|
|
1546
1406
|
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
* @param {string} outputDir 输出目录
|
|
1551
|
-
*/
|
|
1552
|
-
|
|
1553
|
-
function handleProjectConfigInclude$1(appJson, outputDir) {
|
|
1554
|
-
const projectConfigPath = resolve$i(outputDir, 'project.config.json');
|
|
1555
|
-
if (!fs$f.existsSync(projectConfigPath)) return;
|
|
1556
|
-
|
|
1557
|
-
const projectConfig = require(projectConfigPath);
|
|
1558
|
-
|
|
1559
|
-
const hasMetaServices = hasMetaServicesSubpackage(appJson);
|
|
1560
|
-
if (!projectConfig.packOptions) projectConfig.packOptions = {};
|
|
1561
|
-
if (!projectConfig.packOptions.include) projectConfig.packOptions.include = [];
|
|
1562
|
-
const existingIndex = projectConfig.packOptions.include.findIndex(item => item.type === 'folder' && item.value === 'modules/meta-services');
|
|
1563
|
-
|
|
1564
|
-
if (hasMetaServices && existingIndex === -1) {
|
|
1565
|
-
projectConfig.packOptions.include.push({
|
|
1566
|
-
type: 'folder',
|
|
1567
|
-
value: 'modules/meta-services'
|
|
1568
|
-
});
|
|
1569
|
-
info$g('已添加 meta-services 到 project.config.json');
|
|
1570
|
-
} else if (!hasMetaServices && existingIndex !== -1) {
|
|
1571
|
-
projectConfig.packOptions.include.splice(existingIndex, 1);
|
|
1572
|
-
info$g('已从 project.config.json 移除 meta-services');
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
fs$f.writeFileSync(projectConfigPath, JSON.stringify(projectConfig, null, 2));
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
var handleAgentConfig$2 = /*#__PURE__*/Object.freeze({
|
|
1579
|
-
__proto__: null,
|
|
1580
|
-
handleAgentConfig: handleAgentConfig$1,
|
|
1581
|
-
handleProjectConfigInclude: handleProjectConfigInclude$1
|
|
1582
|
-
});
|
|
1583
|
-
|
|
1584
|
-
var require$$8 = /*@__PURE__*/getAugmentedNamespace(handleAgentConfig$2);
|
|
1407
|
+
var handleAgentConfig_1 = {
|
|
1408
|
+
handleAgentConfig: handleAgentConfig$1
|
|
1409
|
+
};
|
|
1585
1410
|
|
|
1586
1411
|
/**
|
|
1587
1412
|
* 生成编译后的app.json
|
|
1588
1413
|
*/
|
|
1589
|
-
/* eslint-disable no-param-reassign */
|
|
1590
1414
|
|
|
1415
|
+
/* eslint-disable no-param-reassign */
|
|
1591
1416
|
const fs$e = require$$0__default$1;
|
|
1592
1417
|
const pp$1 = require$$1__default$3;
|
|
1593
1418
|
const {
|
|
@@ -1610,44 +1435,39 @@ const {
|
|
|
1610
1435
|
} = global_1;
|
|
1611
1436
|
const report$9 = report_1;
|
|
1612
1437
|
const {
|
|
1613
|
-
handleAgentConfig
|
|
1614
|
-
|
|
1615
|
-
|
|
1438
|
+
handleAgentConfig
|
|
1439
|
+
} = handleAgentConfig_1;
|
|
1440
|
+
|
|
1616
1441
|
/**
|
|
1617
1442
|
* 更新appJson里面的主包配置
|
|
1618
1443
|
* @param { object } appJson appJson信息
|
|
1619
1444
|
* @param { array } mainPackages 小程序主包信息
|
|
1620
1445
|
* @returns { object } appJson小程序主页配置信息
|
|
1621
1446
|
*/
|
|
1622
|
-
|
|
1623
1447
|
function updateMainPackages(appJson, mainPackages = []) {
|
|
1624
1448
|
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1625
|
-
|
|
1626
1449
|
if (foundMainPackages.length === 0 && appJson.pages.length === 0) {
|
|
1627
1450
|
// 没找到主包
|
|
1628
1451
|
foundMainPackages = [appJson.subpackages[0]];
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1452
|
+
}
|
|
1453
|
+
// 拼装 app.pages
|
|
1632
1454
|
foundMainPackages.forEach(subpackage => {
|
|
1633
1455
|
if (!subpackage.allowNoPages && (!subpackage.pages || !subpackage.pages.length)) {
|
|
1634
1456
|
fail$6(`主包 ${subpackage} 不能没有 pages`, foundMainPackages, subpackage);
|
|
1635
1457
|
process.exit(-1);
|
|
1636
1458
|
}
|
|
1637
|
-
|
|
1638
1459
|
subpackage.pages.forEach(page => {
|
|
1639
1460
|
const pagePath = `${subpackage.root}/${page}`;
|
|
1640
|
-
|
|
1641
1461
|
if (!appJson.pages.includes(pagePath)) {
|
|
1642
1462
|
appJson.pages.push(pagePath);
|
|
1643
1463
|
}
|
|
1644
1464
|
});
|
|
1645
|
-
|
|
1646
1465
|
if (subpackage.plugins) {
|
|
1647
1466
|
Object.assign(appJson.plugins, subpackage.plugins);
|
|
1648
1467
|
}
|
|
1649
|
-
});
|
|
1468
|
+
});
|
|
1650
1469
|
|
|
1470
|
+
// 去掉 subpackages 中的主包配置
|
|
1651
1471
|
const foundMainPackageNames = foundMainPackages.map(item => item.name);
|
|
1652
1472
|
appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
|
|
1653
1473
|
return appJson;
|
|
@@ -1657,41 +1477,39 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1657
1477
|
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1658
1478
|
* @returns
|
|
1659
1479
|
*/
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
1480
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
1663
1481
|
if (!fs$e.existsSync(sourceAppJsonPath)) {
|
|
1664
1482
|
fail$6(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1665
1483
|
process.exit(1);
|
|
1666
1484
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1485
|
+
const appJson = JSON.parse(fs$e.readFileSync(sourceAppJsonPath), 'utf-8');
|
|
1486
|
+
// 加入默认值
|
|
1670
1487
|
appJson.subpackages = appJson.subpackages || [];
|
|
1671
1488
|
appJson.pages = appJson.pages || [];
|
|
1672
1489
|
return appJson;
|
|
1673
1490
|
};
|
|
1491
|
+
|
|
1674
1492
|
/**
|
|
1675
1493
|
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
1676
1494
|
* @param {Object} appJson appjson
|
|
1677
1495
|
*/
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
1496
|
const fixAppJson = appJson => {
|
|
1681
1497
|
const {
|
|
1682
1498
|
subpackages
|
|
1683
|
-
} = appJson;
|
|
1684
|
-
|
|
1685
|
-
const pluginsMap = {};
|
|
1686
|
-
|
|
1687
|
-
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
1499
|
+
} = appJson;
|
|
1500
|
+
// 创建插件映射,用于检测插件配置冲突
|
|
1501
|
+
const pluginsMap = {};
|
|
1502
|
+
// 记录app.json顶层的插件配置
|
|
1503
|
+
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
1688
1504
|
|
|
1505
|
+
// 处理每个分包的配置
|
|
1689
1506
|
const subps = subpackages.map(subp => {
|
|
1690
1507
|
// 需要从分包提取到app.json顶层的数组类型字段
|
|
1691
|
-
const arrOfFileType = ['requiredBackgroundModes', 'embeddedAppIdList'];
|
|
1692
|
-
|
|
1693
|
-
const objOfFileType = ['preloadRule'];
|
|
1508
|
+
const arrOfFileType = ['requiredBackgroundModes', 'embeddedAppIdList'];
|
|
1509
|
+
// 需要从分包提取到app.json顶层的对象类型字段
|
|
1510
|
+
const objOfFileType = ['preloadRule'];
|
|
1694
1511
|
|
|
1512
|
+
// 遍历分包中的每个配置项
|
|
1695
1513
|
Object.keys(subp).forEach(key => {
|
|
1696
1514
|
// 处理插件配置,检查是否有重复配置的插件
|
|
1697
1515
|
if (key === 'plugins') {
|
|
@@ -1699,15 +1517,15 @@ const fixAppJson = appJson => {
|
|
|
1699
1517
|
// 记录每个插件被哪些地方配置
|
|
1700
1518
|
pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
|
|
1701
1519
|
});
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1520
|
+
}
|
|
1704
1521
|
|
|
1522
|
+
// 处理数组类型字段(如requiredBackgroundModes),合并到app.json顶层并去重
|
|
1705
1523
|
if (arrOfFileType.indexOf(key) > -1) {
|
|
1706
1524
|
const preVal = appJson[key];
|
|
1707
1525
|
preVal ? appJson[key] = Array.from(new Set(preVal.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1526
|
+
}
|
|
1710
1527
|
|
|
1528
|
+
// 处理对象类型字段(如preloadRule),合并到app.json顶层,已存在的键值不覆盖
|
|
1711
1529
|
if (objOfFileType.indexOf(key) > -1) {
|
|
1712
1530
|
const preloadRuleMap = appJson[key] || {};
|
|
1713
1531
|
subp[key] && Object.keys(subp[key]).forEach(page => {
|
|
@@ -1717,45 +1535,46 @@ const fixAppJson = appJson => {
|
|
|
1717
1535
|
});
|
|
1718
1536
|
appJson[key] = preloadRuleMap;
|
|
1719
1537
|
}
|
|
1720
|
-
});
|
|
1538
|
+
});
|
|
1721
1539
|
|
|
1540
|
+
// 从分包配置中移除已提取到顶层的字段以及一些构建相关的内部字段
|
|
1722
1541
|
return filterField$7(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
|
|
1723
|
-
});
|
|
1542
|
+
});
|
|
1724
1543
|
|
|
1544
|
+
// 检查插件配置冲突,如果同一个插件在多处配置则报错
|
|
1725
1545
|
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
1726
1546
|
if (pluginsMap[pk].length > 1) {
|
|
1727
1547
|
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
1728
1548
|
}
|
|
1729
|
-
|
|
1730
1549
|
return '';
|
|
1731
1550
|
}).reduce((pre, cur) => pre + cur, '');
|
|
1732
|
-
|
|
1733
1551
|
if (pluginsErrMsg) {
|
|
1734
1552
|
throw new Error(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1553
|
+
}
|
|
1737
1554
|
|
|
1555
|
+
// 用处理后的分包配置更新app.json的subpackages字段
|
|
1738
1556
|
appJson.subpackages = subps;
|
|
1739
1557
|
};
|
|
1558
|
+
|
|
1740
1559
|
/**
|
|
1741
1560
|
* 合并分包配置,保留已有分包,添加新分包
|
|
1742
1561
|
* @param {Array} existingPackages 现有的分包配置
|
|
1743
1562
|
* @param {Array} newPackages 新的分包配置
|
|
1744
1563
|
* @returns {Array} 合并后的分包配置
|
|
1745
1564
|
*/
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
1565
|
function mergeSubPackages(existingPackages, newPackages) {
|
|
1749
1566
|
// 创建结果数组和root到索引的映射
|
|
1750
1567
|
const resultPackages = [...existingPackages];
|
|
1751
|
-
const rootMap = {};
|
|
1568
|
+
const rootMap = {};
|
|
1752
1569
|
|
|
1570
|
+
// 建立现有分包的root映射
|
|
1753
1571
|
existingPackages.forEach((pkg, index) => {
|
|
1754
1572
|
if (pkg.root) {
|
|
1755
1573
|
rootMap[pkg.root] = index;
|
|
1756
1574
|
}
|
|
1757
|
-
});
|
|
1575
|
+
});
|
|
1758
1576
|
|
|
1577
|
+
// 合并新分包
|
|
1759
1578
|
newPackages.forEach(newPkg => {
|
|
1760
1579
|
if (!newPkg.root) return; // 忽略没有root的分包
|
|
1761
1580
|
|
|
@@ -1769,45 +1588,42 @@ function mergeSubPackages(existingPackages, newPackages) {
|
|
|
1769
1588
|
});
|
|
1770
1589
|
return resultPackages;
|
|
1771
1590
|
}
|
|
1591
|
+
|
|
1772
1592
|
/**
|
|
1773
1593
|
* 动态生成编译后的app.json
|
|
1774
1594
|
* @param {object} tmsConfig
|
|
1775
1595
|
* @param {array} modules 用户要编译的模块列表
|
|
1776
1596
|
* @returns
|
|
1777
1597
|
*/
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
1598
|
async function buildOutputAppJson$3(tmsConfig, modules) {
|
|
1781
1599
|
try {
|
|
1782
1600
|
var _tmsConfig$hooks;
|
|
1783
|
-
|
|
1784
1601
|
// 获取所有模块,合并模块依赖的模块
|
|
1785
|
-
const modulesConfig = getModulesConfig(modules, tmsConfig, false);
|
|
1786
|
-
|
|
1787
|
-
const newSubPackages = getSubPackages$3(modulesConfig);
|
|
1788
|
-
|
|
1789
|
-
let appJson = getAppJsonContent(resolve$h('./app.json'));
|
|
1602
|
+
const modulesConfig = getModulesConfig(modules, tmsConfig, false);
|
|
1603
|
+
// 获取所有的分包
|
|
1604
|
+
const newSubPackages = getSubPackages$3(modulesConfig);
|
|
1605
|
+
// 获取app.json的配置
|
|
1606
|
+
let appJson = getAppJsonContent(resolve$h('./app.json'));
|
|
1790
1607
|
|
|
1608
|
+
// 保留已有分包配置,合并新的分包配置
|
|
1791
1609
|
const existingSubpackages = appJson.subpackages || [];
|
|
1792
1610
|
appJson.subpackages = mergeSubPackages(existingSubpackages, newSubPackages);
|
|
1793
|
-
appJson.subpackages.sort((item1, item2) => item1.root.localeCompare(item2.root));
|
|
1611
|
+
appJson.subpackages.sort((item1, item2) => item1.root.localeCompare(item2.root));
|
|
1794
1612
|
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
updateMainPackages(appJson, tmsConfig.mainPackages); // 模板渲染:先将 app.json 转为字符串,然后通过 preprocess 渲染
|
|
1613
|
+
// 处理appJson中重复||冲突的地方
|
|
1614
|
+
fixAppJson(appJson);
|
|
1615
|
+
// 处理 agent 配置:根据是否包含 meta-services 分包来添加或删除
|
|
1616
|
+
handleAgentConfig(appJson);
|
|
1617
|
+
// 更新主包,需在subpackages处理完成后执行, pages/
|
|
1618
|
+
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1802
1619
|
|
|
1620
|
+
// 模板渲染:先将 app.json 转为字符串,然后通过 preprocess 渲染
|
|
1803
1621
|
const appJsonStr = JSON.stringify(appJson, null, 2);
|
|
1804
1622
|
const preprocessedStr = pp$1.preprocess(appJsonStr, tmsConfig.templateVars || {}, 'json');
|
|
1805
1623
|
fs$e.writeFileSync(resolve$h(`${tmsConfig.outputDir}/app.json`), preprocessedStr, 'utf8');
|
|
1806
1624
|
appJson = JSON.parse(preprocessedStr);
|
|
1807
|
-
|
|
1808
1625
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1809
1626
|
var _tmsConfig$hooks2;
|
|
1810
|
-
|
|
1811
1627
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
|
|
1812
1628
|
tmsConfig: filterField$7(tmsConfig, ['gitAccount']),
|
|
1813
1629
|
cmdOptions: global$a.getData('cmdOptions'),
|
|
@@ -1817,14 +1633,12 @@ async function buildOutputAppJson$3(tmsConfig, modules) {
|
|
|
1817
1633
|
}));
|
|
1818
1634
|
report$9('hooks:updateAppJson');
|
|
1819
1635
|
}
|
|
1820
|
-
|
|
1821
1636
|
return appJson;
|
|
1822
1637
|
} catch (e) {
|
|
1823
1638
|
handleError$8(`生成app.json出现错误: ${e}`);
|
|
1824
1639
|
info$f(e);
|
|
1825
1640
|
}
|
|
1826
1641
|
}
|
|
1827
|
-
|
|
1828
1642
|
var buildAppJson = {
|
|
1829
1643
|
buildOutputAppJson: buildOutputAppJson$3
|
|
1830
1644
|
};
|
|
@@ -1851,16 +1665,15 @@ const {
|
|
|
1851
1665
|
const {
|
|
1852
1666
|
global: global$9
|
|
1853
1667
|
} = global_1;
|
|
1668
|
+
|
|
1854
1669
|
/**
|
|
1855
1670
|
* 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
|
|
1856
1671
|
* @param {*} httpRepoUrl
|
|
1857
1672
|
* @param {*} moduleName
|
|
1858
1673
|
* @returns
|
|
1859
1674
|
*/
|
|
1860
|
-
|
|
1861
1675
|
function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
1862
1676
|
var _tmsConfig$gitAccount, _tmsConfig$gitAccount2, _tmsConfig$gitAccount3;
|
|
1863
|
-
|
|
1864
1677
|
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1865
1678
|
const tmsConfig = global$9.getData('tmsConfig');
|
|
1866
1679
|
let gitUrl = httpRepoUrl;
|
|
@@ -1871,13 +1684,12 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
1871
1684
|
pass = ''
|
|
1872
1685
|
} = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount2 = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount2 === void 0 ? void 0 : _tmsConfig$gitAccount2[httpRepoUrl]) || (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount3 = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount3 === void 0 ? void 0 : _tmsConfig$gitAccount3[group]) || {};
|
|
1873
1686
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
1874
|
-
|
|
1875
1687
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
1876
1688
|
gitUrl = gitUrl.replace(urlPrefixReg, val => `${val}${encodeURIComponent(username)}:${encodeURIComponent(pass)}@`);
|
|
1877
1689
|
}
|
|
1878
|
-
|
|
1879
1690
|
return gitUrl;
|
|
1880
1691
|
}
|
|
1692
|
+
|
|
1881
1693
|
/**
|
|
1882
1694
|
* 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
|
|
1883
1695
|
* @param { string } sourceDir 缓存文件夹
|
|
@@ -1885,33 +1697,28 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
1885
1697
|
* @param { arrary } ignore
|
|
1886
1698
|
* @returns { undefined } no return
|
|
1887
1699
|
*/
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
1700
|
function moveFile(sourceDir, targetDir, ignore = []) {
|
|
1891
1701
|
if (fs$d.existsSync(targetDir)) {
|
|
1892
1702
|
shelljs$5.rm('-rf', targetDir);
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
|
|
1703
|
+
}
|
|
1704
|
+
// 删除不是文件夹的文件
|
|
1896
1705
|
return new Promise((resolve, reject) => {
|
|
1897
1706
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1898
1707
|
if (e) {
|
|
1899
1708
|
fail$5(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
|
|
1900
1709
|
reject(e);
|
|
1901
1710
|
}
|
|
1902
|
-
|
|
1903
1711
|
resolve();
|
|
1904
1712
|
});
|
|
1905
1713
|
});
|
|
1906
1714
|
}
|
|
1715
|
+
|
|
1907
1716
|
/**
|
|
1908
1717
|
* 根据gitUrl 和 branch取md5值
|
|
1909
1718
|
* @param {*} gitUrl
|
|
1910
1719
|
* @param {*} branch
|
|
1911
1720
|
* @returns
|
|
1912
1721
|
*/
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
1722
|
function md5ByGitUrlBranch(gitUrl, branch) {
|
|
1916
1723
|
const newBranch = branch && typeof branch === 'string' ? branch : 'master';
|
|
1917
1724
|
return crypto$2.createHash('md5').update(JSON.stringify({
|
|
@@ -1919,19 +1726,19 @@ function md5ByGitUrlBranch(gitUrl, branch) {
|
|
|
1919
1726
|
branch: newBranch
|
|
1920
1727
|
})).digest('hex');
|
|
1921
1728
|
}
|
|
1729
|
+
|
|
1922
1730
|
/**
|
|
1923
1731
|
* 下载目标模块
|
|
1924
1732
|
* @param { string } sourceDir 缓存文件夹
|
|
1925
1733
|
* @param { string } targetDir 目标文件夹
|
|
1926
1734
|
* @returns { array } modules 描述模块的列表
|
|
1927
1735
|
*/
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
1736
|
async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
1931
|
-
const cwd = process.cwd();
|
|
1932
|
-
|
|
1933
|
-
const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules);
|
|
1737
|
+
const cwd = process.cwd();
|
|
1738
|
+
// 收集下载模块代码的任务
|
|
1739
|
+
const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules);
|
|
1934
1740
|
|
|
1741
|
+
// 开始执行下载和移动代码的任务
|
|
1935
1742
|
const arrPromises = [];
|
|
1936
1743
|
downloadTasksMap.forEach(({
|
|
1937
1744
|
promiseTask,
|
|
@@ -1951,14 +1758,13 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1951
1758
|
await Promise.all(arrPromises);
|
|
1952
1759
|
shelljs$5.cd(cwd);
|
|
1953
1760
|
}
|
|
1761
|
+
|
|
1954
1762
|
/**
|
|
1955
1763
|
* 收集下载模块代码的任务
|
|
1956
1764
|
* @param { string } sourceDir 代码缓存文件夹
|
|
1957
1765
|
* @param { string } targetDir 代码要放到的目标文件夹
|
|
1958
1766
|
* @returns { array } modules 描述模块的列表
|
|
1959
1767
|
*/
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
1768
|
function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
1963
1769
|
// 下载代码任务 Map (key解释 缓存代码路径/md5(gitUrl,branch)
|
|
1964
1770
|
// {
|
|
@@ -1973,7 +1779,6 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1973
1779
|
// }
|
|
1974
1780
|
// }
|
|
1975
1781
|
const downloadTasksMap = new Map();
|
|
1976
|
-
|
|
1977
1782
|
for (const moduleInfo of modules) {
|
|
1978
1783
|
if (moduleInfo.repoInfo) {
|
|
1979
1784
|
const {
|
|
@@ -1984,18 +1789,20 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1984
1789
|
},
|
|
1985
1790
|
path,
|
|
1986
1791
|
moduleName
|
|
1987
|
-
} = moduleInfo;
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1792
|
+
} = moduleInfo;
|
|
1793
|
+
|
|
1794
|
+
// 处理仓库权限问题
|
|
1795
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
|
|
1796
|
+
// 根据gitUrl与branch计算md5
|
|
1797
|
+
const md5Key = md5ByGitUrlBranch(gitUrl, branch);
|
|
1798
|
+
// git源码临时存在的源目录
|
|
1799
|
+
const sourcePath = resolve$g(sourceDir, md5Key);
|
|
1800
|
+
// 模块源码要放到目标目录
|
|
1801
|
+
const targetPath = resolve$g(targetDir, path);
|
|
1802
|
+
// 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
|
|
1803
|
+
const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath;
|
|
1804
|
+
|
|
1805
|
+
// 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
|
|
1999
1806
|
const callback = {
|
|
2000
1807
|
params: {
|
|
2001
1808
|
sourceModulePath,
|
|
@@ -2005,18 +1812,15 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
2005
1812
|
if (fs$d.existsSync(targetPath)) {
|
|
2006
1813
|
shelljs$5.rm('-rf', `${targetPath}/*`);
|
|
2007
1814
|
}
|
|
2008
|
-
|
|
2009
1815
|
await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
|
|
2010
1816
|
}
|
|
2011
1817
|
};
|
|
2012
|
-
|
|
2013
1818
|
if (downloadTasksMap.has(sourcePath)) {
|
|
2014
1819
|
const task = downloadTasksMap.get(sourcePath);
|
|
2015
1820
|
task.callbacks.push(callback);
|
|
2016
1821
|
downloadTasksMap.set(sourcePath, task);
|
|
2017
1822
|
} else {
|
|
2018
1823
|
let promiseTask;
|
|
2019
|
-
|
|
2020
1824
|
if (fs$d.existsSync(sourcePath) && fs$d.existsSync(`${sourcePath}/.git`)) {
|
|
2021
1825
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
2022
1826
|
info$e(`git pull:${httpRepoUrl} --branch: ${branch}`);
|
|
@@ -2031,7 +1835,6 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
2031
1835
|
return downloadRepoForGit(gitUrl, sourcePath, branch);
|
|
2032
1836
|
};
|
|
2033
1837
|
}
|
|
2034
|
-
|
|
2035
1838
|
downloadTasksMap.set(sourcePath, {
|
|
2036
1839
|
promiseTask,
|
|
2037
1840
|
params: {
|
|
@@ -2045,17 +1848,15 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
2045
1848
|
}
|
|
2046
1849
|
}
|
|
2047
1850
|
}
|
|
2048
|
-
|
|
2049
1851
|
return downloadTasksMap;
|
|
2050
1852
|
}
|
|
1853
|
+
|
|
2051
1854
|
/**
|
|
2052
1855
|
* 检查远程模块的gitUrl与 branch是否有更新
|
|
2053
1856
|
* @param {string} sourceDir 模块源码在缓存区的目录
|
|
2054
1857
|
* @param {object} moduleInfo 模块的配置信息
|
|
2055
1858
|
* @returns
|
|
2056
1859
|
*/
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
1860
|
function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
2060
1861
|
if (moduleInfo.repoInfo) {
|
|
2061
1862
|
const {
|
|
@@ -2067,15 +1868,12 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
|
2067
1868
|
} = moduleInfo;
|
|
2068
1869
|
const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
|
|
2069
1870
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
2070
|
-
|
|
2071
1871
|
if (!fs$d.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
2072
1872
|
return true;
|
|
2073
1873
|
}
|
|
2074
1874
|
}
|
|
2075
|
-
|
|
2076
1875
|
return false;
|
|
2077
1876
|
}
|
|
2078
|
-
|
|
2079
1877
|
var cloneModules_1 = {
|
|
2080
1878
|
cloneModules: cloneModules$1,
|
|
2081
1879
|
checkRemoteModGitUrlBranch
|
|
@@ -2083,11 +1881,11 @@ var cloneModules_1 = {
|
|
|
2083
1881
|
|
|
2084
1882
|
const ci = require$$0__default$7;
|
|
2085
1883
|
const path$c = require$$1__default$1;
|
|
1884
|
+
|
|
2086
1885
|
/**
|
|
2087
1886
|
* 获取小程序ci的Project对象
|
|
2088
1887
|
* @returns {Object} 小程序ci对象
|
|
2089
1888
|
*/
|
|
2090
|
-
|
|
2091
1889
|
const getMpCi = ({
|
|
2092
1890
|
appId,
|
|
2093
1891
|
projectPath,
|
|
@@ -2095,9 +1893,7 @@ const getMpCi = ({
|
|
|
2095
1893
|
privateKey = 'TODO'
|
|
2096
1894
|
}) => {
|
|
2097
1895
|
var _projectCg$packOption, _projectCg$packOption2;
|
|
2098
|
-
|
|
2099
1896
|
const projectCg = require(path$c.join(projectPath, 'project.config.json'));
|
|
2100
|
-
|
|
2101
1897
|
const ignores = (projectCg === null || projectCg === void 0 ? void 0 : (_projectCg$packOption = projectCg.packOptions) === null || _projectCg$packOption === void 0 ? void 0 : (_projectCg$packOption2 = _projectCg$packOption.ignore) === null || _projectCg$packOption2 === void 0 ? void 0 : _projectCg$packOption2.map(({
|
|
2102
1898
|
value
|
|
2103
1899
|
}) => value)) || [];
|
|
@@ -2109,22 +1905,21 @@ const getMpCi = ({
|
|
|
2109
1905
|
ignores: ['node_modules/**/*', 'cloud/**/*', ...ignores]
|
|
2110
1906
|
});
|
|
2111
1907
|
};
|
|
1908
|
+
|
|
2112
1909
|
/**
|
|
2113
1910
|
* 格式化构建npm结果信息
|
|
2114
1911
|
* @param {Array<String>} warning 构建时的告警信息
|
|
2115
1912
|
* @returns {String} npm构建错误信息
|
|
2116
1913
|
*/
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
1914
|
const formatPackNpmWarning = warning => {
|
|
2120
1915
|
if (!warning) {
|
|
2121
1916
|
return '';
|
|
2122
1917
|
}
|
|
2123
|
-
|
|
2124
1918
|
const result = warning.map((it, index) => `${index + 1}. ${it.msg}
|
|
2125
1919
|
\t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
|
|
2126
1920
|
return result;
|
|
2127
1921
|
};
|
|
1922
|
+
|
|
2128
1923
|
/**
|
|
2129
1924
|
* 构建miniprogram_npm https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E6%9E%84%E5%BB%BAnpm
|
|
2130
1925
|
* * @param {object} {
|
|
@@ -2133,8 +1928,6 @@ const formatPackNpmWarning = warning => {
|
|
|
2133
1928
|
* privateKey,
|
|
2134
1929
|
* }
|
|
2135
1930
|
*/
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
1931
|
const buildMpNpm$1 = async ({
|
|
2139
1932
|
appId,
|
|
2140
1933
|
projectPath,
|
|
@@ -2149,13 +1942,12 @@ const buildMpNpm$1 = async ({
|
|
|
2149
1942
|
ignores: ['cloud/**/*']
|
|
2150
1943
|
});
|
|
2151
1944
|
const packNpmMsg = formatPackNpmWarning(packNpmWarning);
|
|
2152
|
-
|
|
2153
1945
|
if (packNpmMsg) {
|
|
2154
1946
|
return Promise.reject(packNpmMsg);
|
|
2155
1947
|
}
|
|
2156
|
-
|
|
2157
1948
|
return Promise.resolve();
|
|
2158
1949
|
};
|
|
1950
|
+
|
|
2159
1951
|
/**
|
|
2160
1952
|
* 预览小程序码 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88
|
|
2161
1953
|
* @param {object} {
|
|
@@ -2166,8 +1958,6 @@ const buildMpNpm$1 = async ({
|
|
|
2166
1958
|
* robot
|
|
2167
1959
|
* }
|
|
2168
1960
|
*/
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
1961
|
const previewMp = async (params = {}) => {
|
|
2172
1962
|
const {
|
|
2173
1963
|
appId,
|
|
@@ -2186,6 +1976,7 @@ const previewMp = async (params = {}) => {
|
|
|
2186
1976
|
onProgressUpdate: () => {}
|
|
2187
1977
|
});
|
|
2188
1978
|
};
|
|
1979
|
+
|
|
2189
1980
|
/**
|
|
2190
1981
|
* 上传小程序 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E4%B8%8A%E4%BC%A0
|
|
2191
1982
|
* @param {object} {
|
|
@@ -2196,8 +1987,6 @@ const previewMp = async (params = {}) => {
|
|
|
2196
1987
|
* desc
|
|
2197
1988
|
* }
|
|
2198
1989
|
*/
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
1990
|
const uploadMp = async (params = {}) => {
|
|
2202
1991
|
const {
|
|
2203
1992
|
appId,
|
|
@@ -2216,7 +2005,6 @@ const uploadMp = async (params = {}) => {
|
|
|
2216
2005
|
onProgressUpdate: () => {}
|
|
2217
2006
|
});
|
|
2218
2007
|
};
|
|
2219
|
-
|
|
2220
2008
|
const getDevSourceMap = async (params = {}) => {
|
|
2221
2009
|
const {
|
|
2222
2010
|
appId,
|
|
@@ -2236,7 +2024,6 @@ const getDevSourceMap = async (params = {}) => {
|
|
|
2236
2024
|
sourceMapSavePath
|
|
2237
2025
|
});
|
|
2238
2026
|
};
|
|
2239
|
-
|
|
2240
2027
|
var mpCi$3 = {
|
|
2241
2028
|
buildMpNpm: buildMpNpm$1,
|
|
2242
2029
|
previewMp,
|
|
@@ -2252,42 +2039,31 @@ const {
|
|
|
2252
2039
|
const {
|
|
2253
2040
|
ensureDirExist: ensureDirExist$4
|
|
2254
2041
|
} = io$3;
|
|
2255
|
-
|
|
2256
2042
|
function getCache$1(projectDir, type) {
|
|
2257
2043
|
var _content$projectDir;
|
|
2258
|
-
|
|
2259
2044
|
const filePath = NPM_CACHE_FILE;
|
|
2260
|
-
|
|
2261
2045
|
if (!fs$c.existsSync(filePath)) {
|
|
2262
2046
|
return null;
|
|
2263
2047
|
}
|
|
2264
|
-
|
|
2265
2048
|
const content = require(filePath);
|
|
2266
|
-
|
|
2267
2049
|
return content === null || content === void 0 ? void 0 : (_content$projectDir = content[projectDir]) === null || _content$projectDir === void 0 ? void 0 : _content$projectDir[type];
|
|
2268
2050
|
}
|
|
2269
|
-
|
|
2270
2051
|
function setCache$1(projectDir, type = 'miniprogram_npm', data) {
|
|
2271
2052
|
const filePath = NPM_CACHE_FILE;
|
|
2272
|
-
|
|
2273
2053
|
if (!fs$c.existsSync(filePath)) {
|
|
2274
2054
|
const dir = path$b.dirname(filePath);
|
|
2275
2055
|
ensureDirExist$4(dir);
|
|
2276
2056
|
fs$c.writeFileSync(filePath, '{}');
|
|
2277
2057
|
}
|
|
2278
|
-
|
|
2279
2058
|
const content = require(filePath);
|
|
2280
|
-
|
|
2281
2059
|
if (!content[projectDir]) {
|
|
2282
2060
|
content[projectDir] = {};
|
|
2283
2061
|
}
|
|
2284
|
-
|
|
2285
2062
|
content[projectDir] = {
|
|
2286
2063
|
[type]: data
|
|
2287
2064
|
};
|
|
2288
2065
|
fs$c.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
2289
2066
|
}
|
|
2290
|
-
|
|
2291
2067
|
var cache = {
|
|
2292
2068
|
setCache: setCache$1,
|
|
2293
2069
|
getCache: getCache$1
|
|
@@ -2331,26 +2107,23 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
2331
2107
|
// }
|
|
2332
2108
|
// }
|
|
2333
2109
|
const npmTasksMap = new Map();
|
|
2334
|
-
|
|
2335
2110
|
for (const packageJsonPath of packageJsonFiles) {
|
|
2336
2111
|
const packageContent = fs$b.readFileSync(packageJsonPath);
|
|
2337
2112
|
let packageJson;
|
|
2338
|
-
|
|
2339
2113
|
try {
|
|
2340
2114
|
packageJson = JSON.parse(packageContent);
|
|
2341
2115
|
} catch (e) {
|
|
2342
2116
|
throw new Error(`${packageJsonPath}json解析出现错误:${e}`);
|
|
2343
2117
|
}
|
|
2344
|
-
|
|
2345
2118
|
const md5Obj = {
|
|
2346
2119
|
dependencies: packageJson.dependencies || {}
|
|
2347
2120
|
};
|
|
2348
|
-
|
|
2349
2121
|
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
2350
2122
|
const md5Key = crypto$1.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
2351
2123
|
const cacheNMPath = path$a.join(cacheDir, md5Key);
|
|
2352
|
-
const cacheNMTarFile = path$a.join(cacheNMPath, 'node_modules.tar.gz');
|
|
2124
|
+
const cacheNMTarFile = path$a.join(cacheNMPath, 'node_modules.tar.gz');
|
|
2353
2125
|
|
|
2126
|
+
// 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
2354
2127
|
const callback = {
|
|
2355
2128
|
params: {
|
|
2356
2129
|
cacheNMPath,
|
|
@@ -2361,7 +2134,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
2361
2134
|
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
2362
2135
|
shell.cd(cacheNMPath);
|
|
2363
2136
|
shell.cp('-Rf', cacheNMTarFile, `${packageJsonDir}/`);
|
|
2364
|
-
const newShellJsOption = {
|
|
2137
|
+
const newShellJsOption = {
|
|
2138
|
+
...shellJsOption,
|
|
2365
2139
|
cwd: packageJsonDir
|
|
2366
2140
|
};
|
|
2367
2141
|
shell.cd(packageJsonDir);
|
|
@@ -2369,16 +2143,13 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
2369
2143
|
shell.rm('-rf', './node_modules.tar.gz');
|
|
2370
2144
|
}
|
|
2371
2145
|
};
|
|
2372
|
-
|
|
2373
2146
|
if (npmTasksMap.has(cacheNMPath)) {
|
|
2374
2147
|
const task = npmTasksMap.get(cacheNMPath);
|
|
2375
2148
|
task.callbacks.push(callback);
|
|
2376
2149
|
npmTasksMap.set(cacheNMPath, task);
|
|
2377
2150
|
} else {
|
|
2378
2151
|
const missCache = !fsExtra.pathExistsSync(cacheNMPath) || !fsExtra.existsSync(cacheNMTarFile) || fsExtra.statSync(cacheNMTarFile).size < 512;
|
|
2379
|
-
|
|
2380
2152
|
let promiseTask = () => Promise.resolve();
|
|
2381
|
-
|
|
2382
2153
|
if (missCache) {
|
|
2383
2154
|
promiseTask = (packageJsonPath, cacheNMPath, shell) => {
|
|
2384
2155
|
fsExtra.emptydirSync(cacheNMPath);
|
|
@@ -2386,7 +2157,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
2386
2157
|
log.info(`npm install: ${packageJsonPath}`);
|
|
2387
2158
|
const tmsConfig = global$8.getData('tmsConfig');
|
|
2388
2159
|
return npmInstall$2(cacheNMPath, tmsConfig.npm).then(() => {
|
|
2389
|
-
const newShellJsOption = {
|
|
2160
|
+
const newShellJsOption = {
|
|
2161
|
+
...shellJsOption,
|
|
2390
2162
|
cwd: cacheNMPath
|
|
2391
2163
|
};
|
|
2392
2164
|
shell.cd(cacheNMPath);
|
|
@@ -2395,7 +2167,6 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
2395
2167
|
});
|
|
2396
2168
|
};
|
|
2397
2169
|
}
|
|
2398
|
-
|
|
2399
2170
|
npmTasksMap.set(cacheNMPath, {
|
|
2400
2171
|
promiseTask,
|
|
2401
2172
|
params: {
|
|
@@ -2408,17 +2179,18 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
2408
2179
|
}
|
|
2409
2180
|
}
|
|
2410
2181
|
}
|
|
2411
|
-
|
|
2412
2182
|
return npmTasksMap;
|
|
2413
|
-
};
|
|
2414
|
-
|
|
2183
|
+
};
|
|
2415
2184
|
|
|
2185
|
+
// 遍历安装指定目录下所有项目的npm依赖
|
|
2416
2186
|
const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
|
|
2417
2187
|
const cwd = process.cwd();
|
|
2418
|
-
const packageJsonFiles = await findAllPackageJson(subPackages, contextDir);
|
|
2188
|
+
const packageJsonFiles = await findAllPackageJson(subPackages, contextDir);
|
|
2419
2189
|
|
|
2420
|
-
|
|
2190
|
+
// 收集npm install的任务
|
|
2191
|
+
const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir);
|
|
2421
2192
|
|
|
2193
|
+
// 开始执行npm install和回调(移动)的任务
|
|
2422
2194
|
const arrPromises = [];
|
|
2423
2195
|
npmTasksMap.forEach(({
|
|
2424
2196
|
promiseTask,
|
|
@@ -2439,14 +2211,13 @@ const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
|
|
|
2439
2211
|
shell.cd(cwd);
|
|
2440
2212
|
return packageJsonFiles;
|
|
2441
2213
|
};
|
|
2214
|
+
|
|
2442
2215
|
/**
|
|
2443
2216
|
* 递归查找指定条件的文件
|
|
2444
2217
|
* @param {String} startPath 开始查找的根路径
|
|
2445
2218
|
* @param {String} filter 匹配的字符串
|
|
2446
2219
|
* @returns {Array<String>} 查找到的文件路径列表
|
|
2447
2220
|
*/
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
2221
|
const findFilesByFilter = (startPath, filter) => {
|
|
2451
2222
|
const result = [];
|
|
2452
2223
|
/**
|
|
@@ -2455,27 +2226,24 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
2455
2226
|
* @param {String} filter 筛选器
|
|
2456
2227
|
* @returns {Undefined} 无需返回值
|
|
2457
2228
|
*/
|
|
2458
|
-
|
|
2459
2229
|
const find = (startPath, filter) => {
|
|
2460
2230
|
// 目录不存在
|
|
2461
2231
|
if (!fs$b.existsSync(startPath)) {
|
|
2462
2232
|
log.fail(`${startPath}目录不存在`);
|
|
2463
2233
|
process.exit(-1);
|
|
2464
2234
|
return;
|
|
2465
|
-
}
|
|
2466
|
-
|
|
2235
|
+
}
|
|
2467
2236
|
|
|
2237
|
+
// 当前目录下的所有文件 / 文件夹
|
|
2468
2238
|
const exceptDir = ['node_modules', 'miniprogram_npm'];
|
|
2469
|
-
|
|
2470
2239
|
if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
|
|
2471
2240
|
return;
|
|
2472
2241
|
}
|
|
2473
|
-
|
|
2474
2242
|
const files = fs$b.readdirSync(startPath);
|
|
2475
2243
|
files.forEach(file => {
|
|
2476
2244
|
const filename = path$a.join(startPath, file);
|
|
2477
|
-
const stat = fs$b.lstatSync(filename);
|
|
2478
|
-
|
|
2245
|
+
const stat = fs$b.lstatSync(filename);
|
|
2246
|
+
// 当前文件是文件夹类型,继续递归
|
|
2479
2247
|
if (stat.isDirectory()) {
|
|
2480
2248
|
find(filename, filter);
|
|
2481
2249
|
} else if (filename.indexOf(filter) >= 0) {
|
|
@@ -2484,33 +2252,28 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
2484
2252
|
}
|
|
2485
2253
|
});
|
|
2486
2254
|
};
|
|
2487
|
-
|
|
2488
2255
|
find(startPath, filter);
|
|
2489
2256
|
return result;
|
|
2490
2257
|
};
|
|
2258
|
+
|
|
2491
2259
|
/**
|
|
2492
2260
|
* 找到项目中所有的package.json文件
|
|
2493
2261
|
* @param {Array<String>} subRoots 需要安装npm依赖的路径
|
|
2494
2262
|
* @param {String} contextDir 命令运行的目录
|
|
2495
2263
|
* @returns {Array<String>} 找到的所有package.json文件的路径
|
|
2496
2264
|
*/
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
2265
|
const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
2500
2266
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
2501
|
-
|
|
2502
2267
|
const cwd = contextDir || dirPath;
|
|
2503
2268
|
const result = [path$a.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
2504
2269
|
|
|
2505
2270
|
subRoots.forEach(subRoot => {
|
|
2506
2271
|
const toppath = path$a.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
2507
|
-
|
|
2508
2272
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
2509
2273
|
result.push(...list);
|
|
2510
2274
|
});
|
|
2511
2275
|
return result;
|
|
2512
2276
|
};
|
|
2513
|
-
|
|
2514
2277
|
var npm = {
|
|
2515
2278
|
npmInstallAll: npmInstallAll$1,
|
|
2516
2279
|
findAllPackageJson,
|
|
@@ -2519,7 +2282,6 @@ var npm = {
|
|
|
2519
2282
|
|
|
2520
2283
|
const crypto = require$$1__default$6;
|
|
2521
2284
|
const fs$a = require$$0__default$1;
|
|
2522
|
-
|
|
2523
2285
|
function fileMd5$1(filePath) {
|
|
2524
2286
|
return new Promise((resolve, reject) => {
|
|
2525
2287
|
const md5sum = crypto.createHash('md5');
|
|
@@ -2536,7 +2298,6 @@ function fileMd5$1(filePath) {
|
|
|
2536
2298
|
});
|
|
2537
2299
|
});
|
|
2538
2300
|
}
|
|
2539
|
-
|
|
2540
2301
|
var md5 = {
|
|
2541
2302
|
fileMd5: fileMd5$1
|
|
2542
2303
|
};
|
|
@@ -2552,30 +2313,25 @@ const shelljs$4 = require$$0__default$2;
|
|
|
2552
2313
|
const {
|
|
2553
2314
|
handleError: handleError$5
|
|
2554
2315
|
} = handleError_1;
|
|
2555
|
-
|
|
2556
2316
|
const getLatestVersion = npmName => {
|
|
2557
2317
|
const data = shelljs$4.exec(`npm view ${npmName} version`);
|
|
2558
|
-
|
|
2559
2318
|
if (data.code === 0) {
|
|
2560
2319
|
return data.stdout;
|
|
2561
2320
|
}
|
|
2562
|
-
|
|
2563
2321
|
return '0.0.0';
|
|
2564
|
-
};
|
|
2565
|
-
|
|
2322
|
+
};
|
|
2566
2323
|
|
|
2324
|
+
// 收集package.json
|
|
2567
2325
|
function collectPackageJson(subPackages, cwd, outputDir) {
|
|
2568
2326
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
2569
2327
|
// 1.1根目录的package.json
|
|
2570
|
-
|
|
2571
2328
|
const packageArr = [{
|
|
2572
2329
|
srcPackageDir: path$9.join(cwd, packageJsonName),
|
|
2573
2330
|
destNpmDir: resolve$f(outputDir, 'node_modules')
|
|
2574
|
-
}];
|
|
2575
|
-
|
|
2331
|
+
}];
|
|
2332
|
+
// 1.2模块的package.json
|
|
2576
2333
|
subPackages.forEach(item => {
|
|
2577
2334
|
const srcPackageDir = `${getAbsolutePath$5(item.path)}/package.json`;
|
|
2578
|
-
|
|
2579
2335
|
if (fs$9.existsSync(srcPackageDir)) {
|
|
2580
2336
|
packageArr.push({
|
|
2581
2337
|
srcPackageDir,
|
|
@@ -2584,22 +2340,21 @@ function collectPackageJson(subPackages, cwd, outputDir) {
|
|
|
2584
2340
|
}
|
|
2585
2341
|
});
|
|
2586
2342
|
return packageArr;
|
|
2587
|
-
}
|
|
2588
|
-
|
|
2343
|
+
}
|
|
2589
2344
|
|
|
2345
|
+
// 读取package.json的依赖
|
|
2590
2346
|
function readPackageDependencies(srcPackageDir) {
|
|
2591
2347
|
const packageJson = fs$9.readFileSync(srcPackageDir, 'utf-8');
|
|
2592
2348
|
let dependencies = {};
|
|
2593
|
-
|
|
2594
2349
|
try {
|
|
2595
2350
|
const json = packageJson ? JSON.parse(packageJson) : {};
|
|
2596
2351
|
dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
|
|
2597
2352
|
} catch (e) {
|
|
2598
2353
|
handleError$5(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
2599
2354
|
}
|
|
2600
|
-
|
|
2601
2355
|
return dependencies;
|
|
2602
2356
|
}
|
|
2357
|
+
|
|
2603
2358
|
/**
|
|
2604
2359
|
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
2605
2360
|
* @param {*} subPackages 模块
|
|
@@ -2607,51 +2362,40 @@ function readPackageDependencies(srcPackageDir) {
|
|
|
2607
2362
|
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
2608
2363
|
* @returns
|
|
2609
2364
|
*/
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
2365
|
const isDependenciesUpdate$1 = (subPackages, cwd, outputDir) => {
|
|
2613
2366
|
// 步骤1. 收集package.json
|
|
2614
|
-
const packageArr = collectPackageJson(subPackages, cwd, outputDir);
|
|
2615
|
-
|
|
2367
|
+
const packageArr = collectPackageJson(subPackages, cwd, outputDir);
|
|
2368
|
+
// 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
2616
2369
|
return checkPackageVersion$1(packageArr);
|
|
2617
|
-
};
|
|
2618
|
-
|
|
2370
|
+
};
|
|
2619
2371
|
|
|
2372
|
+
// 比较package.json的依赖与node_modules依赖的版本号
|
|
2620
2373
|
const checkPackageVersion$1 = packageArr => {
|
|
2621
2374
|
for (const item of packageArr) {
|
|
2622
2375
|
const dependencies = readPackageDependencies(item.srcPackageDir);
|
|
2623
2376
|
const dependenciesKeys = Object.keys(dependencies);
|
|
2624
|
-
|
|
2625
2377
|
for (const key of dependenciesKeys) {
|
|
2626
2378
|
const depPath = path$9.join(item.destNpmDir, key);
|
|
2627
|
-
|
|
2628
2379
|
if (!fs$9.existsSync(depPath)) {
|
|
2629
2380
|
return true;
|
|
2630
2381
|
}
|
|
2631
|
-
|
|
2632
2382
|
const depPackagePath = path$9.join(depPath, 'package.json');
|
|
2633
|
-
|
|
2634
2383
|
if (fs$9.existsSync(depPackagePath)) {
|
|
2635
2384
|
const packageData = require(depPackagePath);
|
|
2636
|
-
|
|
2637
2385
|
if (dependencies[key] === 'latest') {
|
|
2638
2386
|
dependencies[key] = getLatestVersion(key);
|
|
2639
2387
|
}
|
|
2640
|
-
|
|
2641
2388
|
if (packageData.version === 'latest') {
|
|
2642
2389
|
packageData.version = getLatestVersion(key);
|
|
2643
2390
|
}
|
|
2644
|
-
|
|
2645
2391
|
if (semver$1.lt(packageData.version, semver$1.minVersion(dependencies[key]).version)) {
|
|
2646
2392
|
return true;
|
|
2647
2393
|
}
|
|
2648
2394
|
}
|
|
2649
2395
|
}
|
|
2650
2396
|
}
|
|
2651
|
-
|
|
2652
2397
|
return false;
|
|
2653
2398
|
};
|
|
2654
|
-
|
|
2655
2399
|
var checkDependencies = {
|
|
2656
2400
|
isDependenciesUpdate: isDependenciesUpdate$1,
|
|
2657
2401
|
checkPackageVersion: checkPackageVersion$1
|
|
@@ -2692,15 +2436,12 @@ const {
|
|
|
2692
2436
|
const {
|
|
2693
2437
|
isDependenciesUpdate
|
|
2694
2438
|
} = checkDependencies;
|
|
2695
|
-
|
|
2696
2439
|
async function install$3(tmsConfig, subPackages, useCache = true) {
|
|
2697
2440
|
var _tmsConfig$hooks;
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2441
|
+
const cwd = process.cwd();
|
|
2442
|
+
// 加npm install之前的钩子
|
|
2701
2443
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeNpmInstall) === 'function') {
|
|
2702
2444
|
var _tmsConfig$hooks2;
|
|
2703
|
-
|
|
2704
2445
|
info$d('—————— 执行beforeNpmInstall ————');
|
|
2705
2446
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeNpmInstall({
|
|
2706
2447
|
tmsConfig: filterField$6(tmsConfig, ['gitAccount']),
|
|
@@ -2708,8 +2449,9 @@ async function install$3(tmsConfig, subPackages, useCache = true) {
|
|
|
2708
2449
|
}));
|
|
2709
2450
|
info$d('—————— 执行beforeNpmInstall 完成 ————');
|
|
2710
2451
|
}
|
|
2711
|
-
const npmInstallRes = await createTask$5(npmInstall$1, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache);
|
|
2452
|
+
const npmInstallRes = await createTask$5(npmInstall$1, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache);
|
|
2712
2453
|
|
|
2454
|
+
// 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
|
|
2713
2455
|
if (!npmInstallRes.isCache) {
|
|
2714
2456
|
// 构建miniprogram_npm, 不使用缓存
|
|
2715
2457
|
await createTask$5(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
|
|
@@ -2717,10 +2459,8 @@ async function install$3(tmsConfig, subPackages, useCache = true) {
|
|
|
2717
2459
|
// 构建miniprogram_npm
|
|
2718
2460
|
await createTask$5(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
|
|
2719
2461
|
}
|
|
2720
|
-
|
|
2721
2462
|
shelljs$3.cd(cwd);
|
|
2722
2463
|
}
|
|
2723
|
-
|
|
2724
2464
|
async function npmInstall$1(tmsConfig, subPackages, useCache) {
|
|
2725
2465
|
// 如果依赖没有更新和使用缓存数据(则命中缓存)
|
|
2726
2466
|
if (!isDependenciesUpdate(subPackages, resolve$e('./'), tmsConfig.outputDir) && useCache) {
|
|
@@ -2728,9 +2468,8 @@ async function npmInstall$1(tmsConfig, subPackages, useCache) {
|
|
|
2728
2468
|
return {
|
|
2729
2469
|
isCache: true
|
|
2730
2470
|
};
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2733
|
-
|
|
2471
|
+
}
|
|
2472
|
+
// 拷贝模块的package.json到编译输出目录
|
|
2734
2473
|
subPackages.forEach(item => {
|
|
2735
2474
|
const outputModuleDir = resolve$e(`${tmsConfig.outputDir}/${item.root}`);
|
|
2736
2475
|
io$1.ensureDirExist(outputModuleDir);
|
|
@@ -2741,20 +2480,17 @@ async function npmInstall$1(tmsConfig, subPackages, useCache) {
|
|
|
2741
2480
|
return {
|
|
2742
2481
|
isCache: false
|
|
2743
2482
|
};
|
|
2744
|
-
}
|
|
2745
|
-
|
|
2483
|
+
}
|
|
2746
2484
|
|
|
2485
|
+
// 构建miniprogram_npm
|
|
2747
2486
|
async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
2748
2487
|
const packageJsonFiles = [];
|
|
2749
2488
|
const rootPackFile = resolve$e(`${tmsConfig.outputDir}/package.json`);
|
|
2750
|
-
|
|
2751
2489
|
if (fs$8.existsSync(rootPackFile)) {
|
|
2752
2490
|
packageJsonFiles.push(rootPackFile);
|
|
2753
2491
|
}
|
|
2754
|
-
|
|
2755
2492
|
subPackages.forEach(item => {
|
|
2756
2493
|
const packageJsonFile = resolve$e(`${tmsConfig.outputDir}/${item.root}/package.json`);
|
|
2757
|
-
|
|
2758
2494
|
if (fs$8.existsSync(packageJsonFile)) {
|
|
2759
2495
|
packageJsonFiles.push(packageJsonFile);
|
|
2760
2496
|
}
|
|
@@ -2764,29 +2500,27 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
|
2764
2500
|
success: 1,
|
|
2765
2501
|
doing: 2
|
|
2766
2502
|
};
|
|
2767
|
-
|
|
2768
2503
|
if (useCache) {
|
|
2769
2504
|
let flag = true;
|
|
2770
2505
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2771
2506
|
const packageDir = path$8.dirname(item);
|
|
2772
2507
|
const mpDir = resolve$e(`${packageDir}/miniprogram_npm`);
|
|
2773
2508
|
const md5Value = await getMNPMd5(packageDir);
|
|
2774
|
-
const preCache = getCache(mpDir, 'miniprogram_npm');
|
|
2509
|
+
const preCache = getCache(mpDir, 'miniprogram_npm');
|
|
2510
|
+
// console.log('miniprogram_npm', preCache, md5Value);
|
|
2775
2511
|
// 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
|
|
2776
|
-
|
|
2777
2512
|
if ((preCache === null || preCache === void 0 ? void 0 : preCache.status) !== statusMap.success || (preCache === null || preCache === void 0 ? void 0 : preCache.md5) !== md5Value) {
|
|
2778
2513
|
flag = false;
|
|
2779
2514
|
}
|
|
2780
2515
|
}));
|
|
2781
2516
|
isCache = flag;
|
|
2782
2517
|
}
|
|
2783
|
-
|
|
2784
2518
|
if (isCache) {
|
|
2785
2519
|
info$d('miniprogram_npm命中缓存');
|
|
2786
2520
|
return;
|
|
2787
|
-
}
|
|
2788
|
-
|
|
2521
|
+
}
|
|
2789
2522
|
|
|
2523
|
+
// 即将构建,在cache中标记开始
|
|
2790
2524
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2791
2525
|
const packageDir = path$8.dirname(item);
|
|
2792
2526
|
const mpDir = resolve$e(`${packageDir}/miniprogram_npm`);
|
|
@@ -2799,8 +2533,9 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
|
2799
2533
|
appId: tmsConfig.appId,
|
|
2800
2534
|
projectPath: resolve$e('./'),
|
|
2801
2535
|
privateKey: tmsConfig.privateKey
|
|
2802
|
-
});
|
|
2536
|
+
});
|
|
2803
2537
|
|
|
2538
|
+
// 构建成功后,计算md5写入cache
|
|
2804
2539
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2805
2540
|
const packageDir = path$8.dirname(item);
|
|
2806
2541
|
const mpDir = resolve$e(`${packageDir}/miniprogram_npm`);
|
|
@@ -2810,16 +2545,15 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
|
2810
2545
|
status: statusMap.success
|
|
2811
2546
|
});
|
|
2812
2547
|
}));
|
|
2813
|
-
}
|
|
2814
|
-
|
|
2548
|
+
}
|
|
2815
2549
|
|
|
2550
|
+
// 计算miniprogram_npm压缩文件的md5值
|
|
2816
2551
|
async function getMNPMd5(cwd) {
|
|
2817
2552
|
const shellJsOption = {
|
|
2818
2553
|
async: false,
|
|
2819
2554
|
silent: true
|
|
2820
2555
|
};
|
|
2821
2556
|
shelljs$3.cd(cwd);
|
|
2822
|
-
|
|
2823
2557
|
if (fs$8.existsSync('miniprogram_npm')) {
|
|
2824
2558
|
shelljs$3.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
|
|
2825
2559
|
cwd,
|
|
@@ -2830,10 +2564,8 @@ async function getMNPMd5(cwd) {
|
|
|
2830
2564
|
shelljs$3.rm('-rf', tarDir);
|
|
2831
2565
|
return md5Value;
|
|
2832
2566
|
}
|
|
2833
|
-
|
|
2834
2567
|
return '';
|
|
2835
2568
|
}
|
|
2836
|
-
|
|
2837
2569
|
var install_1 = install$3;
|
|
2838
2570
|
|
|
2839
2571
|
const shelljs$2 = require$$0__default$2;
|
|
@@ -2862,6 +2594,7 @@ const {
|
|
|
2862
2594
|
info: info$c
|
|
2863
2595
|
} = log$1;
|
|
2864
2596
|
const install$2 = install_1;
|
|
2597
|
+
|
|
2865
2598
|
/**
|
|
2866
2599
|
* 拷贝相关配置文件到编译输出目录
|
|
2867
2600
|
* @param { object } tmsConfig
|
|
@@ -2869,7 +2602,6 @@ const install$2 = install_1;
|
|
|
2869
2602
|
* @param { array } defaultFiles 默认需要拷贝的配置项
|
|
2870
2603
|
* @returns
|
|
2871
2604
|
*/
|
|
2872
|
-
|
|
2873
2605
|
const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
2874
2606
|
const outputDir = resolve$d(tmsConfig.outputDir);
|
|
2875
2607
|
io.ensureDirExist(outputDir);
|
|
@@ -2879,26 +2611,28 @@ const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
|
2879
2611
|
}
|
|
2880
2612
|
});
|
|
2881
2613
|
};
|
|
2882
|
-
|
|
2883
2614
|
async function task(tmsConfig, targetModules) {
|
|
2884
2615
|
// 下载和移动代码
|
|
2885
|
-
await createTask$4(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$d('./'), targetModules);
|
|
2886
|
-
|
|
2887
|
-
const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
|
|
2616
|
+
await createTask$4(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$d('./'), targetModules);
|
|
2888
2617
|
|
|
2889
|
-
|
|
2618
|
+
// 获取所有模块,合并模块依赖的模块
|
|
2619
|
+
const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true);
|
|
2620
|
+
// 获取所有的分包
|
|
2621
|
+
const newSubPackages = getSubPackages$2(newModules);
|
|
2890
2622
|
|
|
2891
|
-
|
|
2623
|
+
// 拷贝相关配置文件到输出目录
|
|
2624
|
+
await createTask$4(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1);
|
|
2892
2625
|
|
|
2893
|
-
|
|
2626
|
+
// install
|
|
2627
|
+
await install$2(tmsConfig, newSubPackages, true);
|
|
2894
2628
|
|
|
2629
|
+
// 动态生成编译后的app.json;
|
|
2895
2630
|
await createTask$4(buildOutputAppJson$2, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
2896
2631
|
return {
|
|
2897
2632
|
modules: newModules,
|
|
2898
2633
|
subPackages: newSubPackages
|
|
2899
2634
|
};
|
|
2900
2635
|
}
|
|
2901
|
-
|
|
2902
2636
|
async function init$3(tmsConfig, targetModules) {
|
|
2903
2637
|
try {
|
|
2904
2638
|
const taskRes = await task(tmsConfig, targetModules);
|
|
@@ -2910,11 +2644,9 @@ async function init$3(tmsConfig, targetModules) {
|
|
|
2910
2644
|
process.exit(1);
|
|
2911
2645
|
}
|
|
2912
2646
|
}
|
|
2913
|
-
|
|
2914
2647
|
var init_1 = init$3;
|
|
2915
2648
|
|
|
2916
2649
|
/* eslint-disable no-param-reassign */
|
|
2917
|
-
|
|
2918
2650
|
function mpProjectJson$1() {
|
|
2919
2651
|
return function ({
|
|
2920
2652
|
vinyl,
|
|
@@ -2925,11 +2657,9 @@ function mpProjectJson$1() {
|
|
|
2925
2657
|
contents = contents.replace(/"miniprogramRoot"[^,]+,/g, '');
|
|
2926
2658
|
vinyl.contents = Buffer.from(contents);
|
|
2927
2659
|
}
|
|
2928
|
-
|
|
2929
2660
|
next();
|
|
2930
2661
|
};
|
|
2931
2662
|
}
|
|
2932
|
-
|
|
2933
2663
|
var mpProjectJson_1 = mpProjectJson$1;
|
|
2934
2664
|
|
|
2935
2665
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
@@ -2938,15 +2668,15 @@ const pp = require$$1__default$3;
|
|
|
2938
2668
|
const path$7 = require$$1__default$1;
|
|
2939
2669
|
const chalk$4 = require$$3__default;
|
|
2940
2670
|
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
2941
|
-
// 允许渲染的文件类型列表
|
|
2942
2671
|
|
|
2672
|
+
// 允许渲染的文件类型列表
|
|
2943
2673
|
const TEMPLATE_FILE_EXTENSIONS = ['.json', '.js', '.ts', '.wxml', '.wxss', '.wxs', '.css', '.less', '.scss'];
|
|
2674
|
+
|
|
2944
2675
|
/**
|
|
2945
2676
|
* 获取预处理器类型
|
|
2946
2677
|
* @param {string} extName 文件扩展名
|
|
2947
2678
|
* @returns {string} 预处理器类型
|
|
2948
2679
|
*/
|
|
2949
|
-
|
|
2950
2680
|
const getPreprocessType = extName => {
|
|
2951
2681
|
const type = extName.replace('.', '');
|
|
2952
2682
|
if (type === 'wxml') return 'html';
|
|
@@ -2954,6 +2684,7 @@ const getPreprocessType = extName => {
|
|
|
2954
2684
|
if (type === 'wxss') return 'css';
|
|
2955
2685
|
return type;
|
|
2956
2686
|
};
|
|
2687
|
+
|
|
2957
2688
|
/**
|
|
2958
2689
|
* 获取错误上下文信息
|
|
2959
2690
|
* @param {string} content 文件内容
|
|
@@ -2961,80 +2692,67 @@ const getPreprocessType = extName => {
|
|
|
2961
2692
|
* @param {number} contextLines 上下文行数
|
|
2962
2693
|
* @returns {string} 格式化的错误上下文
|
|
2963
2694
|
*/
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
2695
|
const getErrorContext = (content, errorLine, contextLines = 2) => {
|
|
2967
2696
|
const lines = content.split('\n');
|
|
2968
2697
|
const start = Math.max(1, errorLine - contextLines);
|
|
2969
2698
|
const end = Math.min(lines.length, errorLine + contextLines);
|
|
2970
2699
|
let context = '';
|
|
2971
|
-
|
|
2972
2700
|
for (let i = start; i <= end; i++) {
|
|
2973
2701
|
const marker = i === errorLine ? ' >> ' : ' ';
|
|
2974
2702
|
context += `${marker}${i}| ${lines[i - 1]}\n`;
|
|
2975
2703
|
}
|
|
2976
|
-
|
|
2977
2704
|
return context;
|
|
2978
2705
|
};
|
|
2706
|
+
|
|
2979
2707
|
/**
|
|
2980
2708
|
* 打印错误信息
|
|
2981
2709
|
* @param {string} filePath 文件路径
|
|
2982
2710
|
* @param {string} context 错误上下文
|
|
2983
2711
|
* @param {Error} error 错误对象
|
|
2984
2712
|
*/
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
2713
|
const printError = (filePath, context, error) => {
|
|
2988
2714
|
console.error(`${chalk$4.yellow('渲染模板出错,请检查处理:')}\n${chalk$4.yellow('文件:')}\n${chalk$4.yellow(filePath)}\n${chalk$4.yellow('错误位置:')}\n${chalk$4.gray(context)}\n${chalk$4.red('错误信息:')}\n${chalk$4.red(error.message)}\n${chalk$4.gray('--------------------------------')}`);
|
|
2989
2715
|
};
|
|
2716
|
+
|
|
2990
2717
|
/**
|
|
2991
2718
|
* 模板渲染插件
|
|
2992
2719
|
* @param {Object} tmsConfig 配置对象
|
|
2993
2720
|
* @returns {Object} through2 转换流
|
|
2994
2721
|
*/
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
2722
|
var tmsTemplateRender = function tmsTemplateRender(tmsConfig) {
|
|
2998
2723
|
return through$1.obj((file, encoding, callback) => {
|
|
2999
2724
|
if (!file.isBuffer()) {
|
|
3000
2725
|
return callback(null, file);
|
|
3001
2726
|
}
|
|
3002
|
-
|
|
3003
2727
|
const extName = path$7.extname(file.path).toLowerCase();
|
|
3004
|
-
|
|
3005
2728
|
if (!TEMPLATE_FILE_EXTENSIONS.includes(extName)) {
|
|
3006
2729
|
return callback(null, file);
|
|
3007
2730
|
}
|
|
3008
|
-
|
|
3009
2731
|
const content = file.contents.toString(encoding);
|
|
3010
|
-
|
|
3011
2732
|
try {
|
|
3012
2733
|
const vars = tmsConfig.templateVars || {};
|
|
3013
|
-
const ppType = getPreprocessType(extName);
|
|
3014
|
-
|
|
2734
|
+
const ppType = getPreprocessType(extName);
|
|
2735
|
+
// 手动检查 @echo 引用的变量是否存在
|
|
3015
2736
|
const echoPattern = /\/\* @echo (\w+) \*\//g;
|
|
3016
2737
|
let match;
|
|
3017
|
-
|
|
3018
2738
|
while ((match = echoPattern.exec(content)) !== null) {
|
|
3019
|
-
const variableName = match[1];
|
|
3020
|
-
|
|
2739
|
+
const variableName = match[1];
|
|
2740
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
3021
2741
|
if (!vars.hasOwnProperty(variableName)) {
|
|
3022
2742
|
const error = new Error(`变量 ${variableName} 未定义`);
|
|
3023
2743
|
error.line = content.substring(0, match.index).split('\n').length;
|
|
3024
2744
|
throw error;
|
|
3025
2745
|
}
|
|
3026
2746
|
}
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
2747
|
+
const rendered = pp.preprocess(content, vars, ppType);
|
|
2748
|
+
// eslint-disable-next-line no-param-reassign
|
|
3030
2749
|
file.contents = Buffer.from(rendered);
|
|
3031
2750
|
} catch (err) {
|
|
3032
2751
|
const context = getErrorContext(content, err.line || 1);
|
|
3033
|
-
printError(file.path, context, err);
|
|
3034
|
-
|
|
2752
|
+
printError(file.path, context, err);
|
|
2753
|
+
// 直接抛出异常,中断编译流程
|
|
3035
2754
|
throw new Error(`模板渲染失败: ${file.path}\n${err.message}`);
|
|
3036
2755
|
}
|
|
3037
|
-
|
|
3038
2756
|
callback(null, file);
|
|
3039
2757
|
});
|
|
3040
2758
|
};
|
|
@@ -3054,13 +2772,11 @@ const through = require$$0__default$8;
|
|
|
3054
2772
|
const {
|
|
3055
2773
|
fail: fail$3
|
|
3056
2774
|
} = log$1;
|
|
3057
|
-
|
|
3058
2775
|
const getTargetFile$2 = (sourceFile, module, outputDir) => {
|
|
3059
2776
|
const sourceFileRelativeModule = path$6.relative(resolve$c(module.from), sourceFile);
|
|
3060
2777
|
const targetFile = resolve$c(outputDir, module.to, sourceFileRelativeModule);
|
|
3061
2778
|
return targetFile;
|
|
3062
2779
|
};
|
|
3063
|
-
|
|
3064
2780
|
const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
|
|
3065
2781
|
const {
|
|
3066
2782
|
plugins = []
|
|
@@ -3082,7 +2798,6 @@ const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
|
|
|
3082
2798
|
this.push(vinyl);
|
|
3083
2799
|
}))), srcPipe);
|
|
3084
2800
|
};
|
|
3085
|
-
|
|
3086
2801
|
var compile$1 = function (tmsConfig, {
|
|
3087
2802
|
glob,
|
|
3088
2803
|
destPath,
|
|
@@ -3096,12 +2811,15 @@ var compile$1 = function (tmsConfig, {
|
|
|
3096
2811
|
taskFn: (sourceFile, targetPath) => {
|
|
3097
2812
|
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : glob;
|
|
3098
2813
|
const newDestPath = targetPath ? targetPath : destPath;
|
|
3099
|
-
let srcPipe = src$2(newGlobValue, {
|
|
3100
|
-
|
|
2814
|
+
let srcPipe = src$2(newGlobValue, {
|
|
2815
|
+
...srcOption
|
|
2816
|
+
});
|
|
3101
2817
|
|
|
2818
|
+
// 在文件读取后,插件处理之前先加入模板渲染插件
|
|
3102
2819
|
const templateRender = tmsTemplateRender;
|
|
3103
|
-
srcPipe = srcPipe.pipe(templateRender(tmsConfig));
|
|
2820
|
+
srcPipe = srcPipe.pipe(templateRender(tmsConfig));
|
|
3104
2821
|
|
|
2822
|
+
// 后续步骤继续执行其他插件
|
|
3105
2823
|
const pluginParams = {
|
|
3106
2824
|
module,
|
|
3107
2825
|
isDev
|
|
@@ -3117,7 +2835,6 @@ var compile$1 = function (tmsConfig, {
|
|
|
3117
2835
|
|
|
3118
2836
|
/* eslint-disable */
|
|
3119
2837
|
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
3120
|
-
|
|
3121
2838
|
const assign = require$$0__default$a;
|
|
3122
2839
|
const path$5 = require$$1__default$1;
|
|
3123
2840
|
const PluginError = require$$2__default$1;
|
|
@@ -3133,69 +2850,52 @@ const anymatch = require$$9__default;
|
|
|
3133
2850
|
const pathIsAbsolute = require$$10__default$1;
|
|
3134
2851
|
const globParent = require$$11__default;
|
|
3135
2852
|
const slash = require$$12__default;
|
|
3136
|
-
|
|
3137
2853
|
function normalizeGlobs(globs) {
|
|
3138
2854
|
if (!globs) {
|
|
3139
2855
|
throw new PluginError('gulp-watch', 'glob argument required');
|
|
3140
2856
|
}
|
|
3141
|
-
|
|
3142
2857
|
if (typeof globs === 'string') {
|
|
3143
2858
|
globs = [globs];
|
|
3144
2859
|
}
|
|
3145
|
-
|
|
3146
2860
|
if (!Array.isArray(globs)) {
|
|
3147
2861
|
throw new PluginError('gulp-watch', `glob should be String or Array, not ${typeof globs}`);
|
|
3148
2862
|
}
|
|
3149
|
-
|
|
3150
2863
|
return globs;
|
|
3151
2864
|
}
|
|
3152
|
-
|
|
3153
2865
|
function watch$3(globs, opts, cb) {
|
|
3154
2866
|
globs = normalizeGlobs(globs);
|
|
3155
|
-
|
|
3156
2867
|
if (typeof opts === 'function') {
|
|
3157
2868
|
cb = opts;
|
|
3158
2869
|
opts = {};
|
|
3159
2870
|
}
|
|
3160
|
-
|
|
3161
2871
|
opts = assign({}, watch$3._defaultOptions, opts);
|
|
3162
|
-
|
|
3163
2872
|
cb = cb || function () {};
|
|
3164
|
-
|
|
3165
2873
|
function resolveFilepath(filepath) {
|
|
3166
2874
|
if (pathIsAbsolute(filepath)) {
|
|
3167
2875
|
return path$5.normalize(filepath);
|
|
3168
2876
|
}
|
|
3169
|
-
|
|
3170
2877
|
return path$5.resolve(opts.cwd || process.cwd(), filepath);
|
|
3171
2878
|
}
|
|
3172
|
-
|
|
3173
2879
|
function resolveGlob(glob) {
|
|
3174
2880
|
let mod = '';
|
|
3175
|
-
|
|
3176
2881
|
if (glob[0] === '!') {
|
|
3177
2882
|
mod = glob[0];
|
|
3178
2883
|
glob = glob.slice(1);
|
|
3179
2884
|
}
|
|
3180
|
-
|
|
3181
2885
|
return mod + slash(resolveFilepath(glob));
|
|
3182
2886
|
}
|
|
3183
|
-
|
|
3184
2887
|
globs = globs.map(resolveGlob);
|
|
3185
2888
|
const baseForced = Boolean(opts.base);
|
|
3186
2889
|
const outputStream = new Duplex({
|
|
3187
2890
|
objectMode: true,
|
|
3188
2891
|
allowHalfOpen: true
|
|
3189
2892
|
});
|
|
3190
|
-
|
|
3191
2893
|
outputStream._write = function _write(file, enc, done) {
|
|
3192
2894
|
cb(file);
|
|
3193
2895
|
this.push(file);
|
|
3194
2896
|
done();
|
|
3195
2897
|
};
|
|
3196
|
-
|
|
3197
2898
|
outputStream._read = function _read() {};
|
|
3198
|
-
|
|
3199
2899
|
const watcher = chokidar.watch(globs, opts);
|
|
3200
2900
|
opts.events.forEach(ev => {
|
|
3201
2901
|
watcher.on(ev, processEvent.bind(undefined, ev));
|
|
@@ -3203,86 +2903,72 @@ function watch$3(globs, opts, cb) {
|
|
|
3203
2903
|
['add', 'change', 'unlink', 'addDir', 'unlinkDir', 'error', 'ready', 'raw'].forEach(ev => {
|
|
3204
2904
|
watcher.on(ev, outputStream.emit.bind(outputStream, ev));
|
|
3205
2905
|
});
|
|
3206
|
-
|
|
3207
2906
|
outputStream.add = function add(newGlobs) {
|
|
3208
2907
|
newGlobs = normalizeGlobs(newGlobs).map(resolveGlob);
|
|
3209
2908
|
watcher.add(newGlobs);
|
|
3210
2909
|
globs.push.apply(globs, newGlobs);
|
|
3211
2910
|
};
|
|
3212
|
-
|
|
3213
2911
|
outputStream.unwatch = watcher.unwatch.bind(watcher);
|
|
3214
|
-
|
|
3215
2912
|
outputStream.close = function () {
|
|
3216
2913
|
watcher.close();
|
|
3217
2914
|
this.emit('end');
|
|
3218
2915
|
};
|
|
3219
|
-
|
|
3220
2916
|
function processEvent(event, filepath) {
|
|
3221
2917
|
filepath = resolveFilepath(filepath);
|
|
3222
2918
|
const fileOpts = assign({}, opts);
|
|
3223
2919
|
let glob;
|
|
3224
2920
|
let currentFilepath = filepath;
|
|
3225
|
-
|
|
3226
2921
|
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$5.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
|
|
3227
2922
|
|
|
3228
|
-
|
|
3229
2923
|
if (!glob) {
|
|
3230
2924
|
console.error('[gulp-watch]没有匹配到glob');
|
|
3231
2925
|
return;
|
|
3232
2926
|
}
|
|
3233
|
-
|
|
3234
2927
|
if (!baseForced) {
|
|
3235
2928
|
fileOpts.base = path$5.normalize(globParent(glob));
|
|
3236
|
-
}
|
|
3237
|
-
|
|
2929
|
+
}
|
|
3238
2930
|
|
|
2931
|
+
// Do not stat deleted files
|
|
3239
2932
|
if (event === 'unlink' || event === 'unlinkDir' || event === 'addDir') {
|
|
3240
2933
|
fileOpts.path = filepath;
|
|
3241
2934
|
write(event, null, new File(fileOpts));
|
|
3242
2935
|
return;
|
|
3243
|
-
}
|
|
3244
|
-
|
|
2936
|
+
}
|
|
3245
2937
|
|
|
2938
|
+
// Workaround for early read
|
|
3246
2939
|
setTimeout(() => {
|
|
3247
2940
|
vinyl.read(filepath, fileOpts).then(file => {
|
|
3248
2941
|
write(event, null, file);
|
|
3249
2942
|
});
|
|
3250
2943
|
}, opts.readDelay);
|
|
3251
2944
|
}
|
|
3252
|
-
|
|
3253
2945
|
function write(event, err, file) {
|
|
3254
2946
|
if (err) {
|
|
3255
2947
|
outputStream.emit('error', err);
|
|
3256
2948
|
return;
|
|
3257
2949
|
}
|
|
3258
|
-
|
|
3259
2950
|
if (opts.verbose) {
|
|
3260
2951
|
log(event, file);
|
|
3261
2952
|
}
|
|
3262
|
-
|
|
3263
2953
|
file.event = event;
|
|
3264
2954
|
outputStream.push(file);
|
|
3265
2955
|
cb(file);
|
|
3266
2956
|
}
|
|
3267
|
-
|
|
3268
2957
|
function log(event, file) {
|
|
3269
2958
|
event = event[event.length - 1] === 'e' ? `${event}d` : `${event}ed`;
|
|
3270
2959
|
const msg = [colors.magenta(file.relative), 'was', event];
|
|
3271
|
-
|
|
3272
2960
|
if (opts.name) {
|
|
3273
2961
|
msg.unshift(`${colors.cyan(opts.name)} saw`);
|
|
3274
2962
|
}
|
|
3275
|
-
|
|
3276
2963
|
fancyLog.info.apply(null, msg);
|
|
3277
2964
|
}
|
|
3278
|
-
|
|
3279
2965
|
return outputStream;
|
|
3280
|
-
}
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
// This is not part of the public API as that would lead to global state (singleton) pollution,
|
|
3281
2969
|
// and allow unexpected interference between unrelated modules that make use of gulp-watch.
|
|
3282
2970
|
// This can be useful for unit tests and root application configuration, though.
|
|
3283
2971
|
// Avoid modifying gulp-watch's default options inside a library/reusable package, please.
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
2972
|
watch$3._defaultOptions = {
|
|
3287
2973
|
events: ['add', 'change', 'unlink'],
|
|
3288
2974
|
ignoreInitial: true,
|
|
@@ -3331,7 +3017,6 @@ const TIP_MAP = {
|
|
|
3331
3017
|
check: () => true
|
|
3332
3018
|
}
|
|
3333
3019
|
};
|
|
3334
|
-
|
|
3335
3020
|
const logTip = (fileName, sourceFile, targetFile, tipMap) => {
|
|
3336
3021
|
try {
|
|
3337
3022
|
for (const item in tipMap) {
|
|
@@ -3340,20 +3025,18 @@ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
|
|
|
3340
3025
|
return;
|
|
3341
3026
|
}
|
|
3342
3027
|
}
|
|
3343
|
-
|
|
3344
3028
|
info$b(`${fileName}有更新`);
|
|
3345
3029
|
} catch (e) {
|
|
3346
3030
|
fail$2(`${sourceFile}文件更新提示出现错误: ${e.message}`);
|
|
3347
3031
|
}
|
|
3348
3032
|
};
|
|
3349
|
-
|
|
3350
3033
|
const getTargetFile$1 = (sourceFile, module, outputDir) => {
|
|
3351
3034
|
const sourceFileRelativeModule = path$4.relative(resolve$b(module.from), sourceFile);
|
|
3352
3035
|
return resolve$b(outputDir, module.to, sourceFileRelativeModule);
|
|
3353
3036
|
};
|
|
3354
|
-
|
|
3355
3037
|
var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
3356
|
-
watch$2(globValue, {
|
|
3038
|
+
watch$2(globValue, {
|
|
3039
|
+
// readDelay: 100,
|
|
3357
3040
|
...watchOptions
|
|
3358
3041
|
}, async vinyl => {
|
|
3359
3042
|
const sourceFile = vinyl.history[0];
|
|
@@ -3361,19 +3044,16 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3361
3044
|
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
3362
3045
|
const tmsConfig = global$6.getData('tmsConfig');
|
|
3363
3046
|
let targetFile = getTargetFile$1(sourceFile, module, tmsConfig.outputDir);
|
|
3364
|
-
|
|
3365
3047
|
if (module.custom) {
|
|
3366
3048
|
const filePath = sourceFile.replace(/\\/g, '/').replace(module.from, '');
|
|
3367
3049
|
targetFile = path$4.join(module.to, filePath);
|
|
3368
3050
|
}
|
|
3369
|
-
|
|
3370
3051
|
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
3371
3052
|
info$b(`删除${sourceFileName}`);
|
|
3372
3053
|
shellJs$2.rm('-rf', targetFile);
|
|
3373
3054
|
updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
|
|
3374
3055
|
return;
|
|
3375
3056
|
}
|
|
3376
|
-
|
|
3377
3057
|
await runCallback({
|
|
3378
3058
|
tmsConfig,
|
|
3379
3059
|
sourceFile,
|
|
@@ -3383,9 +3063,9 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3383
3063
|
});
|
|
3384
3064
|
logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
|
|
3385
3065
|
});
|
|
3386
|
-
};
|
|
3387
|
-
|
|
3066
|
+
};
|
|
3388
3067
|
|
|
3068
|
+
// 开始执行watch 文件的 callback函数
|
|
3389
3069
|
async function runCallback({
|
|
3390
3070
|
tmsConfig,
|
|
3391
3071
|
sourceFile,
|
|
@@ -3405,12 +3085,11 @@ async function runCallback({
|
|
|
3405
3085
|
await callback([sourceFile], path$4.dirname(targetFile));
|
|
3406
3086
|
await updateFileHook(tmsConfig, sourceFile, targetFile, type);
|
|
3407
3087
|
}
|
|
3408
|
-
}
|
|
3409
|
-
|
|
3088
|
+
}
|
|
3410
3089
|
|
|
3090
|
+
// 执行源码文件更新的钩子
|
|
3411
3091
|
async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
|
|
3412
3092
|
var _tmsConfig$hooks;
|
|
3413
|
-
|
|
3414
3093
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateFile) === 'function') {
|
|
3415
3094
|
await tmsConfig.hooks.updateFile({
|
|
3416
3095
|
tmsConfig: filterField$5(tmsConfig, ['gitAccount']),
|
|
@@ -3453,10 +3132,10 @@ const {
|
|
|
3453
3132
|
global: global$5
|
|
3454
3133
|
} = global_1;
|
|
3455
3134
|
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
3456
|
-
|
|
3457
3135
|
var dev$4 = async (tmsConfig, modules, isDev = true) => {
|
|
3458
|
-
const compileTasksMap = new Map();
|
|
3136
|
+
const compileTasksMap = new Map();
|
|
3459
3137
|
|
|
3138
|
+
// 监听根目录的文件
|
|
3460
3139
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3461
3140
|
glob: DEFAULT_COPY_CONFIG.map(item => resolve$a(item)),
|
|
3462
3141
|
module: {
|
|
@@ -3468,8 +3147,9 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3468
3147
|
allowEmpty: true
|
|
3469
3148
|
},
|
|
3470
3149
|
isDev
|
|
3471
|
-
}));
|
|
3150
|
+
}));
|
|
3472
3151
|
|
|
3152
|
+
// 监听extendFiles
|
|
3473
3153
|
if (tmsConfig.watchExtendFiles.length) {
|
|
3474
3154
|
tmsConfig.watchExtendFiles.forEach(item => {
|
|
3475
3155
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
@@ -3486,19 +3166,19 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3486
3166
|
isDev
|
|
3487
3167
|
}));
|
|
3488
3168
|
});
|
|
3489
|
-
}
|
|
3490
|
-
|
|
3169
|
+
}
|
|
3491
3170
|
|
|
3171
|
+
// 监听模块的文件
|
|
3492
3172
|
for (let moduleItem of modules) {
|
|
3493
3173
|
// 处理默认参数
|
|
3494
|
-
moduleItem = {
|
|
3174
|
+
moduleItem = {
|
|
3175
|
+
...{
|
|
3495
3176
|
exclude: []
|
|
3496
3177
|
},
|
|
3497
3178
|
...moduleItem
|
|
3498
3179
|
};
|
|
3499
3180
|
const srcModulePath = getAbsolutePath$3(moduleItem.path);
|
|
3500
3181
|
const buildModulePath = resolve$a(tmsConfig.outputDir, moduleItem.modulePath);
|
|
3501
|
-
|
|
3502
3182
|
if (isDev) {
|
|
3503
3183
|
// 监听模块配置文件
|
|
3504
3184
|
watch$1([`${srcModulePath}/**/module.config.json`], {
|
|
@@ -3508,15 +3188,12 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3508
3188
|
to: buildModulePath
|
|
3509
3189
|
});
|
|
3510
3190
|
}
|
|
3511
|
-
|
|
3512
3191
|
const excludes = moduleItem.exclude.map(ePath => {
|
|
3513
3192
|
const newPath = getAbsolutePath$3(ePath, srcModulePath);
|
|
3514
3193
|
const ext = path$3.extname(ePath).slice(1);
|
|
3515
|
-
|
|
3516
3194
|
if (ext) {
|
|
3517
3195
|
return `!${resolve$a(srcModulePath, newPath)}`;
|
|
3518
3196
|
}
|
|
3519
|
-
|
|
3520
3197
|
return `!${resolve$a(srcModulePath, newPath)}/**/*`;
|
|
3521
3198
|
});
|
|
3522
3199
|
const moduleConfigPath = `${srcModulePath}/**/module.config.json`;
|
|
@@ -3533,22 +3210,20 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3533
3210
|
},
|
|
3534
3211
|
isDev
|
|
3535
3212
|
}));
|
|
3536
|
-
}
|
|
3537
|
-
|
|
3213
|
+
}
|
|
3538
3214
|
|
|
3215
|
+
// static静态资源目录
|
|
3539
3216
|
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
|
|
3540
3217
|
for (const item of tmsConfig.static) {
|
|
3541
3218
|
item.from = getAbsolutePath$3(item.from);
|
|
3542
3219
|
item.to = getAbsolutePath$3(item.to);
|
|
3543
3220
|
let glob = {};
|
|
3544
3221
|
const ext = path$3.extname(item.from).slice(1);
|
|
3545
|
-
|
|
3546
3222
|
if (ext) {
|
|
3547
3223
|
glob = [item.from];
|
|
3548
3224
|
} else {
|
|
3549
3225
|
glob = [`${item.from}/**/*`];
|
|
3550
3226
|
}
|
|
3551
|
-
|
|
3552
3227
|
const from = fs$6.lstatSync(item.from).isFile() ? path$3.dirname(item.from) : item.from;
|
|
3553
3228
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3554
3229
|
glob,
|
|
@@ -3564,21 +3239,17 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3564
3239
|
}));
|
|
3565
3240
|
}
|
|
3566
3241
|
}
|
|
3567
|
-
|
|
3568
3242
|
let sTime;
|
|
3569
3243
|
let eTime;
|
|
3570
3244
|
const spinner = ora$1();
|
|
3571
|
-
|
|
3572
3245
|
function start(cb) {
|
|
3573
3246
|
info$a('启动编译...');
|
|
3574
3247
|
spinner.start();
|
|
3575
3248
|
sTime = new Date().getTime();
|
|
3576
3249
|
cb();
|
|
3577
3250
|
}
|
|
3578
|
-
|
|
3579
3251
|
async function end(cb) {
|
|
3580
3252
|
var _tmsConfig$hooks;
|
|
3581
|
-
|
|
3582
3253
|
if (isDev) {
|
|
3583
3254
|
// 监听app.json
|
|
3584
3255
|
watch$1([resolve$a('app.json')], {
|
|
@@ -3587,8 +3258,8 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3587
3258
|
}, async () => await buildOutputAppJson$1(tmsConfig, modules, isDev), {
|
|
3588
3259
|
from: resolve$a(),
|
|
3589
3260
|
to: resolve$a(tmsConfig.outputDir)
|
|
3590
|
-
});
|
|
3591
|
-
|
|
3261
|
+
});
|
|
3262
|
+
// 监听其他文件
|
|
3592
3263
|
compileTasksMap.forEach(({
|
|
3593
3264
|
taskFn,
|
|
3594
3265
|
module
|
|
@@ -3601,12 +3272,9 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3601
3272
|
} else {
|
|
3602
3273
|
await buildOutputAppJson$1(tmsConfig, modules, isDev);
|
|
3603
3274
|
}
|
|
3604
|
-
|
|
3605
3275
|
eTime = new Date().getTime() - sTime;
|
|
3606
|
-
|
|
3607
3276
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterFirstCompile) === 'function') {
|
|
3608
3277
|
var _tmsConfig$hooks2;
|
|
3609
|
-
|
|
3610
3278
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterFirstCompile({
|
|
3611
3279
|
isDev,
|
|
3612
3280
|
tmsConfig: filterField$4(tmsConfig, ['gitAccount']),
|
|
@@ -3615,19 +3283,17 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
|
|
|
3615
3283
|
}));
|
|
3616
3284
|
report$7('hooks:afterCompile');
|
|
3617
3285
|
}
|
|
3618
|
-
|
|
3619
3286
|
spinner.succeed(chalk$3.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
3620
3287
|
spinner.stop();
|
|
3621
3288
|
cb();
|
|
3622
3289
|
}
|
|
3623
|
-
|
|
3624
3290
|
const compileTasks = [];
|
|
3625
3291
|
compileTasksMap.forEach(({
|
|
3626
3292
|
taskFn
|
|
3627
3293
|
}) => {
|
|
3628
3294
|
compileTasks.push(taskFn);
|
|
3629
|
-
});
|
|
3630
|
-
|
|
3295
|
+
});
|
|
3296
|
+
// 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
3631
3297
|
series$1(start, parallel$1(...compileTasks), end)();
|
|
3632
3298
|
};
|
|
3633
3299
|
|
|
@@ -3655,13 +3321,14 @@ const {
|
|
|
3655
3321
|
MODULE_CODE_DIR,
|
|
3656
3322
|
NODE_MODULES_DIR
|
|
3657
3323
|
} = constant;
|
|
3658
|
-
const report$6 = report_1;
|
|
3659
|
-
//
|
|
3324
|
+
const report$6 = report_1;
|
|
3325
|
+
// const { recommendVersion } = require('../../../core/recommendVersion');
|
|
3660
3326
|
|
|
3327
|
+
// 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
3661
3328
|
function delOtherPackages(tmsConfig, targetSubPackages) {
|
|
3662
3329
|
// 获取所有模块,合并模块依赖的模块
|
|
3663
|
-
const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all);
|
|
3664
|
-
|
|
3330
|
+
const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all);
|
|
3331
|
+
// 获取所有的分包
|
|
3665
3332
|
const allSubPackages = getSubPackages$1(allModules);
|
|
3666
3333
|
const targetSubPackagesName = targetSubPackages.map(item => item.name);
|
|
3667
3334
|
allSubPackages.forEach(item => {
|
|
@@ -3669,42 +3336,38 @@ function delOtherPackages(tmsConfig, targetSubPackages) {
|
|
|
3669
3336
|
const moduleRootDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
|
|
3670
3337
|
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
3671
3338
|
silent: true
|
|
3672
|
-
});
|
|
3339
|
+
});
|
|
3340
|
+
// 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
3673
3341
|
// io.ensureDirExist(moduleRootDir);
|
|
3674
3342
|
}
|
|
3675
3343
|
});
|
|
3676
3344
|
}
|
|
3677
|
-
|
|
3678
3345
|
async function dev$3(tmsConfig, targetModules) {
|
|
3679
3346
|
var _tmsConfig$hooks;
|
|
3680
|
-
|
|
3681
3347
|
const {
|
|
3682
3348
|
noCache
|
|
3683
3349
|
} = global$4.getData('cmdOptions');
|
|
3684
|
-
|
|
3685
3350
|
if (noCache) {
|
|
3686
3351
|
if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
|
|
3687
3352
|
shelljs$1.rm('-rf', resolve$9(tmsConfig.outputDir));
|
|
3688
3353
|
}
|
|
3689
|
-
|
|
3690
3354
|
shelljs$1.rm('-rf', MODULE_CODE_DIR);
|
|
3691
3355
|
shelljs$1.rm('-rf', NODE_MODULES_DIR);
|
|
3692
|
-
}
|
|
3356
|
+
}
|
|
3357
|
+
// 推荐tmskit的版本
|
|
3693
3358
|
// await recommendVersion();
|
|
3694
|
-
// 初始化操作
|
|
3695
|
-
|
|
3696
3359
|
|
|
3360
|
+
// 初始化操作
|
|
3697
3361
|
const {
|
|
3698
3362
|
subPackages,
|
|
3699
3363
|
modules: newModules
|
|
3700
|
-
} = await init$2(tmsConfig, targetModules);
|
|
3364
|
+
} = await init$2(tmsConfig, targetModules);
|
|
3701
3365
|
|
|
3366
|
+
// 在启动开发环境前主动执行生成 app.json
|
|
3702
3367
|
await buildOutputAppJson(tmsConfig, newModules);
|
|
3703
3368
|
info$9('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
|
|
3704
|
-
|
|
3705
3369
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
|
|
3706
3370
|
var _tmsConfig$hooks2;
|
|
3707
|
-
|
|
3708
3371
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
|
|
3709
3372
|
isDev: true,
|
|
3710
3373
|
tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
|
|
@@ -3716,11 +3379,9 @@ async function dev$3(tmsConfig, targetModules) {
|
|
|
3716
3379
|
delOtherPackages(tmsConfig, subPackages);
|
|
3717
3380
|
compileDev(tmsConfig, newModules, true);
|
|
3718
3381
|
}
|
|
3719
|
-
|
|
3720
3382
|
var dev_1 = dev$3;
|
|
3721
3383
|
|
|
3722
3384
|
const dev$2 = dev$4;
|
|
3723
|
-
|
|
3724
3385
|
var build$2 = async (tmsConfig, newModules, isDev) => {
|
|
3725
3386
|
dev$2(tmsConfig, newModules, isDev);
|
|
3726
3387
|
};
|
|
@@ -3739,24 +3400,19 @@ const report$5 = report_1;
|
|
|
3739
3400
|
const {
|
|
3740
3401
|
global: global$3
|
|
3741
3402
|
} = global_1;
|
|
3742
|
-
|
|
3743
3403
|
async function build$1(tmsConfig, targetModules) {
|
|
3744
3404
|
var _tmsConfig$hooks;
|
|
3745
|
-
|
|
3746
3405
|
// 开始构建前,清理输出目录
|
|
3747
3406
|
if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
|
|
3748
3407
|
await shelljs.rm('-rf', resolve$8(tmsConfig.outputDir));
|
|
3749
3408
|
}
|
|
3750
|
-
|
|
3751
3409
|
const {
|
|
3752
3410
|
modules: newModules
|
|
3753
3411
|
} = await init$1(tmsConfig, targetModules);
|
|
3754
3412
|
info$8('当前build有效模块', newModules.map(item => item.moduleName).sort());
|
|
3755
3413
|
const isDev = false;
|
|
3756
|
-
|
|
3757
3414
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeFirstCompile) === 'function') {
|
|
3758
3415
|
var _tmsConfig$hooks2;
|
|
3759
|
-
|
|
3760
3416
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeFirstCompile({
|
|
3761
3417
|
isDev,
|
|
3762
3418
|
tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
|
|
@@ -3767,7 +3423,6 @@ async function build$1(tmsConfig, targetModules) {
|
|
|
3767
3423
|
}
|
|
3768
3424
|
compileBuild(tmsConfig, newModules, isDev);
|
|
3769
3425
|
}
|
|
3770
|
-
|
|
3771
3426
|
var build_1 = build$1;
|
|
3772
3427
|
|
|
3773
3428
|
const moment = require$$1__default;
|
|
@@ -3780,39 +3435,32 @@ const {
|
|
|
3780
3435
|
const {
|
|
3781
3436
|
ensureDirExist: ensureDirExist$3
|
|
3782
3437
|
} = io$3;
|
|
3783
|
-
|
|
3784
3438
|
function getAllSize$2(data = {}) {
|
|
3785
3439
|
let allSize;
|
|
3786
|
-
|
|
3787
3440
|
for (const item of data === null || data === void 0 ? void 0 : data.subPackageInfo) {
|
|
3788
3441
|
if (item.name === '__FULL__') {
|
|
3789
3442
|
allSize = item.size;
|
|
3790
3443
|
break;
|
|
3791
3444
|
}
|
|
3792
3445
|
}
|
|
3793
|
-
|
|
3794
3446
|
return allSize;
|
|
3795
3447
|
}
|
|
3796
|
-
|
|
3797
3448
|
const getDesc$3 = (desc = '') => {
|
|
3798
3449
|
const user = getGitUser();
|
|
3799
3450
|
const date = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
3800
3451
|
return `构建描述:${desc}; 构建人: ${user}; 构建时间:${date}`;
|
|
3801
3452
|
};
|
|
3802
|
-
|
|
3803
3453
|
const outputInfo$2 = (infoOutput, data) => {
|
|
3804
3454
|
const outPath = getAbsolutePath$2(infoOutput);
|
|
3805
3455
|
const dir = path$2.dirname(outPath);
|
|
3806
3456
|
ensureDirExist$3(dir);
|
|
3807
3457
|
fs$5.writeFileSync(outPath, JSON.stringify(data, null, 2));
|
|
3808
3458
|
};
|
|
3809
|
-
|
|
3810
3459
|
const getDetaultVersion = () => {
|
|
3811
3460
|
const version = moment().format('gggg,mm').split(',');
|
|
3812
3461
|
version.push('0');
|
|
3813
3462
|
return version.join('.');
|
|
3814
3463
|
};
|
|
3815
|
-
|
|
3816
3464
|
var utils = {
|
|
3817
3465
|
getAllSize: getAllSize$2,
|
|
3818
3466
|
getDesc: getDesc$3,
|
|
@@ -3843,12 +3491,13 @@ const {
|
|
|
3843
3491
|
getDesc: getDesc$2
|
|
3844
3492
|
} = utils;
|
|
3845
3493
|
const report$4 = report_1;
|
|
3846
|
-
|
|
3847
3494
|
const handleParams$2 = (tmsConfig, cmdOptions) => {
|
|
3848
|
-
const params = {
|
|
3495
|
+
const params = {
|
|
3496
|
+
...(tmsConfig.preview ? tmsConfig.preview : {}),
|
|
3849
3497
|
...cmdOptions
|
|
3850
3498
|
};
|
|
3851
|
-
return {
|
|
3499
|
+
return {
|
|
3500
|
+
...params,
|
|
3852
3501
|
appId: params.appId || tmsConfig.appId,
|
|
3853
3502
|
projectPath: resolve$7(tmsConfig.outputDir),
|
|
3854
3503
|
privateKey: params.privateKey || tmsConfig.privateKey,
|
|
@@ -3857,22 +3506,18 @@ const handleParams$2 = (tmsConfig, cmdOptions) => {
|
|
|
3857
3506
|
qrcodeOutputDest: getAbsolutePath$1(params.qrcodeOutputDest || '')
|
|
3858
3507
|
};
|
|
3859
3508
|
};
|
|
3509
|
+
|
|
3860
3510
|
/**
|
|
3861
3511
|
* 预览
|
|
3862
3512
|
* @params {object} tmsConfig
|
|
3863
3513
|
* @param {object} cmdOptions {qrcodeFormat: 'base64', qrcodeOutputDest: './a.txt', robot: 2, infoOutput: './a.txt' }
|
|
3864
3514
|
*/
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
3515
|
async function preview$1(tmsConfig, cmdOptions) {
|
|
3868
3516
|
try {
|
|
3869
3517
|
var _tmsConfig$hooks;
|
|
3870
|
-
|
|
3871
3518
|
const params = handleParams$2(tmsConfig, cmdOptions);
|
|
3872
|
-
|
|
3873
3519
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforePreview) === 'function') {
|
|
3874
3520
|
var _tmsConfig$hooks2;
|
|
3875
|
-
|
|
3876
3521
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforePreview({
|
|
3877
3522
|
tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
|
|
3878
3523
|
cmdOptions: global$2.getData('cmdOptions'),
|
|
@@ -3880,33 +3525,28 @@ async function preview$1(tmsConfig, cmdOptions) {
|
|
|
3880
3525
|
}));
|
|
3881
3526
|
report$4('hooks:beforePreview');
|
|
3882
3527
|
}
|
|
3883
|
-
|
|
3884
3528
|
;
|
|
3885
|
-
const previewRes = await createTask$3(mpCi$2.previewMp, '正在构建预览码', '构建预览码完成')({
|
|
3529
|
+
const previewRes = await createTask$3(mpCi$2.previewMp, '正在构建预览码', '构建预览码完成')({
|
|
3530
|
+
...params
|
|
3886
3531
|
});
|
|
3887
3532
|
const allSize = getAllSize$1(previewRes);
|
|
3888
|
-
|
|
3889
3533
|
if (params.infoOutput) {
|
|
3890
3534
|
let qrcodeBase64 = '';
|
|
3891
|
-
|
|
3892
3535
|
if (params.qrcodeFormat === 'base64' && fs$4.existsSync(params.qrcodeOutputDest)) {
|
|
3893
3536
|
qrcodeBase64 = fs$4.readFileSync(params.qrcodeOutputDest, 'utf8');
|
|
3894
3537
|
}
|
|
3895
|
-
|
|
3896
3538
|
outputInfo$1(params.infoOutput, {
|
|
3897
3539
|
sourceCode: params.projectPath,
|
|
3898
3540
|
qrcodeBase64,
|
|
3899
3541
|
...previewRes
|
|
3900
3542
|
});
|
|
3901
3543
|
}
|
|
3902
|
-
|
|
3903
3544
|
info$7('预览包大小:', `${allSize}k`);
|
|
3904
3545
|
} catch (e) {
|
|
3905
3546
|
console.log('详细错误:', e);
|
|
3906
3547
|
handleError$4(`预览错误: ${e.message}`, true);
|
|
3907
3548
|
}
|
|
3908
3549
|
}
|
|
3909
|
-
|
|
3910
3550
|
var preview_1 = preview$1;
|
|
3911
3551
|
|
|
3912
3552
|
const mpCi$1 = mpCi$3;
|
|
@@ -3930,17 +3570,16 @@ const {
|
|
|
3930
3570
|
getDesc: getDesc$1
|
|
3931
3571
|
} = utils;
|
|
3932
3572
|
const report$3 = report_1;
|
|
3933
|
-
|
|
3934
3573
|
const handleParams$1 = (tmsConfig, cmdOptions) => {
|
|
3935
|
-
const params = {
|
|
3574
|
+
const params = {
|
|
3575
|
+
...(tmsConfig.upload ? tmsConfig.upload : {}),
|
|
3936
3576
|
...cmdOptions
|
|
3937
3577
|
};
|
|
3938
|
-
|
|
3939
3578
|
if (!params.version) {
|
|
3940
3579
|
throw new Error('请指定传入版本号 eg: tmskit run upload --version 2022.28.5');
|
|
3941
3580
|
}
|
|
3942
|
-
|
|
3943
|
-
|
|
3581
|
+
return {
|
|
3582
|
+
...params,
|
|
3944
3583
|
appId: params.appId || tmsConfig.appId,
|
|
3945
3584
|
projectPath: resolve$6(tmsConfig.outputDir),
|
|
3946
3585
|
privateKey: params.privateKey || tmsConfig.privateKey,
|
|
@@ -3948,22 +3587,18 @@ const handleParams$1 = (tmsConfig, cmdOptions) => {
|
|
|
3948
3587
|
desc: params.desc || getDesc$1(params.desc)
|
|
3949
3588
|
};
|
|
3950
3589
|
};
|
|
3590
|
+
|
|
3951
3591
|
/**
|
|
3952
3592
|
* 上传
|
|
3953
3593
|
* @param {object} tmsConfig
|
|
3954
3594
|
* @param {object} cmdOptions {version: '2022.28.5', desc: '', robot: 2, infoOutput: './a.txt' }
|
|
3955
3595
|
*/
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
3596
|
async function upload$1(tmsConfig, cmdOptions) {
|
|
3959
3597
|
try {
|
|
3960
3598
|
var _tmsConfig$hooks;
|
|
3961
|
-
|
|
3962
3599
|
const params = handleParams$1(tmsConfig, cmdOptions);
|
|
3963
|
-
|
|
3964
3600
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeUpload) === 'function') {
|
|
3965
3601
|
var _tmsConfig$hooks2;
|
|
3966
|
-
|
|
3967
3602
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeUpload({
|
|
3968
3603
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3969
3604
|
cmdOptions: global$1.getData('cmdOptions'),
|
|
@@ -3971,26 +3606,23 @@ async function upload$1(tmsConfig, cmdOptions) {
|
|
|
3971
3606
|
}));
|
|
3972
3607
|
report$3('hooks:beforeUpload');
|
|
3973
3608
|
}
|
|
3974
|
-
|
|
3975
3609
|
;
|
|
3976
|
-
const uploadRes = await createTask$2(mpCi$1.uploadMp, '正在上传小程序代码', '上传小程序代码完成')({
|
|
3610
|
+
const uploadRes = await createTask$2(mpCi$1.uploadMp, '正在上传小程序代码', '上传小程序代码完成')({
|
|
3611
|
+
...params
|
|
3977
3612
|
});
|
|
3978
3613
|
const allSize = getAllSize(uploadRes);
|
|
3979
|
-
|
|
3980
3614
|
if (params.infoOutput) {
|
|
3981
3615
|
outputInfo(params.infoOutput, {
|
|
3982
3616
|
sourceCode: params.projectPath,
|
|
3983
3617
|
...uploadRes
|
|
3984
3618
|
});
|
|
3985
3619
|
}
|
|
3986
|
-
|
|
3987
3620
|
info$6(`上传包大小: ${allSize}k; 上传包版本: ${params.version}`);
|
|
3988
3621
|
} catch (e) {
|
|
3989
3622
|
console.log('详细错误:', e);
|
|
3990
3623
|
handleError$3(`上传错误: ${e.message}`, true);
|
|
3991
3624
|
}
|
|
3992
3625
|
}
|
|
3993
|
-
|
|
3994
3626
|
var upload_1 = upload$1;
|
|
3995
3627
|
|
|
3996
3628
|
const mpCi = mpCi$3;
|
|
@@ -4008,9 +3640,9 @@ const {
|
|
|
4008
3640
|
getDesc
|
|
4009
3641
|
} = utils;
|
|
4010
3642
|
const report$2 = report_1;
|
|
4011
|
-
|
|
4012
3643
|
const handleParams = (tmsConfig, cmdOptions) => {
|
|
4013
|
-
const params = {
|
|
3644
|
+
const params = {
|
|
3645
|
+
...(tmsConfig.upload ? tmsConfig.upload : {}),
|
|
4014
3646
|
...cmdOptions
|
|
4015
3647
|
};
|
|
4016
3648
|
return {
|
|
@@ -4023,18 +3655,18 @@ const handleParams = (tmsConfig, cmdOptions) => {
|
|
|
4023
3655
|
desc: params.desc || getDesc(params.desc)
|
|
4024
3656
|
};
|
|
4025
3657
|
};
|
|
3658
|
+
|
|
4026
3659
|
/**
|
|
4027
3660
|
* 获取sourcemap
|
|
4028
3661
|
* @param {object} tmsConfig
|
|
4029
3662
|
* @param {object} cmdOptions {version: '2022.28.5', desc: '', robot: 2, infoOutput: './a.txt' }
|
|
4030
3663
|
*/
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
3664
|
async function sourcemap$1(tmsConfig, cmdOptions) {
|
|
4034
3665
|
try {
|
|
4035
3666
|
const params = handleParams(tmsConfig, cmdOptions);
|
|
4036
3667
|
report$2('sourcemap');
|
|
4037
|
-
await createTask$1(mpCi.getDevSourceMap, '正在获取小程序代码sourcemap', '获取小程序代码sourcemap完成')({
|
|
3668
|
+
await createTask$1(mpCi.getDevSourceMap, '正在获取小程序代码sourcemap', '获取小程序代码sourcemap完成')({
|
|
3669
|
+
...params
|
|
4038
3670
|
});
|
|
4039
3671
|
info$5(`sourcemap文件已保存到${params.sourceMapSavePath}`);
|
|
4040
3672
|
} catch (e) {
|
|
@@ -4042,28 +3674,27 @@ async function sourcemap$1(tmsConfig, cmdOptions) {
|
|
|
4042
3674
|
handleError$2(`获取sourcemap错误: ${e.message}`, true);
|
|
4043
3675
|
}
|
|
4044
3676
|
}
|
|
4045
|
-
|
|
4046
3677
|
var sourcemap_1 = sourcemap$1;
|
|
4047
3678
|
|
|
4048
3679
|
const {
|
|
4049
3680
|
resolve: resolve$4,
|
|
4050
3681
|
getAbsolutePath
|
|
4051
|
-
} = widgets;
|
|
3682
|
+
} = widgets;
|
|
4052
3683
|
|
|
3684
|
+
// 处理tms.config.cloudModules的兼容数据
|
|
4053
3685
|
function getTmsCloudModules(tmsConfig) {
|
|
4054
3686
|
const {
|
|
4055
3687
|
cloudModules
|
|
4056
3688
|
} = tmsConfig;
|
|
4057
|
-
|
|
4058
3689
|
if (Array.isArray(tmsConfig.cloudModules)) {
|
|
4059
3690
|
return {
|
|
4060
3691
|
all: [...tmsConfig.cloudModules],
|
|
4061
3692
|
include: []
|
|
4062
3693
|
};
|
|
4063
3694
|
}
|
|
4064
|
-
|
|
4065
3695
|
return cloudModules;
|
|
4066
3696
|
}
|
|
3697
|
+
|
|
4067
3698
|
/**
|
|
4068
3699
|
* 获取需要监听的云函数
|
|
4069
3700
|
* @param {*} tmsConfig {}
|
|
@@ -4071,21 +3702,17 @@ function getTmsCloudModules(tmsConfig) {
|
|
|
4071
3702
|
* @returns
|
|
4072
3703
|
* [{ name: '', sourcePath: '', targetPath: ''}]
|
|
4073
3704
|
*/
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
3705
|
function getCloudsOfListen$2(tmsConfig, cmdOptions) {
|
|
4077
3706
|
var _cmdOptions$cloud;
|
|
4078
|
-
|
|
4079
3707
|
// 获取tmsconfig配置的云函数的配置项
|
|
4080
3708
|
const cloudModules = getTmsCloudModules(tmsConfig);
|
|
4081
|
-
let includeClouds = (cmdOptions === null || cmdOptions === void 0 ? void 0 : (_cmdOptions$cloud = cmdOptions.cloud) === null || _cmdOptions$cloud === void 0 ? void 0 : _cmdOptions$cloud.split(',')) || cloudModules.include || [];
|
|
3709
|
+
let includeClouds = (cmdOptions === null || cmdOptions === void 0 ? void 0 : (_cmdOptions$cloud = cmdOptions.cloud) === null || _cmdOptions$cloud === void 0 ? void 0 : _cmdOptions$cloud.split(',')) || cloudModules.include || [];
|
|
4082
3710
|
|
|
3711
|
+
// 如果没有配置include, 默认使用所有的数据云函数列表
|
|
4083
3712
|
if (includeClouds.length === 0) {
|
|
4084
3713
|
includeClouds = cloudModules.all.map(item => item.name);
|
|
4085
3714
|
}
|
|
4086
|
-
|
|
4087
3715
|
const result = [];
|
|
4088
|
-
|
|
4089
3716
|
for (const item of cloudModules.all) {
|
|
4090
3717
|
if (includeClouds.includes(item.name)) {
|
|
4091
3718
|
result.push({
|
|
@@ -4095,45 +3722,38 @@ function getCloudsOfListen$2(tmsConfig, cmdOptions) {
|
|
|
4095
3722
|
});
|
|
4096
3723
|
}
|
|
4097
3724
|
}
|
|
4098
|
-
|
|
4099
3725
|
return result;
|
|
4100
3726
|
}
|
|
4101
|
-
|
|
4102
3727
|
var getClouds = getCloudsOfListen$2;
|
|
4103
3728
|
|
|
4104
3729
|
const fs$3 = require$$0__default$1;
|
|
3730
|
+
|
|
4105
3731
|
/**
|
|
4106
3732
|
* 检查云函数的配置项
|
|
4107
3733
|
* @param {*} tmsConfig
|
|
4108
3734
|
*/
|
|
4109
|
-
|
|
4110
3735
|
function checkCloudConfig$2(tmsConfig) {
|
|
4111
3736
|
if (!tmsConfig.cloudModules) {
|
|
4112
3737
|
return '你没有在tms.config.js的cloudModules注册云函数';
|
|
4113
3738
|
}
|
|
4114
|
-
|
|
4115
3739
|
if (!tmsConfig.cloudDir) {
|
|
4116
3740
|
return '你没有在tms.config.js配置云函数编译目录cloudDir';
|
|
4117
3741
|
}
|
|
4118
|
-
|
|
4119
3742
|
return;
|
|
4120
3743
|
}
|
|
3744
|
+
|
|
4121
3745
|
/**
|
|
4122
3746
|
* 检查云函数源码目录是否存在
|
|
4123
3747
|
* @param {Array} clouds [{name: '', sourcePath: '', targetPath: ''}]
|
|
4124
3748
|
*/
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
3749
|
function checkSrcPathIsExist$1(clouds) {
|
|
4128
3750
|
for (const item of clouds) {
|
|
4129
3751
|
if (!fs$3.existsSync(item.sourcePath)) {
|
|
4130
3752
|
return `${item.name}云函数的${item.sourcePath}目录不存在, 请检查tms.config.js>cloudModules>all云函数的配置目录`;
|
|
4131
3753
|
}
|
|
4132
3754
|
}
|
|
4133
|
-
|
|
4134
3755
|
return;
|
|
4135
3756
|
}
|
|
4136
|
-
|
|
4137
3757
|
var check$2 = {
|
|
4138
3758
|
checkCloudConfig: checkCloudConfig$2,
|
|
4139
3759
|
checkSrcPathIsExist: checkSrcPathIsExist$1
|
|
@@ -4160,23 +3780,21 @@ const {
|
|
|
4160
3780
|
const {
|
|
4161
3781
|
checkCloudConfig: checkCloudConfig$1
|
|
4162
3782
|
} = check$2;
|
|
4163
|
-
|
|
4164
3783
|
var link = async (tmsConfig, cmdOptions) => {
|
|
4165
3784
|
try {
|
|
4166
3785
|
ensureDirExist$2(resolve$3(tmsConfig.cloudDir));
|
|
4167
|
-
checkCloudConfig$1(tmsConfig);
|
|
4168
|
-
|
|
4169
|
-
const clouds = getCloudsOfListen$1(tmsConfig, cmdOptions); // 打印启动云函数列表
|
|
3786
|
+
checkCloudConfig$1(tmsConfig);
|
|
4170
3787
|
|
|
3788
|
+
// 获取需要监听的云函数列表
|
|
3789
|
+
const clouds = getCloudsOfListen$1(tmsConfig, cmdOptions);
|
|
3790
|
+
// 打印启动云函数列表
|
|
4171
3791
|
info$4('当前启动云函数列表:', clouds.map(item => item.name).sort());
|
|
4172
3792
|
clouds.forEach(item => {
|
|
4173
3793
|
if (!fs$2.existsSync(item.sourcePath)) {
|
|
4174
3794
|
warn(`云函数${item.sourcePath}不存在`);
|
|
4175
3795
|
return;
|
|
4176
3796
|
}
|
|
4177
|
-
|
|
4178
3797
|
const stat = fs$2.lstatSync(item.targetPath);
|
|
4179
|
-
|
|
4180
3798
|
if (!stat.isSymbolicLink()) {
|
|
4181
3799
|
fs$2.symlinkSync(item.sourcePath, item.targetPath);
|
|
4182
3800
|
}
|
|
@@ -4200,18 +3818,16 @@ const {
|
|
|
4200
3818
|
const {
|
|
4201
3819
|
info: info$3
|
|
4202
3820
|
} = log$1;
|
|
3821
|
+
|
|
4203
3822
|
/**
|
|
4204
3823
|
* npm install
|
|
4205
3824
|
* @param {array} clouds [{name: '', sourcePath: '', targetPath: ''}]
|
|
4206
3825
|
*/
|
|
4207
|
-
|
|
4208
3826
|
const runInstall$1 = async (clouds, tmsConfig) => {
|
|
4209
3827
|
const promises = [];
|
|
4210
|
-
|
|
4211
3828
|
for (const item of clouds) {
|
|
4212
3829
|
ensureDirExist$1(item.targetPath);
|
|
4213
3830
|
const packageFilePath = resolve$2(item.sourcePath, 'package.json');
|
|
4214
|
-
|
|
4215
3831
|
if (fs$1.existsSync(packageFilePath)) {
|
|
4216
3832
|
shellJs$1.cp('-Rf', resolve$2(packageFilePath), item.targetPath);
|
|
4217
3833
|
promises.push(() => {
|
|
@@ -4222,7 +3838,6 @@ const runInstall$1 = async (clouds, tmsConfig) => {
|
|
|
4222
3838
|
}
|
|
4223
3839
|
await Promise.all(promises.map(item => item()));
|
|
4224
3840
|
};
|
|
4225
|
-
|
|
4226
3841
|
var install$1 = {
|
|
4227
3842
|
runInstall: runInstall$1
|
|
4228
3843
|
};
|
|
@@ -4260,13 +3875,13 @@ const {
|
|
|
4260
3875
|
const {
|
|
4261
3876
|
runInstall
|
|
4262
3877
|
} = install$1;
|
|
3878
|
+
|
|
4263
3879
|
/**
|
|
4264
3880
|
* 获取云函数的编译任务
|
|
4265
3881
|
* @param {array} clouds [{name: '', sourcePath: '', targetPath: ''}]
|
|
4266
3882
|
* @param {object} srcOption gulp.src的参数
|
|
4267
3883
|
* @returns Map {'${sourcePath}': {taskFn: () => {}, targetPath: 'xxx'}}
|
|
4268
3884
|
*/
|
|
4269
|
-
|
|
4270
3885
|
const getCompileTasks = (clouds, srcOption) => {
|
|
4271
3886
|
const compileTasksMap = new Map();
|
|
4272
3887
|
clouds.forEach(item => {
|
|
@@ -4284,18 +3899,16 @@ const getCompileTasks = (clouds, srcOption) => {
|
|
|
4284
3899
|
});
|
|
4285
3900
|
return compileTasksMap;
|
|
4286
3901
|
};
|
|
4287
|
-
|
|
4288
3902
|
const getTargetFile = (sourceFile, sourcePath, targetPath) => {
|
|
4289
3903
|
const sourceFileRelativeModule = path$1.relative(sourcePath, sourceFile);
|
|
4290
3904
|
const targetFile = resolve$1(targetPath, sourceFileRelativeModule);
|
|
4291
3905
|
return targetFile;
|
|
4292
3906
|
};
|
|
3907
|
+
|
|
4293
3908
|
/**
|
|
4294
3909
|
* 开始启动编译
|
|
4295
3910
|
* @param {Map} compileTasksMap {'${sourcePath}': {taskFn: () => {}, targetPath: 'xxx'}}
|
|
4296
3911
|
*/
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
3912
|
const runCompile = (compileTasksMap, callback) => {
|
|
4300
3913
|
async function end(next) {
|
|
4301
3914
|
// 监听其他文件
|
|
@@ -4311,16 +3924,16 @@ const runCompile = (compileTasksMap, callback) => {
|
|
|
4311
3924
|
callback && callback();
|
|
4312
3925
|
next();
|
|
4313
3926
|
}
|
|
4314
|
-
|
|
4315
3927
|
const compileTasksArr = [];
|
|
4316
3928
|
compileTasksMap.forEach(({
|
|
4317
3929
|
taskFn
|
|
4318
3930
|
}) => {
|
|
4319
3931
|
compileTasksArr.push(taskFn);
|
|
4320
|
-
});
|
|
4321
|
-
|
|
3932
|
+
});
|
|
3933
|
+
// 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
4322
3934
|
series(parallel(...compileTasksArr), end)();
|
|
4323
3935
|
};
|
|
3936
|
+
|
|
4324
3937
|
/**
|
|
4325
3938
|
* 监听文件变动
|
|
4326
3939
|
* @param {*} sourcePath 云函数的源码目录
|
|
@@ -4328,55 +3941,53 @@ const runCompile = (compileTasksMap, callback) => {
|
|
|
4328
3941
|
* @param {*} callback 监听到变动的回调
|
|
4329
3942
|
* @param {*} targetPath 云函数的编译目录
|
|
4330
3943
|
*/
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
3944
|
const runWatch = (sourcePath, watchOptions, callback, targetPath) => {
|
|
4334
|
-
watch(sourcePath, {
|
|
3945
|
+
watch(sourcePath, {
|
|
3946
|
+
...watchOptions
|
|
4335
3947
|
}, vinyl => {
|
|
4336
3948
|
const sourceFile = vinyl.history[0];
|
|
4337
3949
|
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
4338
3950
|
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
4339
3951
|
const targetFile = getTargetFile(sourceFile, sourcePath, targetPath);
|
|
4340
|
-
|
|
4341
3952
|
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
4342
3953
|
info$2(`删除${sourceFileName}`);
|
|
4343
3954
|
shellJs.rm('-rf', targetFile);
|
|
4344
3955
|
return;
|
|
4345
3956
|
}
|
|
4346
|
-
|
|
4347
3957
|
info$2(`${sourceFileName}有更新`);
|
|
4348
3958
|
return callback([sourceFile], path$1.dirname(targetFile));
|
|
4349
3959
|
});
|
|
4350
3960
|
};
|
|
4351
|
-
|
|
4352
3961
|
var dev$1 = async (tmsConfig, cmdOptions) => {
|
|
4353
3962
|
try {
|
|
4354
3963
|
const sTime = new Date().getTime();
|
|
4355
3964
|
const spinner = ora();
|
|
4356
|
-
spinner.start();
|
|
3965
|
+
spinner.start();
|
|
4357
3966
|
|
|
3967
|
+
// 检查云函数的配置项
|
|
4358
3968
|
const configErrMsg = checkCloudConfig(tmsConfig);
|
|
4359
|
-
|
|
4360
3969
|
if (configErrMsg) {
|
|
4361
3970
|
throw new Error(configErrMsg);
|
|
4362
|
-
}
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
ensureDirExist(resolve$1(tmsConfig.cloudDir)); // 获取需要监听的云函数列表
|
|
3971
|
+
}
|
|
4366
3972
|
|
|
4367
|
-
|
|
3973
|
+
// 确保云函数的编译目录存在
|
|
3974
|
+
ensureDirExist(resolve$1(tmsConfig.cloudDir));
|
|
4368
3975
|
|
|
3976
|
+
// 获取需要监听的云函数列表
|
|
3977
|
+
const clouds = getCloudsOfListen(tmsConfig, cmdOptions);
|
|
3978
|
+
// 检查云函数源码目录是否存在
|
|
4369
3979
|
const srcNotExistErrMsg = checkSrcPathIsExist(clouds);
|
|
4370
|
-
|
|
4371
3980
|
if (srcNotExistErrMsg) {
|
|
4372
3981
|
throw new Error(srcNotExistErrMsg);
|
|
4373
|
-
}
|
|
4374
|
-
|
|
3982
|
+
}
|
|
4375
3983
|
|
|
4376
|
-
|
|
3984
|
+
// 打印启动云函数列表
|
|
3985
|
+
info$2('当前启动云函数列表:', clouds.map(item => item.name).sort());
|
|
4377
3986
|
|
|
4378
|
-
|
|
3987
|
+
// npm install
|
|
3988
|
+
await createTask(runInstall, '开始npm install', 'npm install完成')(clouds, tmsConfig);
|
|
4379
3989
|
|
|
3990
|
+
// 获取云函数列表的编译任务
|
|
4380
3991
|
const compileTasksMap = getCompileTasks(clouds, {
|
|
4381
3992
|
allowEmpty: true
|
|
4382
3993
|
});
|
|
@@ -4415,13 +4026,11 @@ const {
|
|
|
4415
4026
|
getSubPackages,
|
|
4416
4027
|
getModulesByModuleNames
|
|
4417
4028
|
} = tmsMpconfig.exports;
|
|
4418
|
-
|
|
4419
4029
|
const handleModuleArg = cmdOptions => {
|
|
4420
4030
|
// 单模块或多模块开发-用户通过脚手架参数指定的模块
|
|
4421
4031
|
if (typeof cmdOptions.module === 'string') {
|
|
4422
4032
|
return cmdOptions.module.split(',');
|
|
4423
4033
|
}
|
|
4424
|
-
|
|
4425
4034
|
return [];
|
|
4426
4035
|
};
|
|
4427
4036
|
/**
|
|
@@ -4430,47 +4039,38 @@ const handleModuleArg = cmdOptions => {
|
|
|
4430
4039
|
* @param {Object} modulePrivateCfg 私有配置里的模块
|
|
4431
4040
|
* @param {Array} moduleAll 当前小程序全部模块
|
|
4432
4041
|
*/
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
4042
|
const getSpecificModuleNames = (moduleArg, modules) => {
|
|
4436
4043
|
if (moduleArg.length > 0) {
|
|
4437
4044
|
return moduleArg;
|
|
4438
4045
|
}
|
|
4439
|
-
|
|
4440
4046
|
const {
|
|
4441
4047
|
all,
|
|
4442
4048
|
include,
|
|
4443
4049
|
exclude,
|
|
4444
4050
|
blockRemote
|
|
4445
|
-
} = modules;
|
|
4446
|
-
|
|
4051
|
+
} = modules;
|
|
4052
|
+
// 单模块或多模块开发-用户在tms.private.js指定的模块
|
|
4447
4053
|
if ((include === null || include === void 0 ? void 0 : include.length) > 0) {
|
|
4448
4054
|
return include;
|
|
4449
4055
|
}
|
|
4450
|
-
|
|
4451
4056
|
if ((exclude === null || exclude === void 0 ? void 0 : exclude.length) > 0) {
|
|
4452
4057
|
return all.filter(module => !exclude.includes(module.moduleName)).map(item => item.moduleName);
|
|
4453
4058
|
}
|
|
4454
|
-
|
|
4455
4059
|
if (blockRemote === true) {
|
|
4456
4060
|
return all.filter(module => module.repoInfo === undefined).map(item => item.moduleName);
|
|
4457
4061
|
}
|
|
4458
|
-
|
|
4459
4062
|
return all.map(item => item.moduleName);
|
|
4460
4063
|
};
|
|
4461
|
-
|
|
4462
4064
|
async function run(commandName, cmdOptions) {
|
|
4463
|
-
global.setData('commandName', commandName);
|
|
4464
|
-
|
|
4065
|
+
global.setData('commandName', commandName);
|
|
4066
|
+
// 用户本地的配置
|
|
4465
4067
|
const tmsConfig = getTmsConfig$1();
|
|
4466
|
-
|
|
4467
4068
|
try {
|
|
4468
4069
|
// 缓存数据
|
|
4469
4070
|
global.setData({
|
|
4470
4071
|
cmdOptions,
|
|
4471
4072
|
tmsConfig
|
|
4472
4073
|
});
|
|
4473
|
-
|
|
4474
4074
|
if (commandName === 'cloud-link') {
|
|
4475
4075
|
cloudLink(tmsConfig, cmdOptions);
|
|
4476
4076
|
report$1('run:cloud-link', {
|
|
@@ -4478,7 +4078,6 @@ async function run(commandName, cmdOptions) {
|
|
|
4478
4078
|
});
|
|
4479
4079
|
return;
|
|
4480
4080
|
}
|
|
4481
|
-
|
|
4482
4081
|
if (commandName === 'cloud-dev') {
|
|
4483
4082
|
cloudDev(tmsConfig, cmdOptions);
|
|
4484
4083
|
report$1('run:cloud-dev', {
|
|
@@ -4486,7 +4085,6 @@ async function run(commandName, cmdOptions) {
|
|
|
4486
4085
|
});
|
|
4487
4086
|
return;
|
|
4488
4087
|
}
|
|
4489
|
-
|
|
4490
4088
|
otherCommands(tmsConfig, commandName, cmdOptions);
|
|
4491
4089
|
} catch (error) {
|
|
4492
4090
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
@@ -4499,18 +4097,18 @@ async function run(commandName, cmdOptions) {
|
|
|
4499
4097
|
process.exit(1);
|
|
4500
4098
|
}
|
|
4501
4099
|
}
|
|
4502
|
-
|
|
4503
4100
|
function otherCommands(tmsConfig, commandName, cmdOptions) {
|
|
4504
4101
|
// 处理module参数
|
|
4505
|
-
const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmdOptions), tmsConfig.modules);
|
|
4102
|
+
const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmdOptions), tmsConfig.modules);
|
|
4506
4103
|
|
|
4104
|
+
// moduleNames => ['home', 'car']
|
|
4507
4105
|
const moduleNames = [...new Set([...specificModuleNames])];
|
|
4508
|
-
const modules = getModulesByModuleNames(tmsConfig, moduleNames, false);
|
|
4509
|
-
|
|
4510
|
-
const newModules = getModulesByMergeDepModules(tmsConfig, modules, false); // 获取所有的分包
|
|
4106
|
+
const modules = getModulesByModuleNames(tmsConfig, moduleNames, false);
|
|
4511
4107
|
|
|
4108
|
+
// 获取所有模块,合并模块依赖的模块
|
|
4109
|
+
const newModules = getModulesByMergeDepModules(tmsConfig, modules, false);
|
|
4110
|
+
// 获取所有的分包
|
|
4512
4111
|
const subPackages = getSubPackages(newModules);
|
|
4513
|
-
|
|
4514
4112
|
switch (commandName) {
|
|
4515
4113
|
case 'init':
|
|
4516
4114
|
init(tmsConfig, newModules);
|
|
@@ -4518,7 +4116,6 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
|
|
|
4518
4116
|
appName: tmsConfig.appName
|
|
4519
4117
|
});
|
|
4520
4118
|
return;
|
|
4521
|
-
|
|
4522
4119
|
case 'dev':
|
|
4523
4120
|
global.setData('isDev', true);
|
|
4524
4121
|
dev(tmsConfig, newModules);
|
|
@@ -4526,14 +4123,12 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
|
|
|
4526
4123
|
appName: tmsConfig.appName
|
|
4527
4124
|
});
|
|
4528
4125
|
return;
|
|
4529
|
-
|
|
4530
4126
|
case 'install':
|
|
4531
4127
|
install(tmsConfig, subPackages, false);
|
|
4532
4128
|
report$1('run:install', {
|
|
4533
4129
|
appName: tmsConfig.appName
|
|
4534
4130
|
});
|
|
4535
4131
|
return;
|
|
4536
|
-
|
|
4537
4132
|
case 'build':
|
|
4538
4133
|
global.setData('isDev', false);
|
|
4539
4134
|
build(tmsConfig, newModules);
|
|
@@ -4541,33 +4136,28 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
|
|
|
4541
4136
|
appName: tmsConfig.appName
|
|
4542
4137
|
});
|
|
4543
4138
|
return;
|
|
4544
|
-
|
|
4545
4139
|
case 'preview':
|
|
4546
4140
|
preview(tmsConfig, cmdOptions);
|
|
4547
4141
|
report$1('run:preview', {
|
|
4548
4142
|
appName: tmsConfig.appName
|
|
4549
4143
|
});
|
|
4550
4144
|
return;
|
|
4551
|
-
|
|
4552
4145
|
case 'upload':
|
|
4553
4146
|
upload(tmsConfig, cmdOptions);
|
|
4554
4147
|
report$1('run:upload', {
|
|
4555
4148
|
appName: tmsConfig.appName
|
|
4556
4149
|
});
|
|
4557
4150
|
return;
|
|
4558
|
-
|
|
4559
4151
|
case 'sourcemap':
|
|
4560
4152
|
sourcemap(tmsConfig);
|
|
4561
4153
|
report$1('run:sourcemap', {
|
|
4562
4154
|
appName: tmsConfig.appName
|
|
4563
4155
|
});
|
|
4564
4156
|
return;
|
|
4565
|
-
|
|
4566
4157
|
default:
|
|
4567
4158
|
return;
|
|
4568
4159
|
}
|
|
4569
4160
|
}
|
|
4570
|
-
|
|
4571
4161
|
var run_1 = run;
|
|
4572
4162
|
|
|
4573
4163
|
var entry = [{
|
|
@@ -4637,7 +4227,8 @@ var entry = [{
|
|
|
4637
4227
|
action: cmdOptions => {
|
|
4638
4228
|
run_1('cloud-dev', cmdOptions);
|
|
4639
4229
|
}
|
|
4640
|
-
}
|
|
4230
|
+
}
|
|
4231
|
+
// {
|
|
4641
4232
|
// command: 'cloud-link',
|
|
4642
4233
|
// description: '云函数开发',
|
|
4643
4234
|
// options: [
|
|
@@ -4652,7 +4243,7 @@ var entry = [{
|
|
|
4652
4243
|
|
|
4653
4244
|
var require$$12 = {
|
|
4654
4245
|
name: "@tmsfe/tmskit",
|
|
4655
|
-
version: "0.0.
|
|
4246
|
+
version: "0.0.54",
|
|
4656
4247
|
description: "tmskit",
|
|
4657
4248
|
main: "dist/index.cjs",
|
|
4658
4249
|
bin: {
|
|
@@ -4747,13 +4338,13 @@ const {
|
|
|
4747
4338
|
} = log$1;
|
|
4748
4339
|
const requiredVersion = packageJson.engines.node;
|
|
4749
4340
|
const packName = packageJson.name;
|
|
4341
|
+
|
|
4750
4342
|
/**
|
|
4751
4343
|
* 检查node版本
|
|
4752
4344
|
* @param {String} wanted 希望的node版本
|
|
4753
4345
|
* @param {String} id 某node特性
|
|
4754
4346
|
* @returns {Undefined} 无需返回值
|
|
4755
4347
|
*/
|
|
4756
|
-
|
|
4757
4348
|
const checkNodeVersion = (wanted, id) => {
|
|
4758
4349
|
if (!semver.satisfies(process.version, wanted, {
|
|
4759
4350
|
includePrerelease: true
|
|
@@ -4762,17 +4353,15 @@ const checkNodeVersion = (wanted, id) => {
|
|
|
4762
4353
|
process.exit(1);
|
|
4763
4354
|
}
|
|
4764
4355
|
};
|
|
4356
|
+
|
|
4765
4357
|
/**
|
|
4766
4358
|
* 检查运行环境
|
|
4767
4359
|
*/
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
4360
|
function check$1() {
|
|
4771
4361
|
// 执行操作前检查node版本
|
|
4772
4362
|
// 旧版本node直接提示升级,退出脚本
|
|
4773
4363
|
checkNodeVersion(requiredVersion, packName);
|
|
4774
4364
|
}
|
|
4775
|
-
|
|
4776
4365
|
var check_1 = check$1;
|
|
4777
4366
|
|
|
4778
4367
|
/* eslint-disable no-param-reassign */
|
|
@@ -4800,8 +4389,9 @@ const {
|
|
|
4800
4389
|
const report = report_1;
|
|
4801
4390
|
check();
|
|
4802
4391
|
const program = new commander.Command(TMS_NAME);
|
|
4803
|
-
program.version(`${TMS_NAME} ${require$$12.version}`, '-v, -V, --version');
|
|
4392
|
+
program.version(`${TMS_NAME} ${require$$12.version}`, '-v, -V, --version');
|
|
4804
4393
|
|
|
4394
|
+
// 注册命令底层实现
|
|
4805
4395
|
function registerCommand(program, commands) {
|
|
4806
4396
|
commands.forEach(cmd => {
|
|
4807
4397
|
if (cmd.type === 'parent') {
|
|
@@ -4812,56 +4402,53 @@ function registerCommand(program, commands) {
|
|
|
4812
4402
|
program.addCommand(childProgram);
|
|
4813
4403
|
} else {
|
|
4814
4404
|
var _cmd$options;
|
|
4815
|
-
|
|
4816
4405
|
const command = program.command(cmd.command);
|
|
4817
4406
|
cmd.usage && command.usage(cmd.usage);
|
|
4818
4407
|
cmd.description && command.description(cmd.description);
|
|
4819
|
-
(_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
|
|
4820
|
-
|
|
4408
|
+
(_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
|
|
4409
|
+
// 上报
|
|
4821
4410
|
command.hook('preAction', thisCommand => {
|
|
4822
4411
|
report(`${thisCommand._name}-pre`);
|
|
4823
|
-
});
|
|
4824
|
-
|
|
4412
|
+
});
|
|
4413
|
+
// 上报
|
|
4825
4414
|
command.hook('postAction', thisCommand => {
|
|
4826
4415
|
report(`${thisCommand._name}-post`);
|
|
4827
4416
|
});
|
|
4828
4417
|
command.action(cmd.action);
|
|
4829
4418
|
}
|
|
4830
4419
|
});
|
|
4831
|
-
}
|
|
4832
|
-
|
|
4420
|
+
}
|
|
4833
4421
|
|
|
4422
|
+
// 注册扩展命令
|
|
4834
4423
|
function registerExtendCommand(program, configPath) {
|
|
4835
4424
|
const tmsConfig = getTmsConfig(configPath);
|
|
4836
|
-
|
|
4837
4425
|
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.commands) {
|
|
4838
4426
|
const commands = typeof tmsConfig.commands === 'function' ? tmsConfig.commands() : tmsConfig.commands;
|
|
4839
|
-
|
|
4840
4427
|
if (Array.isArray(commands)) {
|
|
4841
4428
|
registerCommand(program, commands);
|
|
4842
4429
|
}
|
|
4843
4430
|
}
|
|
4844
|
-
}
|
|
4845
|
-
|
|
4846
|
-
|
|
4431
|
+
}
|
|
4432
|
+
// 注册所有的命令
|
|
4847
4433
|
function registerAllCmds(program, commands) {
|
|
4848
4434
|
// 注册脚手架内部命令
|
|
4849
|
-
registerCommand(program, commands);
|
|
4435
|
+
registerCommand(program, commands);
|
|
4850
4436
|
|
|
4437
|
+
// 注册npm包扩展命令
|
|
4851
4438
|
const cmdConfigs = loadExtendCmd();
|
|
4852
4439
|
cmdConfigs.forEach(cmdConfig => {
|
|
4853
4440
|
registerExtendCommand(program, path.dirname(cmdConfig));
|
|
4854
|
-
});
|
|
4441
|
+
});
|
|
4855
4442
|
|
|
4443
|
+
// 注册当前目录扩展命令
|
|
4856
4444
|
const tmsConfigPath = resolve('./tms.config.js');
|
|
4857
|
-
|
|
4858
4445
|
if (fs.existsSync(tmsConfigPath)) {
|
|
4859
4446
|
registerExtendCommand(program, path.dirname(tmsConfigPath));
|
|
4860
4447
|
}
|
|
4861
4448
|
}
|
|
4449
|
+
registerAllCmds(program, commands);
|
|
4862
4450
|
|
|
4863
|
-
|
|
4864
|
-
|
|
4451
|
+
// 捕获未注册的命令
|
|
4865
4452
|
program.arguments('<command>').option('-c, --config <value>', '配置', value => {
|
|
4866
4453
|
// 注册指定配置的扩展命令
|
|
4867
4454
|
registerExtendCommand(program, path.dirname(resolve(value)));
|
|
@@ -4876,12 +4463,10 @@ program.arguments('<command>').option('-c, --config <value>', '配置', value =>
|
|
|
4876
4463
|
program.on('--help', () => {
|
|
4877
4464
|
infoNoTime(`Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
4878
4465
|
});
|
|
4879
|
-
|
|
4880
4466
|
if (!process.argv.slice(2).length) {
|
|
4881
4467
|
program.outputHelp();
|
|
4882
4468
|
process.exit(-1);
|
|
4883
4469
|
}
|
|
4884
|
-
|
|
4885
4470
|
program.parse(process.argv);
|
|
4886
4471
|
var src = src$3;
|
|
4887
4472
|
|