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