@tmsfe/tmskit 0.0.17 → 0.0.18
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 +6 -2
- package/dist/index.cjs.js +320 -340
- package/package.json +1 -1
- package/src/compile/dev.js +6 -2
- package/src/config/constant.js +1 -3
- package/src/config/defaultTmsConfig.js +1 -1
- package/src/core/buildAppJson.js +29 -30
- package/src/core/cloneModules.js +3 -3
- package/src/core/tmsMpconfig.js +2 -37
- package/src/scripts/run/build/index.js +5 -2
- package/src/scripts/run/dev/index.js +7 -3
- package/src/scripts/run/index.js +33 -16
- package/src/scripts/run/install/index.js +1 -3
- package/src/utils/widgets.js +17 -0
package/dist/index.cjs.js
CHANGED
|
@@ -105,7 +105,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
|
|
|
105
105
|
* @returns {undefined} 无
|
|
106
106
|
*/
|
|
107
107
|
|
|
108
|
-
const fail$
|
|
108
|
+
const fail$9 = (message = '') => {
|
|
109
109
|
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
110
110
|
|
|
111
111
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
@@ -140,7 +140,7 @@ const warn$2 = message => {
|
|
|
140
140
|
const info$9 = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
141
141
|
|
|
142
142
|
var log$1 = {
|
|
143
|
-
fail: fail$
|
|
143
|
+
fail: fail$9,
|
|
144
144
|
succeed: succeed$2,
|
|
145
145
|
warn: warn$2,
|
|
146
146
|
info: info$9
|
|
@@ -149,8 +149,8 @@ var log$1 = {
|
|
|
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$b = require$$1__default$2;
|
|
153
|
+
const fs$e = require$$0__default$2;
|
|
154
154
|
const shelljs$7 = require$$0__default$3;
|
|
155
155
|
const {
|
|
156
156
|
info: info$8
|
|
@@ -163,8 +163,8 @@ const shelljsOptions = {
|
|
|
163
163
|
|
|
164
164
|
const cwd = process.cwd();
|
|
165
165
|
|
|
166
|
-
function resolve$
|
|
167
|
-
return path$
|
|
166
|
+
function resolve$f(...args) {
|
|
167
|
+
return path$b.resolve(cwd, ...args);
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
170
|
* 用户输入命令时,进行提示
|
|
@@ -194,7 +194,7 @@ const suggestCommands$1 = unknownCommand => {
|
|
|
194
194
|
*/
|
|
195
195
|
|
|
196
196
|
|
|
197
|
-
function isObject$
|
|
197
|
+
function isObject$2(obj) {
|
|
198
198
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
@@ -220,8 +220,8 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
220
220
|
const cwd = process.cwd();
|
|
221
221
|
return new Promise((resolve, reject) => {
|
|
222
222
|
// 如果目标目录不存在
|
|
223
|
-
if (fs$
|
|
224
|
-
shelljs$7.rm('-rf', path$
|
|
223
|
+
if (fs$e.existsSync(dest)) {
|
|
224
|
+
shelljs$7.rm('-rf', path$b.join(dest));
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
shelljs$7.mkdir('-p', dest);
|
|
@@ -334,12 +334,30 @@ const mergeMap = function (obj, src) {
|
|
|
334
334
|
};
|
|
335
335
|
|
|
336
336
|
const relativeCwdPath$1 = function (file) {
|
|
337
|
-
return path$
|
|
337
|
+
return path$b.relative(process.cwd(), file);
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* 从一个对象中,检索出去几个字段
|
|
341
|
+
* @param {*} obj
|
|
342
|
+
* @param {*} name
|
|
343
|
+
* @returns
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
const filterField$3 = (obj, filterNames = []) => {
|
|
348
|
+
const newObj = { ...obj
|
|
349
|
+
};
|
|
350
|
+
filterNames.forEach(name => {
|
|
351
|
+
if (newObj[name]) {
|
|
352
|
+
delete newObj[name];
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
return newObj;
|
|
338
356
|
};
|
|
339
357
|
|
|
340
358
|
var widgets = {
|
|
341
|
-
resolve: resolve$
|
|
342
|
-
isObject: isObject$
|
|
359
|
+
resolve: resolve$f,
|
|
360
|
+
isObject: isObject$2,
|
|
343
361
|
isArray: isArray$1,
|
|
344
362
|
createTask: createTask$3,
|
|
345
363
|
downloadRepoForGit: downloadRepoForGit$2,
|
|
@@ -348,23 +366,24 @@ var widgets = {
|
|
|
348
366
|
camelize,
|
|
349
367
|
npmInstall: npmInstall$1,
|
|
350
368
|
mergeMap,
|
|
351
|
-
relativeCwdPath: relativeCwdPath$1
|
|
369
|
+
relativeCwdPath: relativeCwdPath$1,
|
|
370
|
+
filterField: filterField$3
|
|
352
371
|
};
|
|
353
372
|
|
|
354
|
-
const path$
|
|
373
|
+
const path$a = require('path');
|
|
355
374
|
|
|
356
375
|
const os = require('os'); // 用户目录
|
|
357
376
|
|
|
358
377
|
|
|
359
378
|
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
360
379
|
|
|
361
|
-
const CACHE_DIR$2 = path$
|
|
380
|
+
const CACHE_DIR$2 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
362
381
|
|
|
363
|
-
const TEMPLATE_DIR$1 = path$
|
|
382
|
+
const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
364
383
|
|
|
365
|
-
const MODULE_CODE_DIR$1 = path$
|
|
384
|
+
const MODULE_CODE_DIR$1 = path$a.resolve(CACHE_DIR$2, 'modules_code'); // 脚手架模板代码的具体路径
|
|
366
385
|
|
|
367
|
-
const TEMPLATE_PATH$1 = path$
|
|
386
|
+
const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tmskit-template'); // 脚手架的名称
|
|
368
387
|
|
|
369
388
|
const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
|
|
370
389
|
|
|
@@ -375,10 +394,10 @@ const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目
|
|
|
375
394
|
|
|
376
395
|
const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
377
396
|
|
|
378
|
-
const MODULE_CONFIG_FILENAME$
|
|
397
|
+
const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
|
|
379
398
|
|
|
380
399
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
381
|
-
app: path$
|
|
400
|
+
app: path$a.resolve(process.cwd(), 'app')
|
|
382
401
|
}; // 默认从源码拷贝到编译后的配置
|
|
383
402
|
|
|
384
403
|
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
|
|
@@ -387,7 +406,6 @@ const ENV = {
|
|
|
387
406
|
prod: 'production'
|
|
388
407
|
};
|
|
389
408
|
const TEMPLATE_TKIT_DIR$2 = '_tmskit';
|
|
390
|
-
const MODULE_CONFIG_INVALID_KEY = ['entranceDeclare', 'entryPagePath'];
|
|
391
409
|
|
|
392
410
|
var constant = /*#__PURE__*/Object.freeze({
|
|
393
411
|
__proto__: null,
|
|
@@ -399,20 +417,19 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
399
417
|
TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
|
|
400
418
|
TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME$1,
|
|
401
419
|
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
|
|
402
|
-
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$
|
|
420
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
|
|
403
421
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
404
422
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
405
423
|
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
406
424
|
ENV: ENV,
|
|
407
425
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
408
|
-
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY,
|
|
409
426
|
DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR
|
|
410
427
|
});
|
|
411
428
|
|
|
412
429
|
var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
413
430
|
|
|
414
|
-
const fs$
|
|
415
|
-
const path$
|
|
431
|
+
const fs$d = require$$0__default$2;
|
|
432
|
+
const path$9 = require$$1__default$2;
|
|
416
433
|
const {
|
|
417
434
|
info: info$7
|
|
418
435
|
} = log$1;
|
|
@@ -425,12 +442,12 @@ const {
|
|
|
425
442
|
* @returns
|
|
426
443
|
*/
|
|
427
444
|
|
|
428
|
-
const isDirEmpty = dirname => fs$
|
|
445
|
+
const isDirEmpty = dirname => fs$d.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
429
446
|
|
|
430
447
|
|
|
431
448
|
const isFile = pathName => {
|
|
432
449
|
try {
|
|
433
|
-
const stat = fs$
|
|
450
|
+
const stat = fs$d.lstatSync(pathName);
|
|
434
451
|
return stat.isFile();
|
|
435
452
|
} catch {
|
|
436
453
|
return false;
|
|
@@ -443,8 +460,8 @@ const isFile = pathName => {
|
|
|
443
460
|
|
|
444
461
|
|
|
445
462
|
const ensureDirExist$1 = dirname => {
|
|
446
|
-
if (!fs$
|
|
447
|
-
fs$
|
|
463
|
+
if (!fs$d.existsSync(dirname)) {
|
|
464
|
+
fs$d.mkdirSync(dirname, {
|
|
448
465
|
recursive: true
|
|
449
466
|
});
|
|
450
467
|
}
|
|
@@ -452,20 +469,20 @@ const ensureDirExist$1 = dirname => {
|
|
|
452
469
|
|
|
453
470
|
|
|
454
471
|
const copyFile = function (src, dest) {
|
|
455
|
-
if (fs$
|
|
456
|
-
fs$
|
|
472
|
+
if (fs$d.existsSync(dest)) {
|
|
473
|
+
fs$d.unlinkSync(dest);
|
|
457
474
|
}
|
|
458
475
|
|
|
459
|
-
const dir = path$
|
|
476
|
+
const dir = path$9.dirname(dest);
|
|
460
477
|
ensureDirExist$1(dir);
|
|
461
|
-
fs$
|
|
478
|
+
fs$d.copyFileSync(src, dest);
|
|
462
479
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
463
480
|
|
|
464
481
|
|
|
465
482
|
function diffContentCopyFile$3(originFile, destFile) {
|
|
466
|
-
if (fs$
|
|
467
|
-
const depDestContent = fs$
|
|
468
|
-
const depOriginContent = fs$
|
|
483
|
+
if (fs$d.existsSync(destFile)) {
|
|
484
|
+
const depDestContent = fs$d.readFileSync(destFile, 'utf8');
|
|
485
|
+
const depOriginContent = fs$d.readFileSync(originFile, 'utf8');
|
|
469
486
|
|
|
470
487
|
if (depDestContent !== depOriginContent) {
|
|
471
488
|
info$7(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
@@ -483,7 +500,7 @@ function ext$3(filePath, extensions) {
|
|
|
483
500
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
484
501
|
|
|
485
502
|
try {
|
|
486
|
-
const stat = fs$
|
|
503
|
+
const stat = fs$d.lstatSync(newFilePath);
|
|
487
504
|
|
|
488
505
|
if (stat.isDirectory()) {
|
|
489
506
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -494,7 +511,7 @@ function ext$3(filePath, extensions) {
|
|
|
494
511
|
for (const ext of extensions) {
|
|
495
512
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
496
513
|
|
|
497
|
-
if (fs$
|
|
514
|
+
if (fs$d.existsSync(file)) {
|
|
498
515
|
return {
|
|
499
516
|
ext,
|
|
500
517
|
extPath: extPath + ext,
|
|
@@ -512,11 +529,11 @@ function ext$3(filePath, extensions) {
|
|
|
512
529
|
|
|
513
530
|
|
|
514
531
|
const fileInDir$3 = (dir, file) => {
|
|
515
|
-
if (!fs$
|
|
532
|
+
if (!fs$d.existsSync(dir) || !fs$d.existsSync(file)) {
|
|
516
533
|
return false;
|
|
517
534
|
}
|
|
518
535
|
|
|
519
|
-
const relativePath = path$
|
|
536
|
+
const relativePath = path$9.relative(dir, file);
|
|
520
537
|
|
|
521
538
|
if (relativePath.startsWith('..')) {
|
|
522
539
|
return false;
|
|
@@ -529,10 +546,10 @@ function findAllFilesOfDir$1(dir) {
|
|
|
529
546
|
const list = [];
|
|
530
547
|
|
|
531
548
|
function listFile(dir) {
|
|
532
|
-
const arr = fs$
|
|
549
|
+
const arr = fs$d.readdirSync(dir);
|
|
533
550
|
arr.forEach(item => {
|
|
534
|
-
const fullPath = path$
|
|
535
|
-
const stats = fs$
|
|
551
|
+
const fullPath = path$9.join(dir, item);
|
|
552
|
+
const stats = fs$d.statSync(fullPath);
|
|
536
553
|
|
|
537
554
|
if (stats.isDirectory()) {
|
|
538
555
|
listFile(fullPath);
|
|
@@ -578,10 +595,10 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
578
595
|
|
|
579
596
|
var render_1 = render$1;
|
|
580
597
|
|
|
581
|
-
const fs$
|
|
598
|
+
const fs$c = require$$0__default$2;
|
|
582
599
|
const inquirer = require$$1__default$4;
|
|
583
600
|
const {
|
|
584
|
-
resolve: resolve$
|
|
601
|
+
resolve: resolve$e
|
|
585
602
|
} = widgets;
|
|
586
603
|
const {
|
|
587
604
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
@@ -595,12 +612,12 @@ const {
|
|
|
595
612
|
const parseTemplateQuestions = dir => {
|
|
596
613
|
let prompts = [];
|
|
597
614
|
|
|
598
|
-
if (!fs$
|
|
615
|
+
if (!fs$c.existsSync(`${dir}/questions.json`)) {
|
|
599
616
|
return prompts;
|
|
600
617
|
}
|
|
601
618
|
|
|
602
619
|
try {
|
|
603
|
-
const json = JSON.parse(fs$
|
|
620
|
+
const json = JSON.parse(fs$c.readFileSync(`${dir}/questions.json`));
|
|
604
621
|
|
|
605
622
|
if (Array.isArray(json) && json.length > 0) {
|
|
606
623
|
json.forEach((item, index) => {
|
|
@@ -633,7 +650,7 @@ const isQuestionType = result => {
|
|
|
633
650
|
};
|
|
634
651
|
|
|
635
652
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
636
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
653
|
+
const prompts = parseTemplateQuestions(resolve$e(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
637
654
|
const metadata = metalsmith.metadata();
|
|
638
655
|
const filteredPrompts = prompts.filter(prompt => {
|
|
639
656
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -675,8 +692,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
675
692
|
|
|
676
693
|
var generator_1 = generator$1;
|
|
677
694
|
|
|
678
|
-
const path$
|
|
679
|
-
const fs$
|
|
695
|
+
const path$8 = require$$1__default$2;
|
|
696
|
+
const fs$b = require$$0__default$2;
|
|
680
697
|
const shelljs$6 = require$$0__default$3;
|
|
681
698
|
const {
|
|
682
699
|
TEMPLATE_DIR,
|
|
@@ -686,11 +703,11 @@ const {
|
|
|
686
703
|
const {
|
|
687
704
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
688
705
|
createTask: createTask$2,
|
|
689
|
-
resolve: resolve$
|
|
706
|
+
resolve: resolve$d
|
|
690
707
|
} = widgets;
|
|
691
708
|
const io$2 = io$3;
|
|
692
709
|
const {
|
|
693
|
-
fail: fail$
|
|
710
|
+
fail: fail$8,
|
|
694
711
|
succeed: succeed$1,
|
|
695
712
|
info: info$6
|
|
696
713
|
} = log$1;
|
|
@@ -703,9 +720,9 @@ const generator = generator_1;
|
|
|
703
720
|
|
|
704
721
|
async function createAppDir(targetDir) {
|
|
705
722
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
706
|
-
if (fs$
|
|
723
|
+
if (fs$b.existsSync(targetDir)) {
|
|
707
724
|
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
708
|
-
fail$
|
|
725
|
+
fail$8('该目录名已经存在,换个项目名字吧~');
|
|
709
726
|
process.exit(1);
|
|
710
727
|
}
|
|
711
728
|
} else {
|
|
@@ -721,7 +738,7 @@ async function createAppDir(targetDir) {
|
|
|
721
738
|
|
|
722
739
|
async function create(appName) {
|
|
723
740
|
const cwd = process.cwd();
|
|
724
|
-
const targetDir = path$
|
|
741
|
+
const targetDir = path$8.resolve(cwd, appName);
|
|
725
742
|
const appType = 'mp';
|
|
726
743
|
await createAppDir(targetDir); // 创建缓存目录
|
|
727
744
|
|
|
@@ -729,13 +746,13 @@ async function create(appName) {
|
|
|
729
746
|
|
|
730
747
|
await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
731
748
|
|
|
732
|
-
generator(path$
|
|
749
|
+
generator(path$8.join(TEMPLATE_PATH, appType), targetDir, {
|
|
733
750
|
appName,
|
|
734
751
|
appType
|
|
735
752
|
}).then(() => {
|
|
736
753
|
shelljs$6.cd(appName);
|
|
737
754
|
|
|
738
|
-
const hooks = require(resolve$
|
|
755
|
+
const hooks = require(resolve$d(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
739
756
|
|
|
740
757
|
if (hooks.afterCreate) {
|
|
741
758
|
hooks.afterCreate.forEach(item => {
|
|
@@ -749,23 +766,21 @@ async function create(appName) {
|
|
|
749
766
|
});
|
|
750
767
|
}
|
|
751
768
|
|
|
752
|
-
shelljs$6.rm('-rf', resolve$
|
|
769
|
+
shelljs$6.rm('-rf', resolve$d(appName, TEMPLATE_TKIT_DIR));
|
|
753
770
|
succeed$1('项目创建完成.');
|
|
754
771
|
}).catch(err => {
|
|
755
|
-
fail$
|
|
772
|
+
fail$8(err.message);
|
|
756
773
|
info$6('详细的错误信息:', err);
|
|
757
774
|
});
|
|
758
775
|
}
|
|
759
776
|
|
|
760
777
|
var create_1 = create;
|
|
761
778
|
|
|
762
|
-
var buildAppJson = {exports: {}};
|
|
763
|
-
|
|
764
779
|
var defaultTmsConfig$1 = {
|
|
765
780
|
// 全局的环境配置项
|
|
766
781
|
envData: {},
|
|
767
782
|
// 模块配置信息
|
|
768
|
-
modules:
|
|
783
|
+
modules: {},
|
|
769
784
|
cloudDir: 'cloud',
|
|
770
785
|
// 第三方依赖代码需要拷贝到本项目的
|
|
771
786
|
dependencies: {},
|
|
@@ -783,33 +798,32 @@ var defaultTmsConfig$1 = {
|
|
|
783
798
|
/**
|
|
784
799
|
* 用来读取处理tms.config.js与module.config.json字段
|
|
785
800
|
*/
|
|
786
|
-
const loadash = require$$0__default$6;
|
|
787
|
-
const fs$
|
|
801
|
+
const loadash$1 = require$$0__default$6;
|
|
802
|
+
const fs$a = require$$0__default$2;
|
|
788
803
|
const {
|
|
789
804
|
TMS_CONFIG_FILENAME,
|
|
790
|
-
MODULE_CONFIG_FILENAME,
|
|
805
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
791
806
|
TMS_PRIVATE_FILENAME
|
|
792
807
|
} = require$$4;
|
|
793
808
|
const {
|
|
794
|
-
resolve: resolve$
|
|
795
|
-
isObject,
|
|
809
|
+
resolve: resolve$c,
|
|
810
|
+
isObject: isObject$1,
|
|
796
811
|
isArray
|
|
797
812
|
} = widgets;
|
|
798
813
|
const defaultTmsConfig = defaultTmsConfig$1;
|
|
799
814
|
const {
|
|
800
|
-
fail: fail$
|
|
815
|
+
fail: fail$7
|
|
801
816
|
} = log$1;
|
|
802
|
-
const path$8 = require$$1__default$2;
|
|
803
817
|
/**
|
|
804
818
|
* 读取tms.config.js
|
|
805
819
|
* @param env {string} 环境变量
|
|
806
820
|
*/
|
|
807
821
|
|
|
808
822
|
const readTmsConfig$1 = function (env) {
|
|
809
|
-
const tmsConfigPath = resolve$
|
|
823
|
+
const tmsConfigPath = resolve$c(TMS_CONFIG_FILENAME);
|
|
810
824
|
|
|
811
|
-
if (!fs$
|
|
812
|
-
fail$
|
|
825
|
+
if (!fs$a.existsSync(tmsConfigPath)) {
|
|
826
|
+
fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
813
827
|
process.exit(1);
|
|
814
828
|
}
|
|
815
829
|
|
|
@@ -819,35 +833,8 @@ const readTmsConfig$1 = function (env) {
|
|
|
819
833
|
env
|
|
820
834
|
}); // 合并默认值
|
|
821
835
|
|
|
822
|
-
loadash.mergeWith(tmsConfig, defaultTmsConfig);
|
|
823
|
-
|
|
824
|
-
tmsConfig.modules = convertModules(tmsConfig.modules);
|
|
836
|
+
loadash$1.mergeWith(tmsConfig, defaultTmsConfig);
|
|
825
837
|
return tmsConfig;
|
|
826
|
-
}; // convertModules 处理默认值
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
const convertModules = modules => {
|
|
830
|
-
const newModules = [];
|
|
831
|
-
modules.forEach(module => {
|
|
832
|
-
const newModule = {};
|
|
833
|
-
|
|
834
|
-
if (typeof module === 'string') {
|
|
835
|
-
// 路径字符串
|
|
836
|
-
Object.assign(newModule, {
|
|
837
|
-
name: path$8.basename(module),
|
|
838
|
-
path: module
|
|
839
|
-
});
|
|
840
|
-
} else if (typeof module === 'object') {
|
|
841
|
-
Object.assign(newModule, module);
|
|
842
|
-
|
|
843
|
-
if (module.name === undefined) {
|
|
844
|
-
newModule.name = path$8.basename(module.path);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
newModules.push(newModule);
|
|
849
|
-
});
|
|
850
|
-
return newModules;
|
|
851
838
|
};
|
|
852
839
|
/**
|
|
853
840
|
* 读取tms.private.config.js
|
|
@@ -856,17 +843,10 @@ const convertModules = modules => {
|
|
|
856
843
|
|
|
857
844
|
const readTmsPrivateCf$1 = function () {
|
|
858
845
|
let tmsPrivateCf = {};
|
|
859
|
-
const tmsPrivatePath = resolve$
|
|
846
|
+
const tmsPrivatePath = resolve$c(TMS_PRIVATE_FILENAME);
|
|
860
847
|
|
|
861
|
-
if (fs$
|
|
848
|
+
if (fs$a.existsSync(tmsPrivatePath)) {
|
|
862
849
|
tmsPrivateCf = require(tmsPrivatePath);
|
|
863
|
-
} // 处理modules字段
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
if (tmsPrivateCf.modules instanceof Array) {
|
|
867
|
-
Object.assign(tmsPrivateCf.modules, {
|
|
868
|
-
include: tmsPrivateCf.modules
|
|
869
|
-
});
|
|
870
850
|
}
|
|
871
851
|
|
|
872
852
|
return tmsPrivateCf;
|
|
@@ -882,12 +862,12 @@ const readTmsPrivateCf$1 = function () {
|
|
|
882
862
|
const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
|
|
883
863
|
const targetModules = [];
|
|
884
864
|
modules.forEach(moduleName => {
|
|
885
|
-
const module = tmsConfig.modules.find(module => module.name === moduleName);
|
|
865
|
+
const module = tmsConfig.modules.all.find(module => module.name === moduleName);
|
|
886
866
|
module && targetModules.push(module);
|
|
887
867
|
});
|
|
888
868
|
|
|
889
869
|
if (targetModules.length === 0) {
|
|
890
|
-
fail$
|
|
870
|
+
fail$7(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
|
|
891
871
|
>name字段与module.config.json的name字段是否一致`);
|
|
892
872
|
isQuit && process.exit(1);
|
|
893
873
|
}
|
|
@@ -926,14 +906,6 @@ function adaptMpCgContent(fileContent, appName) {
|
|
|
926
906
|
i--; // eslint-disable-line
|
|
927
907
|
}
|
|
928
908
|
} else {
|
|
929
|
-
if (appName && content.mpConfig && content.mpConfig[appName]) {
|
|
930
|
-
content = { ...content,
|
|
931
|
-
...content.mpConfig[appName]
|
|
932
|
-
};
|
|
933
|
-
delete content.mpConfig;
|
|
934
|
-
delete content.isSubpackages;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
909
|
content = handleContent(appName, content);
|
|
938
910
|
}
|
|
939
911
|
|
|
@@ -947,15 +919,15 @@ function adaptMpCgContent(fileContent, appName) {
|
|
|
947
919
|
*/
|
|
948
920
|
|
|
949
921
|
|
|
950
|
-
function getModuleConfig(modules = [], appName, moduleConfigFilename) {
|
|
922
|
+
function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
|
|
951
923
|
const modulesConfig = {};
|
|
952
924
|
modules.forEach(({
|
|
953
925
|
path
|
|
954
926
|
}) => {
|
|
955
|
-
const moduleConfigPath = resolve$
|
|
927
|
+
const moduleConfigPath = resolve$c(path, moduleConfigFilename);
|
|
956
928
|
|
|
957
|
-
if (fs$
|
|
958
|
-
const content = fs$
|
|
929
|
+
if (fs$a.existsSync(moduleConfigPath)) {
|
|
930
|
+
const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
|
|
959
931
|
modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
|
|
960
932
|
}
|
|
961
933
|
});
|
|
@@ -976,14 +948,14 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
976
948
|
path: relativePath,
|
|
977
949
|
name: moduleName
|
|
978
950
|
}, moduleIndex) => {
|
|
979
|
-
const moduleConfigPath = resolve$
|
|
951
|
+
const moduleConfigPath = resolve$c(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
980
952
|
|
|
981
|
-
if (fs$
|
|
953
|
+
if (fs$a.existsSync(moduleConfigPath)) {
|
|
982
954
|
try {
|
|
983
955
|
let findModule = false;
|
|
984
|
-
let moduleConfigContent = fs$
|
|
956
|
+
let moduleConfigContent = fs$a.readFileSync(moduleConfigPath, 'utf-8');
|
|
985
957
|
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
986
|
-
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
958
|
+
const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
987
959
|
moduleContentArr.forEach(({
|
|
988
960
|
name
|
|
989
961
|
}, moduleContentArrIndex) => {
|
|
@@ -996,11 +968,11 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
996
968
|
});
|
|
997
969
|
|
|
998
970
|
if (!findModule) {
|
|
999
|
-
fail$
|
|
971
|
+
fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
|
|
1000
972
|
process.exit(1);
|
|
1001
973
|
}
|
|
1002
974
|
} catch (e) {
|
|
1003
|
-
fail$
|
|
975
|
+
fail$7(`${moduleConfigPath}配置错误: ${e}`);
|
|
1004
976
|
newModules.push({ ...modules[moduleIndex]
|
|
1005
977
|
});
|
|
1006
978
|
}
|
|
@@ -1052,7 +1024,7 @@ const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
|
|
|
1052
1024
|
var tmsMpconfig = {
|
|
1053
1025
|
readTmsConfig: readTmsConfig$1,
|
|
1054
1026
|
readTmsPrivateCf: readTmsPrivateCf$1,
|
|
1055
|
-
getModuleConfig,
|
|
1027
|
+
getModuleConfig: getModuleConfig$1,
|
|
1056
1028
|
checkModules: checkModules$1,
|
|
1057
1029
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
|
|
1058
1030
|
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
@@ -1084,236 +1056,224 @@ var global_1 = {
|
|
|
1084
1056
|
};
|
|
1085
1057
|
|
|
1086
1058
|
const {
|
|
1087
|
-
fail: fail$
|
|
1059
|
+
fail: fail$6
|
|
1088
1060
|
} = log$1;
|
|
1089
1061
|
const {
|
|
1090
1062
|
global: global$5
|
|
1091
1063
|
} = global_1;
|
|
1092
1064
|
|
|
1093
|
-
function handleError$
|
|
1065
|
+
function handleError$6(error) {
|
|
1094
1066
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1095
1067
|
const isDev = global$5.getData('isDev');
|
|
1096
1068
|
|
|
1097
1069
|
if (isDev) {
|
|
1098
|
-
fail$
|
|
1070
|
+
fail$6(errMsg);
|
|
1099
1071
|
} else {
|
|
1100
|
-
fail$
|
|
1072
|
+
fail$6(errMsg);
|
|
1101
1073
|
process.exit(1);
|
|
1102
1074
|
}
|
|
1103
1075
|
}
|
|
1104
1076
|
|
|
1105
1077
|
var handleError_1 = {
|
|
1106
|
-
handleError: handleError$
|
|
1078
|
+
handleError: handleError$6
|
|
1107
1079
|
};
|
|
1108
1080
|
|
|
1109
1081
|
/**
|
|
1110
1082
|
* 生成编译后的app.json
|
|
1111
1083
|
*/
|
|
1084
|
+
/* eslint-disable no-param-reassign */
|
|
1112
1085
|
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
* @returns { object } appJson小程序主页配置信息
|
|
1141
|
-
*/
|
|
1142
|
-
|
|
1143
|
-
function updateMainPackages(appJson, mainPackages = []) {
|
|
1144
|
-
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1145
|
-
|
|
1146
|
-
if (foundMainPackages.length === 0) {
|
|
1147
|
-
// 没找到主包
|
|
1148
|
-
foundMainPackages = [appJson.subpackages[0]];
|
|
1149
|
-
} // 拼装 app.pages
|
|
1150
|
-
|
|
1086
|
+
const fs$9 = require$$0__default$2;
|
|
1087
|
+
const {
|
|
1088
|
+
MODULE_CONFIG_FILENAME
|
|
1089
|
+
} = require$$4;
|
|
1090
|
+
const {
|
|
1091
|
+
getModuleConfig
|
|
1092
|
+
} = tmsMpconfig;
|
|
1093
|
+
const {
|
|
1094
|
+
fail: fail$5
|
|
1095
|
+
} = log$1;
|
|
1096
|
+
const {
|
|
1097
|
+
resolve: resolve$b,
|
|
1098
|
+
isObject,
|
|
1099
|
+
filterField: filterField$2
|
|
1100
|
+
} = widgets;
|
|
1101
|
+
const {
|
|
1102
|
+
handleError: handleError$5
|
|
1103
|
+
} = handleError_1;
|
|
1104
|
+
const {
|
|
1105
|
+
global: global$4
|
|
1106
|
+
} = global_1;
|
|
1107
|
+
/**
|
|
1108
|
+
* 更新appJson里面的主包配置
|
|
1109
|
+
* @param { object } appJson appJson信息
|
|
1110
|
+
* @param { array } mainPackages 小程序主包信息
|
|
1111
|
+
* @returns { object } appJson小程序主页配置信息
|
|
1112
|
+
*/
|
|
1151
1113
|
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
fail(`主包 ${subpackage} 不能没有 pages`);
|
|
1155
|
-
process.exit(-1);
|
|
1156
|
-
}
|
|
1114
|
+
function updateMainPackages(appJson, mainPackages = []) {
|
|
1115
|
+
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1157
1116
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1117
|
+
if (foundMainPackages.length === 0) {
|
|
1118
|
+
// 没找到主包
|
|
1119
|
+
foundMainPackages = [appJson.subpackages[0]];
|
|
1120
|
+
} // 拼装 app.pages
|
|
1161
1121
|
|
|
1162
|
-
if (subpackage.plugins) {
|
|
1163
|
-
Object.assign(appJson.plugins, subpackage.plugins);
|
|
1164
|
-
}
|
|
1165
|
-
}); // 去掉 subpackages 中的主包配置
|
|
1166
1122
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
* 获取app.json内容
|
|
1173
|
-
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1174
|
-
* @returns
|
|
1175
|
-
*/
|
|
1123
|
+
foundMainPackages.forEach(subpackage => {
|
|
1124
|
+
if (!subpackage.pages || !subpackage.pages.length) {
|
|
1125
|
+
fail$5(`主包 ${subpackage} 不能没有 pages`);
|
|
1126
|
+
process.exit(-1);
|
|
1127
|
+
}
|
|
1176
1128
|
|
|
1129
|
+
subpackage.pages.forEach(page => {
|
|
1130
|
+
appJson.pages.push(`${subpackage.root}/${page}`);
|
|
1131
|
+
});
|
|
1177
1132
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
fail(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1181
|
-
process.exit(1);
|
|
1133
|
+
if (subpackage.plugins) {
|
|
1134
|
+
Object.assign(appJson.plugins, subpackage.plugins);
|
|
1182
1135
|
}
|
|
1136
|
+
}); // 去掉 subpackages 中的主包配置
|
|
1183
1137
|
|
|
1184
|
-
|
|
1138
|
+
const foundMainPackageNames = foundMainPackages.map(item => item.name);
|
|
1139
|
+
appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
|
|
1140
|
+
return appJson;
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* 获取app.json内容
|
|
1144
|
+
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1145
|
+
* @returns
|
|
1146
|
+
*/
|
|
1185
1147
|
|
|
1186
|
-
appJson.subpackages = [];
|
|
1187
|
-
appJson.pages = []; // appJson.plugins = {};
|
|
1188
1148
|
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
* @param {Object} appJson
|
|
1195
|
-
* @param {Object} modulesConfigs
|
|
1196
|
-
*/
|
|
1149
|
+
const getAppJsonContent = sourceAppJsonPath => {
|
|
1150
|
+
if (!fs$9.existsSync(sourceAppJsonPath)) {
|
|
1151
|
+
fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1152
|
+
process.exit(1);
|
|
1153
|
+
}
|
|
1197
1154
|
|
|
1155
|
+
const appJson = JSON.parse(fs$9.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1198
1156
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1157
|
+
appJson.subpackages = [];
|
|
1158
|
+
appJson.pages = [];
|
|
1159
|
+
return appJson;
|
|
1160
|
+
};
|
|
1161
|
+
/**
|
|
1162
|
+
* 更新app.json中的subpackages
|
|
1163
|
+
* @param {Object} appJson
|
|
1164
|
+
* @param {Object} modulesConfigs
|
|
1165
|
+
*/
|
|
1205
1166
|
|
|
1206
|
-
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
1207
|
-
};
|
|
1208
|
-
/**
|
|
1209
|
-
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
1210
|
-
* @param {Object} appJson appjson
|
|
1211
|
-
*/
|
|
1212
1167
|
|
|
1168
|
+
const updateSubpackages = (appJson, modulesConfigs) => {
|
|
1169
|
+
// eslint-disable-next-line
|
|
1170
|
+
for (const modulePath in modulesConfigs) {
|
|
1171
|
+
const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
|
|
1172
|
+
appJson.subpackages = appJson.subpackages.concat(moduleInfo);
|
|
1173
|
+
}
|
|
1213
1174
|
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
const subps = subpackages.map(subp => {
|
|
1221
|
-
const invalidKeys = [];
|
|
1222
|
-
Object.keys(subp).forEach(key => {
|
|
1223
|
-
if (key === 'dependencies') {
|
|
1224
|
-
// eslint-disable-next-line
|
|
1225
|
-
delete subp.dependencies;
|
|
1226
|
-
return;
|
|
1227
|
-
}
|
|
1175
|
+
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
1176
|
+
};
|
|
1177
|
+
/**
|
|
1178
|
+
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
1179
|
+
* @param {Object} appJson appjson
|
|
1180
|
+
*/
|
|
1228
1181
|
|
|
1229
|
-
if (key === 'plugins') {
|
|
1230
|
-
Object.keys(subp.plugins).forEach(pk => {
|
|
1231
|
-
pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
|
|
1232
|
-
});
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
1182
|
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1183
|
+
const fixAppJson = appJson => {
|
|
1184
|
+
const {
|
|
1185
|
+
subpackages
|
|
1186
|
+
} = appJson;
|
|
1187
|
+
const pluginsMap = {};
|
|
1188
|
+
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
1189
|
+
const subps = subpackages.map(subp => {
|
|
1190
|
+
const arrOfFileType = ['requiredBackgroundModes', 'embeddedAppIdList'];
|
|
1191
|
+
const objOfFileType = ['preloadRule'];
|
|
1192
|
+
Object.keys(subp).forEach(key => {
|
|
1193
|
+
if (key === 'plugins') {
|
|
1194
|
+
Object.keys(subp.plugins).forEach(pk => {
|
|
1195
|
+
pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
|
|
1196
|
+
});
|
|
1197
|
+
} // 分包里数组类型字段,提到appjson最上层
|
|
1241
1198
|
|
|
1242
|
-
if (['requiredBackgroundModes', 'embeddedAppIdList'].indexOf(key) > -1) {
|
|
1243
|
-
// 提到appjson最上层处理
|
|
1244
|
-
const preVal = appJson[key];
|
|
1245
|
-
preVal ? appJson[key] = Array.from(new Set(preVal.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
|
|
1246
|
-
return;
|
|
1247
|
-
}
|
|
1248
|
-
});
|
|
1249
1199
|
|
|
1250
|
-
if (
|
|
1251
|
-
|
|
1252
|
-
|
|
1200
|
+
if (arrOfFileType.indexOf(key) > -1) {
|
|
1201
|
+
const preVal = appJson[key];
|
|
1202
|
+
preVal ? appJson[key] = Array.from(new Set(preVal.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
|
|
1203
|
+
} // 分包里对象类型字段,提到appjson最上层
|
|
1253
1204
|
|
|
1254
|
-
invalidKeys.concat(['requiredBackgroundModes', 'embeddedAppIdList']).forEach(k => delete subp[k]);
|
|
1255
|
-
return subp;
|
|
1256
|
-
}); // 如果plugins重复,则错误提示
|
|
1257
1205
|
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1206
|
+
if (objOfFileType.indexOf(key) > -1) {
|
|
1207
|
+
const preloadRuleMap = appJson[key] || {};
|
|
1208
|
+
subp[key] && Object.keys(subp[key]).forEach(page => {
|
|
1209
|
+
if (!preloadRuleMap[page]) {
|
|
1210
|
+
preloadRuleMap[page] = subp[key][page];
|
|
1211
|
+
}
|
|
1212
|
+
});
|
|
1213
|
+
appJson[key] = preloadRuleMap;
|
|
1261
1214
|
}
|
|
1215
|
+
});
|
|
1216
|
+
return filterField$2(subp, [...arrOfFileType, ...objOfFileType, 'dependencies']);
|
|
1217
|
+
}); // 如果plugins重复,则错误提示
|
|
1262
1218
|
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
if (pluginsErrMsg) {
|
|
1267
|
-
fail(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
1219
|
+
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
1220
|
+
if (pluginsMap[pk].length > 1) {
|
|
1221
|
+
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
1268
1222
|
}
|
|
1269
1223
|
|
|
1270
|
-
|
|
1271
|
-
};
|
|
1272
|
-
/**
|
|
1273
|
-
* 动态生成编译后的app.json
|
|
1274
|
-
* @param {object} tmsConfig
|
|
1275
|
-
* @param {array} modules 用户要编译的模块列表
|
|
1276
|
-
* @returns
|
|
1277
|
-
*/
|
|
1224
|
+
return '';
|
|
1225
|
+
}).reduce((pre, cur) => pre + cur, '');
|
|
1278
1226
|
|
|
1227
|
+
if (pluginsErrMsg) {
|
|
1228
|
+
throw new Error(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
1229
|
+
}
|
|
1279
1230
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1231
|
+
appJson.subpackages = subps;
|
|
1232
|
+
};
|
|
1233
|
+
/**
|
|
1234
|
+
* 动态生成编译后的app.json
|
|
1235
|
+
* @param {object} tmsConfig
|
|
1236
|
+
* @param {array} modules 用户要编译的模块列表
|
|
1237
|
+
* @returns
|
|
1238
|
+
*/
|
|
1283
1239
|
|
|
1284
|
-
// 获取当前 modules 下的所有子模块的配置内容
|
|
1285
|
-
const modulesConfigs = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1286
1240
|
|
|
1287
|
-
|
|
1241
|
+
function buildOutputAppJson$1(tmsConfig, modules) {
|
|
1242
|
+
try {
|
|
1243
|
+
var _tmsConfig$hooks;
|
|
1288
1244
|
|
|
1289
|
-
|
|
1245
|
+
// 获取当前 modules 下的所有子模块的配置内容
|
|
1246
|
+
const modulesConfigs = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1290
1247
|
|
|
1291
|
-
|
|
1248
|
+
const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
|
|
1292
1249
|
|
|
1293
|
-
|
|
1294
|
-
fs.writeFileSync(resolve(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1250
|
+
updateSubpackages(appJson, modulesConfigs); // 处理appJson中重复||冲突的地方
|
|
1295
1251
|
|
|
1296
|
-
|
|
1297
|
-
var _tmsConfig$hooks2;
|
|
1252
|
+
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1298
1253
|
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
module,
|
|
1302
|
-
appJson,
|
|
1303
|
-
isDev: global.getData('isDev')
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1254
|
+
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1255
|
+
fs$9.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1306
1256
|
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1257
|
+
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
|
+
var _tmsConfig$hooks2;
|
|
1259
|
+
|
|
1260
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
|
|
1261
|
+
tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
|
|
1262
|
+
modules,
|
|
1263
|
+
appJson,
|
|
1264
|
+
isDev: global$4.getData('isDev')
|
|
1265
|
+
});
|
|
1310
1266
|
}
|
|
1267
|
+
|
|
1268
|
+
return appJson;
|
|
1269
|
+
} catch (e) {
|
|
1270
|
+
handleError$5(`生成app.json出现错误: ${e}`);
|
|
1311
1271
|
}
|
|
1272
|
+
}
|
|
1312
1273
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
})(buildAppJson);
|
|
1274
|
+
var buildAppJson = {
|
|
1275
|
+
buildOutputAppJson: buildOutputAppJson$1
|
|
1276
|
+
};
|
|
1317
1277
|
|
|
1318
1278
|
/**
|
|
1319
1279
|
* 下载第三方代码
|
|
@@ -1335,7 +1295,7 @@ const {
|
|
|
1335
1295
|
handleError: handleError$4
|
|
1336
1296
|
} = handleError_1;
|
|
1337
1297
|
const {
|
|
1338
|
-
global: global$
|
|
1298
|
+
global: global$3
|
|
1339
1299
|
} = global_1;
|
|
1340
1300
|
/**
|
|
1341
1301
|
* 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
|
|
@@ -1345,15 +1305,15 @@ const {
|
|
|
1345
1305
|
*/
|
|
1346
1306
|
|
|
1347
1307
|
function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
1348
|
-
var
|
|
1308
|
+
var _tmsConfig$gitAccout, _tmsConfig$gitAccount;
|
|
1349
1309
|
|
|
1350
1310
|
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1351
|
-
const
|
|
1311
|
+
const tmsConfig = global$3.getData('tmsConfig');
|
|
1352
1312
|
let gitUrl = httpRepoUrl;
|
|
1353
1313
|
const {
|
|
1354
1314
|
username = '',
|
|
1355
1315
|
pass = ''
|
|
1356
|
-
} = (
|
|
1316
|
+
} = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccout = tmsConfig.gitAccout) === null || _tmsConfig$gitAccout === void 0 ? void 0 : _tmsConfig$gitAccout[moduleName]) || (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || {};
|
|
1357
1317
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
1358
1318
|
|
|
1359
1319
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -1892,9 +1852,6 @@ const {
|
|
|
1892
1852
|
const {
|
|
1893
1853
|
mpNpmInstallAll
|
|
1894
1854
|
} = npm;
|
|
1895
|
-
const {
|
|
1896
|
-
global: global$3
|
|
1897
|
-
} = global_1;
|
|
1898
1855
|
const {
|
|
1899
1856
|
fail: fail$3
|
|
1900
1857
|
} = log$1;
|
|
@@ -1914,13 +1871,12 @@ async function install$2(tmsConfig, modules) {
|
|
|
1914
1871
|
if (fs$6.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1915
1872
|
}); // 小程序npm install
|
|
1916
1873
|
|
|
1917
|
-
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
|
|
1918
|
-
const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
|
|
1874
|
+
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`); // 构建miniprogram_npm
|
|
1919
1875
|
|
|
1920
1876
|
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
1921
1877
|
appId: tmsConfig.appId,
|
|
1922
1878
|
projectPath: resolve$9('./'),
|
|
1923
|
-
privateKey:
|
|
1879
|
+
privateKey: tmsConfig.privateKey
|
|
1924
1880
|
});
|
|
1925
1881
|
}
|
|
1926
1882
|
|
|
@@ -2027,7 +1983,7 @@ const {
|
|
|
2027
1983
|
} = widgets;
|
|
2028
1984
|
const {
|
|
2029
1985
|
buildOutputAppJson
|
|
2030
|
-
} = buildAppJson
|
|
1986
|
+
} = buildAppJson;
|
|
2031
1987
|
const {
|
|
2032
1988
|
MODULE_CODE_DIR,
|
|
2033
1989
|
DEFAULT_COPY_CONFIG
|
|
@@ -3088,11 +3044,12 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3088
3044
|
} = require$$0__default$a;
|
|
3089
3045
|
const {
|
|
3090
3046
|
resolve,
|
|
3091
|
-
mergeMap
|
|
3047
|
+
mergeMap,
|
|
3048
|
+
filterField
|
|
3092
3049
|
} = widgets;
|
|
3093
3050
|
const {
|
|
3094
3051
|
buildOutputAppJson
|
|
3095
|
-
} = buildAppJson
|
|
3052
|
+
} = buildAppJson;
|
|
3096
3053
|
const {
|
|
3097
3054
|
DEFAULT_COPY_CONFIG
|
|
3098
3055
|
} = require$$4;
|
|
@@ -3275,7 +3232,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3275
3232
|
|
|
3276
3233
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
|
|
3277
3234
|
isDev,
|
|
3278
|
-
tmsConfig,
|
|
3235
|
+
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3279
3236
|
modules: newModules
|
|
3280
3237
|
}));
|
|
3281
3238
|
}
|
|
@@ -3299,7 +3256,8 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3299
3256
|
const shelljs$1 = require$$0__default$3;
|
|
3300
3257
|
const compileDev = dev$3.exports;
|
|
3301
3258
|
const {
|
|
3302
|
-
resolve: resolve$2
|
|
3259
|
+
resolve: resolve$2,
|
|
3260
|
+
filterField: filterField$1
|
|
3303
3261
|
} = widgets;
|
|
3304
3262
|
const init$4 = init_1;
|
|
3305
3263
|
const {
|
|
@@ -3316,7 +3274,7 @@ const {
|
|
|
3316
3274
|
} = require$$4; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
3317
3275
|
|
|
3318
3276
|
function delOtherModule(tmsConfig, targetModules) {
|
|
3319
|
-
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
|
|
3277
|
+
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules.all, tmsConfig.appName);
|
|
3320
3278
|
const targetModulesName = targetModules.map(item => item.name);
|
|
3321
3279
|
modules.forEach(item => {
|
|
3322
3280
|
if (item.root && targetModulesName.indexOf(item.name) === -1) {
|
|
@@ -3352,7 +3310,7 @@ async function dev$2(tmsConfig, targetModules, env) {
|
|
|
3352
3310
|
|
|
3353
3311
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3354
3312
|
isDev: true,
|
|
3355
|
-
tmsConfig,
|
|
3313
|
+
tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
|
|
3356
3314
|
modules: newModules
|
|
3357
3315
|
}));
|
|
3358
3316
|
}
|
|
@@ -3370,7 +3328,8 @@ var build$2 = async (tmsConfig, newModules) => {
|
|
|
3370
3328
|
|
|
3371
3329
|
const shelljs = require$$0__default$3;
|
|
3372
3330
|
const {
|
|
3373
|
-
resolve: resolve$1
|
|
3331
|
+
resolve: resolve$1,
|
|
3332
|
+
filterField
|
|
3374
3333
|
} = widgets;
|
|
3375
3334
|
const init$3 = init_1;
|
|
3376
3335
|
const compileBuild = build$2;
|
|
@@ -3389,7 +3348,7 @@ async function build$1(tmsConfig, targetModules, env) {
|
|
|
3389
3348
|
|
|
3390
3349
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3391
3350
|
isDev: false,
|
|
3392
|
-
tmsConfig,
|
|
3351
|
+
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3393
3352
|
modules: newModules
|
|
3394
3353
|
}));
|
|
3395
3354
|
}
|
|
@@ -3463,6 +3422,8 @@ var cloud$1 = async tmsConfig => {
|
|
|
3463
3422
|
}
|
|
3464
3423
|
};
|
|
3465
3424
|
|
|
3425
|
+
/* eslint-disable no-param-reassign */
|
|
3426
|
+
const loadash = require$$0__default$6;
|
|
3466
3427
|
const init$2 = init_1;
|
|
3467
3428
|
const dev = dev_1;
|
|
3468
3429
|
const build = build_1;
|
|
@@ -3495,40 +3456,60 @@ const handleModuleArg = cmd => {
|
|
|
3495
3456
|
*/
|
|
3496
3457
|
|
|
3497
3458
|
|
|
3498
|
-
const getSpecificModules = (moduleArg,
|
|
3459
|
+
const getSpecificModules = (moduleArg, modules) => {
|
|
3499
3460
|
if (moduleArg.length > 0) {
|
|
3500
3461
|
return moduleArg;
|
|
3501
|
-
}
|
|
3462
|
+
}
|
|
3502
3463
|
|
|
3464
|
+
const {
|
|
3465
|
+
all,
|
|
3466
|
+
include,
|
|
3467
|
+
exclude,
|
|
3468
|
+
blockRemote
|
|
3469
|
+
} = modules; // 单模块或多模块开发-用户在tms.private.js指定的模块
|
|
3470
|
+
|
|
3471
|
+
if ((include === null || include === void 0 ? void 0 : include.length) > 0) {
|
|
3472
|
+
return include;
|
|
3473
|
+
}
|
|
3503
3474
|
|
|
3504
|
-
if (
|
|
3505
|
-
|
|
3475
|
+
if ((exclude === null || exclude === void 0 ? void 0 : exclude.length) > 0) {
|
|
3476
|
+
return all.filter(module => !exclude.includes(module.name)).map(item => item.name);
|
|
3477
|
+
}
|
|
3506
3478
|
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3479
|
+
if (blockRemote === true) {
|
|
3480
|
+
return all.filter(module => module.repoInfo === undefined).map(item => item.name);
|
|
3481
|
+
}
|
|
3510
3482
|
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
}
|
|
3483
|
+
return all.map(item => item.name);
|
|
3484
|
+
};
|
|
3514
3485
|
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
}
|
|
3518
|
-
}
|
|
3486
|
+
const mergeConfig = (tmsConfig, tmsPrivateCf) => {
|
|
3487
|
+
const modules = {};
|
|
3519
3488
|
|
|
3520
|
-
|
|
3489
|
+
if (Array.isArray(tmsConfig.modules)) {
|
|
3490
|
+
modules.all = tmsConfig.modules;
|
|
3491
|
+
tmsConfig.modules = modules;
|
|
3492
|
+
} // 合并默认值
|
|
3493
|
+
|
|
3494
|
+
|
|
3495
|
+
const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
|
|
3496
|
+
if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
|
|
3497
|
+
return objValue.concat(srcValue);
|
|
3498
|
+
}
|
|
3499
|
+
});
|
|
3500
|
+
return res;
|
|
3521
3501
|
};
|
|
3522
3502
|
|
|
3523
3503
|
async function run(commandName, cmd) {
|
|
3524
|
-
//
|
|
3504
|
+
// 用户本地的私有项目配置
|
|
3525
3505
|
const tmsPrivateCf = readTmsPrivateCf();
|
|
3526
3506
|
const {
|
|
3527
3507
|
env = tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : tmsPrivateCf.env
|
|
3528
3508
|
} = cmd;
|
|
3529
|
-
|
|
3509
|
+
let tmsConfig = readTmsConfig(env);
|
|
3510
|
+
tmsConfig = mergeConfig(tmsConfig, tmsPrivateCf); // 处理module参数
|
|
3530
3511
|
|
|
3531
|
-
const specificModules = getSpecificModules(handleModuleArg(cmd),
|
|
3512
|
+
const specificModules = getSpecificModules(handleModuleArg(cmd), tmsConfig.modules);
|
|
3532
3513
|
const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])], true); // tms.config.js的modules 合并 module.config.json的配置项
|
|
3533
3514
|
|
|
3534
3515
|
let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
@@ -3538,7 +3519,6 @@ async function run(commandName, cmd) {
|
|
|
3538
3519
|
global.setData({
|
|
3539
3520
|
env,
|
|
3540
3521
|
cmd,
|
|
3541
|
-
tmsPrivateCf,
|
|
3542
3522
|
tmsConfig
|
|
3543
3523
|
});
|
|
3544
3524
|
|
|
@@ -3627,7 +3607,7 @@ var entry = [{
|
|
|
3627
3607
|
|
|
3628
3608
|
var require$$7 = {
|
|
3629
3609
|
name: "@tmsfe/tmskit",
|
|
3630
|
-
version: "0.0.
|
|
3610
|
+
version: "0.0.18",
|
|
3631
3611
|
description: "tmskit",
|
|
3632
3612
|
main: "dist/index.cjs",
|
|
3633
3613
|
bin: {
|