@tmsfe/tmskit 0.0.16 → 0.0.17
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 +40 -0
- package/README.md +2 -3
- package/dist/index.cjs.js +412 -315
- package/main.js +0 -0
- package/package.json +2 -2
- package/src/compile/dev.js +13 -12
- package/src/compile/plugins/mpJsonDep.js +1 -1
- package/src/core/buildAppJson.js +14 -17
- package/src/core/tmsMpconfig.js +22 -25
- package/src/entry.js +11 -0
- package/src/scripts/run/build/index.js +3 -0
- package/src/scripts/run/cloud/index.js +12 -0
- package/src/scripts/run/index.js +4 -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$8 = (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时输出红底白色文字
|
|
@@ -119,7 +119,7 @@ const fail$9 = (message = '') => {
|
|
|
119
119
|
*/
|
|
120
120
|
|
|
121
121
|
|
|
122
|
-
const succeed$
|
|
122
|
+
const succeed$2 = (message = '') => {
|
|
123
123
|
const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
|
|
124
124
|
|
|
125
125
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
@@ -133,16 +133,16 @@ const succeed$1 = (message = '') => {
|
|
|
133
133
|
*/
|
|
134
134
|
|
|
135
135
|
|
|
136
|
-
const warn$
|
|
136
|
+
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
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$
|
|
144
|
-
succeed: succeed$
|
|
145
|
-
warn: warn$
|
|
143
|
+
fail: fail$8,
|
|
144
|
+
succeed: succeed$2,
|
|
145
|
+
warn: warn$2,
|
|
146
146
|
info: info$9
|
|
147
147
|
};
|
|
148
148
|
|
|
@@ -194,7 +194,7 @@ const suggestCommands$1 = unknownCommand => {
|
|
|
194
194
|
*/
|
|
195
195
|
|
|
196
196
|
|
|
197
|
-
function isObject$
|
|
197
|
+
function isObject$1(obj) {
|
|
198
198
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
@@ -339,7 +339,7 @@ const relativeCwdPath$1 = function (file) {
|
|
|
339
339
|
|
|
340
340
|
var widgets = {
|
|
341
341
|
resolve: resolve$e,
|
|
342
|
-
isObject: isObject$
|
|
342
|
+
isObject: isObject$1,
|
|
343
343
|
isArray: isArray$1,
|
|
344
344
|
createTask: createTask$3,
|
|
345
345
|
downloadRepoForGit: downloadRepoForGit$2,
|
|
@@ -375,7 +375,7 @@ const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目
|
|
|
375
375
|
|
|
376
376
|
const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
377
377
|
|
|
378
|
-
const MODULE_CONFIG_FILENAME$
|
|
378
|
+
const MODULE_CONFIG_FILENAME$1 = 'module.config.json'; // 默认的webpack entry
|
|
379
379
|
|
|
380
380
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
381
381
|
app: path$b.resolve(process.cwd(), 'app')
|
|
@@ -387,7 +387,7 @@ const ENV = {
|
|
|
387
387
|
prod: 'production'
|
|
388
388
|
};
|
|
389
389
|
const TEMPLATE_TKIT_DIR$2 = '_tmskit';
|
|
390
|
-
const MODULE_CONFIG_INVALID_KEY
|
|
390
|
+
const MODULE_CONFIG_INVALID_KEY = ['entranceDeclare', 'entryPagePath'];
|
|
391
391
|
|
|
392
392
|
var constant = /*#__PURE__*/Object.freeze({
|
|
393
393
|
__proto__: null,
|
|
@@ -399,13 +399,13 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
399
399
|
TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
|
|
400
400
|
TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME$1,
|
|
401
401
|
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
|
|
402
|
-
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$
|
|
402
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
403
403
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
404
404
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
405
405
|
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
406
406
|
ENV: ENV,
|
|
407
407
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
408
|
-
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY
|
|
408
|
+
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY,
|
|
409
409
|
DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR
|
|
410
410
|
});
|
|
411
411
|
|
|
@@ -442,7 +442,7 @@ const isFile = pathName => {
|
|
|
442
442
|
*/
|
|
443
443
|
|
|
444
444
|
|
|
445
|
-
const ensureDirExist = dirname => {
|
|
445
|
+
const ensureDirExist$1 = dirname => {
|
|
446
446
|
if (!fs$c.existsSync(dirname)) {
|
|
447
447
|
fs$c.mkdirSync(dirname, {
|
|
448
448
|
recursive: true
|
|
@@ -457,7 +457,7 @@ const copyFile = function (src, dest) {
|
|
|
457
457
|
}
|
|
458
458
|
|
|
459
459
|
const dir = path$a.dirname(dest);
|
|
460
|
-
ensureDirExist(dir);
|
|
460
|
+
ensureDirExist$1(dir);
|
|
461
461
|
fs$c.copyFileSync(src, dest);
|
|
462
462
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
463
463
|
|
|
@@ -551,7 +551,7 @@ var io$3 = {
|
|
|
551
551
|
isDirEmpty,
|
|
552
552
|
copyFile,
|
|
553
553
|
diffContentCopyFile: diffContentCopyFile$3,
|
|
554
|
-
ensureDirExist,
|
|
554
|
+
ensureDirExist: ensureDirExist$1,
|
|
555
555
|
ext: ext$3,
|
|
556
556
|
fileInDir: fileInDir$3,
|
|
557
557
|
isFile,
|
|
@@ -690,8 +690,8 @@ const {
|
|
|
690
690
|
} = widgets;
|
|
691
691
|
const io$2 = io$3;
|
|
692
692
|
const {
|
|
693
|
-
fail: fail$
|
|
694
|
-
succeed,
|
|
693
|
+
fail: fail$7,
|
|
694
|
+
succeed: succeed$1,
|
|
695
695
|
info: info$6
|
|
696
696
|
} = log$1;
|
|
697
697
|
const generator = generator_1;
|
|
@@ -705,7 +705,7 @@ async function createAppDir(targetDir) {
|
|
|
705
705
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
706
706
|
if (fs$a.existsSync(targetDir)) {
|
|
707
707
|
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
708
|
-
fail$
|
|
708
|
+
fail$7('该目录名已经存在,换个项目名字吧~');
|
|
709
709
|
process.exit(1);
|
|
710
710
|
}
|
|
711
711
|
} else {
|
|
@@ -750,15 +750,17 @@ async function create(appName) {
|
|
|
750
750
|
}
|
|
751
751
|
|
|
752
752
|
shelljs$6.rm('-rf', resolve$c(appName, TEMPLATE_TKIT_DIR));
|
|
753
|
-
succeed('项目创建完成.');
|
|
753
|
+
succeed$1('项目创建完成.');
|
|
754
754
|
}).catch(err => {
|
|
755
|
-
fail$
|
|
755
|
+
fail$7(err.message);
|
|
756
756
|
info$6('详细的错误信息:', err);
|
|
757
757
|
});
|
|
758
758
|
}
|
|
759
759
|
|
|
760
760
|
var create_1 = create;
|
|
761
761
|
|
|
762
|
+
var buildAppJson = {exports: {}};
|
|
763
|
+
|
|
762
764
|
var defaultTmsConfig$1 = {
|
|
763
765
|
// 全局的环境配置项
|
|
764
766
|
envData: {},
|
|
@@ -785,17 +787,17 @@ const loadash = require$$0__default$6;
|
|
|
785
787
|
const fs$9 = require$$0__default$2;
|
|
786
788
|
const {
|
|
787
789
|
TMS_CONFIG_FILENAME,
|
|
788
|
-
MODULE_CONFIG_FILENAME
|
|
790
|
+
MODULE_CONFIG_FILENAME,
|
|
789
791
|
TMS_PRIVATE_FILENAME
|
|
790
792
|
} = require$$4;
|
|
791
793
|
const {
|
|
792
794
|
resolve: resolve$b,
|
|
793
|
-
isObject
|
|
795
|
+
isObject,
|
|
794
796
|
isArray
|
|
795
797
|
} = widgets;
|
|
796
798
|
const defaultTmsConfig = defaultTmsConfig$1;
|
|
797
799
|
const {
|
|
798
|
-
fail: fail$
|
|
800
|
+
fail: fail$6
|
|
799
801
|
} = log$1;
|
|
800
802
|
const path$8 = require$$1__default$2;
|
|
801
803
|
/**
|
|
@@ -807,7 +809,7 @@ const readTmsConfig$1 = function (env) {
|
|
|
807
809
|
const tmsConfigPath = resolve$b(TMS_CONFIG_FILENAME);
|
|
808
810
|
|
|
809
811
|
if (!fs$9.existsSync(tmsConfigPath)) {
|
|
810
|
-
fail$
|
|
812
|
+
fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
811
813
|
process.exit(1);
|
|
812
814
|
}
|
|
813
815
|
|
|
@@ -885,25 +887,13 @@ const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
|
|
|
885
887
|
});
|
|
886
888
|
|
|
887
889
|
if (targetModules.length === 0) {
|
|
888
|
-
fail$
|
|
890
|
+
fail$6(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
|
|
889
891
|
>name字段与module.config.json的name字段是否一致`);
|
|
890
892
|
isQuit && process.exit(1);
|
|
891
893
|
}
|
|
892
894
|
|
|
893
895
|
return targetModules;
|
|
894
896
|
};
|
|
895
|
-
/**
|
|
896
|
-
* 过滤页面为空的分包
|
|
897
|
-
* @param {Array} moduleCfg 模块配置内容
|
|
898
|
-
* @returns pages不为空的分包
|
|
899
|
-
*/
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
const getValidModules$1 = moduleCfg => {
|
|
903
|
-
// 过滤 pages 为空的情况
|
|
904
|
-
const validModules = moduleCfg.filter(item => item.pages.length > 0);
|
|
905
|
-
return validModules;
|
|
906
|
-
};
|
|
907
897
|
/**
|
|
908
898
|
* 适配处理module.config.json的字段
|
|
909
899
|
* @param { object } fileContent module.config.json的内容
|
|
@@ -912,25 +902,39 @@ const getValidModules$1 = moduleCfg => {
|
|
|
912
902
|
|
|
913
903
|
|
|
914
904
|
function adaptMpCgContent(fileContent, appName) {
|
|
915
|
-
const
|
|
905
|
+
const handleContent = function (appName, current) {
|
|
906
|
+
let res = current;
|
|
907
|
+
|
|
908
|
+
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
909
|
+
res = { ...current,
|
|
910
|
+
...current.mpConfig[appName]
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
delete res.mpConfig;
|
|
915
|
+
delete res.isSubpackages;
|
|
916
|
+
return res;
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
let content = JSON.parse(fileContent);
|
|
916
920
|
|
|
917
921
|
if (isArray(content)) {
|
|
918
922
|
let i = content.length - 1;
|
|
919
923
|
|
|
920
924
|
while (i >= 0) {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
924
|
-
current = { ...current,
|
|
925
|
-
...current.mpConfig[appName]
|
|
926
|
-
};
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
delete current.mpConfig;
|
|
930
|
-
delete current.isSubpackages;
|
|
931
|
-
content[i] = current;
|
|
925
|
+
content[i] = handleContent(appName, content[i]);
|
|
932
926
|
i--; // eslint-disable-line
|
|
933
927
|
}
|
|
928
|
+
} 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
|
+
content = handleContent(appName, content);
|
|
934
938
|
}
|
|
935
939
|
|
|
936
940
|
return content;
|
|
@@ -943,7 +947,7 @@ function adaptMpCgContent(fileContent, appName) {
|
|
|
943
947
|
*/
|
|
944
948
|
|
|
945
949
|
|
|
946
|
-
function getModuleConfig
|
|
950
|
+
function getModuleConfig(modules = [], appName, moduleConfigFilename) {
|
|
947
951
|
const modulesConfig = {};
|
|
948
952
|
modules.forEach(({
|
|
949
953
|
path
|
|
@@ -972,15 +976,15 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
972
976
|
path: relativePath,
|
|
973
977
|
name: moduleName
|
|
974
978
|
}, moduleIndex) => {
|
|
975
|
-
const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME
|
|
979
|
+
const moduleConfigPath = resolve$b(relativePath, MODULE_CONFIG_FILENAME);
|
|
976
980
|
|
|
977
981
|
if (fs$9.existsSync(moduleConfigPath)) {
|
|
978
982
|
try {
|
|
979
983
|
let findModule = false;
|
|
980
984
|
let moduleConfigContent = fs$9.readFileSync(moduleConfigPath, 'utf-8');
|
|
981
985
|
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
982
|
-
const moduleContentArr = isObject
|
|
983
|
-
|
|
986
|
+
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
987
|
+
moduleContentArr.forEach(({
|
|
984
988
|
name
|
|
985
989
|
}, moduleContentArrIndex) => {
|
|
986
990
|
if (name === moduleName) {
|
|
@@ -992,11 +996,11 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
|
992
996
|
});
|
|
993
997
|
|
|
994
998
|
if (!findModule) {
|
|
995
|
-
fail$
|
|
999
|
+
fail$6(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
|
|
996
1000
|
process.exit(1);
|
|
997
1001
|
}
|
|
998
1002
|
} catch (e) {
|
|
999
|
-
fail$
|
|
1003
|
+
fail$6(`${moduleConfigPath}配置错误: ${e}`);
|
|
1000
1004
|
newModules.push({ ...modules[moduleIndex]
|
|
1001
1005
|
});
|
|
1002
1006
|
}
|
|
@@ -1048,8 +1052,7 @@ const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
|
|
|
1048
1052
|
var tmsMpconfig = {
|
|
1049
1053
|
readTmsConfig: readTmsConfig$1,
|
|
1050
1054
|
readTmsPrivateCf: readTmsPrivateCf$1,
|
|
1051
|
-
getModuleConfig
|
|
1052
|
-
getValidModules: getValidModules$1,
|
|
1055
|
+
getModuleConfig,
|
|
1053
1056
|
checkModules: checkModules$1,
|
|
1054
1057
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
|
|
1055
1058
|
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
@@ -1081,231 +1084,236 @@ var global_1 = {
|
|
|
1081
1084
|
};
|
|
1082
1085
|
|
|
1083
1086
|
const {
|
|
1084
|
-
fail: fail$
|
|
1087
|
+
fail: fail$5
|
|
1085
1088
|
} = log$1;
|
|
1086
1089
|
const {
|
|
1087
1090
|
global: global$5
|
|
1088
1091
|
} = global_1;
|
|
1089
1092
|
|
|
1090
|
-
function handleError$
|
|
1093
|
+
function handleError$5(error) {
|
|
1091
1094
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1092
1095
|
const isDev = global$5.getData('isDev');
|
|
1093
1096
|
|
|
1094
1097
|
if (isDev) {
|
|
1095
|
-
fail$
|
|
1098
|
+
fail$5(errMsg);
|
|
1096
1099
|
} else {
|
|
1097
|
-
fail$
|
|
1100
|
+
fail$5(errMsg);
|
|
1098
1101
|
process.exit(1);
|
|
1099
1102
|
}
|
|
1100
1103
|
}
|
|
1101
1104
|
|
|
1102
1105
|
var handleError_1 = {
|
|
1103
|
-
handleError: handleError$
|
|
1106
|
+
handleError: handleError$5
|
|
1104
1107
|
};
|
|
1105
1108
|
|
|
1106
1109
|
/**
|
|
1107
1110
|
* 生成编译后的app.json
|
|
1108
1111
|
*/
|
|
1109
|
-
const fs$8 = require$$0__default$2;
|
|
1110
|
-
const {
|
|
1111
|
-
MODULE_CONFIG_FILENAME,
|
|
1112
|
-
MODULE_CONFIG_INVALID_KEY
|
|
1113
|
-
} = require$$4;
|
|
1114
|
-
const {
|
|
1115
|
-
getModuleConfig,
|
|
1116
|
-
getValidModules
|
|
1117
|
-
} = tmsMpconfig;
|
|
1118
|
-
const {
|
|
1119
|
-
fail: fail$5
|
|
1120
|
-
} = log$1;
|
|
1121
|
-
const {
|
|
1122
|
-
resolve: resolve$a,
|
|
1123
|
-
isObject
|
|
1124
|
-
} = widgets;
|
|
1125
|
-
const {
|
|
1126
|
-
handleError: handleError$3
|
|
1127
|
-
} = handleError_1;
|
|
1128
|
-
/**
|
|
1129
|
-
* 更新appJson里面的主包配置
|
|
1130
|
-
* @param { object } appJson appJson信息
|
|
1131
|
-
* @param { array } mainPackages 小程序主包信息
|
|
1132
|
-
* @returns { object } appJson小程序主页配置信息
|
|
1133
|
-
*/
|
|
1134
|
-
|
|
1135
|
-
function updateMainPackages(appJson, mainPackages = []) {
|
|
1136
|
-
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1137
|
-
|
|
1138
|
-
if (foundMainPackages.length === 0) {
|
|
1139
|
-
// 没找到主包
|
|
1140
|
-
foundMainPackages = [appJson.subpackages[0]];
|
|
1141
|
-
} // 拼装 app.pages
|
|
1142
1112
|
|
|
1113
|
+
(function (module) {
|
|
1114
|
+
/* eslint-disable no-param-reassign */
|
|
1115
|
+
const fs = require$$0__default$2;
|
|
1116
|
+
const {
|
|
1117
|
+
MODULE_CONFIG_FILENAME,
|
|
1118
|
+
MODULE_CONFIG_INVALID_KEY
|
|
1119
|
+
} = require$$4;
|
|
1120
|
+
const {
|
|
1121
|
+
getModuleConfig
|
|
1122
|
+
} = tmsMpconfig;
|
|
1123
|
+
const {
|
|
1124
|
+
fail
|
|
1125
|
+
} = log$1;
|
|
1126
|
+
const {
|
|
1127
|
+
resolve,
|
|
1128
|
+
isObject
|
|
1129
|
+
} = widgets;
|
|
1130
|
+
const {
|
|
1131
|
+
handleError
|
|
1132
|
+
} = handleError_1;
|
|
1133
|
+
const {
|
|
1134
|
+
global
|
|
1135
|
+
} = global_1;
|
|
1136
|
+
/**
|
|
1137
|
+
* 更新appJson里面的主包配置
|
|
1138
|
+
* @param { object } appJson appJson信息
|
|
1139
|
+
* @param { array } mainPackages 小程序主包信息
|
|
1140
|
+
* @returns { object } appJson小程序主页配置信息
|
|
1141
|
+
*/
|
|
1143
1142
|
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
fail$5(`主包 ${subpackage} 不能没有 pages`);
|
|
1147
|
-
process.exit(-1);
|
|
1148
|
-
}
|
|
1143
|
+
function updateMainPackages(appJson, mainPackages = []) {
|
|
1144
|
+
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1149
1145
|
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1146
|
+
if (foundMainPackages.length === 0) {
|
|
1147
|
+
// 没找到主包
|
|
1148
|
+
foundMainPackages = [appJson.subpackages[0]];
|
|
1149
|
+
} // 拼装 app.pages
|
|
1153
1150
|
|
|
1154
|
-
if (subpackage.plugins) {
|
|
1155
|
-
Object.assign(appJson.plugins, subpackage.plugins);
|
|
1156
|
-
}
|
|
1157
|
-
}); // 去掉 subpackages 中的主包配置
|
|
1158
1151
|
|
|
1159
|
-
|
|
1152
|
+
foundMainPackages.forEach(subpackage => {
|
|
1153
|
+
if (!subpackage.pages || !subpackage.pages.length) {
|
|
1154
|
+
fail(`主包 ${subpackage} 不能没有 pages`);
|
|
1155
|
+
process.exit(-1);
|
|
1156
|
+
}
|
|
1160
1157
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* 获取app.json内容
|
|
1166
|
-
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1167
|
-
* @returns
|
|
1168
|
-
*/
|
|
1158
|
+
subpackage.pages.forEach(page => {
|
|
1159
|
+
appJson.pages.push(`${subpackage.root}/${page}`);
|
|
1160
|
+
});
|
|
1169
1161
|
|
|
1162
|
+
if (subpackage.plugins) {
|
|
1163
|
+
Object.assign(appJson.plugins, subpackage.plugins);
|
|
1164
|
+
}
|
|
1165
|
+
}); // 去掉 subpackages 中的主包配置
|
|
1170
1166
|
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
process.exit(1);
|
|
1167
|
+
const foundMainPackageNames = foundMainPackages.map(item => item.name);
|
|
1168
|
+
appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
|
|
1169
|
+
return appJson;
|
|
1175
1170
|
}
|
|
1171
|
+
/**
|
|
1172
|
+
* 获取app.json内容
|
|
1173
|
+
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1174
|
+
* @returns
|
|
1175
|
+
*/
|
|
1176
1176
|
|
|
1177
|
-
const appJson = JSON.parse(fs$8.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1178
1177
|
|
|
1179
|
-
|
|
1180
|
-
|
|
1178
|
+
const getAppJsonContent = sourceAppJsonPath => {
|
|
1179
|
+
if (!fs.existsSync(sourceAppJsonPath)) {
|
|
1180
|
+
fail(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
1181
|
+
process.exit(1);
|
|
1182
|
+
}
|
|
1181
1183
|
|
|
1182
|
-
|
|
1183
|
-
return appJson;
|
|
1184
|
-
};
|
|
1185
|
-
/**
|
|
1186
|
-
* 更新app.json中的subpackages
|
|
1187
|
-
* @param {Object} appJson
|
|
1188
|
-
* @param {Object} modulesConfig
|
|
1189
|
-
*/
|
|
1184
|
+
const appJson = JSON.parse(fs.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
1190
1185
|
|
|
1186
|
+
appJson.subpackages = [];
|
|
1187
|
+
appJson.pages = []; // appJson.plugins = {};
|
|
1191
1188
|
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1189
|
+
delete appJson.entranceDeclare;
|
|
1190
|
+
return appJson;
|
|
1191
|
+
};
|
|
1192
|
+
/**
|
|
1193
|
+
* 更新app.json中的subpackages
|
|
1194
|
+
* @param {Object} appJson
|
|
1195
|
+
* @param {Object} modulesConfigs
|
|
1196
|
+
*/
|
|
1196
1197
|
|
|
1197
|
-
const validModules = getValidModules(moduleInfo); // eslint-disable-next-line
|
|
1198
1198
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
*/
|
|
1199
|
+
const updateSubpackages = (appJson, modulesConfigs) => {
|
|
1200
|
+
// eslint-disable-next-line
|
|
1201
|
+
for (const modulePath in modulesConfigs) {
|
|
1202
|
+
const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
|
|
1203
|
+
appJson.subpackages = appJson.subpackages.concat(moduleInfo);
|
|
1204
|
+
}
|
|
1206
1205
|
|
|
1206
|
+
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
1207
|
+
};
|
|
1208
|
+
/**
|
|
1209
|
+
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
1210
|
+
* @param {Object} appJson appjson
|
|
1211
|
+
*/
|
|
1207
1212
|
|
|
1208
|
-
const fixAppJson = appJson => {
|
|
1209
|
-
const {
|
|
1210
|
-
subpackages
|
|
1211
|
-
} = appJson;
|
|
1212
|
-
const pluginsMap = {};
|
|
1213
|
-
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
1214
|
-
const subps = subpackages.map(subp => {
|
|
1215
|
-
const invalidKeys = [];
|
|
1216
|
-
Object.keys(subp).forEach(key => {
|
|
1217
|
-
if (key === 'dependencies') {
|
|
1218
|
-
// eslint-disable-next-line
|
|
1219
|
-
delete subp.dependencies;
|
|
1220
|
-
return;
|
|
1221
|
-
}
|
|
1222
1213
|
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1214
|
+
const fixAppJson = appJson => {
|
|
1215
|
+
const {
|
|
1216
|
+
subpackages
|
|
1217
|
+
} = appJson;
|
|
1218
|
+
const pluginsMap = {};
|
|
1219
|
+
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
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
|
+
}
|
|
1229
1228
|
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
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
1235
|
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1236
|
+
if (MODULE_CONFIG_INVALID_KEY.indexOf(key) > -1) {
|
|
1237
|
+
// 如果分包配置中有不支持的key,则错误提醒
|
|
1238
|
+
invalidKeys.push(key);
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
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
|
+
});
|
|
1239
1249
|
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
return;
|
|
1250
|
+
if (invalidKeys.length) {
|
|
1251
|
+
fail(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
1243
1252
|
}
|
|
1244
|
-
});
|
|
1245
1253
|
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
} //
|
|
1254
|
+
invalidKeys.concat(['requiredBackgroundModes', 'embeddedAppIdList']).forEach(k => delete subp[k]);
|
|
1255
|
+
return subp;
|
|
1256
|
+
}); // 如果plugins重复,则错误提示
|
|
1249
1257
|
|
|
1258
|
+
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
1259
|
+
if (pluginsMap[pk].length > 1) {
|
|
1260
|
+
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
1261
|
+
}
|
|
1250
1262
|
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
}); // 如果plugins重复,则错误提示
|
|
1263
|
+
return '';
|
|
1264
|
+
}).reduce((pre, cur) => pre + cur, '');
|
|
1254
1265
|
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
1266
|
+
if (pluginsErrMsg) {
|
|
1267
|
+
fail(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
1258
1268
|
}
|
|
1259
1269
|
|
|
1260
|
-
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1270
|
+
appJson.subpackages = subps;
|
|
1271
|
+
};
|
|
1272
|
+
/**
|
|
1273
|
+
* 动态生成编译后的app.json
|
|
1274
|
+
* @param {object} tmsConfig
|
|
1275
|
+
* @param {array} modules 用户要编译的模块列表
|
|
1276
|
+
* @returns
|
|
1277
|
+
*/
|
|
1267
1278
|
|
|
1268
|
-
appJson.subpackages = subps;
|
|
1269
|
-
};
|
|
1270
|
-
/**
|
|
1271
|
-
* 动态生成编译后的app.json
|
|
1272
|
-
* @param {object} tmsConfig
|
|
1273
|
-
* @param {array} modules 用户要编译的模块列表
|
|
1274
|
-
* @returns
|
|
1275
|
-
*/
|
|
1276
1279
|
|
|
1280
|
+
function buildOutputAppJson(tmsConfig, modules) {
|
|
1281
|
+
try {
|
|
1282
|
+
var _tmsConfig$hooks;
|
|
1277
1283
|
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
var _tmsConfig$hooks;
|
|
1284
|
+
// 获取当前 modules 下的所有子模块的配置内容
|
|
1285
|
+
const modulesConfigs = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1281
1286
|
|
|
1282
|
-
|
|
1283
|
-
const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME); // 获取app.json的配置
|
|
1287
|
+
const appJson = getAppJsonContent(resolve('./app.json')); // 更新app.json中的subpackages
|
|
1284
1288
|
|
|
1285
|
-
|
|
1289
|
+
updateSubpackages(appJson, modulesConfigs); // 处理appJson中重复||冲突的地方
|
|
1286
1290
|
|
|
1287
|
-
|
|
1291
|
+
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1288
1292
|
|
|
1289
|
-
|
|
1293
|
+
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1294
|
+
fs.writeFileSync(resolve(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
1290
1295
|
|
|
1291
|
-
|
|
1292
|
-
|
|
1296
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
|
|
1297
|
+
var _tmsConfig$hooks2;
|
|
1293
1298
|
|
|
1294
|
-
|
|
1295
|
-
|
|
1299
|
+
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
|
|
1300
|
+
tmsConfig,
|
|
1301
|
+
module,
|
|
1302
|
+
appJson,
|
|
1303
|
+
isDev: global.getData('isDev')
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1296
1306
|
|
|
1297
|
-
|
|
1307
|
+
return appJson;
|
|
1308
|
+
} catch (e) {
|
|
1309
|
+
handleError(`生成app.json出现错误: ${e}`);
|
|
1298
1310
|
}
|
|
1299
|
-
|
|
1300
|
-
return appJson;
|
|
1301
|
-
} catch (e) {
|
|
1302
|
-
handleError$3(`生成app.json出现错误: ${e}`);
|
|
1303
1311
|
}
|
|
1304
|
-
}
|
|
1305
1312
|
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
};
|
|
1313
|
+
module.exports = {
|
|
1314
|
+
buildOutputAppJson
|
|
1315
|
+
};
|
|
1316
|
+
})(buildAppJson);
|
|
1309
1317
|
|
|
1310
1318
|
/**
|
|
1311
1319
|
* 下载第三方代码
|
|
@@ -1315,16 +1323,16 @@ const crypto$1 = require$$1__default$5;
|
|
|
1315
1323
|
const {
|
|
1316
1324
|
downloadRepoForGit,
|
|
1317
1325
|
pullRepoForGit,
|
|
1318
|
-
resolve: resolve$
|
|
1326
|
+
resolve: resolve$a
|
|
1319
1327
|
} = widgets;
|
|
1320
1328
|
const {
|
|
1321
1329
|
fail: fail$4,
|
|
1322
1330
|
info: info$5
|
|
1323
1331
|
} = log$1;
|
|
1324
|
-
const fs$
|
|
1332
|
+
const fs$8 = require$$0__default$2;
|
|
1325
1333
|
const shelljs$5 = require$$0__default$3;
|
|
1326
1334
|
const {
|
|
1327
|
-
handleError: handleError$
|
|
1335
|
+
handleError: handleError$4
|
|
1328
1336
|
} = handleError_1;
|
|
1329
1337
|
const {
|
|
1330
1338
|
global: global$4
|
|
@@ -1417,7 +1425,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1417
1425
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1418
1426
|
return Promise.all(callArr);
|
|
1419
1427
|
}).catch(e => {
|
|
1420
|
-
handleError$
|
|
1428
|
+
handleError$4(`下载代码${params.httpRepoUrl}出现错误:${e}`);
|
|
1421
1429
|
}));
|
|
1422
1430
|
});
|
|
1423
1431
|
await Promise.all(arrPromises);
|
|
@@ -1462,9 +1470,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1462
1470
|
|
|
1463
1471
|
const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
|
|
1464
1472
|
|
|
1465
|
-
const sourcePath = resolve$
|
|
1473
|
+
const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
|
|
1466
1474
|
|
|
1467
|
-
const targetPath = resolve$
|
|
1475
|
+
const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
|
|
1468
1476
|
|
|
1469
1477
|
const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
|
|
1470
1478
|
|
|
@@ -1474,7 +1482,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1474
1482
|
targetPath
|
|
1475
1483
|
},
|
|
1476
1484
|
fn: async (sourceModulePath, targetPath) => {
|
|
1477
|
-
if (fs$
|
|
1485
|
+
if (fs$8.existsSync(targetPath)) {
|
|
1478
1486
|
shelljs$5.rm('-rf', `${targetPath}/*`);
|
|
1479
1487
|
}
|
|
1480
1488
|
|
|
@@ -1489,7 +1497,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1489
1497
|
} else {
|
|
1490
1498
|
let promiseTask;
|
|
1491
1499
|
|
|
1492
|
-
if (fs$
|
|
1500
|
+
if (fs$8.existsSync(sourcePath) && fs$8.existsSync(`${sourcePath}/.git`)) {
|
|
1493
1501
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1494
1502
|
info$5(`git pull:${httpRepoUrl}`);
|
|
1495
1503
|
return pullRepoForGit(sourcePath, branch);
|
|
@@ -1537,7 +1545,7 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
|
1537
1545
|
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
|
|
1538
1546
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1539
1547
|
|
|
1540
|
-
if (!fs$
|
|
1548
|
+
if (!fs$8.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
1541
1549
|
return true;
|
|
1542
1550
|
}
|
|
1543
1551
|
}
|
|
@@ -1634,7 +1642,7 @@ var mpCi = {
|
|
|
1634
1642
|
/**
|
|
1635
1643
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1636
1644
|
*/
|
|
1637
|
-
const fs$
|
|
1645
|
+
const fs$7 = require$$0__default$2;
|
|
1638
1646
|
const fsExtra = require$$1__default$6;
|
|
1639
1647
|
const crypto = require$$1__default$5;
|
|
1640
1648
|
const path$6 = require$$1__default$2;
|
|
@@ -1645,7 +1653,7 @@ const {
|
|
|
1645
1653
|
npmInstall
|
|
1646
1654
|
} = widgets;
|
|
1647
1655
|
const {
|
|
1648
|
-
handleError: handleError$
|
|
1656
|
+
handleError: handleError$3
|
|
1649
1657
|
} = handleError_1;
|
|
1650
1658
|
const shellJsOption = {
|
|
1651
1659
|
async: false,
|
|
@@ -1669,7 +1677,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1669
1677
|
const npmTasksMap = new Map();
|
|
1670
1678
|
|
|
1671
1679
|
for (const packageJsonPath of packageJsonFiles) {
|
|
1672
|
-
const packageContent = fs$
|
|
1680
|
+
const packageContent = fs$7.readFileSync(packageJsonPath);
|
|
1673
1681
|
const packageJson = JSON.parse(packageContent);
|
|
1674
1682
|
const md5Obj = {
|
|
1675
1683
|
dependencies: packageJson.dependencies || {}
|
|
@@ -1760,7 +1768,7 @@ const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
|
1760
1768
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1761
1769
|
return Promise.all(callArr);
|
|
1762
1770
|
}).catch(e => {
|
|
1763
|
-
handleError$
|
|
1771
|
+
handleError$3(`npm install ${params.packageJsonPath}出现错误:${e}`);
|
|
1764
1772
|
}));
|
|
1765
1773
|
});
|
|
1766
1774
|
await Promise.all(arrPromises);
|
|
@@ -1785,7 +1793,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1785
1793
|
|
|
1786
1794
|
const find = (startPath, filter) => {
|
|
1787
1795
|
// 目录不存在
|
|
1788
|
-
if (!fs$
|
|
1796
|
+
if (!fs$7.existsSync(startPath)) {
|
|
1789
1797
|
log.fail(`${startPath}目录不存在`);
|
|
1790
1798
|
process.exit(-1);
|
|
1791
1799
|
return;
|
|
@@ -1798,10 +1806,10 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1798
1806
|
return;
|
|
1799
1807
|
}
|
|
1800
1808
|
|
|
1801
|
-
const files = fs$
|
|
1809
|
+
const files = fs$7.readdirSync(startPath);
|
|
1802
1810
|
files.forEach(file => {
|
|
1803
1811
|
const filename = path$6.join(startPath, file);
|
|
1804
|
-
const stat = fs$
|
|
1812
|
+
const stat = fs$7.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1805
1813
|
|
|
1806
1814
|
if (stat.isDirectory()) {
|
|
1807
1815
|
find(filename, filter);
|
|
@@ -1869,11 +1877,11 @@ var npm = {
|
|
|
1869
1877
|
};
|
|
1870
1878
|
|
|
1871
1879
|
const shelljs$4 = require$$0__default$3;
|
|
1872
|
-
const fs$
|
|
1880
|
+
const fs$6 = require$$0__default$2;
|
|
1873
1881
|
const io$1 = io$3;
|
|
1874
1882
|
const {
|
|
1875
1883
|
createTask: createTask$1,
|
|
1876
|
-
resolve: resolve$
|
|
1884
|
+
resolve: resolve$9
|
|
1877
1885
|
} = widgets;
|
|
1878
1886
|
const {
|
|
1879
1887
|
buildMpNpm
|
|
@@ -1894,39 +1902,39 @@ const {
|
|
|
1894
1902
|
async function install$2(tmsConfig, modules) {
|
|
1895
1903
|
// 拷贝模块的package.json到编译输出目录
|
|
1896
1904
|
modules.forEach(item => {
|
|
1897
|
-
const outputModuleDir = resolve$
|
|
1905
|
+
const outputModuleDir = resolve$9(`${tmsConfig.outputDir}/${item.root}`);
|
|
1898
1906
|
|
|
1899
|
-
if (!fs$
|
|
1907
|
+
if (!fs$6.existsSync(resolve$9(item.path))) {
|
|
1900
1908
|
fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1901
1909
|
process.exit(1);
|
|
1902
1910
|
}
|
|
1903
1911
|
|
|
1904
1912
|
io$1.ensureDirExist(outputModuleDir);
|
|
1905
|
-
const modulePackagePath = resolve$
|
|
1906
|
-
if (fs$
|
|
1913
|
+
const modulePackagePath = resolve$9(item.path, 'package.json');
|
|
1914
|
+
if (fs$6.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1907
1915
|
}); // 小程序npm install
|
|
1908
1916
|
|
|
1909
|
-
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$
|
|
1917
|
+
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$9(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
|
|
1910
1918
|
const tmsPrivateCf = global$3.getData('tmsPrivateCf'); // 构建miniprogram_npm
|
|
1911
1919
|
|
|
1912
1920
|
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
1913
1921
|
appId: tmsConfig.appId,
|
|
1914
|
-
projectPath: resolve$
|
|
1922
|
+
projectPath: resolve$9('./'),
|
|
1915
1923
|
privateKey: tmsPrivateCf.privateKey
|
|
1916
1924
|
});
|
|
1917
1925
|
}
|
|
1918
1926
|
|
|
1919
1927
|
var install_1 = install$2;
|
|
1920
1928
|
|
|
1921
|
-
const fs$
|
|
1929
|
+
const fs$5 = require$$0__default$2;
|
|
1922
1930
|
const semver$1 = require$$1__default$7;
|
|
1923
1931
|
const {
|
|
1924
|
-
resolve: resolve$
|
|
1932
|
+
resolve: resolve$8
|
|
1925
1933
|
} = widgets;
|
|
1926
1934
|
const path$5 = require$$1__default$2;
|
|
1927
1935
|
const shelljs$3 = require$$0__default$3;
|
|
1928
1936
|
const {
|
|
1929
|
-
handleError
|
|
1937
|
+
handleError: handleError$2
|
|
1930
1938
|
} = handleError_1;
|
|
1931
1939
|
|
|
1932
1940
|
const getLatestVersion = npmName => {
|
|
@@ -1949,29 +1957,29 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
|
1949
1957
|
|
|
1950
1958
|
const packageArr = [{
|
|
1951
1959
|
srcPackageDir: path$5.join(cwd, packageJsonName),
|
|
1952
|
-
destNpmDir: resolve$
|
|
1960
|
+
destNpmDir: resolve$8(outputDir, 'node_modules')
|
|
1953
1961
|
}]; // 1.2模块的package.json
|
|
1954
1962
|
|
|
1955
1963
|
modules.forEach(item => {
|
|
1956
1964
|
const srcPackageDir = path$5.join(cwd, item.path, 'package.json');
|
|
1957
1965
|
|
|
1958
|
-
if (fs$
|
|
1966
|
+
if (fs$5.existsSync(srcPackageDir)) {
|
|
1959
1967
|
packageArr.push({
|
|
1960
1968
|
srcPackageDir,
|
|
1961
|
-
destNpmDir: resolve$
|
|
1969
|
+
destNpmDir: resolve$8(outputDir, item.root, 'node_modules')
|
|
1962
1970
|
});
|
|
1963
1971
|
}
|
|
1964
1972
|
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1965
1973
|
|
|
1966
1974
|
for (const item of packageArr) {
|
|
1967
|
-
const packageJson = fs$
|
|
1975
|
+
const packageJson = fs$5.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1968
1976
|
let dependencies = {};
|
|
1969
1977
|
|
|
1970
1978
|
try {
|
|
1971
1979
|
const json = JSON.parse(packageJson);
|
|
1972
1980
|
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
1973
1981
|
} catch (e) {
|
|
1974
|
-
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
1982
|
+
handleError$2(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
1975
1983
|
}
|
|
1976
1984
|
|
|
1977
1985
|
const dependenciesKeys = Object.keys(dependencies);
|
|
@@ -1979,13 +1987,13 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
|
1979
1987
|
for (const key of dependenciesKeys) {
|
|
1980
1988
|
const depPath = path$5.join(item.destNpmDir, key);
|
|
1981
1989
|
|
|
1982
|
-
if (!fs$
|
|
1990
|
+
if (!fs$5.existsSync(depPath)) {
|
|
1983
1991
|
return true;
|
|
1984
1992
|
}
|
|
1985
1993
|
|
|
1986
1994
|
const depPackagePath = path$5.join(depPath, 'package.json');
|
|
1987
1995
|
|
|
1988
|
-
if (fs$
|
|
1996
|
+
if (fs$5.existsSync(depPackagePath)) {
|
|
1989
1997
|
const packageData = require(depPackagePath);
|
|
1990
1998
|
|
|
1991
1999
|
if (dependencies[key] === 'latest') {
|
|
@@ -2011,15 +2019,15 @@ var checkDependencies_1 = {
|
|
|
2011
2019
|
};
|
|
2012
2020
|
|
|
2013
2021
|
const shelljs$2 = require$$0__default$3;
|
|
2014
|
-
const fs$
|
|
2022
|
+
const fs$4 = require$$0__default$2;
|
|
2015
2023
|
const io = io$3;
|
|
2016
2024
|
const {
|
|
2017
|
-
resolve: resolve$
|
|
2025
|
+
resolve: resolve$7,
|
|
2018
2026
|
createTask
|
|
2019
2027
|
} = widgets;
|
|
2020
2028
|
const {
|
|
2021
2029
|
buildOutputAppJson
|
|
2022
|
-
} = buildAppJson;
|
|
2030
|
+
} = buildAppJson.exports;
|
|
2023
2031
|
const {
|
|
2024
2032
|
MODULE_CODE_DIR,
|
|
2025
2033
|
DEFAULT_COPY_CONFIG
|
|
@@ -2048,11 +2056,11 @@ const {
|
|
|
2048
2056
|
*/
|
|
2049
2057
|
|
|
2050
2058
|
const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
2051
|
-
const outputDir = resolve$
|
|
2059
|
+
const outputDir = resolve$7(tmsConfig.outputDir);
|
|
2052
2060
|
io.ensureDirExist(outputDir);
|
|
2053
2061
|
defaultFiles.forEach(item => {
|
|
2054
|
-
if (fs$
|
|
2055
|
-
shelljs$2.cp('-rf', resolve$
|
|
2062
|
+
if (fs$4.existsSync(resolve$7(item))) {
|
|
2063
|
+
shelljs$2.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
|
|
2056
2064
|
}
|
|
2057
2065
|
});
|
|
2058
2066
|
};
|
|
@@ -2070,7 +2078,7 @@ function checkConfig(targetModules) {
|
|
|
2070
2078
|
} // 判断源码目录是否有该模块
|
|
2071
2079
|
|
|
2072
2080
|
|
|
2073
|
-
if (item.path && !fs$
|
|
2081
|
+
if (item.path && !fs$4.existsSync(resolve$7(item.path))) {
|
|
2074
2082
|
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2075
2083
|
}
|
|
2076
2084
|
}
|
|
@@ -2080,7 +2088,7 @@ function checkConfig(targetModules) {
|
|
|
2080
2088
|
|
|
2081
2089
|
async function task(tmsConfig, targetModules) {
|
|
2082
2090
|
// 下载和移动代码
|
|
2083
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$
|
|
2091
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$7('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
2084
2092
|
|
|
2085
2093
|
let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
2086
2094
|
|
|
@@ -2089,7 +2097,7 @@ async function task(tmsConfig, targetModules) {
|
|
|
2089
2097
|
|
|
2090
2098
|
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG); // install
|
|
2091
2099
|
|
|
2092
|
-
if (checkDependencies(newModules, resolve$
|
|
2100
|
+
if (checkDependencies(newModules, resolve$7('./'), tmsConfig.outputDir)) {
|
|
2093
2101
|
await install$1(tmsConfig, newModules);
|
|
2094
2102
|
} // 动态生成编译后的app.json;
|
|
2095
2103
|
|
|
@@ -2183,9 +2191,9 @@ const {
|
|
|
2183
2191
|
diffContentCopyFile: diffContentCopyFile$2
|
|
2184
2192
|
} = io$3;
|
|
2185
2193
|
const {
|
|
2186
|
-
resolve: resolve$
|
|
2194
|
+
resolve: resolve$6
|
|
2187
2195
|
} = widgets;
|
|
2188
|
-
const fs$
|
|
2196
|
+
const fs$3 = require$$0__default$2;
|
|
2189
2197
|
const {
|
|
2190
2198
|
pluginError: pluginError$2
|
|
2191
2199
|
} = pluginError_1;
|
|
@@ -2198,7 +2206,7 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2198
2206
|
let contents = '';
|
|
2199
2207
|
|
|
2200
2208
|
try {
|
|
2201
|
-
contents = fs$
|
|
2209
|
+
contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
|
|
2202
2210
|
} catch (e) {
|
|
2203
2211
|
pluginError$2(e, isWatch);
|
|
2204
2212
|
}
|
|
@@ -2215,12 +2223,12 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
2215
2223
|
extPath
|
|
2216
2224
|
} = ext$2(depOriginPath, extensions);
|
|
2217
2225
|
|
|
2218
|
-
if (!fs$
|
|
2226
|
+
if (!fs$3.existsSync(depOriginFile)) {
|
|
2219
2227
|
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
2220
2228
|
return;
|
|
2221
2229
|
}
|
|
2222
2230
|
|
|
2223
|
-
const depDestPath = resolve$
|
|
2231
|
+
const depDestPath = resolve$6(path$4.dirname(anaFileDestFile), depItem);
|
|
2224
2232
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2225
2233
|
|
|
2226
2234
|
if (!resDep.has(depDestFile)) {
|
|
@@ -2244,8 +2252,8 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2244
2252
|
const stream = through$2.obj(function (file, enc, cb) {
|
|
2245
2253
|
// 依赖分析的文件
|
|
2246
2254
|
const anaFileOriginFile = file.history[0];
|
|
2247
|
-
const anaFileRelativeModule = path$4.relative(resolve$
|
|
2248
|
-
const anaFileDestFile = resolve$
|
|
2255
|
+
const anaFileRelativeModule = path$4.relative(resolve$6(module.from), anaFileOriginFile);
|
|
2256
|
+
const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2249
2257
|
|
|
2250
2258
|
if (file.isBuffer()) {
|
|
2251
2259
|
let contents = String(file.contents);
|
|
@@ -2274,7 +2282,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
2274
2282
|
const regRes = depItem.match(reg) || [];
|
|
2275
2283
|
|
|
2276
2284
|
if (regRes[2]) {
|
|
2277
|
-
const depDestPath = resolve$
|
|
2285
|
+
const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2278
2286
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2279
2287
|
|
|
2280
2288
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2327,9 +2335,9 @@ const {
|
|
|
2327
2335
|
diffContentCopyFile: diffContentCopyFile$1
|
|
2328
2336
|
} = io$3;
|
|
2329
2337
|
const {
|
|
2330
|
-
resolve: resolve$
|
|
2338
|
+
resolve: resolve$5
|
|
2331
2339
|
} = widgets;
|
|
2332
|
-
const fs$
|
|
2340
|
+
const fs$2 = require$$0__default$2;
|
|
2333
2341
|
const {
|
|
2334
2342
|
pluginError: pluginError$1
|
|
2335
2343
|
} = pluginError_1;
|
|
@@ -2341,8 +2349,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2341
2349
|
const stream = through$1.obj(function (file, enc, cb) {
|
|
2342
2350
|
// 当前分析的文件的路径
|
|
2343
2351
|
const anaFileOriginFile = file.history[0];
|
|
2344
|
-
const anaFileRelativeModule = path$3.relative(resolve$
|
|
2345
|
-
const anaFileDestFile = resolve$
|
|
2352
|
+
const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
|
|
2353
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2346
2354
|
|
|
2347
2355
|
if (file.isBuffer()) {
|
|
2348
2356
|
let contents = String(file.contents);
|
|
@@ -2377,11 +2385,11 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2377
2385
|
} // eslint-disable-next-line
|
|
2378
2386
|
|
|
2379
2387
|
|
|
2380
|
-
const reg = new RegExp(`^(
|
|
2388
|
+
const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2381
2389
|
const regRes = componentPath.match(reg) || [];
|
|
2382
2390
|
|
|
2383
2391
|
if (regRes[2]) {
|
|
2384
|
-
const depDestPath = resolve$
|
|
2392
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2385
2393
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2386
2394
|
|
|
2387
2395
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2415,7 +2423,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2415
2423
|
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2416
2424
|
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2417
2425
|
|
|
2418
|
-
if (fs$
|
|
2426
|
+
if (fs$2.existsSync(originFile)) {
|
|
2419
2427
|
diffContentCopyFile$1(originFile, destFile);
|
|
2420
2428
|
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2421
2429
|
|
|
@@ -2449,7 +2457,7 @@ var mpJsonDep_1 = {
|
|
|
2449
2457
|
/* eslint-disable no-param-reassign */
|
|
2450
2458
|
const through = require$$0__default$9;
|
|
2451
2459
|
const htmlparser2 = require$$1__default$9;
|
|
2452
|
-
const fs = require$$0__default$2;
|
|
2460
|
+
const fs$1 = require$$0__default$2;
|
|
2453
2461
|
const path$2 = require$$1__default$2;
|
|
2454
2462
|
const {
|
|
2455
2463
|
diffContentCopyFile,
|
|
@@ -2457,7 +2465,7 @@ const {
|
|
|
2457
2465
|
fileInDir
|
|
2458
2466
|
} = io$3;
|
|
2459
2467
|
const {
|
|
2460
|
-
resolve: resolve$
|
|
2468
|
+
resolve: resolve$4
|
|
2461
2469
|
} = widgets;
|
|
2462
2470
|
const {
|
|
2463
2471
|
dfsFindCommonDep
|
|
@@ -2496,7 +2504,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2496
2504
|
let contents = '';
|
|
2497
2505
|
|
|
2498
2506
|
try {
|
|
2499
|
-
contents = fs.readFileSync(anaFileOriginFile, 'utf8');
|
|
2507
|
+
contents = fs$1.readFileSync(anaFileOriginFile, 'utf8');
|
|
2500
2508
|
} catch (e) {
|
|
2501
2509
|
pluginError(e, isWatch);
|
|
2502
2510
|
}
|
|
@@ -2514,7 +2522,7 @@ const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = t
|
|
|
2514
2522
|
extPath
|
|
2515
2523
|
} = extFile(name, depOriginPath);
|
|
2516
2524
|
|
|
2517
|
-
if (!fs.existsSync(depOriginFile)) {
|
|
2525
|
+
if (!fs$1.existsSync(depOriginFile)) {
|
|
2518
2526
|
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2519
2527
|
return;
|
|
2520
2528
|
}
|
|
@@ -2571,8 +2579,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2571
2579
|
const stream = through.obj(function (file, enc, cb) {
|
|
2572
2580
|
// 依赖分析的文件
|
|
2573
2581
|
const anaFileOriginFile = file.history[0];
|
|
2574
|
-
const anaFileRelativeModule = path$2.relative(resolve$
|
|
2575
|
-
const anaFileDestFile = resolve$
|
|
2582
|
+
const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
|
|
2583
|
+
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2576
2584
|
|
|
2577
2585
|
if (file.isBuffer()) {
|
|
2578
2586
|
let contents = String(file.contents);
|
|
@@ -2603,7 +2611,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2603
2611
|
const regRes = attributes.src.match(reg) || [];
|
|
2604
2612
|
|
|
2605
2613
|
if (regRes[2]) {
|
|
2606
|
-
const depDestPath = resolve$
|
|
2614
|
+
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2607
2615
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2608
2616
|
|
|
2609
2617
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2630,7 +2638,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2630
2638
|
beforeDepPath,
|
|
2631
2639
|
afterDepPath
|
|
2632
2640
|
}) => {
|
|
2633
|
-
if (fs.existsSync(depOriginFile)) {
|
|
2641
|
+
if (fs$1.existsSync(depOriginFile)) {
|
|
2634
2642
|
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2635
2643
|
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2636
2644
|
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
@@ -2998,10 +3006,10 @@ const path = require$$1__default$2;
|
|
|
2998
3006
|
const shellJs = require$$0__default$3;
|
|
2999
3007
|
const {
|
|
3000
3008
|
info: info$3,
|
|
3001
|
-
warn
|
|
3009
|
+
warn: warn$1
|
|
3002
3010
|
} = log$1;
|
|
3003
3011
|
const {
|
|
3004
|
-
resolve: resolve$
|
|
3012
|
+
resolve: resolve$3
|
|
3005
3013
|
} = widgets;
|
|
3006
3014
|
const {
|
|
3007
3015
|
global: global$2
|
|
@@ -3018,7 +3026,7 @@ const logTip = (fileName, tipMap) => {
|
|
|
3018
3026
|
// eslint-disable-next-line
|
|
3019
3027
|
for (const item in tipMap) {
|
|
3020
3028
|
if (fileName.indexOf(item) > -1) {
|
|
3021
|
-
warn(`${fileName}有更新, ${tipMap[item]}`);
|
|
3029
|
+
warn$1(`${fileName}有更新, ${tipMap[item]}`);
|
|
3022
3030
|
return;
|
|
3023
3031
|
}
|
|
3024
3032
|
}
|
|
@@ -3027,8 +3035,8 @@ const logTip = (fileName, tipMap) => {
|
|
|
3027
3035
|
};
|
|
3028
3036
|
|
|
3029
3037
|
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
3030
|
-
const sourceFileRelativeModule = path.relative(resolve$
|
|
3031
|
-
const targetFile = resolve$
|
|
3038
|
+
const sourceFileRelativeModule = path.relative(resolve$3(module.from), sourceFile);
|
|
3039
|
+
const targetFile = resolve$3(outputDir, module.to, sourceFileRelativeModule);
|
|
3032
3040
|
return targetFile;
|
|
3033
3041
|
};
|
|
3034
3042
|
|
|
@@ -3073,6 +3081,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3073
3081
|
const path = require$$1__default$2;
|
|
3074
3082
|
const fs = require$$0__default$2;
|
|
3075
3083
|
const ora = require$$2__default;
|
|
3084
|
+
const chalk = require$$0__default;
|
|
3076
3085
|
const {
|
|
3077
3086
|
parallel,
|
|
3078
3087
|
series
|
|
@@ -3083,7 +3092,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3083
3092
|
} = widgets;
|
|
3084
3093
|
const {
|
|
3085
3094
|
buildOutputAppJson
|
|
3086
|
-
} = buildAppJson;
|
|
3095
|
+
} = buildAppJson.exports;
|
|
3087
3096
|
const {
|
|
3088
3097
|
DEFAULT_COPY_CONFIG
|
|
3089
3098
|
} = require$$4;
|
|
@@ -3123,20 +3132,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3123
3132
|
}
|
|
3124
3133
|
|
|
3125
3134
|
module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
3126
|
-
const compileTasksMap = new Map(); //
|
|
3127
|
-
|
|
3128
|
-
if (isDev) {
|
|
3129
|
-
watch([resolve('app.json')], {
|
|
3130
|
-
ignoreInitial: false,
|
|
3131
|
-
events: watchEvents
|
|
3132
|
-
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
3133
|
-
from: resolve(),
|
|
3134
|
-
to: resolve(tmsConfig.outputDir)
|
|
3135
|
-
});
|
|
3136
|
-
} else {
|
|
3137
|
-
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
3138
|
-
} // 监听根目录的文件
|
|
3139
|
-
|
|
3135
|
+
const compileTasksMap = new Map(); // 监听根目录的文件
|
|
3140
3136
|
|
|
3141
3137
|
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
3142
3138
|
glob: {
|
|
@@ -3250,6 +3246,15 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3250
3246
|
var _tmsConfig$hooks;
|
|
3251
3247
|
|
|
3252
3248
|
if (isDev) {
|
|
3249
|
+
// 监听app.json
|
|
3250
|
+
watch([resolve('app.json')], {
|
|
3251
|
+
ignoreInitial: false,
|
|
3252
|
+
events: watchEvents
|
|
3253
|
+
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
3254
|
+
from: resolve(),
|
|
3255
|
+
to: resolve(tmsConfig.outputDir)
|
|
3256
|
+
}); // 监听其他文件
|
|
3257
|
+
|
|
3253
3258
|
compileTasksMap.forEach(({
|
|
3254
3259
|
taskFn,
|
|
3255
3260
|
module
|
|
@@ -3259,6 +3264,8 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3259
3264
|
events: watchEvents
|
|
3260
3265
|
}, taskFn, module);
|
|
3261
3266
|
});
|
|
3267
|
+
} else {
|
|
3268
|
+
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
3262
3269
|
}
|
|
3263
3270
|
|
|
3264
3271
|
eTime = new Date().getTime() - sTime;
|
|
@@ -3273,7 +3280,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3273
3280
|
}));
|
|
3274
3281
|
}
|
|
3275
3282
|
|
|
3276
|
-
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
|
|
3283
|
+
spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
3277
3284
|
spinner.stop();
|
|
3278
3285
|
cb();
|
|
3279
3286
|
}
|
|
@@ -3283,7 +3290,8 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3283
3290
|
taskFn
|
|
3284
3291
|
}) => {
|
|
3285
3292
|
compileTasks.push(taskFn);
|
|
3286
|
-
});
|
|
3293
|
+
}); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
3294
|
+
|
|
3287
3295
|
series(start, parallel(...compileTasks), end)();
|
|
3288
3296
|
};
|
|
3289
3297
|
})(dev$3);
|
|
@@ -3291,7 +3299,7 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
|
3291
3299
|
const shelljs$1 = require$$0__default$3;
|
|
3292
3300
|
const compileDev = dev$3.exports;
|
|
3293
3301
|
const {
|
|
3294
|
-
resolve: resolve$
|
|
3302
|
+
resolve: resolve$2
|
|
3295
3303
|
} = widgets;
|
|
3296
3304
|
const init$4 = init_1;
|
|
3297
3305
|
const {
|
|
@@ -3312,7 +3320,7 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
3312
3320
|
const targetModulesName = targetModules.map(item => item.name);
|
|
3313
3321
|
modules.forEach(item => {
|
|
3314
3322
|
if (item.root && targetModulesName.indexOf(item.name) === -1) {
|
|
3315
|
-
const moduleRootDir = resolve$
|
|
3323
|
+
const moduleRootDir = resolve$2(`dist/${item.root}`);
|
|
3316
3324
|
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
3317
3325
|
silent: true
|
|
3318
3326
|
}); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
@@ -3330,7 +3338,7 @@ async function dev$2(tmsConfig, targetModules, env) {
|
|
|
3330
3338
|
} = global$1.getData('cmd');
|
|
3331
3339
|
|
|
3332
3340
|
if (noCache) {
|
|
3333
|
-
shelljs$1.rm('-rf', resolve$
|
|
3341
|
+
shelljs$1.rm('-rf', resolve$2(tmsConfig.outputDir));
|
|
3334
3342
|
shelljs$1.rm('-rf', CACHE_DIR);
|
|
3335
3343
|
} // 初始化操作
|
|
3336
3344
|
|
|
@@ -3362,26 +3370,104 @@ var build$2 = async (tmsConfig, newModules) => {
|
|
|
3362
3370
|
|
|
3363
3371
|
const shelljs = require$$0__default$3;
|
|
3364
3372
|
const {
|
|
3365
|
-
resolve
|
|
3373
|
+
resolve: resolve$1
|
|
3366
3374
|
} = widgets;
|
|
3367
3375
|
const init$3 = init_1;
|
|
3368
3376
|
const compileBuild = build$2;
|
|
3369
3377
|
|
|
3370
3378
|
async function build$1(tmsConfig, targetModules, env) {
|
|
3379
|
+
var _tmsConfig$hooks;
|
|
3380
|
+
|
|
3371
3381
|
// 开始构建前,清理输出目录
|
|
3372
|
-
await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
3382
|
+
await shelljs.rm('-rf', resolve$1(tmsConfig.outputDir));
|
|
3373
3383
|
const {
|
|
3374
3384
|
targetModules: newModules
|
|
3375
3385
|
} = await init$3(tmsConfig, targetModules);
|
|
3386
|
+
|
|
3387
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3388
|
+
var _tmsConfig$hooks2;
|
|
3389
|
+
|
|
3390
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3391
|
+
isDev: false,
|
|
3392
|
+
tmsConfig,
|
|
3393
|
+
modules: newModules
|
|
3394
|
+
}));
|
|
3395
|
+
}
|
|
3376
3396
|
compileBuild(tmsConfig, newModules, env);
|
|
3377
3397
|
}
|
|
3378
3398
|
|
|
3379
3399
|
var build_1 = build$1;
|
|
3380
3400
|
|
|
3401
|
+
const fs = require$$0__default$2;
|
|
3402
|
+
const {
|
|
3403
|
+
resolve
|
|
3404
|
+
} = widgets;
|
|
3405
|
+
const {
|
|
3406
|
+
handleError: handleError$1
|
|
3407
|
+
} = handleError_1;
|
|
3408
|
+
const {
|
|
3409
|
+
ensureDirExist
|
|
3410
|
+
} = io$3;
|
|
3411
|
+
const {
|
|
3412
|
+
warn
|
|
3413
|
+
} = log$1;
|
|
3414
|
+
/**
|
|
3415
|
+
* 根据相关配置创建软链接
|
|
3416
|
+
* @param { object } tmsConfig
|
|
3417
|
+
*/
|
|
3418
|
+
|
|
3419
|
+
const symLink$1 = tmsConfig => {
|
|
3420
|
+
try {
|
|
3421
|
+
ensureDirExist(resolve(tmsConfig.cloudDir));
|
|
3422
|
+
|
|
3423
|
+
if (tmsConfig.cloudModules) {
|
|
3424
|
+
tmsConfig.cloudModules.forEach(item => {
|
|
3425
|
+
const sourcePath = resolve(item.path);
|
|
3426
|
+
const targetPath = resolve(tmsConfig.cloudDir, item.name);
|
|
3427
|
+
|
|
3428
|
+
if (!fs.existsSync(sourcePath)) {
|
|
3429
|
+
warn(`云函数${sourcePath}不存在`);
|
|
3430
|
+
return;
|
|
3431
|
+
}
|
|
3432
|
+
|
|
3433
|
+
if (!fs.existsSync(targetPath)) {
|
|
3434
|
+
fs.symlinkSync(sourcePath, targetPath);
|
|
3435
|
+
}
|
|
3436
|
+
});
|
|
3437
|
+
}
|
|
3438
|
+
} catch (e) {
|
|
3439
|
+
handleError$1(`创建软链错误: ${e}`);
|
|
3440
|
+
}
|
|
3441
|
+
};
|
|
3442
|
+
|
|
3443
|
+
var symbolicLink = {
|
|
3444
|
+
symLink: symLink$1
|
|
3445
|
+
};
|
|
3446
|
+
|
|
3447
|
+
const {
|
|
3448
|
+
symLink
|
|
3449
|
+
} = symbolicLink;
|
|
3450
|
+
const {
|
|
3451
|
+
handleError
|
|
3452
|
+
} = handleError_1;
|
|
3453
|
+
const {
|
|
3454
|
+
succeed
|
|
3455
|
+
} = log$1;
|
|
3456
|
+
|
|
3457
|
+
var cloud$1 = async tmsConfig => {
|
|
3458
|
+
try {
|
|
3459
|
+
await symLink(tmsConfig);
|
|
3460
|
+
succeed('云函数创建软链成功');
|
|
3461
|
+
} catch (e) {
|
|
3462
|
+
handleError(`创建软链错误: ${e}`);
|
|
3463
|
+
}
|
|
3464
|
+
};
|
|
3465
|
+
|
|
3381
3466
|
const init$2 = init_1;
|
|
3382
3467
|
const dev = dev_1;
|
|
3383
3468
|
const build = build_1;
|
|
3384
3469
|
const install = install_1;
|
|
3470
|
+
const cloud = cloud$1;
|
|
3385
3471
|
const {
|
|
3386
3472
|
global
|
|
3387
3473
|
} = global_1;
|
|
@@ -3466,6 +3552,10 @@ async function run(commandName, cmd) {
|
|
|
3466
3552
|
dev(tmsConfig, newModules, env);
|
|
3467
3553
|
return;
|
|
3468
3554
|
|
|
3555
|
+
case 'cloud':
|
|
3556
|
+
cloud(tmsConfig, env);
|
|
3557
|
+
return;
|
|
3558
|
+
|
|
3469
3559
|
case 'install':
|
|
3470
3560
|
install(tmsConfig, newModules, env);
|
|
3471
3561
|
return;
|
|
@@ -3506,6 +3596,13 @@ var entry = [{
|
|
|
3506
3596
|
action: cmd => {
|
|
3507
3597
|
run_1('dev', cmd);
|
|
3508
3598
|
}
|
|
3599
|
+
}, {
|
|
3600
|
+
command: 'cloud',
|
|
3601
|
+
description: '云函数开发',
|
|
3602
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
3603
|
+
action: cmd => {
|
|
3604
|
+
run_1('cloud', cmd);
|
|
3605
|
+
}
|
|
3509
3606
|
}, {
|
|
3510
3607
|
command: 'build',
|
|
3511
3608
|
description: 'prod 打包编译',
|
|
@@ -3530,7 +3627,7 @@ var entry = [{
|
|
|
3530
3627
|
|
|
3531
3628
|
var require$$7 = {
|
|
3532
3629
|
name: "@tmsfe/tmskit",
|
|
3533
|
-
version: "0.0.
|
|
3630
|
+
version: "0.0.17",
|
|
3534
3631
|
description: "tmskit",
|
|
3535
3632
|
main: "dist/index.cjs",
|
|
3536
3633
|
bin: {
|
|
@@ -3594,7 +3691,7 @@ var require$$7 = {
|
|
|
3594
3691
|
lodash: "^4.17.21",
|
|
3595
3692
|
metalsmith: "^2.3.0",
|
|
3596
3693
|
"miniprogram-ci": "1.4.13",
|
|
3597
|
-
moment: "^2.29.
|
|
3694
|
+
moment: "^2.29.2",
|
|
3598
3695
|
"object-assign": "^4.0.1",
|
|
3599
3696
|
ora: "^5.1.0",
|
|
3600
3697
|
"plugin-error": "^1.0.0",
|