@tmsfe/tmskit 0.0.18 → 0.0.19
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/CHANGELOG.md +2 -1
- package/dist/index.cjs.js +386 -179
- package/package.json +1 -1
- package/src/config/constant.js +5 -0
- package/src/core/cache.js +36 -0
- package/src/core/checkDependencies.js +2 -2
- package/src/core/npm.js +3 -2
- package/src/core/tmsMpconfig.js +2 -3
- package/src/scripts/run/dev/index.js +1 -1
- package/src/scripts/run/index.js +1 -1
- package/src/scripts/run/init/index.js +2 -4
- package/src/scripts/run/install/index.js +109 -16
- package/src/utils/md5.js +25 -0
- package/src/utils/widgets.js +14 -0
- package/src/core/isInIt.js +0 -65
package/dist/index.cjs.js
CHANGED
|
@@ -8,6 +8,7 @@ var require$$2 = require('ora');
|
|
|
8
8
|
var require$$1$2 = require('path');
|
|
9
9
|
var require$$0$2 = require('fs');
|
|
10
10
|
var require$$0$3 = require('shelljs');
|
|
11
|
+
var require$$6 = require('glob-ignore');
|
|
11
12
|
var require$$0$4 = require('async');
|
|
12
13
|
var require$$1$3 = require('ejs');
|
|
13
14
|
var require$$1$4 = require('inquirer');
|
|
@@ -15,7 +16,6 @@ var require$$0$5 = require('metalsmith');
|
|
|
15
16
|
var require$$0$6 = require('lodash');
|
|
16
17
|
var require$$1$5 = require('crypto');
|
|
17
18
|
var require$$0$7 = require('miniprogram-ci');
|
|
18
|
-
var require$$5 = require('glob-ignore');
|
|
19
19
|
var require$$1$6 = require('fs-extra');
|
|
20
20
|
var require$$1$7 = require('semver');
|
|
21
21
|
var require$$0$8 = require('strip-comments');
|
|
@@ -26,8 +26,8 @@ var require$$0$a = require('gulp');
|
|
|
26
26
|
var require$$0$b = require('object-assign');
|
|
27
27
|
var require$$3 = require('fancy-log');
|
|
28
28
|
var require$$4$1 = require('ansi-colors');
|
|
29
|
-
var require$$5
|
|
30
|
-
var require$$6 = require('readable-stream');
|
|
29
|
+
var require$$5 = require('chokidar');
|
|
30
|
+
var require$$6$1 = require('readable-stream');
|
|
31
31
|
var require$$7$1 = require('vinyl-file');
|
|
32
32
|
var require$$8 = require('vinyl');
|
|
33
33
|
var require$$9 = require('anymatch');
|
|
@@ -46,6 +46,7 @@ var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
|
46
46
|
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
47
47
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
48
48
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
49
|
+
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
49
50
|
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
50
51
|
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
51
52
|
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
@@ -53,7 +54,6 @@ var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
|
53
54
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
54
55
|
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
55
56
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
56
|
-
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
57
57
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
58
58
|
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
59
59
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
@@ -64,8 +64,8 @@ var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
|
64
64
|
var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
|
|
65
65
|
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
66
66
|
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
|
|
67
|
-
var require$$5__default
|
|
68
|
-
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
67
|
+
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
68
|
+
var require$$6__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
|
|
69
69
|
var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7$1);
|
|
70
70
|
var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
|
|
71
71
|
var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
|
|
@@ -137,23 +137,24 @@ const warn$2 = message => {
|
|
|
137
137
|
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$3.yellow(message));
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
-
const info$
|
|
140
|
+
const info$a = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
141
141
|
|
|
142
142
|
var log$1 = {
|
|
143
143
|
fail: fail$9,
|
|
144
144
|
succeed: succeed$2,
|
|
145
145
|
warn: warn$2,
|
|
146
|
-
info: info$
|
|
146
|
+
info: info$a
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
const program$1 = require$$0__default$1;
|
|
150
150
|
const leven = require$$1__default$1;
|
|
151
151
|
const ora = require$$2__default;
|
|
152
|
-
const path$
|
|
153
|
-
const fs$
|
|
152
|
+
const path$d = require$$1__default$2;
|
|
153
|
+
const fs$g = require$$0__default$2;
|
|
154
154
|
const shelljs$7 = require$$0__default$3;
|
|
155
|
+
const glob$1 = require$$6__default;
|
|
155
156
|
const {
|
|
156
|
-
info: info$
|
|
157
|
+
info: info$9
|
|
157
158
|
} = log$1;
|
|
158
159
|
const chalk$2 = require$$0__default;
|
|
159
160
|
const shelljsOptions = {
|
|
@@ -164,7 +165,7 @@ const shelljsOptions = {
|
|
|
164
165
|
const cwd = process.cwd();
|
|
165
166
|
|
|
166
167
|
function resolve$f(...args) {
|
|
167
|
-
return path$
|
|
168
|
+
return path$d.resolve(cwd, ...args);
|
|
168
169
|
}
|
|
169
170
|
/**
|
|
170
171
|
* 用户输入命令时,进行提示
|
|
@@ -184,7 +185,7 @@ const suggestCommands$1 = unknownCommand => {
|
|
|
184
185
|
});
|
|
185
186
|
|
|
186
187
|
if (suggestion) {
|
|
187
|
-
info$
|
|
188
|
+
info$9(` ${chalk$2.red(`Did you mean ${chalk$2.yellow(suggestion)}?`)}`);
|
|
188
189
|
}
|
|
189
190
|
};
|
|
190
191
|
/**
|
|
@@ -220,8 +221,8 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
220
221
|
const cwd = process.cwd();
|
|
221
222
|
return new Promise((resolve, reject) => {
|
|
222
223
|
// 如果目标目录不存在
|
|
223
|
-
if (fs$
|
|
224
|
-
shelljs$7.rm('-rf', path$
|
|
224
|
+
if (fs$g.existsSync(dest)) {
|
|
225
|
+
shelljs$7.rm('-rf', path$d.join(dest));
|
|
225
226
|
}
|
|
226
227
|
|
|
227
228
|
shelljs$7.mkdir('-p', dest);
|
|
@@ -270,7 +271,7 @@ function pullRepoForGit$1(dest, branch) {
|
|
|
270
271
|
*/
|
|
271
272
|
|
|
272
273
|
|
|
273
|
-
function npmInstall$
|
|
274
|
+
function npmInstall$2(dir) {
|
|
274
275
|
return new Promise((resolve, reject) => {
|
|
275
276
|
shelljs$7.exec('npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
276
277
|
cwd: dir,
|
|
@@ -305,7 +306,7 @@ function createTask$3(task, startText, endText) {
|
|
|
305
306
|
return async (...args) => {
|
|
306
307
|
const start = Date.now();
|
|
307
308
|
const spinner = ora();
|
|
308
|
-
info$
|
|
309
|
+
info$9(startText);
|
|
309
310
|
spinner.start();
|
|
310
311
|
const result = await task(...args);
|
|
311
312
|
endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
|
|
@@ -334,7 +335,7 @@ const mergeMap = function (obj, src) {
|
|
|
334
335
|
};
|
|
335
336
|
|
|
336
337
|
const relativeCwdPath$1 = function (file) {
|
|
337
|
-
return path$
|
|
338
|
+
return path$d.relative(process.cwd(), file);
|
|
338
339
|
};
|
|
339
340
|
/**
|
|
340
341
|
* 从一个对象中,检索出去几个字段
|
|
@@ -353,7 +354,20 @@ const filterField$3 = (obj, filterNames = []) => {
|
|
|
353
354
|
}
|
|
354
355
|
});
|
|
355
356
|
return newObj;
|
|
356
|
-
};
|
|
357
|
+
}; // 检索出文件列表
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
function findFiles(globPath, filter = []) {
|
|
361
|
+
return new Promise((resolve, reject) => {
|
|
362
|
+
glob$1(globPath, filter, (err, files) => {
|
|
363
|
+
if (err) {
|
|
364
|
+
reject(err);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
resolve(files);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
}
|
|
357
371
|
|
|
358
372
|
var widgets = {
|
|
359
373
|
resolve: resolve$f,
|
|
@@ -364,26 +378,29 @@ var widgets = {
|
|
|
364
378
|
pullRepoForGit: pullRepoForGit$1,
|
|
365
379
|
suggestCommands: suggestCommands$1,
|
|
366
380
|
camelize,
|
|
367
|
-
npmInstall: npmInstall$
|
|
381
|
+
npmInstall: npmInstall$2,
|
|
368
382
|
mergeMap,
|
|
369
383
|
relativeCwdPath: relativeCwdPath$1,
|
|
370
|
-
filterField: filterField$3
|
|
384
|
+
filterField: filterField$3,
|
|
385
|
+
findFiles
|
|
371
386
|
};
|
|
372
387
|
|
|
373
|
-
const path$
|
|
388
|
+
const path$c = require('path');
|
|
374
389
|
|
|
375
390
|
const os = require('os'); // 用户目录
|
|
376
391
|
|
|
377
392
|
|
|
378
393
|
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
379
394
|
|
|
380
|
-
const CACHE_DIR$
|
|
395
|
+
const CACHE_DIR$3 = path$c.resolve(HOME_DIR, '.tmskit'); // 缓存文件
|
|
396
|
+
|
|
397
|
+
const CACHE_FILE$1 = 'cache_file.json'; // 脚手架模板代码所在目录
|
|
381
398
|
|
|
382
|
-
const TEMPLATE_DIR$1 = path$
|
|
399
|
+
const TEMPLATE_DIR$1 = path$c.resolve(CACHE_DIR$3, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
383
400
|
|
|
384
|
-
const MODULE_CODE_DIR$1 = path$
|
|
401
|
+
const MODULE_CODE_DIR$1 = path$c.resolve(CACHE_DIR$3, 'modules_code'); // 脚手架模板代码的具体路径
|
|
385
402
|
|
|
386
|
-
const TEMPLATE_PATH$1 = path$
|
|
403
|
+
const TEMPLATE_PATH$1 = path$c.resolve(TEMPLATE_DIR$1, 'tools/tmskit-template'); // 脚手架的名称
|
|
387
404
|
|
|
388
405
|
const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
|
|
389
406
|
|
|
@@ -397,7 +414,7 @@ const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
|
397
414
|
const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
|
|
398
415
|
|
|
399
416
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
400
|
-
app: path$
|
|
417
|
+
app: path$c.resolve(process.cwd(), 'app')
|
|
401
418
|
}; // 默认从源码拷贝到编译后的配置
|
|
402
419
|
|
|
403
420
|
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
|
|
@@ -410,7 +427,8 @@ const TEMPLATE_TKIT_DIR$2 = '_tmskit';
|
|
|
410
427
|
var constant = /*#__PURE__*/Object.freeze({
|
|
411
428
|
__proto__: null,
|
|
412
429
|
HOME_DIR: HOME_DIR,
|
|
413
|
-
CACHE_DIR: CACHE_DIR$
|
|
430
|
+
CACHE_DIR: CACHE_DIR$3,
|
|
431
|
+
CACHE_FILE: CACHE_FILE$1,
|
|
414
432
|
TEMPLATE_DIR: TEMPLATE_DIR$1,
|
|
415
433
|
TEMPLATE_PATH: TEMPLATE_PATH$1,
|
|
416
434
|
TMS_NAME: TMS_NAME$1,
|
|
@@ -428,10 +446,10 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
428
446
|
|
|
429
447
|
var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
430
448
|
|
|
431
|
-
const fs$
|
|
432
|
-
const path$
|
|
449
|
+
const fs$f = require$$0__default$2;
|
|
450
|
+
const path$b = require$$1__default$2;
|
|
433
451
|
const {
|
|
434
|
-
info: info$
|
|
452
|
+
info: info$8
|
|
435
453
|
} = log$1;
|
|
436
454
|
const {
|
|
437
455
|
relativeCwdPath
|
|
@@ -442,12 +460,12 @@ const {
|
|
|
442
460
|
* @returns
|
|
443
461
|
*/
|
|
444
462
|
|
|
445
|
-
const isDirEmpty = dirname => fs$
|
|
463
|
+
const isDirEmpty = dirname => fs$f.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
446
464
|
|
|
447
465
|
|
|
448
466
|
const isFile = pathName => {
|
|
449
467
|
try {
|
|
450
|
-
const stat = fs$
|
|
468
|
+
const stat = fs$f.lstatSync(pathName);
|
|
451
469
|
return stat.isFile();
|
|
452
470
|
} catch {
|
|
453
471
|
return false;
|
|
@@ -459,9 +477,9 @@ const isFile = pathName => {
|
|
|
459
477
|
*/
|
|
460
478
|
|
|
461
479
|
|
|
462
|
-
const ensureDirExist$
|
|
463
|
-
if (!fs$
|
|
464
|
-
fs$
|
|
480
|
+
const ensureDirExist$2 = dirname => {
|
|
481
|
+
if (!fs$f.existsSync(dirname)) {
|
|
482
|
+
fs$f.mkdirSync(dirname, {
|
|
465
483
|
recursive: true
|
|
466
484
|
});
|
|
467
485
|
}
|
|
@@ -469,27 +487,27 @@ const ensureDirExist$1 = dirname => {
|
|
|
469
487
|
|
|
470
488
|
|
|
471
489
|
const copyFile = function (src, dest) {
|
|
472
|
-
if (fs$
|
|
473
|
-
fs$
|
|
490
|
+
if (fs$f.existsSync(dest)) {
|
|
491
|
+
fs$f.unlinkSync(dest);
|
|
474
492
|
}
|
|
475
493
|
|
|
476
|
-
const dir = path$
|
|
477
|
-
ensureDirExist$
|
|
478
|
-
fs$
|
|
494
|
+
const dir = path$b.dirname(dest);
|
|
495
|
+
ensureDirExist$2(dir);
|
|
496
|
+
fs$f.copyFileSync(src, dest);
|
|
479
497
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
480
498
|
|
|
481
499
|
|
|
482
500
|
function diffContentCopyFile$3(originFile, destFile) {
|
|
483
|
-
if (fs$
|
|
484
|
-
const depDestContent = fs$
|
|
485
|
-
const depOriginContent = fs$
|
|
501
|
+
if (fs$f.existsSync(destFile)) {
|
|
502
|
+
const depDestContent = fs$f.readFileSync(destFile, 'utf8');
|
|
503
|
+
const depOriginContent = fs$f.readFileSync(originFile, 'utf8');
|
|
486
504
|
|
|
487
505
|
if (depDestContent !== depOriginContent) {
|
|
488
|
-
info$
|
|
506
|
+
info$8(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
489
507
|
copyFile(originFile, destFile);
|
|
490
508
|
}
|
|
491
509
|
} else {
|
|
492
|
-
info$
|
|
510
|
+
info$8(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
493
511
|
copyFile(originFile, destFile);
|
|
494
512
|
}
|
|
495
513
|
} // 添加后缀
|
|
@@ -500,7 +518,7 @@ function ext$3(filePath, extensions) {
|
|
|
500
518
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
501
519
|
|
|
502
520
|
try {
|
|
503
|
-
const stat = fs$
|
|
521
|
+
const stat = fs$f.lstatSync(newFilePath);
|
|
504
522
|
|
|
505
523
|
if (stat.isDirectory()) {
|
|
506
524
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -511,7 +529,7 @@ function ext$3(filePath, extensions) {
|
|
|
511
529
|
for (const ext of extensions) {
|
|
512
530
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
513
531
|
|
|
514
|
-
if (fs$
|
|
532
|
+
if (fs$f.existsSync(file)) {
|
|
515
533
|
return {
|
|
516
534
|
ext,
|
|
517
535
|
extPath: extPath + ext,
|
|
@@ -529,11 +547,11 @@ function ext$3(filePath, extensions) {
|
|
|
529
547
|
|
|
530
548
|
|
|
531
549
|
const fileInDir$3 = (dir, file) => {
|
|
532
|
-
if (!fs$
|
|
550
|
+
if (!fs$f.existsSync(dir) || !fs$f.existsSync(file)) {
|
|
533
551
|
return false;
|
|
534
552
|
}
|
|
535
553
|
|
|
536
|
-
const relativePath = path$
|
|
554
|
+
const relativePath = path$b.relative(dir, file);
|
|
537
555
|
|
|
538
556
|
if (relativePath.startsWith('..')) {
|
|
539
557
|
return false;
|
|
@@ -546,10 +564,10 @@ function findAllFilesOfDir$1(dir) {
|
|
|
546
564
|
const list = [];
|
|
547
565
|
|
|
548
566
|
function listFile(dir) {
|
|
549
|
-
const arr = fs$
|
|
567
|
+
const arr = fs$f.readdirSync(dir);
|
|
550
568
|
arr.forEach(item => {
|
|
551
|
-
const fullPath = path$
|
|
552
|
-
const stats = fs$
|
|
569
|
+
const fullPath = path$b.join(dir, item);
|
|
570
|
+
const stats = fs$f.statSync(fullPath);
|
|
553
571
|
|
|
554
572
|
if (stats.isDirectory()) {
|
|
555
573
|
listFile(fullPath);
|
|
@@ -568,7 +586,7 @@ var io$3 = {
|
|
|
568
586
|
isDirEmpty,
|
|
569
587
|
copyFile,
|
|
570
588
|
diffContentCopyFile: diffContentCopyFile$3,
|
|
571
|
-
ensureDirExist: ensureDirExist$
|
|
589
|
+
ensureDirExist: ensureDirExist$2,
|
|
572
590
|
ext: ext$3,
|
|
573
591
|
fileInDir: fileInDir$3,
|
|
574
592
|
isFile,
|
|
@@ -595,7 +613,7 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
595
613
|
|
|
596
614
|
var render_1 = render$1;
|
|
597
615
|
|
|
598
|
-
const fs$
|
|
616
|
+
const fs$e = require$$0__default$2;
|
|
599
617
|
const inquirer = require$$1__default$4;
|
|
600
618
|
const {
|
|
601
619
|
resolve: resolve$e
|
|
@@ -612,12 +630,12 @@ const {
|
|
|
612
630
|
const parseTemplateQuestions = dir => {
|
|
613
631
|
let prompts = [];
|
|
614
632
|
|
|
615
|
-
if (!fs$
|
|
633
|
+
if (!fs$e.existsSync(`${dir}/questions.json`)) {
|
|
616
634
|
return prompts;
|
|
617
635
|
}
|
|
618
636
|
|
|
619
637
|
try {
|
|
620
|
-
const json = JSON.parse(fs$
|
|
638
|
+
const json = JSON.parse(fs$e.readFileSync(`${dir}/questions.json`));
|
|
621
639
|
|
|
622
640
|
if (Array.isArray(json) && json.length > 0) {
|
|
623
641
|
json.forEach((item, index) => {
|
|
@@ -692,8 +710,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
692
710
|
|
|
693
711
|
var generator_1 = generator$1;
|
|
694
712
|
|
|
695
|
-
const path$
|
|
696
|
-
const fs$
|
|
713
|
+
const path$a = require$$1__default$2;
|
|
714
|
+
const fs$d = require$$0__default$2;
|
|
697
715
|
const shelljs$6 = require$$0__default$3;
|
|
698
716
|
const {
|
|
699
717
|
TEMPLATE_DIR,
|
|
@@ -709,7 +727,7 @@ const io$2 = io$3;
|
|
|
709
727
|
const {
|
|
710
728
|
fail: fail$8,
|
|
711
729
|
succeed: succeed$1,
|
|
712
|
-
info: info$
|
|
730
|
+
info: info$7
|
|
713
731
|
} = log$1;
|
|
714
732
|
const generator = generator_1;
|
|
715
733
|
/**
|
|
@@ -720,7 +738,7 @@ const generator = generator_1;
|
|
|
720
738
|
|
|
721
739
|
async function createAppDir(targetDir) {
|
|
722
740
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
723
|
-
if (fs$
|
|
741
|
+
if (fs$d.existsSync(targetDir)) {
|
|
724
742
|
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
725
743
|
fail$8('该目录名已经存在,换个项目名字吧~');
|
|
726
744
|
process.exit(1);
|
|
@@ -738,7 +756,7 @@ async function createAppDir(targetDir) {
|
|
|
738
756
|
|
|
739
757
|
async function create(appName) {
|
|
740
758
|
const cwd = process.cwd();
|
|
741
|
-
const targetDir = path$
|
|
759
|
+
const targetDir = path$a.resolve(cwd, appName);
|
|
742
760
|
const appType = 'mp';
|
|
743
761
|
await createAppDir(targetDir); // 创建缓存目录
|
|
744
762
|
|
|
@@ -746,7 +764,7 @@ async function create(appName) {
|
|
|
746
764
|
|
|
747
765
|
await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
748
766
|
|
|
749
|
-
generator(path$
|
|
767
|
+
generator(path$a.join(TEMPLATE_PATH, appType), targetDir, {
|
|
750
768
|
appName,
|
|
751
769
|
appType
|
|
752
770
|
}).then(() => {
|
|
@@ -770,7 +788,7 @@ async function create(appName) {
|
|
|
770
788
|
succeed$1('项目创建完成.');
|
|
771
789
|
}).catch(err => {
|
|
772
790
|
fail$8(err.message);
|
|
773
|
-
info$
|
|
791
|
+
info$7('详细的错误信息:', err);
|
|
774
792
|
});
|
|
775
793
|
}
|
|
776
794
|
|
|
@@ -799,7 +817,7 @@ var defaultTmsConfig$1 = {
|
|
|
799
817
|
* 用来读取处理tms.config.js与module.config.json字段
|
|
800
818
|
*/
|
|
801
819
|
const loadash$1 = require$$0__default$6;
|
|
802
|
-
const fs$
|
|
820
|
+
const fs$c = require$$0__default$2;
|
|
803
821
|
const {
|
|
804
822
|
TMS_CONFIG_FILENAME,
|
|
805
823
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
@@ -822,7 +840,7 @@ const {
|
|
|
822
840
|
const readTmsConfig$1 = function (env) {
|
|
823
841
|
const tmsConfigPath = resolve$c(TMS_CONFIG_FILENAME);
|
|
824
842
|
|
|
825
|
-
if (!fs$
|
|
843
|
+
if (!fs$c.existsSync(tmsConfigPath)) {
|
|
826
844
|
fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
827
845
|
process.exit(1);
|
|
828
846
|
}
|
|
@@ -833,8 +851,7 @@ const readTmsConfig$1 = function (env) {
|
|
|
833
851
|
env
|
|
834
852
|
}); // 合并默认值
|
|
835
853
|
|
|
836
|
-
loadash$1.mergeWith(
|
|
837
|
-
return tmsConfig;
|
|
854
|
+
return loadash$1.mergeWith(defaultTmsConfig, tmsConfig);
|
|
838
855
|
};
|
|
839
856
|
/**
|
|
840
857
|
* 读取tms.private.config.js
|
|
@@ -845,7 +862,7 @@ const readTmsPrivateCf$1 = function () {
|
|
|
845
862
|
let tmsPrivateCf = {};
|
|
846
863
|
const tmsPrivatePath = resolve$c(TMS_PRIVATE_FILENAME);
|
|
847
864
|
|
|
848
|
-
if (fs$
|
|
865
|
+
if (fs$c.existsSync(tmsPrivatePath)) {
|
|
849
866
|
tmsPrivateCf = require(tmsPrivatePath);
|
|
850
867
|
}
|
|
851
868
|
|
|
@@ -926,8 +943,8 @@ function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
|
|
|
926
943
|
}) => {
|
|
927
944
|
const moduleConfigPath = resolve$c(path, moduleConfigFilename);
|
|
928
945
|
|
|
929
|
-
if (fs$
|
|
930
|
-
const content = fs$
|
|
946
|
+
if (fs$c.existsSync(moduleConfigPath)) {
|
|
947
|
+
const content = fs$c.readFileSync(moduleConfigPath, 'utf-8');
|
|
931
948
|
modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
|
|
932
949
|
}
|
|
933
950
|
});
|
|
@@ -950,10 +967,10 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
950
967
|
}, moduleIndex) => {
|
|
951
968
|
const moduleConfigPath = resolve$c(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
952
969
|
|
|
953
|
-
if (fs$
|
|
970
|
+
if (fs$c.existsSync(moduleConfigPath)) {
|
|
954
971
|
try {
|
|
955
972
|
let findModule = false;
|
|
956
|
-
let moduleConfigContent = fs$
|
|
973
|
+
let moduleConfigContent = fs$c.readFileSync(moduleConfigPath, 'utf-8');
|
|
957
974
|
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
958
975
|
const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
959
976
|
moduleContentArr.forEach(({
|
|
@@ -1083,7 +1100,7 @@ var handleError_1 = {
|
|
|
1083
1100
|
*/
|
|
1084
1101
|
/* eslint-disable no-param-reassign */
|
|
1085
1102
|
|
|
1086
|
-
const fs$
|
|
1103
|
+
const fs$b = require$$0__default$2;
|
|
1087
1104
|
const {
|
|
1088
1105
|
MODULE_CONFIG_FILENAME
|
|
1089
1106
|
} = require$$4;
|
|
@@ -1147,12 +1164,12 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
1147
1164
|
|
|
1148
1165
|
|
|
1149
1166
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
1150
|
-
if (!fs$
|
|
1167
|
+
if (!fs$b.existsSync(sourceAppJsonPath)) {
|
|
1151
1168
|
fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1152
1169
|
process.exit(1);
|
|
1153
1170
|
}
|
|
1154
1171
|
|
|
1155
|
-
const appJson = JSON.parse(fs$
|
|
1172
|
+
const appJson = JSON.parse(fs$b.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1156
1173
|
|
|
1157
1174
|
appJson.subpackages = [];
|
|
1158
1175
|
appJson.pages = [];
|
|
@@ -1252,7 +1269,7 @@ function buildOutputAppJson$1(tmsConfig, modules) {
|
|
|
1252
1269
|
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1253
1270
|
|
|
1254
1271
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1255
|
-
fs$
|
|
1272
|
+
fs$b.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1256
1273
|
|
|
1257
1274
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1258
1275
|
var _tmsConfig$hooks2;
|
|
@@ -1279,7 +1296,7 @@ var buildAppJson = {
|
|
|
1279
1296
|
* 下载第三方代码
|
|
1280
1297
|
*/
|
|
1281
1298
|
const MetalSmith = require$$0__default$5;
|
|
1282
|
-
const crypto$
|
|
1299
|
+
const crypto$2 = require$$1__default$5;
|
|
1283
1300
|
const {
|
|
1284
1301
|
downloadRepoForGit,
|
|
1285
1302
|
pullRepoForGit,
|
|
@@ -1287,9 +1304,9 @@ const {
|
|
|
1287
1304
|
} = widgets;
|
|
1288
1305
|
const {
|
|
1289
1306
|
fail: fail$4,
|
|
1290
|
-
info: info$
|
|
1307
|
+
info: info$6
|
|
1291
1308
|
} = log$1;
|
|
1292
|
-
const fs$
|
|
1309
|
+
const fs$a = require$$0__default$2;
|
|
1293
1310
|
const shelljs$5 = require$$0__default$3;
|
|
1294
1311
|
const {
|
|
1295
1312
|
handleError: handleError$4
|
|
@@ -1354,7 +1371,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
1354
1371
|
|
|
1355
1372
|
function md5ByGitUrlBranch(gitUrl, branch) {
|
|
1356
1373
|
const newBranch = branch && typeof branch === 'string' ? branch : 'master';
|
|
1357
|
-
return crypto$
|
|
1374
|
+
return crypto$2.createHash('md5').update(JSON.stringify({
|
|
1358
1375
|
gitUrl,
|
|
1359
1376
|
branch: newBranch
|
|
1360
1377
|
})).digest('hex');
|
|
@@ -1442,7 +1459,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1442
1459
|
targetPath
|
|
1443
1460
|
},
|
|
1444
1461
|
fn: async (sourceModulePath, targetPath) => {
|
|
1445
|
-
if (fs$
|
|
1462
|
+
if (fs$a.existsSync(targetPath)) {
|
|
1446
1463
|
shelljs$5.rm('-rf', `${targetPath}/*`);
|
|
1447
1464
|
}
|
|
1448
1465
|
|
|
@@ -1457,14 +1474,14 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1457
1474
|
} else {
|
|
1458
1475
|
let promiseTask;
|
|
1459
1476
|
|
|
1460
|
-
if (fs$
|
|
1477
|
+
if (fs$a.existsSync(sourcePath) && fs$a.existsSync(`${sourcePath}/.git`)) {
|
|
1461
1478
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1462
|
-
info$
|
|
1479
|
+
info$6(`git pull:${httpRepoUrl}`);
|
|
1463
1480
|
return pullRepoForGit(sourcePath, branch);
|
|
1464
1481
|
};
|
|
1465
1482
|
} else {
|
|
1466
1483
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1467
|
-
info$
|
|
1484
|
+
info$6(`git clone: ${httpRepoUrl}`);
|
|
1468
1485
|
return downloadRepoForGit(gitUrl, sourcePath, branch);
|
|
1469
1486
|
};
|
|
1470
1487
|
}
|
|
@@ -1505,7 +1522,7 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
|
1505
1522
|
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
|
|
1506
1523
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1507
1524
|
|
|
1508
|
-
if (!fs$
|
|
1525
|
+
if (!fs$a.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
1509
1526
|
return true;
|
|
1510
1527
|
}
|
|
1511
1528
|
}
|
|
@@ -1519,7 +1536,7 @@ var cloneModules_1 = {
|
|
|
1519
1536
|
};
|
|
1520
1537
|
|
|
1521
1538
|
const ci = require$$0__default$7;
|
|
1522
|
-
const path$
|
|
1539
|
+
const path$9 = require$$1__default$2;
|
|
1523
1540
|
/**
|
|
1524
1541
|
* 获取小程序ci的Project对象
|
|
1525
1542
|
* @returns {Object} 小程序ci对象
|
|
@@ -1533,7 +1550,7 @@ const getMpCi = ({
|
|
|
1533
1550
|
}) => {
|
|
1534
1551
|
var _cfgJsonContent$packO;
|
|
1535
1552
|
|
|
1536
|
-
const cfgJsonContent = require(path$
|
|
1553
|
+
const cfgJsonContent = require(path$9.join(projectPath, 'project.config.json'));
|
|
1537
1554
|
|
|
1538
1555
|
const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
|
|
1539
1556
|
value
|
|
@@ -1599,18 +1616,68 @@ var mpCi = {
|
|
|
1599
1616
|
buildMpNpm: buildMpNpm$1
|
|
1600
1617
|
};
|
|
1601
1618
|
|
|
1619
|
+
const fs$9 = require$$0__default$2;
|
|
1620
|
+
const path$8 = require$$1__default$2;
|
|
1621
|
+
const {
|
|
1622
|
+
CACHE_FILE,
|
|
1623
|
+
CACHE_DIR: CACHE_DIR$2
|
|
1624
|
+
} = require$$4;
|
|
1625
|
+
const {
|
|
1626
|
+
ensureDirExist: ensureDirExist$1
|
|
1627
|
+
} = io$3;
|
|
1628
|
+
|
|
1629
|
+
function getCache$1(projectDir, type) {
|
|
1630
|
+
var _content$projectDir;
|
|
1631
|
+
|
|
1632
|
+
const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
|
|
1633
|
+
|
|
1634
|
+
if (!fs$9.existsSync(filePath)) {
|
|
1635
|
+
return null;
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
const content = require(filePath);
|
|
1639
|
+
|
|
1640
|
+
return content === null || content === void 0 ? void 0 : (_content$projectDir = content[projectDir]) === null || _content$projectDir === void 0 ? void 0 : _content$projectDir[type];
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
function setCache$1(projectDir, type = 'miniprogram_npm', data) {
|
|
1644
|
+
const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
|
|
1645
|
+
|
|
1646
|
+
if (!fs$9.existsSync(filePath)) {
|
|
1647
|
+
const dir = path$8.dirname(filePath);
|
|
1648
|
+
ensureDirExist$1(dir);
|
|
1649
|
+
fs$9.writeFileSync(filePath, '{}');
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
const content = require(filePath);
|
|
1653
|
+
|
|
1654
|
+
if (!content[projectDir]) {
|
|
1655
|
+
content[projectDir] = {};
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
content[projectDir] = {
|
|
1659
|
+
[type]: data
|
|
1660
|
+
};
|
|
1661
|
+
fs$9.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
var cache = {
|
|
1665
|
+
setCache: setCache$1,
|
|
1666
|
+
getCache: getCache$1
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1602
1669
|
/**
|
|
1603
1670
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1604
1671
|
*/
|
|
1605
|
-
const fs$
|
|
1672
|
+
const fs$8 = require$$0__default$2;
|
|
1606
1673
|
const fsExtra = require$$1__default$6;
|
|
1607
|
-
const crypto = require$$1__default$5;
|
|
1608
|
-
const path$
|
|
1674
|
+
const crypto$1 = require$$1__default$5;
|
|
1675
|
+
const path$7 = require$$1__default$2;
|
|
1609
1676
|
const shell = require$$0__default$3;
|
|
1610
|
-
const glob = require$$
|
|
1677
|
+
const glob = require$$6__default;
|
|
1611
1678
|
const log = log$1;
|
|
1612
1679
|
const {
|
|
1613
|
-
npmInstall
|
|
1680
|
+
npmInstall: npmInstall$1
|
|
1614
1681
|
} = widgets;
|
|
1615
1682
|
const {
|
|
1616
1683
|
handleError: handleError$3
|
|
@@ -1637,22 +1704,22 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1637
1704
|
const npmTasksMap = new Map();
|
|
1638
1705
|
|
|
1639
1706
|
for (const packageJsonPath of packageJsonFiles) {
|
|
1640
|
-
const packageContent = fs$
|
|
1707
|
+
const packageContent = fs$8.readFileSync(packageJsonPath);
|
|
1641
1708
|
const packageJson = JSON.parse(packageContent);
|
|
1642
1709
|
const md5Obj = {
|
|
1643
1710
|
dependencies: packageJson.dependencies || {}
|
|
1644
1711
|
};
|
|
1645
1712
|
|
|
1646
1713
|
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
1647
|
-
const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1648
|
-
const cacheNMPath = path$
|
|
1649
|
-
const cacheNMTarFile = path$
|
|
1714
|
+
const md5Key = crypto$1.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1715
|
+
const cacheNMPath = path$7.join(cacheDir, md5Key);
|
|
1716
|
+
const cacheNMTarFile = path$7.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
1650
1717
|
|
|
1651
1718
|
const callback = {
|
|
1652
1719
|
params: {
|
|
1653
1720
|
cacheNMPath,
|
|
1654
1721
|
cacheNMTarFile,
|
|
1655
|
-
packageJsonDir: path$
|
|
1722
|
+
packageJsonDir: path$7.dirname(packageJsonPath),
|
|
1656
1723
|
shell
|
|
1657
1724
|
},
|
|
1658
1725
|
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
@@ -1681,7 +1748,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1681
1748
|
fsExtra.emptydirSync(cacheNMPath);
|
|
1682
1749
|
shell.cp('-f', packageJsonPath, cacheNMPath);
|
|
1683
1750
|
log.info(`npm install: ${packageJsonPath}`);
|
|
1684
|
-
return npmInstall(cacheNMPath).then(() => {
|
|
1751
|
+
return npmInstall$1(cacheNMPath).then(() => {
|
|
1685
1752
|
const newShellJsOption = { ...shellJsOption,
|
|
1686
1753
|
cwd: cacheNMPath
|
|
1687
1754
|
};
|
|
@@ -1709,7 +1776,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1709
1776
|
}; // 遍历安装指定目录下所有项目的npm依赖
|
|
1710
1777
|
|
|
1711
1778
|
|
|
1712
|
-
const
|
|
1779
|
+
const npmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
1713
1780
|
const cwd = process.cwd();
|
|
1714
1781
|
const packageJsonFiles = await findAllPackageJson(modules, contextDir); // 收集npm install的任务
|
|
1715
1782
|
|
|
@@ -1733,6 +1800,7 @@ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
|
1733
1800
|
});
|
|
1734
1801
|
await Promise.all(arrPromises);
|
|
1735
1802
|
shell.cd(cwd);
|
|
1803
|
+
return packageJsonFiles;
|
|
1736
1804
|
};
|
|
1737
1805
|
/**
|
|
1738
1806
|
* 递归查找指定条件的文件
|
|
@@ -1753,7 +1821,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1753
1821
|
|
|
1754
1822
|
const find = (startPath, filter) => {
|
|
1755
1823
|
// 目录不存在
|
|
1756
|
-
if (!fs$
|
|
1824
|
+
if (!fs$8.existsSync(startPath)) {
|
|
1757
1825
|
log.fail(`${startPath}目录不存在`);
|
|
1758
1826
|
process.exit(-1);
|
|
1759
1827
|
return;
|
|
@@ -1766,10 +1834,10 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1766
1834
|
return;
|
|
1767
1835
|
}
|
|
1768
1836
|
|
|
1769
|
-
const files = fs$
|
|
1837
|
+
const files = fs$8.readdirSync(startPath);
|
|
1770
1838
|
files.forEach(file => {
|
|
1771
|
-
const filename = path$
|
|
1772
|
-
const stat = fs$
|
|
1839
|
+
const filename = path$7.join(startPath, file);
|
|
1840
|
+
const stat = fs$8.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1773
1841
|
|
|
1774
1842
|
if (stat.isDirectory()) {
|
|
1775
1843
|
find(filename, filter);
|
|
@@ -1795,7 +1863,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1795
1863
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1796
1864
|
|
|
1797
1865
|
const cwd = contextDir || dirPath;
|
|
1798
|
-
const result = [path$
|
|
1866
|
+
const result = [path$7.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1799
1867
|
|
|
1800
1868
|
subRoots.forEach(subRoot => {
|
|
1801
1869
|
if (!subRoot.root) {
|
|
@@ -1803,7 +1871,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1803
1871
|
process.exit(1);
|
|
1804
1872
|
}
|
|
1805
1873
|
|
|
1806
|
-
const toppath = path$
|
|
1874
|
+
const toppath = path$7.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1807
1875
|
|
|
1808
1876
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1809
1877
|
result.push(...list);
|
|
@@ -1819,7 +1887,7 @@ function cloudNpmInstall(contextDir) {
|
|
|
1819
1887
|
}
|
|
1820
1888
|
|
|
1821
1889
|
files.forEach(file => {
|
|
1822
|
-
const dir = path$
|
|
1890
|
+
const dir = path$7.dirname(file);
|
|
1823
1891
|
shell.cd(dir);
|
|
1824
1892
|
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1825
1893
|
silent: false
|
|
@@ -1832,69 +1900,47 @@ function cloudNpmInstall(contextDir) {
|
|
|
1832
1900
|
|
|
1833
1901
|
var npm = {
|
|
1834
1902
|
cloudNpmInstall,
|
|
1835
|
-
|
|
1903
|
+
npmInstallAll: npmInstallAll$1,
|
|
1836
1904
|
findAllPackageJson
|
|
1837
1905
|
};
|
|
1838
1906
|
|
|
1839
|
-
const
|
|
1840
|
-
const fs$
|
|
1841
|
-
const io$1 = io$3;
|
|
1842
|
-
const {
|
|
1843
|
-
createTask: createTask$1,
|
|
1844
|
-
resolve: resolve$9
|
|
1845
|
-
} = widgets;
|
|
1846
|
-
const {
|
|
1847
|
-
buildMpNpm
|
|
1848
|
-
} = mpCi;
|
|
1849
|
-
const {
|
|
1850
|
-
CACHE_DIR: CACHE_DIR$1
|
|
1851
|
-
} = require$$4;
|
|
1852
|
-
const {
|
|
1853
|
-
mpNpmInstallAll
|
|
1854
|
-
} = npm;
|
|
1855
|
-
const {
|
|
1856
|
-
fail: fail$3
|
|
1857
|
-
} = log$1;
|
|
1858
|
-
|
|
1859
|
-
async function install$2(tmsConfig, modules) {
|
|
1860
|
-
// 拷贝模块的package.json到编译输出目录
|
|
1861
|
-
modules.forEach(item => {
|
|
1862
|
-
const outputModuleDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
|
|
1863
|
-
|
|
1864
|
-
if (!fs$6.existsSync(resolve$9(item.path))) {
|
|
1865
|
-
fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1866
|
-
process.exit(1);
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
io$1.ensureDirExist(outputModuleDir);
|
|
1870
|
-
const modulePackagePath = resolve$9(item.path, 'package.json');
|
|
1871
|
-
if (fs$6.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1872
|
-
}); // 小程序npm install
|
|
1873
|
-
|
|
1874
|
-
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`); // 构建miniprogram_npm
|
|
1907
|
+
const crypto = require$$1__default$5;
|
|
1908
|
+
const fs$7 = require$$0__default$2;
|
|
1875
1909
|
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1910
|
+
function fileMd5$1(filePath) {
|
|
1911
|
+
return new Promise((resolve, reject) => {
|
|
1912
|
+
const md5sum = crypto.createHash('md5');
|
|
1913
|
+
const stream = fs$7.ReadStream(filePath);
|
|
1914
|
+
stream.on('data', d => {
|
|
1915
|
+
md5sum.update(d);
|
|
1916
|
+
});
|
|
1917
|
+
stream.on('error', err => {
|
|
1918
|
+
reject(err);
|
|
1919
|
+
});
|
|
1920
|
+
stream.on('end', () => {
|
|
1921
|
+
const hash = md5sum.digest('hex');
|
|
1922
|
+
resolve(hash);
|
|
1923
|
+
});
|
|
1880
1924
|
});
|
|
1881
1925
|
}
|
|
1882
1926
|
|
|
1883
|
-
var
|
|
1927
|
+
var md5 = {
|
|
1928
|
+
fileMd5: fileMd5$1
|
|
1929
|
+
};
|
|
1884
1930
|
|
|
1885
|
-
const fs$
|
|
1931
|
+
const fs$6 = require$$0__default$2;
|
|
1886
1932
|
const semver$1 = require$$1__default$7;
|
|
1887
1933
|
const {
|
|
1888
|
-
resolve: resolve$
|
|
1934
|
+
resolve: resolve$9
|
|
1889
1935
|
} = widgets;
|
|
1890
|
-
const path$
|
|
1891
|
-
const shelljs$
|
|
1936
|
+
const path$6 = require$$1__default$2;
|
|
1937
|
+
const shelljs$4 = require$$0__default$3;
|
|
1892
1938
|
const {
|
|
1893
1939
|
handleError: handleError$2
|
|
1894
1940
|
} = handleError_1;
|
|
1895
1941
|
|
|
1896
1942
|
const getLatestVersion = npmName => {
|
|
1897
|
-
const data = shelljs$
|
|
1943
|
+
const data = shelljs$4.exec(`npm view ${npmName} version`);
|
|
1898
1944
|
return data.stdout || '0.0.0';
|
|
1899
1945
|
};
|
|
1900
1946
|
/**
|
|
@@ -1906,29 +1952,29 @@ const getLatestVersion = npmName => {
|
|
|
1906
1952
|
*/
|
|
1907
1953
|
|
|
1908
1954
|
|
|
1909
|
-
const
|
|
1955
|
+
const isDependenciesUpdate$1 = (modules, cwd, outputDir) => {
|
|
1910
1956
|
// 步骤1. 收集package.json
|
|
1911
1957
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1912
1958
|
// 1.1根目录的package.json
|
|
1913
1959
|
|
|
1914
1960
|
const packageArr = [{
|
|
1915
|
-
srcPackageDir: path$
|
|
1916
|
-
destNpmDir: resolve$
|
|
1961
|
+
srcPackageDir: path$6.join(cwd, packageJsonName),
|
|
1962
|
+
destNpmDir: resolve$9(outputDir, 'node_modules')
|
|
1917
1963
|
}]; // 1.2模块的package.json
|
|
1918
1964
|
|
|
1919
1965
|
modules.forEach(item => {
|
|
1920
|
-
const srcPackageDir = path$
|
|
1966
|
+
const srcPackageDir = path$6.join(cwd, item.path, 'package.json');
|
|
1921
1967
|
|
|
1922
|
-
if (fs$
|
|
1968
|
+
if (fs$6.existsSync(srcPackageDir)) {
|
|
1923
1969
|
packageArr.push({
|
|
1924
1970
|
srcPackageDir,
|
|
1925
|
-
destNpmDir: resolve$
|
|
1971
|
+
destNpmDir: resolve$9(outputDir, item.root, 'node_modules')
|
|
1926
1972
|
});
|
|
1927
1973
|
}
|
|
1928
1974
|
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1929
1975
|
|
|
1930
1976
|
for (const item of packageArr) {
|
|
1931
|
-
const packageJson = fs$
|
|
1977
|
+
const packageJson = fs$6.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1932
1978
|
let dependencies = {};
|
|
1933
1979
|
|
|
1934
1980
|
try {
|
|
@@ -1941,15 +1987,15 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
|
1941
1987
|
const dependenciesKeys = Object.keys(dependencies);
|
|
1942
1988
|
|
|
1943
1989
|
for (const key of dependenciesKeys) {
|
|
1944
|
-
const depPath = path$
|
|
1990
|
+
const depPath = path$6.join(item.destNpmDir, key);
|
|
1945
1991
|
|
|
1946
|
-
if (!fs$
|
|
1992
|
+
if (!fs$6.existsSync(depPath)) {
|
|
1947
1993
|
return true;
|
|
1948
1994
|
}
|
|
1949
1995
|
|
|
1950
|
-
const depPackagePath = path$
|
|
1996
|
+
const depPackagePath = path$6.join(depPath, 'package.json');
|
|
1951
1997
|
|
|
1952
|
-
if (fs$
|
|
1998
|
+
if (fs$6.existsSync(depPackagePath)) {
|
|
1953
1999
|
const packageData = require(depPackagePath);
|
|
1954
2000
|
|
|
1955
2001
|
if (dependencies[key] === 'latest') {
|
|
@@ -1970,10 +2016,177 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
|
1970
2016
|
return false;
|
|
1971
2017
|
};
|
|
1972
2018
|
|
|
1973
|
-
var
|
|
1974
|
-
|
|
2019
|
+
var checkDependencies = {
|
|
2020
|
+
isDependenciesUpdate: isDependenciesUpdate$1
|
|
1975
2021
|
};
|
|
1976
2022
|
|
|
2023
|
+
const shelljs$3 = require$$0__default$3;
|
|
2024
|
+
const fs$5 = require$$0__default$2;
|
|
2025
|
+
const path$5 = require$$1__default$2;
|
|
2026
|
+
const io$1 = io$3;
|
|
2027
|
+
const {
|
|
2028
|
+
createTask: createTask$1,
|
|
2029
|
+
resolve: resolve$8
|
|
2030
|
+
} = widgets;
|
|
2031
|
+
const {
|
|
2032
|
+
buildMpNpm
|
|
2033
|
+
} = mpCi;
|
|
2034
|
+
const {
|
|
2035
|
+
setCache,
|
|
2036
|
+
getCache
|
|
2037
|
+
} = cache;
|
|
2038
|
+
const {
|
|
2039
|
+
CACHE_DIR: CACHE_DIR$1
|
|
2040
|
+
} = require$$4;
|
|
2041
|
+
const {
|
|
2042
|
+
npmInstallAll
|
|
2043
|
+
} = npm;
|
|
2044
|
+
const {
|
|
2045
|
+
fail: fail$3,
|
|
2046
|
+
info: info$5
|
|
2047
|
+
} = log$1;
|
|
2048
|
+
const {
|
|
2049
|
+
fileMd5
|
|
2050
|
+
} = md5;
|
|
2051
|
+
const {
|
|
2052
|
+
isDependenciesUpdate
|
|
2053
|
+
} = checkDependencies;
|
|
2054
|
+
|
|
2055
|
+
async function install$2(tmsConfig, modules, env, useCache = true) {
|
|
2056
|
+
const cwd = process.cwd();
|
|
2057
|
+
const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, modules, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
|
|
2058
|
+
|
|
2059
|
+
if (!npmInstallRes.isCache) {
|
|
2060
|
+
// 构建miniprogram_npm, 不使用缓存
|
|
2061
|
+
await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, modules, false);
|
|
2062
|
+
} else {
|
|
2063
|
+
// 构建miniprogram_npm
|
|
2064
|
+
await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, modules, useCache);
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
shelljs$3.cd(cwd);
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
async function npmInstall(tmsConfig, modules, useCache) {
|
|
2071
|
+
// 如果依赖没有更新和使用缓存数据(则命中缓存)
|
|
2072
|
+
if (!isDependenciesUpdate(modules, resolve$8('./'), tmsConfig.outputDir) && useCache) {
|
|
2073
|
+
info$5('node_modules命中缓存');
|
|
2074
|
+
return {
|
|
2075
|
+
isCache: true
|
|
2076
|
+
};
|
|
2077
|
+
} // 拷贝模块的package.json到编译输出目录
|
|
2078
|
+
|
|
2079
|
+
|
|
2080
|
+
modules.forEach(item => {
|
|
2081
|
+
const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
|
|
2082
|
+
|
|
2083
|
+
if (!fs$5.existsSync(resolve$8(item.path))) {
|
|
2084
|
+
fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2085
|
+
process.exit(1);
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
io$1.ensureDirExist(outputModuleDir);
|
|
2089
|
+
const modulePackagePath = resolve$8(item.path, 'package.json');
|
|
2090
|
+
if (fs$5.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
2091
|
+
});
|
|
2092
|
+
await npmInstallAll(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
|
|
2093
|
+
return {
|
|
2094
|
+
isCache: false
|
|
2095
|
+
};
|
|
2096
|
+
} // 构建miniprogram_npm
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
async function mpCiInstall(tmsConfig, modules, useCache) {
|
|
2100
|
+
const packageJsonFiles = [];
|
|
2101
|
+
const rootPackFile = resolve$8(`${tmsConfig.outputDir}/package.json`);
|
|
2102
|
+
|
|
2103
|
+
if (fs$5.existsSync(rootPackFile)) {
|
|
2104
|
+
packageJsonFiles.push(rootPackFile);
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
modules.forEach(item => {
|
|
2108
|
+
const packageJsonFile = resolve$8(`${tmsConfig.outputDir}/${item.root}/package.json`);
|
|
2109
|
+
|
|
2110
|
+
if (fs$5.existsSync(packageJsonFile)) {
|
|
2111
|
+
packageJsonFiles.push(packageJsonFile);
|
|
2112
|
+
}
|
|
2113
|
+
});
|
|
2114
|
+
let isCache = false;
|
|
2115
|
+
const statusMap = {
|
|
2116
|
+
success: 1,
|
|
2117
|
+
doing: 2
|
|
2118
|
+
};
|
|
2119
|
+
|
|
2120
|
+
if (useCache) {
|
|
2121
|
+
let flag = true;
|
|
2122
|
+
await Promise.all(packageJsonFiles.map(async item => {
|
|
2123
|
+
const packageDir = path$5.dirname(item);
|
|
2124
|
+
const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
|
|
2125
|
+
const md5Value = await getMNPMd5(packageDir);
|
|
2126
|
+
const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
|
|
2127
|
+
// 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
|
|
2128
|
+
|
|
2129
|
+
if ((preCache === null || preCache === void 0 ? void 0 : preCache.status) !== statusMap.success || (preCache === null || preCache === void 0 ? void 0 : preCache.md5) !== md5Value) {
|
|
2130
|
+
flag = false;
|
|
2131
|
+
}
|
|
2132
|
+
}));
|
|
2133
|
+
isCache = flag;
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
if (isCache) {
|
|
2137
|
+
info$5('miniprogram_npm命中缓存');
|
|
2138
|
+
return;
|
|
2139
|
+
} // 即将构建,在cache中标记开始
|
|
2140
|
+
|
|
2141
|
+
|
|
2142
|
+
await Promise.all(packageJsonFiles.map(async item => {
|
|
2143
|
+
const packageDir = path$5.dirname(item);
|
|
2144
|
+
const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
|
|
2145
|
+
setCache(mpDir, 'miniprogram_npm', {
|
|
2146
|
+
md5: '',
|
|
2147
|
+
status: statusMap.doing
|
|
2148
|
+
});
|
|
2149
|
+
}));
|
|
2150
|
+
await buildMpNpm({
|
|
2151
|
+
appId: tmsConfig.appId,
|
|
2152
|
+
projectPath: resolve$8('./'),
|
|
2153
|
+
privateKey: tmsConfig.privateKey
|
|
2154
|
+
}); // 构建成功后,计算md5写入cache
|
|
2155
|
+
|
|
2156
|
+
await Promise.all(packageJsonFiles.map(async item => {
|
|
2157
|
+
const packageDir = path$5.dirname(item);
|
|
2158
|
+
const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
|
|
2159
|
+
const md5Value = await getMNPMd5(packageDir);
|
|
2160
|
+
setCache(mpDir, 'miniprogram_npm', {
|
|
2161
|
+
md5: md5Value,
|
|
2162
|
+
status: statusMap.success
|
|
2163
|
+
});
|
|
2164
|
+
}));
|
|
2165
|
+
} // 计算miniprogram_npm压缩文件的md5值
|
|
2166
|
+
|
|
2167
|
+
|
|
2168
|
+
async function getMNPMd5(cwd) {
|
|
2169
|
+
const shellJsOption = {
|
|
2170
|
+
async: false,
|
|
2171
|
+
silent: true
|
|
2172
|
+
};
|
|
2173
|
+
shelljs$3.cd(cwd);
|
|
2174
|
+
|
|
2175
|
+
if (fs$5.existsSync('miniprogram_npm')) {
|
|
2176
|
+
shelljs$3.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
|
|
2177
|
+
cwd,
|
|
2178
|
+
...shellJsOption
|
|
2179
|
+
});
|
|
2180
|
+
const md5Value = await fileMd5('./miniprogram_npm.tar.gz');
|
|
2181
|
+
shelljs$3.rm('-rf', path$5.join(cwd, './miniprogram_npm.tar.gz'));
|
|
2182
|
+
return md5Value;
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
return '';
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
var install_1 = install$2;
|
|
2189
|
+
|
|
1977
2190
|
const shelljs$2 = require$$0__default$3;
|
|
1978
2191
|
const fs$4 = require$$0__default$2;
|
|
1979
2192
|
const io = io$3;
|
|
@@ -2000,9 +2213,6 @@ const {
|
|
|
2000
2213
|
info: info$4
|
|
2001
2214
|
} = log$1;
|
|
2002
2215
|
const install$1 = install_1;
|
|
2003
|
-
const {
|
|
2004
|
-
checkDependencies
|
|
2005
|
-
} = checkDependencies_1;
|
|
2006
2216
|
/**
|
|
2007
2217
|
* 拷贝相关配置文件到编译输出目录
|
|
2008
2218
|
* @param { object } tmsConfig
|
|
@@ -2053,10 +2263,7 @@ async function task(tmsConfig, targetModules) {
|
|
|
2053
2263
|
|
|
2054
2264
|
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG); // install
|
|
2055
2265
|
|
|
2056
|
-
|
|
2057
|
-
await install$1(tmsConfig, newModules);
|
|
2058
|
-
} // 动态生成编译后的app.json;
|
|
2059
|
-
|
|
2266
|
+
await install$1(tmsConfig, newModules); // 动态生成编译后的app.json;
|
|
2060
2267
|
|
|
2061
2268
|
await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
2062
2269
|
return newModules;
|
|
@@ -2790,10 +2997,10 @@ const path$1 = require$$1__default$2;
|
|
|
2790
2997
|
const PluginError = require$$2__default$1;
|
|
2791
2998
|
const fancyLog = require$$3__default;
|
|
2792
2999
|
const colors = require$$4__default;
|
|
2793
|
-
const chokidar = require$$5__default
|
|
3000
|
+
const chokidar = require$$5__default;
|
|
2794
3001
|
const {
|
|
2795
3002
|
Duplex
|
|
2796
|
-
} = require$$6__default;
|
|
3003
|
+
} = require$$6__default$1;
|
|
2797
3004
|
const vinyl = require$$7__default;
|
|
2798
3005
|
const File = require$$8__default;
|
|
2799
3006
|
const anymatch = require$$9__default;
|
|
@@ -3278,7 +3485,7 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
3278
3485
|
const targetModulesName = targetModules.map(item => item.name);
|
|
3279
3486
|
modules.forEach(item => {
|
|
3280
3487
|
if (item.root && targetModulesName.indexOf(item.name) === -1) {
|
|
3281
|
-
const moduleRootDir = resolve$2(
|
|
3488
|
+
const moduleRootDir = resolve$2(`${tmsConfig.outputDir}/${item.root}`);
|
|
3282
3489
|
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
3283
3490
|
silent: true
|
|
3284
3491
|
}); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
@@ -3537,7 +3744,7 @@ async function run(commandName, cmd) {
|
|
|
3537
3744
|
return;
|
|
3538
3745
|
|
|
3539
3746
|
case 'install':
|
|
3540
|
-
install(tmsConfig, newModules, env);
|
|
3747
|
+
install(tmsConfig, newModules, env, false);
|
|
3541
3748
|
return;
|
|
3542
3749
|
|
|
3543
3750
|
case 'build':
|
|
@@ -3607,7 +3814,7 @@ var entry = [{
|
|
|
3607
3814
|
|
|
3608
3815
|
var require$$7 = {
|
|
3609
3816
|
name: "@tmsfe/tmskit",
|
|
3610
|
-
version: "0.0.
|
|
3817
|
+
version: "0.0.19",
|
|
3611
3818
|
description: "tmskit",
|
|
3612
3819
|
main: "dist/index.cjs",
|
|
3613
3820
|
bin: {
|