@tmsfe/tmskit 0.0.7 → 0.0.9-beta.1
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/README.md +27 -27
- package/dist/index.cjs.js +1284 -983
- package/main.js +3 -3
- package/package.json +73 -75
- package/src/{gulp → compile}/build.js +5 -5
- package/src/{gulp → compile}/compile.js +90 -81
- package/src/{gulp → compile}/dev.js +129 -102
- package/src/{gulp → compile}/plugins/less.js +116 -116
- package/src/{gulp → compile}/plugins/mpCommonDep.js +131 -131
- package/src/{gulp → compile}/plugins/mpJsonDep.js +112 -108
- package/src/{gulp → compile}/plugins/mpWxmlDep.js +194 -194
- package/src/{gulp → compile}/plugins/postcss-font-base64.js +72 -72
- package/src/{gulp → compile}/plugins/replaceEnv.js +29 -29
- package/src/{gulp → compile}/plugins/utils/pluginError.js +25 -25
- package/src/config/constant.js +69 -71
- package/src/config/defaultTmsConfig.js +16 -16
- package/src/{utils → core}/buildAppJson.js +166 -221
- package/src/{utils → core}/checkDependencies.js +77 -77
- package/src/core/cloneModules.js +203 -0
- package/src/{utils → core}/handleError.js +18 -16
- package/src/core/isInIt.js +69 -0
- package/src/{utils/mpCiUtils.js → core/mpCi.js} +73 -73
- package/src/core/npm.js +218 -0
- package/src/core/symbolicLink.js +24 -0
- package/src/{utils/tkitUtils.js → core/tmsMpconfig.js} +234 -158
- package/src/entry.js +62 -60
- package/src/index.js +63 -62
- package/src/init.js +33 -33
- package/src/scripts/create/ask.js +63 -63
- package/src/scripts/create/generator.js +25 -25
- package/src/scripts/create/ignoreFiles.js +7 -7
- package/src/scripts/create/index.js +72 -72
- package/src/scripts/create/render.js +19 -19
- package/src/scripts/run/build/index.js +16 -17
- package/src/scripts/run/dev/index.js +42 -84
- package/src/scripts/run/index.js +97 -68
- package/src/scripts/run/init/index.js +95 -87
- package/src/scripts/run/install/index.js +31 -29
- package/src/utils/findCssImport.js +30 -30
- package/src/utils/global.js +22 -36
- package/src/utils/io.js +107 -106
- package/src/utils/log.js +47 -44
- package/src/utils/widgets.js +178 -167
- package/src/utils/cliUtils.js +0 -35
- package/src/utils/cloneModules.js +0 -116
- package/src/utils/npmUtils.js +0 -166
package/dist/index.cjs.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var require$$0 = require('
|
|
3
|
+
var require$$0 = require('chalk');
|
|
4
|
+
var require$$0$1 = require('commander');
|
|
4
5
|
var require$$1 = require('leven');
|
|
5
6
|
var require$$2 = require('ora');
|
|
6
|
-
var require$$3
|
|
7
|
-
var require$$0$
|
|
8
|
-
var require$$
|
|
9
|
-
var require$$
|
|
10
|
-
var require$$0$2 = require('chalk');
|
|
11
|
-
var require$$0$3 = require('async');
|
|
7
|
+
var require$$3 = require('path');
|
|
8
|
+
var require$$0$2 = require('fs');
|
|
9
|
+
var require$$0$3 = require('shelljs');
|
|
10
|
+
var require$$0$4 = require('async');
|
|
12
11
|
var require$$1$1 = require('ejs');
|
|
13
12
|
var require$$1$2 = require('inquirer');
|
|
14
|
-
var require$$0$
|
|
15
|
-
var require$$0$
|
|
16
|
-
var require$$
|
|
13
|
+
var require$$0$5 = require('metalsmith');
|
|
14
|
+
var require$$0$6 = require('lodash');
|
|
15
|
+
var require$$1$3 = require('crypto');
|
|
16
|
+
var require$$0$7 = require('miniprogram-ci');
|
|
17
17
|
var require$$5 = require('glob-ignore');
|
|
18
|
-
var require$$1$
|
|
19
|
-
var require$$
|
|
20
|
-
var require$$0$7 = require('through2');
|
|
18
|
+
var require$$1$4 = require('fs-extra');
|
|
19
|
+
var require$$9 = require('console');
|
|
21
20
|
var require$$0$8 = require('strip-comments');
|
|
22
|
-
var require$$
|
|
23
|
-
var require$$1$5 = require('
|
|
24
|
-
var require$$
|
|
25
|
-
var require$$
|
|
26
|
-
var require$$
|
|
27
|
-
var require$$1
|
|
21
|
+
var require$$0$9 = require('through2');
|
|
22
|
+
var require$$1$5 = require('precinct');
|
|
23
|
+
var require$$1$6 = require('htmlparser2');
|
|
24
|
+
var require$$0$a = require('gulp');
|
|
25
|
+
var require$$1$7 = require('gulp-px-to-rpx');
|
|
26
|
+
var require$$2$1 = require('gulp-watch');
|
|
27
|
+
var require$$1$8 = require('semver');
|
|
28
28
|
|
|
29
29
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
30
30
|
|
|
31
31
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
32
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
32
33
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
33
34
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
34
|
-
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3
|
|
35
|
-
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
36
|
-
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
37
|
-
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
|
|
35
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
38
36
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
39
37
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
38
|
+
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
40
39
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
41
40
|
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
42
|
-
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
43
41
|
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
44
42
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
45
|
-
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
46
43
|
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
47
|
-
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
48
44
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
49
|
-
var require$$
|
|
45
|
+
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
50
46
|
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
51
|
-
var require$$
|
|
47
|
+
var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
|
|
48
|
+
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
52
49
|
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
50
|
+
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
53
51
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
54
|
-
var require$$
|
|
52
|
+
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
55
53
|
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
54
|
+
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
55
|
+
var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
|
|
56
56
|
|
|
57
57
|
function getAugmentedNamespace(n) {
|
|
58
58
|
if (n.__esModule) return n;
|
|
@@ -71,36 +71,86 @@ function getAugmentedNamespace(n) {
|
|
|
71
71
|
|
|
72
72
|
var src$2 = {};
|
|
73
73
|
|
|
74
|
-
const
|
|
74
|
+
const chalk$3 = require$$0__default;
|
|
75
|
+
/**
|
|
76
|
+
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按,用来还原属性
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 打印红底黑字格式的文字
|
|
83
|
+
* @param {String} message 需要打印的文字信息
|
|
84
|
+
* @returns {undefined} 无
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
const fail$9 = (message = '') => {
|
|
88
|
+
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
89
|
+
|
|
90
|
+
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
91
|
+
|
|
92
|
+
console.log(`${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* 打印绿底黑字格式的文字
|
|
96
|
+
* @param {String} message 需要打印的文字信息
|
|
97
|
+
* @returns {undefined} 无
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
const succeed$1 = (message = '') => {
|
|
102
|
+
const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
|
|
103
|
+
|
|
104
|
+
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
105
|
+
|
|
106
|
+
console.log(`${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* 打印warn提示
|
|
110
|
+
* @param {String} message 需要打印的文字信息
|
|
111
|
+
* @returns {undefined} 无
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
const warn = message => {
|
|
116
|
+
console.log(chalk$3.yellow(message));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const info$9 = (...args) => console.log(...args);
|
|
120
|
+
|
|
121
|
+
var log$1 = {
|
|
122
|
+
fail: fail$9,
|
|
123
|
+
succeed: succeed$1,
|
|
124
|
+
warn,
|
|
125
|
+
info: info$9
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const program$1 = require$$0__default$1;
|
|
75
129
|
const leven = require$$1__default;
|
|
76
130
|
const ora = require$$2__default;
|
|
77
131
|
const path$a = require$$3__default;
|
|
78
|
-
const fs$
|
|
79
|
-
const shelljs$6 = require$$
|
|
80
|
-
const
|
|
81
|
-
|
|
132
|
+
const fs$e = require$$0__default$2;
|
|
133
|
+
const shelljs$6 = require$$0__default$3;
|
|
134
|
+
const {
|
|
135
|
+
info: info$8
|
|
136
|
+
} = log$1;
|
|
137
|
+
const chalk$2 = require$$0__default;
|
|
82
138
|
const shelljsOptions = {
|
|
83
|
-
slient: true
|
|
139
|
+
slient: true,
|
|
140
|
+
async: false
|
|
84
141
|
}; // 获取当前目录
|
|
85
142
|
|
|
86
143
|
const cwd = process.cwd();
|
|
87
144
|
|
|
88
|
-
function resolve$
|
|
145
|
+
function resolve$f(...args) {
|
|
89
146
|
return path$a.resolve(cwd, ...args);
|
|
90
147
|
}
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
* @
|
|
148
|
+
/**
|
|
149
|
+
* 用户输入命令时,进行提示
|
|
150
|
+
* @param {String} unknownCommand 非预期的命令
|
|
151
|
+
* @returns {Undefined} 无需返回值
|
|
94
152
|
*/
|
|
95
153
|
|
|
96
|
-
const log$3 = (...args) => console.log(...args);
|
|
97
|
-
/**
|
|
98
|
-
* 用户输入命令时,进行提示
|
|
99
|
-
* @param {String} unknownCommand 非预期的命令
|
|
100
|
-
* @returns {Undefined} 无需返回值
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
154
|
const suggestCommands$1 = unknownCommand => {
|
|
105
155
|
const availableCommands = program$1.commands.map(cmd => cmd._name);
|
|
106
156
|
let suggestion;
|
|
@@ -113,155 +163,167 @@ const suggestCommands$1 = unknownCommand => {
|
|
|
113
163
|
});
|
|
114
164
|
|
|
115
165
|
if (suggestion) {
|
|
116
|
-
|
|
166
|
+
info$8(` ${chalk$2.red(`Did you mean ${chalk$2.yellow(suggestion)}?`)}`);
|
|
117
167
|
}
|
|
118
168
|
};
|
|
119
|
-
/**
|
|
120
|
-
* 判断变量是否是一个数组
|
|
121
|
-
* @param { unknown } obj 变量
|
|
122
|
-
* @returns { boolean } 是否是一个数组
|
|
169
|
+
/**
|
|
170
|
+
* 判断变量是否是一个数组
|
|
171
|
+
* @param { unknown } obj 变量
|
|
172
|
+
* @returns { boolean } 是否是一个数组
|
|
123
173
|
*/
|
|
124
174
|
|
|
125
175
|
|
|
126
176
|
function isObject$2(obj) {
|
|
127
177
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
128
178
|
}
|
|
129
|
-
/**
|
|
130
|
-
* 判断变量是否是一个对象
|
|
131
|
-
* @param { unknown } obj 变量
|
|
132
|
-
* @returns { boolean } 是否是一个对象
|
|
179
|
+
/**
|
|
180
|
+
* 判断变量是否是一个对象
|
|
181
|
+
* @param { unknown } obj 变量
|
|
182
|
+
* @returns { boolean } 是否是一个对象
|
|
133
183
|
*/
|
|
134
184
|
|
|
135
185
|
|
|
136
186
|
function isArray$1(obj) {
|
|
137
187
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
138
188
|
}
|
|
139
|
-
/**
|
|
140
|
-
*
|
|
141
|
-
* @param { string }
|
|
142
|
-
* @param {
|
|
143
|
-
* @
|
|
189
|
+
/**
|
|
190
|
+
* 下载模块代码
|
|
191
|
+
* @param { string } url 模块地址
|
|
192
|
+
* @param { string } dest 目标地址
|
|
193
|
+
* @param { string } branch 分支名
|
|
194
|
+
* @returns { undefined } no return
|
|
144
195
|
*/
|
|
145
196
|
|
|
146
197
|
|
|
147
|
-
function
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
gitUrl,
|
|
155
|
-
branch
|
|
156
|
-
} = downloadOptions;
|
|
157
|
-
|
|
158
|
-
if (fs$d.existsSync(dest)) {
|
|
159
|
-
shelljs$6.rm('-rf', dest);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
shelljs$6.mkdir('-p', dest);
|
|
163
|
-
return new Promise(resolve => {
|
|
164
|
-
download(`${repoUrl}#${branch}`, dest, {
|
|
165
|
-
clone: true
|
|
166
|
-
}, async e => {
|
|
167
|
-
if (e) {
|
|
168
|
-
console.log(e); // eslint-disable-line
|
|
198
|
+
function downloadRepoForGit$2(url, dest, branch) {
|
|
199
|
+
const cwd = process.cwd();
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
// 如果目标目录不存在
|
|
202
|
+
if (fs$e.existsSync(dest)) {
|
|
203
|
+
shelljs$6.rm('-rf', path$a.join(dest));
|
|
204
|
+
}
|
|
169
205
|
|
|
170
|
-
|
|
206
|
+
shelljs$6.mkdir('-p', dest);
|
|
207
|
+
shelljs$6.cd(dest);
|
|
208
|
+
shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
|
|
209
|
+
silent: true
|
|
210
|
+
}, (code, stdout, stderr) => {
|
|
211
|
+
if (code !== 0) {
|
|
212
|
+
reject(stderr);
|
|
171
213
|
}
|
|
172
214
|
|
|
215
|
+
shelljs$6.cd(cwd);
|
|
173
216
|
resolve();
|
|
174
217
|
});
|
|
175
218
|
});
|
|
176
219
|
}
|
|
177
|
-
/**
|
|
178
|
-
*
|
|
179
|
-
* @param { string }
|
|
180
|
-
* @param { string }
|
|
181
|
-
* @
|
|
182
|
-
* @returns { undefined } no return
|
|
220
|
+
/**
|
|
221
|
+
* pull模块代码
|
|
222
|
+
* @param { string } dest 下载代码的路径
|
|
223
|
+
* @param { string } branch 分支名
|
|
224
|
+
* @returns { undefined } no return
|
|
183
225
|
*/
|
|
184
226
|
|
|
185
227
|
|
|
186
|
-
function
|
|
228
|
+
function pullRepoForGit$1(dest, branch) {
|
|
187
229
|
const cwd = process.cwd();
|
|
188
230
|
return new Promise((resolve, reject) => {
|
|
189
|
-
// 如果目标目录不存在
|
|
190
|
-
if (fs$d.existsSync(dest)) {
|
|
191
|
-
shelljs$6.rm('-rf', path$a.join(dest));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
shelljs$6.mkdir('-p', dest);
|
|
195
231
|
shelljs$6.cd(dest);
|
|
196
|
-
|
|
232
|
+
shelljs$6.exec('git config pull.rebase false', shelljsOptions);
|
|
233
|
+
shelljs$6.exec(`git pull origin ${branch}`, {
|
|
234
|
+
silent: true
|
|
235
|
+
}, (code, stdout, stderr) => {
|
|
236
|
+
if (code !== 0) {
|
|
237
|
+
reject(stderr);
|
|
238
|
+
}
|
|
197
239
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
240
|
+
shelljs$6.cd(cwd);
|
|
241
|
+
resolve();
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* npm 下载依赖
|
|
247
|
+
* @param {*} dir
|
|
248
|
+
* @returns
|
|
249
|
+
*/
|
|
201
250
|
|
|
202
|
-
|
|
203
|
-
|
|
251
|
+
|
|
252
|
+
function npmInstall$1(dir) {
|
|
253
|
+
return new Promise((resolve, reject) => {
|
|
254
|
+
shelljs$6.exec('npx yarn --production --registry http://mirrors.tencent.com/npm/', {
|
|
255
|
+
cwd: dir,
|
|
256
|
+
silent: true
|
|
257
|
+
}, (code, stdout, stderr) => {
|
|
258
|
+
if (code !== 0) {
|
|
259
|
+
reject(stderr);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
resolve();
|
|
263
|
+
});
|
|
204
264
|
});
|
|
205
265
|
}
|
|
206
|
-
/**
|
|
207
|
-
* 计算各项任务耗时
|
|
208
|
-
* @param {Number} start 任务开始时间
|
|
209
|
-
* @returns {Undefined} 无需返回值
|
|
266
|
+
/**
|
|
267
|
+
* 计算各项任务耗时
|
|
268
|
+
* @param {Number} start 任务开始时间
|
|
269
|
+
* @returns {Undefined} 无需返回值
|
|
210
270
|
*/
|
|
211
271
|
|
|
212
272
|
|
|
213
273
|
const cost = start => Date.now() - start;
|
|
214
|
-
/**
|
|
215
|
-
* 创建构建子任务
|
|
216
|
-
* @param {Function} task 子任务执行函数
|
|
217
|
-
* @param {String} startText 任务开始前提示语
|
|
218
|
-
* @param {String} endText 任务结束后提示语
|
|
219
|
-
* @returns {Undefined} 无需返回值
|
|
274
|
+
/**
|
|
275
|
+
* 创建构建子任务
|
|
276
|
+
* @param {Function} task 子任务执行函数
|
|
277
|
+
* @param {String} startText 任务开始前提示语
|
|
278
|
+
* @param {String} endText 任务结束后提示语
|
|
279
|
+
* @returns {Undefined} 无需返回值
|
|
220
280
|
*/
|
|
221
281
|
|
|
222
282
|
|
|
223
|
-
function createTask$
|
|
283
|
+
function createTask$3(task, startText, endText) {
|
|
224
284
|
return async (...args) => {
|
|
225
285
|
const start = Date.now();
|
|
226
286
|
const spinner = ora(startText);
|
|
227
287
|
spinner.start();
|
|
228
|
-
|
|
288
|
+
info$8('\n');
|
|
229
289
|
const result = await task(...args);
|
|
230
290
|
endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
|
|
231
291
|
spinner.stop();
|
|
232
292
|
return result;
|
|
233
293
|
};
|
|
234
294
|
}
|
|
235
|
-
/**
|
|
236
|
-
* 字符串驼峰化处理
|
|
237
|
-
* @param {String} str 需要处理的字符串
|
|
238
|
-
* @returns {String} 经过驼峰处理的字符串
|
|
295
|
+
/**
|
|
296
|
+
* 字符串驼峰化处理
|
|
297
|
+
* @param {String} str 需要处理的字符串
|
|
298
|
+
* @returns {String} 经过驼峰处理的字符串
|
|
239
299
|
*/
|
|
240
300
|
|
|
241
301
|
const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
|
|
242
302
|
|
|
243
303
|
var widgets = {
|
|
244
|
-
resolve: resolve$
|
|
245
|
-
log: log$3,
|
|
304
|
+
resolve: resolve$f,
|
|
246
305
|
isObject: isObject$2,
|
|
247
306
|
isArray: isArray$1,
|
|
248
|
-
createTask: createTask$
|
|
249
|
-
downloadRepo,
|
|
307
|
+
createTask: createTask$3,
|
|
250
308
|
downloadRepoForGit: downloadRepoForGit$2,
|
|
309
|
+
pullRepoForGit: pullRepoForGit$1,
|
|
251
310
|
suggestCommands: suggestCommands$1,
|
|
252
|
-
camelize
|
|
311
|
+
camelize,
|
|
312
|
+
npmInstall: npmInstall$1
|
|
253
313
|
};
|
|
254
314
|
|
|
255
|
-
const path$9 = require('path');
|
|
315
|
+
const path$9 = require('path');
|
|
316
|
+
|
|
317
|
+
const os = require('os'); // 用户目录
|
|
256
318
|
|
|
257
319
|
|
|
258
|
-
const HOME_DIR =
|
|
320
|
+
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
259
321
|
|
|
260
322
|
const CACHE_DIR$1 = path$9.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
261
323
|
|
|
262
324
|
const TEMPLATE_DIR$1 = path$9.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
263
325
|
|
|
264
|
-
const MODULE_CODE_DIR$
|
|
326
|
+
const MODULE_CODE_DIR$2 = path$9.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
|
|
265
327
|
|
|
266
328
|
const TEMPLATE_PATH$1 = path$9.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
|
|
267
329
|
|
|
@@ -270,7 +332,9 @@ const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
|
|
|
270
332
|
const TMS_CONFIG_FILENAME$1 = 'tms.config.js';
|
|
271
333
|
const TMS_PRIVATE_FILENAME$1 = 'tms.private.config.js'; // 模块代码的默认在modules子目录
|
|
272
334
|
|
|
273
|
-
const DEFAULT_MODULE_DIR = 'modules'; //
|
|
335
|
+
const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目录
|
|
336
|
+
|
|
337
|
+
const DEFAULT_CLOUD_MODULE_DIR$1 = './cloud'; // 模块的配置文件的名称
|
|
274
338
|
|
|
275
339
|
const MODULE_CONFIG_FILENAME$3 = 'module.config.json'; // 默认的webpack entry
|
|
276
340
|
|
|
@@ -278,12 +342,7 @@ const DEFAULT_WEBPACK_ENTRY = {
|
|
|
278
342
|
app: path$9.resolve(process.cwd(), 'app')
|
|
279
343
|
}; // 默认从源码拷贝到编译后的配置
|
|
280
344
|
|
|
281
|
-
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
|
|
282
|
-
|
|
283
|
-
const MODE$1 = {
|
|
284
|
-
all: 'all',
|
|
285
|
-
multi: 'multi'
|
|
286
|
-
};
|
|
345
|
+
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json'];
|
|
287
346
|
const ENV = {
|
|
288
347
|
dev: 'development',
|
|
289
348
|
prod: 'production'
|
|
@@ -304,43 +363,46 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
304
363
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$3,
|
|
305
364
|
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
306
365
|
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
307
|
-
MODULE_CODE_DIR: MODULE_CODE_DIR$
|
|
308
|
-
MODE: MODE$1,
|
|
366
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$2,
|
|
309
367
|
ENV: ENV,
|
|
310
368
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
311
|
-
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1
|
|
369
|
+
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1,
|
|
370
|
+
DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR$1
|
|
312
371
|
});
|
|
313
372
|
|
|
314
|
-
var require$$
|
|
373
|
+
var require$$4 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
315
374
|
|
|
316
|
-
const fs$
|
|
375
|
+
const fs$d = require$$0__default$2;
|
|
317
376
|
const path$8 = require$$3__default;
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
377
|
+
const {
|
|
378
|
+
info: info$7
|
|
379
|
+
} = log$1;
|
|
380
|
+
/**
|
|
381
|
+
* 判断目录是否为空
|
|
382
|
+
* @param {string} dirname 目录名
|
|
383
|
+
* @returns
|
|
322
384
|
*/
|
|
323
385
|
|
|
324
|
-
const isDirEmpty = dirname => fs$
|
|
386
|
+
const isDirEmpty = dirname => fs$d.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
325
387
|
|
|
326
388
|
|
|
327
389
|
const isFile = pathName => {
|
|
328
390
|
try {
|
|
329
|
-
const stat = fs$
|
|
391
|
+
const stat = fs$d.lstatSync(pathName);
|
|
330
392
|
return stat.isFile();
|
|
331
393
|
} catch {
|
|
332
394
|
return false;
|
|
333
395
|
}
|
|
334
396
|
};
|
|
335
|
-
/**
|
|
336
|
-
* 确保目录存在,不存在就创建一个
|
|
337
|
-
* @param {*} dirname 目录名
|
|
397
|
+
/**
|
|
398
|
+
* 确保目录存在,不存在就创建一个
|
|
399
|
+
* @param {*} dirname 目录名
|
|
338
400
|
*/
|
|
339
401
|
|
|
340
402
|
|
|
341
403
|
const ensureDirExist = dirname => {
|
|
342
|
-
if (!fs$
|
|
343
|
-
fs$
|
|
404
|
+
if (!fs$d.existsSync(dirname)) {
|
|
405
|
+
fs$d.mkdirSync(dirname, {
|
|
344
406
|
recursive: true
|
|
345
407
|
});
|
|
346
408
|
}
|
|
@@ -348,27 +410,27 @@ const ensureDirExist = dirname => {
|
|
|
348
410
|
|
|
349
411
|
|
|
350
412
|
const copyFile = function (src, dest) {
|
|
351
|
-
if (fs$
|
|
352
|
-
fs$
|
|
413
|
+
if (fs$d.existsSync(dest)) {
|
|
414
|
+
fs$d.unlinkSync(dest);
|
|
353
415
|
}
|
|
354
416
|
|
|
355
417
|
const dir = path$8.dirname(dest);
|
|
356
418
|
ensureDirExist(dir);
|
|
357
|
-
fs$
|
|
419
|
+
fs$d.copyFileSync(src, dest);
|
|
358
420
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
359
421
|
|
|
360
422
|
|
|
361
423
|
function diffContentCopyFile$3(originFile, destFile) {
|
|
362
|
-
if (fs$
|
|
363
|
-
const depDestContent = fs$
|
|
364
|
-
const depOriginContent = fs$
|
|
424
|
+
if (fs$d.existsSync(destFile)) {
|
|
425
|
+
const depDestContent = fs$d.readFileSync(destFile, 'utf8');
|
|
426
|
+
const depOriginContent = fs$d.readFileSync(originFile, 'utf8');
|
|
365
427
|
|
|
366
428
|
if (depDestContent !== depOriginContent) {
|
|
367
|
-
|
|
429
|
+
info$7(`拷贝${originFile}内容到${destFile}`);
|
|
368
430
|
copyFile(originFile, destFile);
|
|
369
431
|
}
|
|
370
432
|
} else {
|
|
371
|
-
|
|
433
|
+
info$7(`拷贝${originFile}内容到${destFile}`);
|
|
372
434
|
copyFile(originFile, destFile);
|
|
373
435
|
}
|
|
374
436
|
} // 添加后缀
|
|
@@ -379,7 +441,7 @@ function ext$3(filePath, extensions) {
|
|
|
379
441
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
380
442
|
|
|
381
443
|
try {
|
|
382
|
-
const stat = fs$
|
|
444
|
+
const stat = fs$d.lstatSync(newFilePath);
|
|
383
445
|
|
|
384
446
|
if (stat.isDirectory()) {
|
|
385
447
|
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
@@ -390,7 +452,7 @@ function ext$3(filePath, extensions) {
|
|
|
390
452
|
for (const ext of extensions) {
|
|
391
453
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
392
454
|
|
|
393
|
-
if (fs$
|
|
455
|
+
if (fs$d.existsSync(file)) {
|
|
394
456
|
return {
|
|
395
457
|
ext,
|
|
396
458
|
extPath: extPath + ext,
|
|
@@ -408,7 +470,7 @@ function ext$3(filePath, extensions) {
|
|
|
408
470
|
|
|
409
471
|
|
|
410
472
|
const fileInDir$3 = (dir, file) => {
|
|
411
|
-
if (!fs$
|
|
473
|
+
if (!fs$d.existsSync(dir) || !fs$d.existsSync(file)) {
|
|
412
474
|
return false;
|
|
413
475
|
}
|
|
414
476
|
|
|
@@ -431,58 +493,7 @@ var io$2 = {
|
|
|
431
493
|
isFile
|
|
432
494
|
};
|
|
433
495
|
|
|
434
|
-
const
|
|
435
|
-
/**
|
|
436
|
-
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
437
|
-
*/
|
|
438
|
-
|
|
439
|
-
const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按,用来还原属性
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* 打印红底黑字格式的文字
|
|
443
|
-
* @param {String} message 需要打印的文字信息
|
|
444
|
-
* @returns {undefined} 无
|
|
445
|
-
*/
|
|
446
|
-
|
|
447
|
-
const fail$9 = (message = '') => {
|
|
448
|
-
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
449
|
-
|
|
450
|
-
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
451
|
-
|
|
452
|
-
console.log(`${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
453
|
-
};
|
|
454
|
-
/**
|
|
455
|
-
* 打印绿底黑字格式的文字
|
|
456
|
-
* @param {String} message 需要打印的文字信息
|
|
457
|
-
* @returns {undefined} 无
|
|
458
|
-
*/
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
const succeed$1 = (message = '') => {
|
|
462
|
-
const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
|
|
463
|
-
|
|
464
|
-
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
465
|
-
|
|
466
|
-
console.log(`${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
467
|
-
};
|
|
468
|
-
/**
|
|
469
|
-
* 打印warn提示
|
|
470
|
-
* @param {String} message 需要打印的文字信息
|
|
471
|
-
* @returns {undefined} 无
|
|
472
|
-
*/
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const warn = message => {
|
|
476
|
-
console.log(chalk$2.yellow(message));
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
var log$2 = {
|
|
480
|
-
fail: fail$9,
|
|
481
|
-
succeed: succeed$1,
|
|
482
|
-
warn
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
const async = require$$0__default$3;
|
|
496
|
+
const async = require$$0__default$4;
|
|
486
497
|
const ejs = require$$1__default$1;
|
|
487
498
|
|
|
488
499
|
const render$1 = (files, metalsmith, next) => {
|
|
@@ -502,29 +513,29 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
502
513
|
|
|
503
514
|
var render_1 = render$1;
|
|
504
515
|
|
|
505
|
-
const fs$
|
|
516
|
+
const fs$c = require$$0__default$2;
|
|
506
517
|
const inquirer = require$$1__default$2;
|
|
507
518
|
const {
|
|
508
|
-
resolve: resolve$
|
|
519
|
+
resolve: resolve$e
|
|
509
520
|
} = widgets;
|
|
510
521
|
const {
|
|
511
522
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
512
|
-
} = require$$
|
|
513
|
-
/**
|
|
514
|
-
* 获取模板内的问题
|
|
515
|
-
* @param {string} dir questions.json所在的目录
|
|
516
|
-
* @returns {Array} inquirer 问题数组
|
|
523
|
+
} = require$$4;
|
|
524
|
+
/**
|
|
525
|
+
* 获取模板内的问题
|
|
526
|
+
* @param {string} dir questions.json所在的目录
|
|
527
|
+
* @returns {Array} inquirer 问题数组
|
|
517
528
|
*/
|
|
518
529
|
|
|
519
530
|
const parseTemplateQuestions = dir => {
|
|
520
531
|
let prompts = [];
|
|
521
532
|
|
|
522
|
-
if (!fs$
|
|
533
|
+
if (!fs$c.existsSync(`${dir}/questions.json`)) {
|
|
523
534
|
return prompts;
|
|
524
535
|
}
|
|
525
536
|
|
|
526
537
|
try {
|
|
527
|
-
const json = JSON.parse(fs$
|
|
538
|
+
const json = JSON.parse(fs$c.readFileSync(`${dir}/questions.json`));
|
|
528
539
|
|
|
529
540
|
if (Array.isArray(json) && json.length > 0) {
|
|
530
541
|
json.forEach((item, index) => {
|
|
@@ -557,7 +568,7 @@ const isQuestionType = result => {
|
|
|
557
568
|
};
|
|
558
569
|
|
|
559
570
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
560
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
571
|
+
const prompts = parseTemplateQuestions(resolve$e(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
561
572
|
const metadata = metalsmith.metadata();
|
|
562
573
|
const filteredPrompts = prompts.filter(prompt => {
|
|
563
574
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -582,7 +593,7 @@ var ask_1 = ask$1;
|
|
|
582
593
|
const FILES_TO_IGNORE$1 = ['node_modules'];
|
|
583
594
|
var ignoreFiles = FILES_TO_IGNORE$1;
|
|
584
595
|
|
|
585
|
-
const Metalsmith = require$$0__default$
|
|
596
|
+
const Metalsmith = require$$0__default$5;
|
|
586
597
|
const render = render_1;
|
|
587
598
|
const ask = ask_1;
|
|
588
599
|
const FILES_TO_IGNORE = ignoreFiles;
|
|
@@ -600,33 +611,34 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
600
611
|
var generator_1 = generator$1;
|
|
601
612
|
|
|
602
613
|
const path$7 = require$$3__default;
|
|
603
|
-
const fs$
|
|
604
|
-
const shelljs$5 = require$$
|
|
614
|
+
const fs$b = require$$0__default$2;
|
|
615
|
+
const shelljs$5 = require$$0__default$3;
|
|
605
616
|
const {
|
|
606
617
|
TEMPLATE_DIR,
|
|
607
618
|
TEMPLATE_PATH,
|
|
608
619
|
TEMPLATE_TKIT_DIR
|
|
609
|
-
} = require$$
|
|
620
|
+
} = require$$4;
|
|
610
621
|
const {
|
|
611
622
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
612
|
-
createTask: createTask$
|
|
613
|
-
resolve: resolve$
|
|
623
|
+
createTask: createTask$2,
|
|
624
|
+
resolve: resolve$d
|
|
614
625
|
} = widgets;
|
|
615
626
|
const io$1 = io$2;
|
|
616
627
|
const {
|
|
617
628
|
fail: fail$8,
|
|
618
|
-
succeed
|
|
619
|
-
|
|
629
|
+
succeed,
|
|
630
|
+
info: info$6
|
|
631
|
+
} = log$1;
|
|
620
632
|
const generator = generator_1;
|
|
621
|
-
/**
|
|
622
|
-
* 如果该目录下面存在文件,换个名字
|
|
623
|
-
* @param { string } targetDir 当前文件夹
|
|
624
|
-
* @returns { undefined }
|
|
633
|
+
/**
|
|
634
|
+
* 如果该目录下面存在文件,换个名字
|
|
635
|
+
* @param { string } targetDir 当前文件夹
|
|
636
|
+
* @returns { undefined }
|
|
625
637
|
*/
|
|
626
638
|
|
|
627
639
|
async function createAppDir(targetDir) {
|
|
628
640
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
629
|
-
if (fs$
|
|
641
|
+
if (fs$b.existsSync(targetDir)) {
|
|
630
642
|
if (!(await io$1.isDirEmpty(targetDir))) {
|
|
631
643
|
fail$8('该目录名已经存在,换个项目名字吧~');
|
|
632
644
|
process.exit(1);
|
|
@@ -635,10 +647,10 @@ async function createAppDir(targetDir) {
|
|
|
635
647
|
shelljs$5.mkdir('-p', targetDir);
|
|
636
648
|
}
|
|
637
649
|
}
|
|
638
|
-
/**
|
|
639
|
-
* 创建本地小程序运行环境
|
|
640
|
-
* @param { string } appType 项目类型
|
|
641
|
-
* @param { string } appName 项目名称
|
|
650
|
+
/**
|
|
651
|
+
* 创建本地小程序运行环境
|
|
652
|
+
* @param { string } appType 项目类型
|
|
653
|
+
* @param { string } appName 项目名称
|
|
642
654
|
*/
|
|
643
655
|
|
|
644
656
|
|
|
@@ -650,7 +662,7 @@ async function create(appName) {
|
|
|
650
662
|
|
|
651
663
|
io$1.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
|
|
652
664
|
|
|
653
|
-
await createTask$
|
|
665
|
+
await createTask$2(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
654
666
|
|
|
655
667
|
generator(path$7.join(TEMPLATE_PATH, appType), targetDir, {
|
|
656
668
|
appName,
|
|
@@ -658,7 +670,7 @@ async function create(appName) {
|
|
|
658
670
|
}).then(() => {
|
|
659
671
|
shelljs$5.cd(appName);
|
|
660
672
|
|
|
661
|
-
const hooks = require(resolve$
|
|
673
|
+
const hooks = require(resolve$d(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
662
674
|
|
|
663
675
|
if (hooks.afterCreate) {
|
|
664
676
|
hooks.afterCreate.forEach(item => {
|
|
@@ -672,59 +684,170 @@ async function create(appName) {
|
|
|
672
684
|
});
|
|
673
685
|
}
|
|
674
686
|
|
|
675
|
-
shelljs$5.rm('-rf', resolve$
|
|
687
|
+
shelljs$5.rm('-rf', resolve$d(appName, TEMPLATE_TKIT_DIR));
|
|
676
688
|
succeed('项目创建完成.');
|
|
677
689
|
}).catch(err => {
|
|
678
690
|
fail$8(err.message);
|
|
679
|
-
|
|
691
|
+
info$6('详细的错误信息:', err);
|
|
680
692
|
});
|
|
681
693
|
}
|
|
682
694
|
|
|
683
695
|
var create_1 = create;
|
|
684
696
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
}
|
|
697
|
+
var defaultTmsConfig$1 = {
|
|
698
|
+
// 全局的环境配置项
|
|
699
|
+
envData: {},
|
|
700
|
+
// 模块配置信息
|
|
701
|
+
modules: [],
|
|
702
|
+
cloudDir: 'cloud',
|
|
703
|
+
// 第三方依赖代码需要拷贝到本项目的
|
|
704
|
+
dependencies: {},
|
|
688
705
|
|
|
689
|
-
|
|
690
|
-
|
|
706
|
+
/** 编译输出文件夹位置 */
|
|
707
|
+
outputDir: 'dist',
|
|
691
708
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
} else {
|
|
695
|
-
fail$7(errMsg);
|
|
696
|
-
process.exit(1);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
709
|
+
/** 源码监听路径 */
|
|
710
|
+
sourceDir: './',
|
|
699
711
|
|
|
700
|
-
|
|
701
|
-
|
|
712
|
+
/** 静态资源目录 */
|
|
713
|
+
static: []
|
|
702
714
|
};
|
|
703
715
|
|
|
704
|
-
|
|
716
|
+
/**
|
|
717
|
+
* 用来读取处理tms.config.js与module.config.json字段
|
|
718
|
+
*/
|
|
719
|
+
const loadash = require$$0__default$6;
|
|
720
|
+
const fs$a = require$$0__default$2;
|
|
705
721
|
const {
|
|
722
|
+
TMS_NAME: TMS_NAME$1,
|
|
723
|
+
TMS_CONFIG_FILENAME,
|
|
706
724
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
|
|
707
|
-
|
|
708
|
-
} = require$$
|
|
709
|
-
const {
|
|
710
|
-
fail: fail$6
|
|
711
|
-
} = log$2;
|
|
725
|
+
TMS_PRIVATE_FILENAME
|
|
726
|
+
} = require$$4;
|
|
712
727
|
const {
|
|
713
|
-
resolve: resolve$
|
|
728
|
+
resolve: resolve$c,
|
|
714
729
|
isObject: isObject$1,
|
|
715
730
|
isArray
|
|
716
731
|
} = widgets;
|
|
732
|
+
const defaultTmsConfig = defaultTmsConfig$1;
|
|
717
733
|
const {
|
|
718
|
-
|
|
719
|
-
} =
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
*
|
|
723
|
-
* @param {
|
|
734
|
+
fail: fail$7
|
|
735
|
+
} = log$1;
|
|
736
|
+
const path$6 = require$$3__default;
|
|
737
|
+
/**
|
|
738
|
+
* 读取tms.config.js
|
|
739
|
+
* @param env {string} 环境变量
|
|
724
740
|
*/
|
|
725
741
|
|
|
726
|
-
|
|
727
|
-
const
|
|
742
|
+
const readTmsConfig$1 = function (env) {
|
|
743
|
+
const tmsConfigPath = resolve$c(TMS_CONFIG_FILENAME);
|
|
744
|
+
|
|
745
|
+
if (!fs$a.existsSync(tmsConfigPath)) {
|
|
746
|
+
fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
747
|
+
process.exit(1);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const tmsConfigFn = require(tmsConfigPath);
|
|
751
|
+
|
|
752
|
+
const tmsConfig = tmsConfigFn({
|
|
753
|
+
env
|
|
754
|
+
}); // 合并默认值
|
|
755
|
+
|
|
756
|
+
loadash.mergeWith(tmsConfig, defaultTmsConfig); // modules兼容处理
|
|
757
|
+
|
|
758
|
+
tmsConfig.modules = convertModules(tmsConfig.modules);
|
|
759
|
+
return tmsConfig;
|
|
760
|
+
}; // convertModules 处理默认值
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
const convertModules = modules => {
|
|
764
|
+
const newModules = [];
|
|
765
|
+
modules.forEach(module => {
|
|
766
|
+
const newModule = {};
|
|
767
|
+
|
|
768
|
+
if (typeof module === 'string') {
|
|
769
|
+
// 路径字符串
|
|
770
|
+
Object.assign(newModule, {
|
|
771
|
+
name: path$6.basename(module),
|
|
772
|
+
path: module
|
|
773
|
+
});
|
|
774
|
+
} else if (typeof module === 'object') {
|
|
775
|
+
Object.assign(newModule, module);
|
|
776
|
+
|
|
777
|
+
if (module.name === undefined) {
|
|
778
|
+
newModule.name = path$6.basename(module.path);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
newModules.push(newModule);
|
|
783
|
+
});
|
|
784
|
+
return newModules;
|
|
785
|
+
};
|
|
786
|
+
/**
|
|
787
|
+
* 读取tms.private.config.js
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
const readTmsPrivateCf$1 = function () {
|
|
792
|
+
let tmsPrivateCf = {};
|
|
793
|
+
const tmsPrivatePath = resolve$c(TMS_PRIVATE_FILENAME);
|
|
794
|
+
|
|
795
|
+
if (fs$a.existsSync(tmsPrivatePath)) {
|
|
796
|
+
tmsPrivateCf = require(tmsPrivatePath);
|
|
797
|
+
} // 处理modules字段
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
if (tmsPrivateCf.modules instanceof Array) {
|
|
801
|
+
Object.assign(tmsPrivateCf.modules, {
|
|
802
|
+
include: tmsPrivateCf.modules
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
return tmsPrivateCf;
|
|
807
|
+
};
|
|
808
|
+
/**
|
|
809
|
+
* 从tms.config.json中检索用户传入的有效modules
|
|
810
|
+
* @param { object } tmsConfig
|
|
811
|
+
* @param { array } modules
|
|
812
|
+
* @returns
|
|
813
|
+
*/
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
const checkModules$1 = function (tmsConfig, modules) {
|
|
817
|
+
const targetModules = [];
|
|
818
|
+
modules.forEach(moduleName => {
|
|
819
|
+
const module = tmsConfig.modules.find(module => module.name === moduleName);
|
|
820
|
+
module && targetModules.push(module);
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
if (targetModules.length === 0) {
|
|
824
|
+
fail$7(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
|
|
825
|
+
process.exit(1);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
return targetModules;
|
|
829
|
+
};
|
|
830
|
+
/**
|
|
831
|
+
* 过滤页面为空的分包
|
|
832
|
+
* @param {Array} moduleCfg 模块配置内容
|
|
833
|
+
* @returns pages不为空的分包
|
|
834
|
+
*/
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
const getValidModules$1 = moduleCfg => {
|
|
838
|
+
// 过滤 pages 为空的情况
|
|
839
|
+
const validModules = moduleCfg.filter(item => item.pages.length > 0);
|
|
840
|
+
return validModules;
|
|
841
|
+
};
|
|
842
|
+
/**
|
|
843
|
+
* 适配处理module.config.json的字段
|
|
844
|
+
* @param { object } fileContent module.config.json的内容
|
|
845
|
+
* @param { string } appName 小程序的名称
|
|
846
|
+
*/
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
function adaptMpCgContent(fileContent, appName) {
|
|
850
|
+
const content = fileContent.contents ? JSON.parse(fileContent.contents.toString()) : JSON.parse(fileContent);
|
|
728
851
|
|
|
729
852
|
if (isArray(content)) {
|
|
730
853
|
let i = content.length - 1;
|
|
@@ -747,33 +870,200 @@ function setModuleConfig$1(file, appName) {
|
|
|
747
870
|
|
|
748
871
|
return content;
|
|
749
872
|
}
|
|
750
|
-
/**
|
|
751
|
-
* 递归获取本地所有模块的配置信息
|
|
873
|
+
/**
|
|
874
|
+
* 递归获取本地所有模块的配置信息
|
|
875
|
+
* @param {array} modules 用户要编译的模块列表
|
|
876
|
+
* @param { string } appName 小程序的名称
|
|
877
|
+
* @param { string } moduleConfigFilename moduleConfig的文件名
|
|
752
878
|
*/
|
|
753
879
|
|
|
754
880
|
|
|
755
|
-
function
|
|
881
|
+
function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
|
|
756
882
|
const modulesConfig = {};
|
|
757
883
|
modules.forEach(({
|
|
758
884
|
path
|
|
759
885
|
}) => {
|
|
760
|
-
const moduleConfigPath = resolve$
|
|
886
|
+
const moduleConfigPath = resolve$c(path, moduleConfigFilename);
|
|
761
887
|
|
|
762
|
-
if (fs$
|
|
763
|
-
const content = fs$
|
|
764
|
-
modulesConfig[moduleConfigPath] =
|
|
888
|
+
if (fs$a.existsSync(moduleConfigPath)) {
|
|
889
|
+
const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
|
|
890
|
+
modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
|
|
765
891
|
}
|
|
766
892
|
});
|
|
767
893
|
return modulesConfig;
|
|
768
894
|
}
|
|
769
|
-
/**
|
|
770
|
-
*
|
|
771
|
-
* @param {
|
|
772
|
-
* @param {
|
|
773
|
-
* @
|
|
895
|
+
/**
|
|
896
|
+
* tms.config.js的modules 合并 module.config.json的配置项
|
|
897
|
+
* @param {array} modules
|
|
898
|
+
* @param {string} appName
|
|
899
|
+
* @param {string} moduleDir
|
|
900
|
+
* @returns
|
|
774
901
|
*/
|
|
775
902
|
|
|
776
903
|
|
|
904
|
+
const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
905
|
+
const newModules = [];
|
|
906
|
+
modules.forEach(({
|
|
907
|
+
path: relativePath,
|
|
908
|
+
name: moduleName
|
|
909
|
+
}, moduleIndex) => {
|
|
910
|
+
const moduleConfigPath = resolve$c(relativePath, MODULE_CONFIG_FILENAME$2);
|
|
911
|
+
|
|
912
|
+
if (fs$a.existsSync(moduleConfigPath)) {
|
|
913
|
+
try {
|
|
914
|
+
let findModule = false;
|
|
915
|
+
let moduleConfigContent = fs$a.readFileSync(moduleConfigPath, 'utf-8');
|
|
916
|
+
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
917
|
+
const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
918
|
+
getValidModules$1(moduleContentArr).forEach(({
|
|
919
|
+
name
|
|
920
|
+
}, moduleContentArrIndex) => {
|
|
921
|
+
if (name === moduleName) {
|
|
922
|
+
findModule = true;
|
|
923
|
+
newModules.push({ ...modules[moduleIndex],
|
|
924
|
+
...moduleContentArr[moduleContentArrIndex]
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
if (!findModule) {
|
|
930
|
+
fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
|
|
931
|
+
process.exit(1);
|
|
932
|
+
}
|
|
933
|
+
} catch (e) {
|
|
934
|
+
fail$7(`${moduleConfigPath}配置错误: ${e}`);
|
|
935
|
+
newModules.push({ ...modules[moduleIndex]
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
} else {
|
|
939
|
+
newModules.push({ ...modules[moduleIndex]
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
return newModules;
|
|
944
|
+
};
|
|
945
|
+
/**
|
|
946
|
+
* 分包依赖了分包的模块 合并所依赖的modules
|
|
947
|
+
* @param { object } tmsConfig
|
|
948
|
+
* @param {array} modules
|
|
949
|
+
* @param {string} moduleDir
|
|
950
|
+
* @returns
|
|
951
|
+
*/
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
|
|
955
|
+
const moduleNames = [];
|
|
956
|
+
modules.forEach(({
|
|
957
|
+
name: moduleName
|
|
958
|
+
}) => {
|
|
959
|
+
moduleNames.push(moduleName);
|
|
960
|
+
});
|
|
961
|
+
let mergeModules = modules;
|
|
962
|
+
let isOver = true;
|
|
963
|
+
modules.forEach(({
|
|
964
|
+
dependencies: dependencyModules
|
|
965
|
+
}) => {
|
|
966
|
+
dependencyModules === null || dependencyModules === void 0 ? void 0 : dependencyModules.forEach(item => {
|
|
967
|
+
// 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
|
|
968
|
+
// 否则递归处理,根据name找到相关配置加到modules里
|
|
969
|
+
if (moduleNames.indexOf(item) === -1) {
|
|
970
|
+
isOver = false;
|
|
971
|
+
const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
|
|
972
|
+
mergeModules = [...mergeModules, ...tmpModules];
|
|
973
|
+
mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
|
|
974
|
+
}
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
return isOver ? mergeModules : subModulesMergeDepModules$2(tmsConfig, mergeModules);
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
var tmsMpconfig = {
|
|
981
|
+
readTmsConfig: readTmsConfig$1,
|
|
982
|
+
readTmsPrivateCf: readTmsPrivateCf$1,
|
|
983
|
+
getModuleConfig: getModuleConfig$1,
|
|
984
|
+
getValidModules: getValidModules$1,
|
|
985
|
+
checkModules: checkModules$1,
|
|
986
|
+
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
|
|
987
|
+
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
const global$5 = {
|
|
991
|
+
data: {},
|
|
992
|
+
|
|
993
|
+
setData(...args) {
|
|
994
|
+
if (args.length === 1) {
|
|
995
|
+
Object.keys(args[0]).forEach(k => {
|
|
996
|
+
if (args[0][k]) {
|
|
997
|
+
this.data[k] = args[0][k];
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
} else {
|
|
1001
|
+
const [name, value] = args;
|
|
1002
|
+
this.data[name] = value;
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
|
|
1006
|
+
getData(name) {
|
|
1007
|
+
return this.data[name];
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
};
|
|
1011
|
+
var global_1 = {
|
|
1012
|
+
global: global$5
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
const {
|
|
1016
|
+
fail: fail$6
|
|
1017
|
+
} = log$1;
|
|
1018
|
+
const {
|
|
1019
|
+
global: global$4
|
|
1020
|
+
} = global_1;
|
|
1021
|
+
|
|
1022
|
+
function handleError$5(error) {
|
|
1023
|
+
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1024
|
+
const isDev = global$4.getData('isDev');
|
|
1025
|
+
|
|
1026
|
+
if (isDev) {
|
|
1027
|
+
fail$6(errMsg);
|
|
1028
|
+
} else {
|
|
1029
|
+
fail$6(errMsg);
|
|
1030
|
+
process.exit(1);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
var handleError_1 = {
|
|
1035
|
+
handleError: handleError$5
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* 生成编译后的app.json
|
|
1040
|
+
*/
|
|
1041
|
+
const fs$9 = require$$0__default$2;
|
|
1042
|
+
const {
|
|
1043
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
1044
|
+
MODULE_CONFIG_INVALID_KEY
|
|
1045
|
+
} = require$$4;
|
|
1046
|
+
const {
|
|
1047
|
+
getModuleConfig,
|
|
1048
|
+
getValidModules
|
|
1049
|
+
} = tmsMpconfig;
|
|
1050
|
+
const {
|
|
1051
|
+
fail: fail$5
|
|
1052
|
+
} = log$1;
|
|
1053
|
+
const {
|
|
1054
|
+
resolve: resolve$b,
|
|
1055
|
+
isObject
|
|
1056
|
+
} = widgets;
|
|
1057
|
+
const {
|
|
1058
|
+
handleError: handleError$4
|
|
1059
|
+
} = handleError_1;
|
|
1060
|
+
/**
|
|
1061
|
+
* 更新appJson里面的主包配置
|
|
1062
|
+
* @param { object } appJson appJson信息
|
|
1063
|
+
* @param { array } mainPackages 小程序主包信息
|
|
1064
|
+
* @returns { object } appJson小程序主页配置信息
|
|
1065
|
+
*/
|
|
1066
|
+
|
|
777
1067
|
function updateMainPackages(appJson, mainPackages = []) {
|
|
778
1068
|
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
779
1069
|
|
|
@@ -785,7 +1075,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
785
1075
|
|
|
786
1076
|
foundMainPackages.forEach(subpackage => {
|
|
787
1077
|
if (!subpackage.pages || !subpackage.pages.length) {
|
|
788
|
-
fail$
|
|
1078
|
+
fail$5(`主包 ${subpackage} 不能没有 pages`);
|
|
789
1079
|
process.exit(-1);
|
|
790
1080
|
}
|
|
791
1081
|
|
|
@@ -803,16 +1093,16 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
803
1093
|
appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
|
|
804
1094
|
return appJson;
|
|
805
1095
|
}
|
|
806
|
-
/**
|
|
807
|
-
* 获取app.json内容
|
|
808
|
-
* @param {string} sourceAppJsonPath
|
|
809
|
-
* @returns
|
|
1096
|
+
/**
|
|
1097
|
+
* 获取app.json内容
|
|
1098
|
+
* @param {string} sourceAppJsonPath app.json存在的源码路径
|
|
1099
|
+
* @returns
|
|
810
1100
|
*/
|
|
811
1101
|
|
|
812
1102
|
|
|
813
1103
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
814
1104
|
if (!fs$9.existsSync(sourceAppJsonPath)) {
|
|
815
|
-
fail$
|
|
1105
|
+
fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
816
1106
|
process.exit(1);
|
|
817
1107
|
}
|
|
818
1108
|
|
|
@@ -824,42 +1114,30 @@ const getAppJsonContent = sourceAppJsonPath => {
|
|
|
824
1114
|
delete appJson.entranceDeclare;
|
|
825
1115
|
return appJson;
|
|
826
1116
|
};
|
|
827
|
-
/**
|
|
828
|
-
* 更新app.json中的subpackages
|
|
829
|
-
* @param {Object} appJson
|
|
830
|
-
* @param {Object} modulesConfig
|
|
1117
|
+
/**
|
|
1118
|
+
* 更新app.json中的subpackages
|
|
1119
|
+
* @param {Object} appJson
|
|
1120
|
+
* @param {Object} modulesConfig
|
|
831
1121
|
*/
|
|
832
1122
|
|
|
833
1123
|
|
|
834
1124
|
const updateSubpackages = (appJson, modulesConfig) => {
|
|
835
1125
|
// eslint-disable-next-line
|
|
836
1126
|
for (const name in modulesConfig) {
|
|
837
|
-
const moduleInfo = isObject
|
|
1127
|
+
const moduleInfo = isObject(modulesConfig[name]) ? [modulesConfig[name]] : modulesConfig[name]; // 过滤 pages 为空的情况
|
|
838
1128
|
|
|
839
|
-
const validModules = getValidModules
|
|
1129
|
+
const validModules = getValidModules(moduleInfo); // eslint-disable-next-line
|
|
840
1130
|
|
|
841
1131
|
appJson.subpackages = appJson.subpackages.concat(validModules);
|
|
842
1132
|
}
|
|
843
1133
|
};
|
|
844
|
-
/**
|
|
845
|
-
*
|
|
846
|
-
* @param {
|
|
847
|
-
* @returns pages不为空的分包
|
|
848
|
-
*/
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
const getValidModules$1 = moduleCfg => {
|
|
852
|
-
// 过滤 pages 为空的情况
|
|
853
|
-
const validModules = moduleCfg.filter(item => item.pages.length > 0);
|
|
854
|
-
return validModules;
|
|
855
|
-
};
|
|
856
|
-
/**
|
|
857
|
-
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
858
|
-
* @param {Object} appJson appjson
|
|
1134
|
+
/**
|
|
1135
|
+
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
1136
|
+
* @param {Object} appJson appjson
|
|
859
1137
|
*/
|
|
860
1138
|
|
|
861
1139
|
|
|
862
|
-
const
|
|
1140
|
+
const fixAppJson = appJson => {
|
|
863
1141
|
const {
|
|
864
1142
|
subpackages
|
|
865
1143
|
} = appJson;
|
|
@@ -898,7 +1176,7 @@ const processAppJson = appJson => {
|
|
|
898
1176
|
});
|
|
899
1177
|
|
|
900
1178
|
if (invalidKeys.length) {
|
|
901
|
-
fail$
|
|
1179
|
+
fail$5(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
902
1180
|
} // eslint-disable-next-line
|
|
903
1181
|
|
|
904
1182
|
|
|
@@ -915,326 +1193,113 @@ const processAppJson = appJson => {
|
|
|
915
1193
|
}).reduce((pre, cur) => pre + cur, '');
|
|
916
1194
|
|
|
917
1195
|
if (pluginsErrMsg) {
|
|
918
|
-
fail$
|
|
1196
|
+
fail$5(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
919
1197
|
} // eslint-disable-next-line
|
|
920
1198
|
|
|
921
1199
|
|
|
922
1200
|
appJson.subpackages = subps;
|
|
923
1201
|
};
|
|
924
|
-
/**
|
|
925
|
-
* 动态生成编译后的app.json
|
|
926
|
-
* @param {object} tmsConfig
|
|
927
|
-
* @param {array} modules
|
|
928
|
-
* @returns
|
|
1202
|
+
/**
|
|
1203
|
+
* 动态生成编译后的app.json
|
|
1204
|
+
* @param {object} tmsConfig
|
|
1205
|
+
* @param {array} modules 用户要编译的模块列表
|
|
1206
|
+
* @returns
|
|
929
1207
|
*/
|
|
930
1208
|
|
|
931
1209
|
|
|
932
|
-
function buildOutputAppJson$1(tmsConfig, modules
|
|
1210
|
+
function buildOutputAppJson$1(tmsConfig, modules) {
|
|
933
1211
|
try {
|
|
934
1212
|
// 获取当前 modules 下的所有子模块的配置内容
|
|
935
|
-
const modulesConfig =
|
|
1213
|
+
const modulesConfig = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
|
|
936
1214
|
|
|
937
|
-
const appJson = getAppJsonContent(resolve$
|
|
1215
|
+
const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
|
|
938
1216
|
|
|
939
1217
|
updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
|
|
940
1218
|
|
|
941
|
-
|
|
1219
|
+
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
942
1220
|
|
|
943
1221
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
944
|
-
fs$9.writeFileSync(resolve$
|
|
1222
|
+
fs$9.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
945
1223
|
return appJson;
|
|
946
1224
|
} catch (e) {
|
|
947
|
-
handleError$
|
|
1225
|
+
handleError$4(`生成app.json出现错误: ${e}`);
|
|
948
1226
|
}
|
|
949
1227
|
}
|
|
950
1228
|
|
|
951
1229
|
var buildAppJson = {
|
|
952
|
-
setModuleConfig: setModuleConfig$1,
|
|
953
|
-
getValidModules: getValidModules$1,
|
|
954
1230
|
buildOutputAppJson: buildOutputAppJson$1
|
|
955
1231
|
};
|
|
956
1232
|
|
|
957
|
-
|
|
958
|
-
constructor() {
|
|
959
|
-
this.moduleCache = {};
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
setModuleCache(url, branch, dest) {
|
|
963
|
-
const instance = getGlobalInstance$1();
|
|
964
|
-
const key = `${branch}:${url}`;
|
|
965
|
-
instance.moduleCache[key] = {
|
|
966
|
-
dest
|
|
967
|
-
};
|
|
968
|
-
return instance.moduleCache[key];
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
getModuleCache(url, branch) {
|
|
972
|
-
const instance = getGlobalInstance$1();
|
|
973
|
-
return instance.moduleCache[`${branch}:${url}`];
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
let instance;
|
|
979
|
-
|
|
980
|
-
function getGlobalInstance$1() {
|
|
981
|
-
if (instance) {
|
|
982
|
-
return instance;
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
return instance = new Globale();
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
var global = {
|
|
989
|
-
getGlobalInstance: getGlobalInstance$1
|
|
990
|
-
};
|
|
991
|
-
|
|
992
|
-
var defaultTmsConfig$1 = {
|
|
993
|
-
// 全局的环境配置项
|
|
994
|
-
envData: {},
|
|
995
|
-
// 模块配置信息
|
|
996
|
-
modules: [],
|
|
997
|
-
cloudDir: 'cloud',
|
|
998
|
-
// 第三方依赖代码需要拷贝到本项目的
|
|
999
|
-
dependencies: {},
|
|
1000
|
-
|
|
1001
|
-
/** 编译输出文件夹位置 */
|
|
1002
|
-
outputDir: 'dist',
|
|
1003
|
-
|
|
1004
|
-
/** 源码监听路径 */
|
|
1005
|
-
sourceDir: './',
|
|
1006
|
-
|
|
1007
|
-
/** 静态资源目录 */
|
|
1008
|
-
static: []
|
|
1009
|
-
};
|
|
1010
|
-
|
|
1011
|
-
const loadash = require$$0__default$5;
|
|
1012
|
-
const fs$8 = require$$0__default$1;
|
|
1233
|
+
const fs$8 = require$$0__default$2;
|
|
1013
1234
|
const {
|
|
1014
|
-
|
|
1015
|
-
TMS_CONFIG_FILENAME,
|
|
1016
|
-
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
1017
|
-
TMS_PRIVATE_FILENAME
|
|
1018
|
-
} = require$$3;
|
|
1019
|
-
const {
|
|
1020
|
-
resolve: resolve$9,
|
|
1021
|
-
isObject
|
|
1235
|
+
resolve: resolve$a
|
|
1022
1236
|
} = widgets;
|
|
1023
|
-
const {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
/**
|
|
1033
|
-
* 读取tms.config.js
|
|
1034
|
-
* @param env {string} 环境变量
|
|
1035
|
-
*/
|
|
1036
|
-
|
|
1037
|
-
const readTmsConfig$1 = function (env) {
|
|
1038
|
-
const tmsConfigPath = resolve$9(TMS_CONFIG_FILENAME);
|
|
1039
|
-
|
|
1040
|
-
if (!fs$8.existsSync(tmsConfigPath)) {
|
|
1041
|
-
fail$5('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
1042
|
-
process.exit(1);
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
const tmsConfigFn = require(tmsConfigPath);
|
|
1046
|
-
|
|
1047
|
-
const tmsConfig = tmsConfigFn({
|
|
1048
|
-
env
|
|
1049
|
-
}); // 合并默认值
|
|
1050
|
-
|
|
1051
|
-
loadash.mergeWith(tmsConfig, defaultTmsConfig); // modules兼容处理
|
|
1052
|
-
|
|
1053
|
-
tmsConfig.modules = convertModules(tmsConfig.modules);
|
|
1054
|
-
return tmsConfig;
|
|
1055
|
-
}; // convertModules 处理默认值
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
const convertModules = modules => {
|
|
1059
|
-
const newModules = [];
|
|
1060
|
-
modules.forEach((module, index) => {
|
|
1061
|
-
const newModule = {};
|
|
1062
|
-
|
|
1063
|
-
if (typeof module === 'string') {
|
|
1064
|
-
// 路径字符串
|
|
1065
|
-
Object.assign(newModule, {
|
|
1066
|
-
name: path$6.basename(module),
|
|
1067
|
-
path: module
|
|
1068
|
-
});
|
|
1069
|
-
} else if (typeof module === 'object') {
|
|
1070
|
-
Object.assign(newModule, module);
|
|
1071
|
-
|
|
1072
|
-
if (module.name === undefined) {
|
|
1073
|
-
newModule.name = path$6.basename(module.path);
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
newModules.push(newModule);
|
|
1078
|
-
});
|
|
1079
|
-
return newModules;
|
|
1080
|
-
};
|
|
1081
|
-
/**
|
|
1082
|
-
* 读取tms.private.js
|
|
1083
|
-
*/
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
const readTmsPrivateCf$2 = function () {
|
|
1087
|
-
let tmsPrivateCg;
|
|
1088
|
-
const tmsPrivatePath = resolve$9(TMS_PRIVATE_FILENAME);
|
|
1089
|
-
|
|
1090
|
-
if (fs$8.existsSync(tmsPrivatePath)) {
|
|
1091
|
-
tmsPrivateCg = require(tmsPrivatePath);
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
return tmsPrivateCg;
|
|
1095
|
-
};
|
|
1096
|
-
/**
|
|
1097
|
-
* 从tms.config.json中检索用户传入的有效modules
|
|
1098
|
-
* @param { object } tmsConfig
|
|
1099
|
-
* @param { array } modules
|
|
1100
|
-
* @returns
|
|
1101
|
-
*/
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
const checkModules$1 = function (tmsConfig, modules) {
|
|
1105
|
-
const targetModules = [];
|
|
1106
|
-
modules.forEach(moduleName => {
|
|
1107
|
-
const module = tmsConfig.modules.find(module => module.name === moduleName);
|
|
1108
|
-
module && targetModules.push(module);
|
|
1109
|
-
});
|
|
1110
|
-
|
|
1111
|
-
if (targetModules.length === 0) {
|
|
1112
|
-
fail$5(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
|
|
1113
|
-
process.exit(1);
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
return targetModules;
|
|
1117
|
-
};
|
|
1118
|
-
/**
|
|
1119
|
-
* tms.config.js的modules 合并 module.config.json的配置项
|
|
1120
|
-
* @param {array} modules
|
|
1121
|
-
* @param {string} appName
|
|
1122
|
-
* @param {string} moduleDir
|
|
1123
|
-
* @returns
|
|
1124
|
-
*/
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
1128
|
-
const newModules = [];
|
|
1129
|
-
modules.forEach(({
|
|
1130
|
-
path: relativePath,
|
|
1131
|
-
name: moduleName
|
|
1132
|
-
}, moduleIndex) => {
|
|
1133
|
-
const moduleConfigPath = resolve$9(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
1134
|
-
|
|
1135
|
-
if (fs$8.existsSync(moduleConfigPath)) {
|
|
1136
|
-
try {
|
|
1137
|
-
let moduleConfigContent = fs$8.readFileSync(moduleConfigPath, 'utf-8');
|
|
1138
|
-
moduleConfigContent = setModuleConfig(moduleConfigContent, appName);
|
|
1139
|
-
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
1140
|
-
getValidModules(moduleContentArr).forEach(({
|
|
1141
|
-
name
|
|
1142
|
-
}, moduleContentArrIndex) => {
|
|
1143
|
-
if (name === moduleName) {
|
|
1144
|
-
newModules.push({ ...modules[moduleIndex],
|
|
1145
|
-
...moduleContentArr[moduleContentArrIndex]
|
|
1146
|
-
});
|
|
1147
|
-
}
|
|
1148
|
-
});
|
|
1149
|
-
} catch (e) {
|
|
1150
|
-
fail$5(`${moduleConfigPath}配置错误: ${e}`);
|
|
1151
|
-
newModules.push({ ...modules[moduleIndex]
|
|
1152
|
-
});
|
|
1153
|
-
}
|
|
1154
|
-
} else {
|
|
1155
|
-
newModules.push({ ...modules[moduleIndex]
|
|
1156
|
-
});
|
|
1157
|
-
}
|
|
1158
|
-
});
|
|
1159
|
-
return newModules;
|
|
1160
|
-
};
|
|
1161
|
-
/**
|
|
1162
|
-
* 分包依赖了分包的模块 合并所依赖的modules
|
|
1163
|
-
* @param { object } tmsConfig
|
|
1164
|
-
* @param {array} modules
|
|
1165
|
-
* @param {string} moduleDir
|
|
1166
|
-
* @returns
|
|
1237
|
+
const {
|
|
1238
|
+
handleError: handleError$3
|
|
1239
|
+
} = handleError_1;
|
|
1240
|
+
const {
|
|
1241
|
+
DEFAULT_CLOUD_MODULE_DIR
|
|
1242
|
+
} = require$$4;
|
|
1243
|
+
/**
|
|
1244
|
+
* 根据相关配置创建软链接
|
|
1245
|
+
* @param { object } tmsConfig
|
|
1167
1246
|
*/
|
|
1168
1247
|
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
})
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
modules.forEach(({
|
|
1180
|
-
dependencies: dependencyModules
|
|
1181
|
-
}) => {
|
|
1182
|
-
dependencyModules === null || dependencyModules === void 0 ? void 0 : dependencyModules.forEach(item => {
|
|
1183
|
-
// 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
|
|
1184
|
-
// 否则递归处理,根据name找到相关配置加到modules里
|
|
1185
|
-
if (moduleNames.indexOf(item) === -1) {
|
|
1186
|
-
isOver = false;
|
|
1187
|
-
const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
|
|
1188
|
-
mergeModules = [...mergeModules, ...tmpModules];
|
|
1189
|
-
mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
|
|
1190
|
-
}
|
|
1191
|
-
});
|
|
1192
|
-
});
|
|
1193
|
-
return isOver ? mergeModules : subModulesMergeDepModules$2(tmsConfig, mergeModules);
|
|
1248
|
+
const symLink$1 = tmsConfig => {
|
|
1249
|
+
try {
|
|
1250
|
+
if (tmsConfig.cloudModules) {
|
|
1251
|
+
tmsConfig.cloudModules.forEach(item => {
|
|
1252
|
+
fs$8.symlinkSync(resolve$a(item.path), resolve$a(DEFAULT_CLOUD_MODULE_DIR, item.name));
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
} catch (e) {
|
|
1256
|
+
handleError$3(`创建软链错误: ${e}`);
|
|
1257
|
+
}
|
|
1194
1258
|
};
|
|
1195
1259
|
|
|
1196
|
-
var
|
|
1197
|
-
|
|
1198
|
-
readTmsPrivateCf: readTmsPrivateCf$2,
|
|
1199
|
-
checkModules: checkModules$1,
|
|
1200
|
-
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
|
|
1201
|
-
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
1260
|
+
var symbolicLink = {
|
|
1261
|
+
symLink: symLink$1
|
|
1202
1262
|
};
|
|
1203
1263
|
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1264
|
+
/**
|
|
1265
|
+
* 下载第三方代码
|
|
1266
|
+
*/
|
|
1267
|
+
const MetalSmith = require$$0__default$5;
|
|
1268
|
+
const crypto$1 = require$$1__default$3;
|
|
1208
1269
|
const {
|
|
1209
1270
|
downloadRepoForGit,
|
|
1210
|
-
|
|
1271
|
+
pullRepoForGit,
|
|
1272
|
+
resolve: resolve$9
|
|
1211
1273
|
} = widgets;
|
|
1212
1274
|
const {
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
const fs$7 = require$$0__default$1;
|
|
1219
|
-
const shelljs$4 = require$$4__default;
|
|
1275
|
+
fail: fail$4,
|
|
1276
|
+
info: info$5
|
|
1277
|
+
} = log$1;
|
|
1278
|
+
const fs$7 = require$$0__default$2;
|
|
1279
|
+
const shelljs$4 = require$$0__default$3;
|
|
1220
1280
|
const {
|
|
1221
|
-
handleError: handleError$
|
|
1281
|
+
handleError: handleError$2
|
|
1222
1282
|
} = handleError_1;
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
*
|
|
1283
|
+
const {
|
|
1284
|
+
global: global$3
|
|
1285
|
+
} = global_1;
|
|
1286
|
+
/**
|
|
1287
|
+
* 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
|
|
1288
|
+
* @param {*} httpRepoUrl
|
|
1289
|
+
* @param {*} moduleName
|
|
1290
|
+
* @returns
|
|
1228
1291
|
*/
|
|
1229
1292
|
|
|
1230
|
-
function replaceGitUrlAccount(httpRepoUrl, moduleName
|
|
1231
|
-
var
|
|
1293
|
+
function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
1294
|
+
var _tmsPrivateCf$gitAcco;
|
|
1232
1295
|
|
|
1296
|
+
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1297
|
+
const tmsPrivateCf = global$3.getData('tmsPrivateCf');
|
|
1233
1298
|
let gitUrl = httpRepoUrl;
|
|
1234
1299
|
const {
|
|
1235
1300
|
username = '',
|
|
1236
1301
|
pass = ''
|
|
1237
|
-
} = (
|
|
1302
|
+
} = (tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : (_tmsPrivateCf$gitAcco = tmsPrivateCf.gitAccout) === null || _tmsPrivateCf$gitAcco === void 0 ? void 0 : _tmsPrivateCf$gitAcco[moduleName]) || {};
|
|
1238
1303
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
1239
1304
|
|
|
1240
1305
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -1243,12 +1308,12 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName, privateCf) {
|
|
|
1243
1308
|
|
|
1244
1309
|
return gitUrl;
|
|
1245
1310
|
}
|
|
1246
|
-
/**
|
|
1247
|
-
* 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
|
|
1248
|
-
* @param { string } sourceDir 缓存文件夹
|
|
1249
|
-
* @param { string } targetDir 目标文件夹
|
|
1250
|
-
* @param { arrary } ignore
|
|
1251
|
-
* @returns { undefined } no return
|
|
1311
|
+
/**
|
|
1312
|
+
* 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
|
|
1313
|
+
* @param { string } sourceDir 缓存文件夹
|
|
1314
|
+
* @param { string } targetDir 目标文件夹
|
|
1315
|
+
* @param { arrary } ignore
|
|
1316
|
+
* @returns { undefined } no return
|
|
1252
1317
|
*/
|
|
1253
1318
|
|
|
1254
1319
|
|
|
@@ -1265,82 +1330,183 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
1265
1330
|
});
|
|
1266
1331
|
});
|
|
1267
1332
|
}
|
|
1268
|
-
/**
|
|
1269
|
-
*
|
|
1270
|
-
* @param {
|
|
1271
|
-
* @param {
|
|
1272
|
-
* @
|
|
1273
|
-
* @returns { array } modules 描述模块的列表
|
|
1333
|
+
/**
|
|
1334
|
+
* 根据gitUrl 和 branch取md5值
|
|
1335
|
+
* @param {*} gitUrl
|
|
1336
|
+
* @param {*} branch
|
|
1337
|
+
* @returns
|
|
1274
1338
|
*/
|
|
1275
1339
|
|
|
1276
1340
|
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1341
|
+
function md5ByGitUrlBranch(gitUrl, branch) {
|
|
1342
|
+
const newBranch = branch && typeof branch === 'string' ? branch : 'master';
|
|
1343
|
+
return crypto$1.createHash('md5').update(JSON.stringify({
|
|
1344
|
+
gitUrl,
|
|
1345
|
+
branch: newBranch
|
|
1346
|
+
})).digest('hex');
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* 下载目标模块
|
|
1350
|
+
* @param { string } sourceDir 缓存文件夹
|
|
1351
|
+
* @param { string } targetDir 目标文件夹
|
|
1352
|
+
* @returns { array } modules 描述模块的列表
|
|
1353
|
+
*/
|
|
1280
1354
|
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1355
|
+
|
|
1356
|
+
async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
1357
|
+
// 收集下载模块代码的任务
|
|
1358
|
+
const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules); // 开始执行下载和移动代码的任务
|
|
1359
|
+
|
|
1360
|
+
const arrPromises = [];
|
|
1361
|
+
downloadTasksMap.forEach(({
|
|
1362
|
+
promiseTask,
|
|
1363
|
+
params,
|
|
1364
|
+
callbacks
|
|
1365
|
+
}) => {
|
|
1366
|
+
arrPromises.push(promiseTask(...Object.keys(params).map(key => params[key])).then(async () => {
|
|
1367
|
+
const callArr = callbacks.map(async ({
|
|
1368
|
+
params: cParams,
|
|
1369
|
+
fn
|
|
1370
|
+
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1371
|
+
return Promise.all(callArr);
|
|
1372
|
+
}).catch(e => {
|
|
1373
|
+
handleError$2(`下载代码${params.httpRepoUrl}出现错误:${e}`);
|
|
1374
|
+
}));
|
|
1375
|
+
});
|
|
1376
|
+
await Promise.all(arrPromises);
|
|
1286
1377
|
}
|
|
1287
|
-
/**
|
|
1288
|
-
*
|
|
1289
|
-
* @param { string } sourceDir 代码缓存文件夹
|
|
1290
|
-
* @param { string } targetDir 代码要放到的目标文件夹
|
|
1291
|
-
* @
|
|
1292
|
-
* @returns { array } moduleInfo 描述模块的信息
|
|
1378
|
+
/**
|
|
1379
|
+
* 收集下载模块代码的任务
|
|
1380
|
+
* @param { string } sourceDir 代码缓存文件夹
|
|
1381
|
+
* @param { string } targetDir 代码要放到的目标文件夹
|
|
1382
|
+
* @returns { array } modules 描述模块的列表
|
|
1293
1383
|
*/
|
|
1294
1384
|
|
|
1295
1385
|
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1386
|
+
function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
1387
|
+
// 下载代码任务 Map (key解释 缓存代码路径/md5(gitUrl,branch)
|
|
1388
|
+
// {
|
|
1389
|
+
// '/Users/odile/.tmskit/modules_code/026cb72509c2369dbd75779181f820bc': {
|
|
1390
|
+
// promiseTask, 下载代码的任务
|
|
1391
|
+
// params: { 下载代码时的参数
|
|
1392
|
+
// gitUrl,
|
|
1393
|
+
// sourcePath,
|
|
1394
|
+
// branch,
|
|
1395
|
+
// },
|
|
1396
|
+
// callbacks: [callback],// 下载完代码后的回调
|
|
1397
|
+
// }
|
|
1398
|
+
// }
|
|
1399
|
+
const downloadTasksMap = new Map();
|
|
1305
1400
|
|
|
1306
|
-
|
|
1401
|
+
for (const moduleInfo of modules) {
|
|
1402
|
+
if (moduleInfo.repoInfo) {
|
|
1403
|
+
const {
|
|
1404
|
+
repoInfo: {
|
|
1405
|
+
buildGitTag: branch,
|
|
1406
|
+
httpRepoUrl,
|
|
1407
|
+
path: gitPath = ''
|
|
1408
|
+
},
|
|
1409
|
+
path,
|
|
1410
|
+
name
|
|
1411
|
+
} = moduleInfo; // 处理仓库权限问题
|
|
1307
1412
|
|
|
1308
|
-
|
|
1413
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name); // 根据gitUrl与branch计算md5
|
|
1309
1414
|
|
|
1310
|
-
|
|
1415
|
+
const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
|
|
1311
1416
|
|
|
1312
|
-
|
|
1313
|
-
const moduleInCache = globalInstance.getModuleCache(httpRepoUrl, cloneBranch);
|
|
1417
|
+
const sourcePath = resolve$9(sourceDir, md5Key); // 模块源码要放到目标目录
|
|
1314
1418
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
//
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1419
|
+
const targetPath = resolve$9(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
|
|
1420
|
+
|
|
1421
|
+
const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
|
|
1422
|
+
|
|
1423
|
+
const callback = {
|
|
1424
|
+
params: {
|
|
1425
|
+
sourceModulePath,
|
|
1426
|
+
targetPath
|
|
1427
|
+
},
|
|
1428
|
+
fn: async (sourceModulePath, targetPath) => {
|
|
1429
|
+
if (fs$7.existsSync(targetPath)) {
|
|
1430
|
+
shelljs$4.rm('-rf', `${targetPath}/*`);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1324
1436
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1437
|
+
if (downloadTasksMap.has(sourcePath)) {
|
|
1438
|
+
const task = downloadTasksMap.get(sourcePath);
|
|
1439
|
+
task.callbacks.push(callback);
|
|
1440
|
+
downloadTasksMap.set(sourcePath, task);
|
|
1441
|
+
} else {
|
|
1442
|
+
let promiseTask;
|
|
1443
|
+
|
|
1444
|
+
if (fs$7.existsSync(sourcePath) && fs$7.existsSync(`${sourcePath}/.git`)) {
|
|
1445
|
+
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1446
|
+
info$5(`git pull仓库:${httpRepoUrl}`);
|
|
1447
|
+
return pullRepoForGit(sourcePath, branch);
|
|
1448
|
+
};
|
|
1449
|
+
} else {
|
|
1450
|
+
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1451
|
+
info$5(`git clone仓库: ${httpRepoUrl}`);
|
|
1452
|
+
return downloadRepoForGit(gitUrl, sourcePath, branch);
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
downloadTasksMap.set(sourcePath, {
|
|
1457
|
+
promiseTask,
|
|
1458
|
+
params: {
|
|
1459
|
+
gitUrl,
|
|
1460
|
+
sourcePath,
|
|
1461
|
+
branch,
|
|
1462
|
+
httpRepoUrl
|
|
1463
|
+
},
|
|
1464
|
+
callbacks: [callback]
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1327
1467
|
}
|
|
1468
|
+
}
|
|
1328
1469
|
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1470
|
+
return downloadTasksMap;
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* 检查远程模块的gitUrl与 branch是否有更新
|
|
1474
|
+
* @param {string} sourceDir 模块源码在缓存区的目录
|
|
1475
|
+
* @param {object} moduleInfo 模块的配置信息
|
|
1476
|
+
* @returns
|
|
1477
|
+
*/
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
function checkRemoteModGitUrlBranch$1(sourceDir, moduleInfo) {
|
|
1481
|
+
if (moduleInfo.repoInfo) {
|
|
1482
|
+
const {
|
|
1483
|
+
repoInfo: {
|
|
1484
|
+
buildGitTag,
|
|
1485
|
+
httpRepoUrl
|
|
1486
|
+
},
|
|
1487
|
+
name
|
|
1488
|
+
} = moduleInfo;
|
|
1489
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
|
|
1490
|
+
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1491
|
+
|
|
1492
|
+
if (!fs$7.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
1493
|
+
return true;
|
|
1494
|
+
}
|
|
1332
1495
|
}
|
|
1496
|
+
|
|
1497
|
+
return false;
|
|
1333
1498
|
}
|
|
1334
1499
|
|
|
1335
1500
|
var cloneModules_1 = {
|
|
1336
|
-
cloneModules: cloneModules$1
|
|
1501
|
+
cloneModules: cloneModules$1,
|
|
1502
|
+
checkRemoteModGitUrlBranch: checkRemoteModGitUrlBranch$1
|
|
1337
1503
|
};
|
|
1338
1504
|
|
|
1339
|
-
const ci = require$$0__default$
|
|
1505
|
+
const ci = require$$0__default$7;
|
|
1340
1506
|
const path$5 = require$$3__default;
|
|
1341
|
-
/**
|
|
1342
|
-
* 获取小程序ci的Project对象
|
|
1343
|
-
* @returns {Object} 小程序ci对象
|
|
1507
|
+
/**
|
|
1508
|
+
* 获取小程序ci的Project对象
|
|
1509
|
+
* @returns {Object} 小程序ci对象
|
|
1344
1510
|
*/
|
|
1345
1511
|
|
|
1346
1512
|
const getMpCi = ({
|
|
@@ -1371,10 +1537,10 @@ const packMpProject = async project => {
|
|
|
1371
1537
|
ignores: ['cloud/**/*']
|
|
1372
1538
|
});
|
|
1373
1539
|
};
|
|
1374
|
-
/**
|
|
1375
|
-
* 格式化构建npm结果信息
|
|
1376
|
-
* @param {Array<String>} warning 构建时的告警信息
|
|
1377
|
-
* @returns {String} npm构建错误信息
|
|
1540
|
+
/**
|
|
1541
|
+
* 格式化构建npm结果信息
|
|
1542
|
+
* @param {Array<String>} warning 构建时的告警信息
|
|
1543
|
+
* @returns {String} npm构建错误信息
|
|
1378
1544
|
*/
|
|
1379
1545
|
|
|
1380
1546
|
|
|
@@ -1387,9 +1553,9 @@ const formatPackNpmWarning = warning => {
|
|
|
1387
1553
|
\t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
|
|
1388
1554
|
return result;
|
|
1389
1555
|
};
|
|
1390
|
-
/**
|
|
1391
|
-
* 构建miniprogram_npm
|
|
1392
|
-
* @returns {Object} 小程序ci对象
|
|
1556
|
+
/**
|
|
1557
|
+
* 构建miniprogram_npm
|
|
1558
|
+
* @returns {Object} 小程序ci对象
|
|
1393
1559
|
*/
|
|
1394
1560
|
|
|
1395
1561
|
|
|
@@ -1413,108 +1579,165 @@ const buildMpNpm$1 = async ({
|
|
|
1413
1579
|
return Promise.resolve();
|
|
1414
1580
|
};
|
|
1415
1581
|
|
|
1416
|
-
var
|
|
1582
|
+
var mpCi = {
|
|
1417
1583
|
buildMpNpm: buildMpNpm$1
|
|
1418
1584
|
};
|
|
1419
1585
|
|
|
1420
|
-
/**
|
|
1421
|
-
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1586
|
+
/**
|
|
1587
|
+
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1422
1588
|
*/
|
|
1423
|
-
const fs$6 = require$$0__default$
|
|
1424
|
-
const fsExtra = require$$1__default$
|
|
1425
|
-
const crypto = require$$
|
|
1589
|
+
const fs$6 = require$$0__default$2;
|
|
1590
|
+
const fsExtra = require$$1__default$4;
|
|
1591
|
+
const crypto = require$$1__default$3;
|
|
1426
1592
|
const path$4 = require$$3__default;
|
|
1427
|
-
const shell = require$$
|
|
1593
|
+
const shell = require$$0__default$3;
|
|
1428
1594
|
const glob = require$$5__default;
|
|
1429
|
-
const
|
|
1595
|
+
const log = log$1;
|
|
1596
|
+
const {
|
|
1597
|
+
npmInstall
|
|
1598
|
+
} = widgets;
|
|
1599
|
+
const {
|
|
1600
|
+
handleError: handleError$1
|
|
1601
|
+
} = handleError_1;
|
|
1602
|
+
const {
|
|
1603
|
+
info: info$4
|
|
1604
|
+
} = require$$9__default;
|
|
1430
1605
|
const shellJsOption = {
|
|
1431
1606
|
async: false,
|
|
1432
1607
|
silent: true
|
|
1433
1608
|
};
|
|
1434
1609
|
const dirPath = process.cwd(); // 项目根目录
|
|
1435
1610
|
|
|
1436
|
-
const
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
//
|
|
1442
|
-
//
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
//
|
|
1448
|
-
//
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
const
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
const missCache = !fsExtra.pathExistsSync(keyPath) || !fsExtra.existsSync(tarFile) || fsExtra.statSync(tarFile).size < 512;
|
|
1611
|
+
const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
1612
|
+
// 下载代码任务 Map (key解释 缓存代码路径/md5(package.json.dependencies)
|
|
1613
|
+
// {
|
|
1614
|
+
// '/Users/odile/.tmskit/node_modules/026cb72509c2369dbd75779181f820bc': {
|
|
1615
|
+
// promiseTask, 下载的任务
|
|
1616
|
+
// params: { 下载代码时的参数
|
|
1617
|
+
// gitUrl,
|
|
1618
|
+
// sourcePath,
|
|
1619
|
+
// branch,
|
|
1620
|
+
// },
|
|
1621
|
+
// callbacks: [callback],// 下载完代码后的回调
|
|
1622
|
+
// }
|
|
1623
|
+
// }
|
|
1624
|
+
const npmTasksMap = new Map();
|
|
1625
|
+
|
|
1626
|
+
for (const packageJsonPath of packageJsonFiles) {
|
|
1627
|
+
const packageContent = fs$6.readFileSync(packageJsonPath);
|
|
1628
|
+
const packageJson = JSON.parse(packageContent);
|
|
1629
|
+
const md5Obj = {
|
|
1630
|
+
dependencies: packageJson.dependencies || {}
|
|
1631
|
+
};
|
|
1459
1632
|
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1633
|
+
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
1634
|
+
const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1635
|
+
const cacheNMPath = path$4.join(cacheDir, md5Key);
|
|
1636
|
+
const cacheNMTarFile = path$4.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
1637
|
+
|
|
1638
|
+
const callback = {
|
|
1639
|
+
params: {
|
|
1640
|
+
cacheNMPath,
|
|
1641
|
+
cacheNMTarFile,
|
|
1642
|
+
packageJsonDir: path$4.dirname(packageJsonPath),
|
|
1643
|
+
shell
|
|
1644
|
+
},
|
|
1645
|
+
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
1646
|
+
shell.cd(cacheNMPath);
|
|
1647
|
+
shell.cp('-Rf', cacheNMTarFile, `${packageJsonDir}/`);
|
|
1648
|
+
const newShellJsOption = { ...shellJsOption,
|
|
1649
|
+
cwd: packageJsonDir
|
|
1650
|
+
};
|
|
1651
|
+
shell.exec('tar -xzvf ./node_modules.tar.gz -C ./', newShellJsOption);
|
|
1652
|
+
shell.exec('rm -rf ./node_modules.tar.gz', newShellJsOption);
|
|
1653
|
+
}
|
|
1654
|
+
};
|
|
1465
1655
|
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1656
|
+
if (npmTasksMap.has(cacheNMPath)) {
|
|
1657
|
+
const task = npmTasksMap.get(cacheNMPath);
|
|
1658
|
+
task.callbacks.push(callback);
|
|
1659
|
+
npmTasksMap.set(cacheNMPath, task);
|
|
1660
|
+
} else {
|
|
1661
|
+
const missCache = !fsExtra.pathExistsSync(cacheNMPath) || !fsExtra.existsSync(cacheNMTarFile) || fsExtra.statSync(cacheNMTarFile).size < 512;
|
|
1662
|
+
|
|
1663
|
+
let promiseTask = () => Promise.resolve();
|
|
1664
|
+
|
|
1665
|
+
if (missCache) {
|
|
1666
|
+
promiseTask = (packageJsonPath, cacheNMPath, shell) => {
|
|
1667
|
+
fsExtra.emptydirSync(cacheNMPath);
|
|
1668
|
+
shell.cp('-f', packageJsonPath, cacheNMPath);
|
|
1669
|
+
info$4(`npm install: ${packageJsonPath}`);
|
|
1670
|
+
return npmInstall(cacheNMPath).then(() => {
|
|
1671
|
+
const newShellJsOption = { ...shellJsOption,
|
|
1672
|
+
cwd: cacheNMPath
|
|
1673
|
+
};
|
|
1674
|
+
shell.exec('tar -zcvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
|
|
1675
|
+
shell.exec('rm -rf ./node_modules', newShellJsOption);
|
|
1676
|
+
});
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1470
1679
|
|
|
1471
|
-
|
|
1472
|
-
|
|
1680
|
+
npmTasksMap.set(cacheNMPath, {
|
|
1681
|
+
promiseTask,
|
|
1682
|
+
params: {
|
|
1683
|
+
packageJsonPath,
|
|
1684
|
+
cacheNMPath,
|
|
1685
|
+
shell
|
|
1686
|
+
},
|
|
1687
|
+
callbacks: [callback]
|
|
1688
|
+
});
|
|
1473
1689
|
}
|
|
1474
|
-
|
|
1475
|
-
throw err;
|
|
1476
1690
|
}
|
|
1477
|
-
|
|
1478
|
-
shell.exec('tar -zcvf ./node_modules.tar.gz ./node_modules', shellJsOption);
|
|
1479
|
-
shell.exec('rm -rf ./node_modules', shellJsOption);
|
|
1480
1691
|
}
|
|
1481
1692
|
|
|
1482
|
-
|
|
1483
|
-
shell.cd(path$4.dirname(packageJsonPath));
|
|
1484
|
-
shell.exec('tar -xzvf ./node_modules.tar.gz -C ./', shellJsOption);
|
|
1485
|
-
shell.exec('rm -rf ./node_modules.tar.gz', shellJsOption);
|
|
1486
|
-
return {
|
|
1487
|
-
missCache,
|
|
1488
|
-
key
|
|
1489
|
-
};
|
|
1693
|
+
return npmTasksMap;
|
|
1490
1694
|
}; // 遍历安装指定目录下所有项目的npm依赖
|
|
1491
1695
|
|
|
1492
1696
|
|
|
1493
1697
|
const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
1494
|
-
const packageJsonFiles = await findAllPackageJson(modules, contextDir);
|
|
1495
|
-
|
|
1698
|
+
const packageJsonFiles = await findAllPackageJson(modules, contextDir); // 收集npm install的任务
|
|
1699
|
+
|
|
1700
|
+
const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir); // 开始执行npm install和回调(移动)的任务
|
|
1701
|
+
|
|
1702
|
+
const arrPromises = [];
|
|
1703
|
+
npmTasksMap.forEach(({
|
|
1704
|
+
promiseTask,
|
|
1705
|
+
params,
|
|
1706
|
+
callbacks
|
|
1707
|
+
}) => {
|
|
1708
|
+
arrPromises.push(promiseTask(...Object.keys(params).map(key => params[key])).then(async () => {
|
|
1709
|
+
const callArr = callbacks.map(async ({
|
|
1710
|
+
params: cParams,
|
|
1711
|
+
fn
|
|
1712
|
+
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1713
|
+
return Promise.all(callArr);
|
|
1714
|
+
}).catch(e => {
|
|
1715
|
+
handleError$1(`npm install ${params.packageJsonPath}出现错误:${e}`);
|
|
1716
|
+
}));
|
|
1717
|
+
});
|
|
1718
|
+
await Promise.all(arrPromises);
|
|
1496
1719
|
};
|
|
1497
|
-
/**
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1720
|
+
/**
|
|
1721
|
+
* 递归查找指定条件的文件
|
|
1722
|
+
* @param {String} startPath 开始查找的根路径
|
|
1723
|
+
* @param {String} filter 匹配的字符串
|
|
1724
|
+
* @returns {Array<String>} 查找到的文件路径列表
|
|
1725
|
+
*/
|
|
1503
1726
|
|
|
1504
1727
|
|
|
1505
1728
|
const findFilesByFilter = (startPath, filter) => {
|
|
1506
1729
|
const result = [];
|
|
1507
|
-
/**
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1730
|
+
/**
|
|
1731
|
+
* 根据指定的筛选器查找文件
|
|
1732
|
+
* @param {String} startPath 开始查找的文件夹路径
|
|
1733
|
+
* @param {String} filter 筛选器
|
|
1734
|
+
* @returns {Undefined} 无需返回值
|
|
1735
|
+
*/
|
|
1513
1736
|
|
|
1514
1737
|
const find = (startPath, filter) => {
|
|
1515
1738
|
// 目录不存在
|
|
1516
1739
|
if (!fs$6.existsSync(startPath)) {
|
|
1517
|
-
|
|
1740
|
+
log.fail(`${startPath}目录不存在`);
|
|
1518
1741
|
process.exit(-1);
|
|
1519
1742
|
return;
|
|
1520
1743
|
} // 当前目录下的所有文件 / 文件夹
|
|
@@ -1543,12 +1766,12 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1543
1766
|
find(startPath, filter);
|
|
1544
1767
|
return result;
|
|
1545
1768
|
};
|
|
1546
|
-
/**
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1769
|
+
/**
|
|
1770
|
+
* 找到项目中所有的package.json文件
|
|
1771
|
+
* @param {Array<String>} subRoots 需要安装npm依赖的路径
|
|
1772
|
+
* @param {String} contextDir 命令运行的目录
|
|
1773
|
+
* @returns {Array<String>} 找到的所有package.json文件的路径
|
|
1774
|
+
*/
|
|
1552
1775
|
|
|
1553
1776
|
|
|
1554
1777
|
const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
@@ -1559,7 +1782,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1559
1782
|
|
|
1560
1783
|
subRoots.forEach(subRoot => {
|
|
1561
1784
|
if (!subRoot.root) {
|
|
1562
|
-
|
|
1785
|
+
log.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
|
|
1563
1786
|
process.exit(1);
|
|
1564
1787
|
}
|
|
1565
1788
|
|
|
@@ -1590,123 +1813,133 @@ function cloudNpmInstall$1(contextDir) {
|
|
|
1590
1813
|
});
|
|
1591
1814
|
}
|
|
1592
1815
|
|
|
1593
|
-
var
|
|
1816
|
+
var npm = {
|
|
1594
1817
|
cloudNpmInstall: cloudNpmInstall$1,
|
|
1595
1818
|
mpNpmInstallAll: mpNpmInstallAll$1,
|
|
1596
1819
|
findAllPackageJson
|
|
1597
1820
|
};
|
|
1598
1821
|
|
|
1599
1822
|
const {
|
|
1600
|
-
createTask: createTask$
|
|
1601
|
-
resolve: resolve$
|
|
1823
|
+
createTask: createTask$1,
|
|
1824
|
+
resolve: resolve$8
|
|
1602
1825
|
} = widgets;
|
|
1603
1826
|
const {
|
|
1604
1827
|
buildMpNpm
|
|
1605
|
-
} =
|
|
1828
|
+
} = mpCi;
|
|
1606
1829
|
const {
|
|
1607
1830
|
CACHE_DIR
|
|
1608
|
-
} = require$$
|
|
1831
|
+
} = require$$4;
|
|
1609
1832
|
const {
|
|
1610
1833
|
cloudNpmInstall,
|
|
1611
1834
|
mpNpmInstallAll
|
|
1612
|
-
} =
|
|
1835
|
+
} = npm;
|
|
1836
|
+
const {
|
|
1837
|
+
global: global$2
|
|
1838
|
+
} = global_1;
|
|
1613
1839
|
|
|
1614
1840
|
async function install$2(tmsConfig, modules, isCloud = false) {
|
|
1615
1841
|
// 小程序npm install
|
|
1616
|
-
await createTask$
|
|
1842
|
+
await createTask$1(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$8(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
|
|
1843
|
+
const tmsPrivateCf = global$2.getData('tmsPrivateCf'); // 构建miniprogram_npm
|
|
1617
1844
|
|
|
1618
|
-
await createTask$
|
|
1845
|
+
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
1619
1846
|
appId: tmsConfig.appId,
|
|
1620
|
-
projectPath: resolve$
|
|
1621
|
-
privateKey:
|
|
1847
|
+
projectPath: resolve$8('./'),
|
|
1848
|
+
privateKey: tmsPrivateCf.privateKey
|
|
1622
1849
|
}); // 安装云函数的
|
|
1623
1850
|
|
|
1624
|
-
isCloud && createTask$
|
|
1851
|
+
isCloud && createTask$1(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$8(tmsConfig.cloudDir));
|
|
1625
1852
|
}
|
|
1626
1853
|
|
|
1627
1854
|
var install_1 = install$2;
|
|
1628
1855
|
|
|
1629
|
-
const shelljs$3 = require$$
|
|
1630
|
-
const fs$5 = require$$0__default$
|
|
1856
|
+
const shelljs$3 = require$$0__default$3;
|
|
1857
|
+
const fs$5 = require$$0__default$2;
|
|
1631
1858
|
const io = io$2;
|
|
1632
1859
|
const {
|
|
1633
|
-
resolve: resolve$
|
|
1634
|
-
createTask
|
|
1860
|
+
resolve: resolve$7,
|
|
1861
|
+
createTask
|
|
1635
1862
|
} = widgets;
|
|
1636
1863
|
const {
|
|
1637
1864
|
buildOutputAppJson
|
|
1638
1865
|
} = buildAppJson;
|
|
1639
1866
|
const {
|
|
1640
|
-
|
|
1867
|
+
symLink
|
|
1868
|
+
} = symbolicLink;
|
|
1869
|
+
const {
|
|
1870
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
1641
1871
|
DEFAULT_COPY_CONFIG
|
|
1642
|
-
} = require$$
|
|
1872
|
+
} = require$$4;
|
|
1643
1873
|
const {
|
|
1644
1874
|
cloneModules
|
|
1645
1875
|
} = cloneModules_1;
|
|
1646
1876
|
const {
|
|
1647
1877
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2,
|
|
1648
1878
|
subModulesMergeDepModules: subModulesMergeDepModules$1
|
|
1649
|
-
} =
|
|
1879
|
+
} = tmsMpconfig;
|
|
1650
1880
|
const {
|
|
1651
|
-
fail: fail$3
|
|
1652
|
-
|
|
1881
|
+
fail: fail$3,
|
|
1882
|
+
info: info$3
|
|
1883
|
+
} = log$1;
|
|
1653
1884
|
const install$1 = install_1;
|
|
1654
|
-
/**
|
|
1655
|
-
* 拷贝相关配置文件到编译输出目录
|
|
1656
|
-
* @param { object } tmsConfig
|
|
1657
|
-
* @param { array } modules
|
|
1658
|
-
* @param { array } defaultFiles 默认需要拷贝的配置项
|
|
1659
|
-
* @returns
|
|
1885
|
+
/**
|
|
1886
|
+
* 拷贝相关配置文件到编译输出目录
|
|
1887
|
+
* @param { object } tmsConfig
|
|
1888
|
+
* @param { array } modules
|
|
1889
|
+
* @param { array } defaultFiles 默认需要拷贝的配置项
|
|
1890
|
+
* @returns
|
|
1660
1891
|
*/
|
|
1661
1892
|
|
|
1662
1893
|
const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
1663
|
-
const outputDir = resolve$
|
|
1894
|
+
const outputDir = resolve$7(tmsConfig.outputDir);
|
|
1664
1895
|
io.ensureDirExist(outputDir);
|
|
1665
1896
|
defaultFiles.forEach(item => {
|
|
1666
|
-
if (fs$5.existsSync(resolve$
|
|
1667
|
-
shelljs$3.cp('-rf', resolve$
|
|
1897
|
+
if (fs$5.existsSync(resolve$7(item))) {
|
|
1898
|
+
shelljs$3.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
|
|
1668
1899
|
}
|
|
1669
1900
|
}); // 拷贝模块的package.json到编译输出目录
|
|
1670
1901
|
|
|
1671
1902
|
targetModules.forEach(item => {
|
|
1672
|
-
const outputModuleDir = resolve$
|
|
1903
|
+
const outputModuleDir = resolve$7(`${tmsConfig.outputDir}/${item.root}`);
|
|
1673
1904
|
|
|
1674
|
-
if (!fs$5.existsSync(resolve$
|
|
1905
|
+
if (!fs$5.existsSync(resolve$7(item.path))) {
|
|
1675
1906
|
fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1676
1907
|
process.exit(1);
|
|
1677
1908
|
}
|
|
1678
1909
|
|
|
1679
1910
|
io.ensureDirExist(outputModuleDir);
|
|
1680
|
-
const modulePackagePath = resolve$
|
|
1911
|
+
const modulePackagePath = resolve$7(item.path, 'package.json');
|
|
1681
1912
|
if (fs$5.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1682
1913
|
});
|
|
1683
1914
|
};
|
|
1684
1915
|
|
|
1685
|
-
async function task(tmsConfig, targetModules
|
|
1916
|
+
async function task(tmsConfig, targetModules) {
|
|
1686
1917
|
// 下载和移动代码
|
|
1687
|
-
await createTask
|
|
1918
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$7('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1688
1919
|
|
|
1689
1920
|
let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
1690
1921
|
|
|
1691
1922
|
newModules = subModulesMergeDepModules$1(tmsConfig, newModules); // 拷贝相关配置文件到输出目录
|
|
1692
1923
|
|
|
1693
|
-
await createTask
|
|
1924
|
+
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
|
|
1694
1925
|
|
|
1695
1926
|
await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
|
|
1696
1927
|
|
|
1697
|
-
await createTask
|
|
1928
|
+
await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
1929
|
+
await createTask(symLink, '开始创建软链接', '创建软链接完成')(tmsConfig);
|
|
1698
1930
|
return newModules;
|
|
1699
1931
|
}
|
|
1700
1932
|
|
|
1701
|
-
async function init$5(tmsConfig, targetModules
|
|
1933
|
+
async function init$5(tmsConfig, targetModules) {
|
|
1702
1934
|
try {
|
|
1703
|
-
const newModules = await task(tmsConfig, targetModules
|
|
1935
|
+
const newModules = await task(tmsConfig, targetModules);
|
|
1704
1936
|
return {
|
|
1705
1937
|
targetModules: newModules
|
|
1706
1938
|
};
|
|
1707
1939
|
} catch (error) {
|
|
1708
1940
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1709
1941
|
fail$3(`init流程出现错误${errMsg}`);
|
|
1942
|
+
info$3('详细的错误信息', error);
|
|
1710
1943
|
process.exit(1);
|
|
1711
1944
|
}
|
|
1712
1945
|
}
|
|
@@ -1715,45 +1948,14 @@ var init_1 = init$5;
|
|
|
1715
1948
|
|
|
1716
1949
|
var dev$3 = {exports: {}};
|
|
1717
1950
|
|
|
1718
|
-
const through$3 = require$$0__default$7;
|
|
1719
|
-
|
|
1720
|
-
function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
|
|
1721
|
-
const stream = through$3.obj(function (file, enc, cb) {
|
|
1722
|
-
if (file.isBuffer()) {
|
|
1723
|
-
let contents = String(file.contents);
|
|
1724
|
-
let resReg; // eslint-disable-next-line
|
|
1725
|
-
|
|
1726
|
-
while ((resReg = reg.exec(contents)) !== null) {
|
|
1727
|
-
const [reg1, reg2, reg3] = resReg;
|
|
1728
|
-
|
|
1729
|
-
if (reg1 && reg2 && reg3) {
|
|
1730
|
-
const value = typeof envData[reg3] === 'object' ? JSON.stringify(envData[reg3]) : envData[reg3];
|
|
1731
|
-
contents = contents.replace(reg1, value);
|
|
1732
|
-
} else if (reg1 && !reg2 && !reg3) {
|
|
1733
|
-
contents = contents.replace(reg1, JSON.stringify(envData));
|
|
1734
|
-
}
|
|
1735
|
-
} // eslint-disable-next-line
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
file.contents = Buffer.from(contents);
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
this.push(file);
|
|
1742
|
-
cb();
|
|
1743
|
-
});
|
|
1744
|
-
return stream;
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
var replaceEnv_1 = replaceEnv$1;
|
|
1748
|
-
|
|
1749
1951
|
/* eslint-disable no-param-reassign */
|
|
1750
1952
|
const strip = require$$0__default$8; // 匹配规则
|
|
1751
1953
|
|
|
1752
1954
|
const MATCH_RULE = new RegExp(/@import *(?:url\(['"]?([^'")]+)['"]?\)|['"]([^'"]+)['"]);?/g);
|
|
1753
|
-
/**
|
|
1754
|
-
* 获取样式文件中的@import语句
|
|
1755
|
-
* @param code 代码片段
|
|
1756
|
-
* @returns 结果数组
|
|
1955
|
+
/**
|
|
1956
|
+
* 获取样式文件中的@import语句
|
|
1957
|
+
* @param code 代码片段
|
|
1958
|
+
* @returns 结果数组
|
|
1757
1959
|
*/
|
|
1758
1960
|
|
|
1759
1961
|
const findCssImports$1 = code => {
|
|
@@ -1783,7 +1985,7 @@ var findCssImport = {
|
|
|
1783
1985
|
/* eslint-disable no-param-reassign */
|
|
1784
1986
|
const {
|
|
1785
1987
|
fail: fail$2
|
|
1786
|
-
} = log$
|
|
1988
|
+
} = log$1;
|
|
1787
1989
|
|
|
1788
1990
|
function pluginError$3(error, isWatch) {
|
|
1789
1991
|
const errMsg = error.message;
|
|
@@ -1801,8 +2003,8 @@ var pluginError_1 = {
|
|
|
1801
2003
|
};
|
|
1802
2004
|
|
|
1803
2005
|
/* eslint-disable no-param-reassign */
|
|
1804
|
-
const through$2 = require$$0__default$
|
|
1805
|
-
const precinct = require$$1__default$
|
|
2006
|
+
const through$2 = require$$0__default$9;
|
|
2007
|
+
const precinct = require$$1__default$5;
|
|
1806
2008
|
const path$3 = require$$3__default;
|
|
1807
2009
|
const {
|
|
1808
2010
|
findCssImports
|
|
@@ -1813,9 +2015,9 @@ const {
|
|
|
1813
2015
|
diffContentCopyFile: diffContentCopyFile$2
|
|
1814
2016
|
} = io$2;
|
|
1815
2017
|
const {
|
|
1816
|
-
resolve: resolve$
|
|
2018
|
+
resolve: resolve$6
|
|
1817
2019
|
} = widgets;
|
|
1818
|
-
const fs$4 = require$$0__default$
|
|
2020
|
+
const fs$4 = require$$0__default$2;
|
|
1819
2021
|
const {
|
|
1820
2022
|
pluginError: pluginError$2
|
|
1821
2023
|
} = pluginError_1;
|
|
@@ -1850,7 +2052,7 @@ const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensi
|
|
|
1850
2052
|
return;
|
|
1851
2053
|
}
|
|
1852
2054
|
|
|
1853
|
-
const depDestPath = resolve$
|
|
2055
|
+
const depDestPath = resolve$6(path$3.dirname(anaFileDestFile), depItem);
|
|
1854
2056
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
1855
2057
|
|
|
1856
2058
|
if (!resDep.has(depDestFile)) {
|
|
@@ -1874,8 +2076,8 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
1874
2076
|
const stream = through$2.obj(function (file, enc, cb) {
|
|
1875
2077
|
// 依赖分析的文件
|
|
1876
2078
|
const anaFileOriginFile = file.history[0];
|
|
1877
|
-
const anaFileRelativeModule = path$3.relative(resolve$
|
|
1878
|
-
const anaFileDestFile = resolve$
|
|
2079
|
+
const anaFileRelativeModule = path$3.relative(resolve$6(module.from), anaFileOriginFile);
|
|
2080
|
+
const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
1879
2081
|
|
|
1880
2082
|
if (file.isBuffer()) {
|
|
1881
2083
|
let contents = String(file.contents);
|
|
@@ -1900,11 +2102,11 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
|
1900
2102
|
} // eslint-disable-next-line
|
|
1901
2103
|
|
|
1902
2104
|
|
|
1903
|
-
const reg = new RegExp(`^(
|
|
2105
|
+
const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
1904
2106
|
const regRes = depItem.match(reg) || [];
|
|
1905
2107
|
|
|
1906
2108
|
if (regRes[2]) {
|
|
1907
|
-
const depDestPath = resolve$
|
|
2109
|
+
const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
1908
2110
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
1909
2111
|
|
|
1910
2112
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -1949,7 +2151,7 @@ var mpCommonDep_1 = {
|
|
|
1949
2151
|
};
|
|
1950
2152
|
|
|
1951
2153
|
/* eslint-disable no-param-reassign */
|
|
1952
|
-
const through$1 = require$$0__default$
|
|
2154
|
+
const through$1 = require$$0__default$9;
|
|
1953
2155
|
const path$2 = require$$3__default;
|
|
1954
2156
|
const {
|
|
1955
2157
|
ext: ext$1,
|
|
@@ -1957,9 +2159,9 @@ const {
|
|
|
1957
2159
|
diffContentCopyFile: diffContentCopyFile$1
|
|
1958
2160
|
} = io$2;
|
|
1959
2161
|
const {
|
|
1960
|
-
resolve: resolve$
|
|
2162
|
+
resolve: resolve$5
|
|
1961
2163
|
} = widgets;
|
|
1962
|
-
const fs$3 = require$$0__default$
|
|
2164
|
+
const fs$3 = require$$0__default$2;
|
|
1963
2165
|
const {
|
|
1964
2166
|
pluginError: pluginError$1
|
|
1965
2167
|
} = pluginError_1;
|
|
@@ -1971,15 +2173,19 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
1971
2173
|
const stream = through$1.obj(function (file, enc, cb) {
|
|
1972
2174
|
// 当前分析的文件的路径
|
|
1973
2175
|
const anaFileOriginFile = file.history[0];
|
|
1974
|
-
const anaFileRelativeModule = path$2.relative(resolve$
|
|
1975
|
-
const anaFileDestFile = resolve$
|
|
2176
|
+
const anaFileRelativeModule = path$2.relative(resolve$5(module.from), anaFileOriginFile);
|
|
2177
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
1976
2178
|
|
|
1977
2179
|
if (file.isBuffer()) {
|
|
1978
|
-
const copyModules = new Map();
|
|
1979
2180
|
let contents = String(file.contents);
|
|
2181
|
+
const copyModules = new Map();
|
|
1980
2182
|
|
|
1981
2183
|
try {
|
|
1982
|
-
|
|
2184
|
+
try {
|
|
2185
|
+
contents = contents ? JSON.parse(contents) : {};
|
|
2186
|
+
} catch (e) {
|
|
2187
|
+
throw new Error(`解析${file.path}出现错误,请检查配置信息: ${e}`);
|
|
2188
|
+
}
|
|
1983
2189
|
|
|
1984
2190
|
if (contents.usingComponents) {
|
|
1985
2191
|
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
@@ -2003,11 +2209,11 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
|
|
|
2003
2209
|
} // eslint-disable-next-line
|
|
2004
2210
|
|
|
2005
2211
|
|
|
2006
|
-
const reg = new RegExp(`^(
|
|
2212
|
+
const reg = new RegExp(`^(\./\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2007
2213
|
const regRes = componentPath.match(reg) || [];
|
|
2008
2214
|
|
|
2009
2215
|
if (regRes[2]) {
|
|
2010
|
-
const depDestPath = resolve$
|
|
2216
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2011
2217
|
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2012
2218
|
|
|
2013
2219
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2073,9 +2279,9 @@ var mpJsonDep_1 = {
|
|
|
2073
2279
|
};
|
|
2074
2280
|
|
|
2075
2281
|
/* eslint-disable no-param-reassign */
|
|
2076
|
-
const through = require$$0__default$
|
|
2077
|
-
const htmlparser2 = require$$1__default$
|
|
2078
|
-
const fs$2 = require$$0__default$
|
|
2282
|
+
const through = require$$0__default$9;
|
|
2283
|
+
const htmlparser2 = require$$1__default$6;
|
|
2284
|
+
const fs$2 = require$$0__default$2;
|
|
2079
2285
|
const path$1 = require$$3__default;
|
|
2080
2286
|
const {
|
|
2081
2287
|
diffContentCopyFile,
|
|
@@ -2083,7 +2289,7 @@ const {
|
|
|
2083
2289
|
fileInDir
|
|
2084
2290
|
} = io$2;
|
|
2085
2291
|
const {
|
|
2086
|
-
resolve: resolve$
|
|
2292
|
+
resolve: resolve$4
|
|
2087
2293
|
} = widgets;
|
|
2088
2294
|
const {
|
|
2089
2295
|
dfsFindCommonDep
|
|
@@ -2197,8 +2403,8 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2197
2403
|
const stream = through.obj(function (file, enc, cb) {
|
|
2198
2404
|
// 依赖分析的文件
|
|
2199
2405
|
const anaFileOriginFile = file.history[0];
|
|
2200
|
-
const anaFileRelativeModule = path$1.relative(resolve$
|
|
2201
|
-
const anaFileDestFile = resolve$
|
|
2406
|
+
const anaFileRelativeModule = path$1.relative(resolve$4(module.from), anaFileOriginFile);
|
|
2407
|
+
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2202
2408
|
|
|
2203
2409
|
if (file.isBuffer()) {
|
|
2204
2410
|
let contents = String(file.contents);
|
|
@@ -2225,11 +2431,11 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
|
2225
2431
|
} // eslint-disable-next-line
|
|
2226
2432
|
|
|
2227
2433
|
|
|
2228
|
-
const reg = new RegExp(`^(
|
|
2434
|
+
const reg = new RegExp(`^(\./\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2229
2435
|
const regRes = attributes.src.match(reg) || [];
|
|
2230
2436
|
|
|
2231
2437
|
if (regRes[2]) {
|
|
2232
|
-
const depDestPath = resolve$
|
|
2438
|
+
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2233
2439
|
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2234
2440
|
|
|
2235
2441
|
if (!copyModules.has(depDestFile)) {
|
|
@@ -2296,12 +2502,12 @@ const {
|
|
|
2296
2502
|
src: src$1,
|
|
2297
2503
|
dest,
|
|
2298
2504
|
lastRun
|
|
2299
|
-
} = require$$0__default$
|
|
2300
|
-
const px2rpx = require$$1__default$
|
|
2301
|
-
const watch = require$$2__default$
|
|
2505
|
+
} = require$$0__default$a;
|
|
2506
|
+
const px2rpx = require$$1__default$7;
|
|
2507
|
+
const watch = require$$2__default$1; // const cache = require('gulp-cache');
|
|
2302
2508
|
// const image = require('gulp-image');
|
|
2509
|
+
// const replaceEnv = require('./plugins/replaceEnv');
|
|
2303
2510
|
|
|
2304
|
-
const replaceEnv = replaceEnv_1;
|
|
2305
2511
|
const {
|
|
2306
2512
|
mpCommonDep
|
|
2307
2513
|
} = mpCommonDep_1;
|
|
@@ -2310,10 +2516,12 @@ const {
|
|
|
2310
2516
|
} = mpJsonDep_1;
|
|
2311
2517
|
const {
|
|
2312
2518
|
mpWxmlDep
|
|
2313
|
-
} = mpWxmlDep_1;
|
|
2519
|
+
} = mpWxmlDep_1; // const postcss = require('gulp-postcss');
|
|
2520
|
+
// const base64 = require('./plugins/postcss-font-base64');
|
|
2521
|
+
|
|
2314
2522
|
const {
|
|
2315
2523
|
fail: fail$1
|
|
2316
|
-
} = log$
|
|
2524
|
+
} = log$1;
|
|
2317
2525
|
|
|
2318
2526
|
const since = task => file => lastRun(task) > file.stat.ctime ? lastRun(task) : 0;
|
|
2319
2527
|
|
|
@@ -2342,13 +2550,20 @@ var compile = function (tmsConfig, {
|
|
|
2342
2550
|
|
|
2343
2551
|
switch (globKey) {
|
|
2344
2552
|
case 'js':
|
|
2345
|
-
srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
2553
|
+
srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
2554
|
+
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch)).pipe(dest(destPath)).on('error', err => {
|
|
2346
2555
|
fail$1(`js编译报错${err}`);
|
|
2347
2556
|
});
|
|
2348
2557
|
break;
|
|
2349
2558
|
|
|
2350
2559
|
case 'wxss':
|
|
2351
|
-
srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).
|
|
2560
|
+
srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).on('error', err => {
|
|
2561
|
+
fail$1(`mpCommonDep编译报错${err}`);
|
|
2562
|
+
}) // .pipe(postcss([base64()]))
|
|
2563
|
+
// .on('error', (err) => {
|
|
2564
|
+
// fail(`postcss编译报错${err}`);
|
|
2565
|
+
// })
|
|
2566
|
+
.pipe(px2rpx({
|
|
2352
2567
|
designWidth: 375,
|
|
2353
2568
|
// 设计稿宽度,默认为750
|
|
2354
2569
|
precision: 2 // 小数最大精度,默认为6
|
|
@@ -2358,7 +2573,7 @@ var compile = function (tmsConfig, {
|
|
|
2358
2573
|
|
|
2359
2574
|
case 'json':
|
|
2360
2575
|
srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch)).on('error', err => {
|
|
2361
|
-
fail$1(`
|
|
2576
|
+
fail$1(`mpJsonDep编译报错${err}`);
|
|
2362
2577
|
}).pipe(dest(destPath));
|
|
2363
2578
|
break;
|
|
2364
2579
|
|
|
@@ -2382,7 +2597,9 @@ var compile = function (tmsConfig, {
|
|
|
2382
2597
|
};
|
|
2383
2598
|
|
|
2384
2599
|
(function (module) {
|
|
2385
|
-
const
|
|
2600
|
+
const path = require$$3__default;
|
|
2601
|
+
const fs = require$$0__default$2;
|
|
2602
|
+
const watch = require$$2__default$1;
|
|
2386
2603
|
const {
|
|
2387
2604
|
resolve
|
|
2388
2605
|
} = widgets;
|
|
@@ -2391,7 +2608,7 @@ var compile = function (tmsConfig, {
|
|
|
2391
2608
|
} = buildAppJson;
|
|
2392
2609
|
const {
|
|
2393
2610
|
DEFAULT_COPY_CONFIG
|
|
2394
|
-
} = require$$
|
|
2611
|
+
} = require$$4;
|
|
2395
2612
|
const compile$1 = compile;
|
|
2396
2613
|
|
|
2397
2614
|
function excludeGlob(glob) {
|
|
@@ -2415,6 +2632,13 @@ var compile = function (tmsConfig, {
|
|
|
2415
2632
|
return Array.from(otherArr);
|
|
2416
2633
|
}
|
|
2417
2634
|
|
|
2635
|
+
function adaptPath(pathDir) {
|
|
2636
|
+
let newPath = pathDir;
|
|
2637
|
+
newPath = newPath.startsWith('/') ? newPath : resolve(newPath);
|
|
2638
|
+
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
2639
|
+
return newPath;
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2418
2642
|
module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
2419
2643
|
// 监听app.json
|
|
2420
2644
|
if (isWatch) {
|
|
@@ -2431,9 +2655,9 @@ var compile = function (tmsConfig, {
|
|
|
2431
2655
|
|
|
2432
2656
|
compile$1(tmsConfig, {
|
|
2433
2657
|
glob: {
|
|
2434
|
-
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
2435
|
-
|
|
2436
|
-
|
|
2658
|
+
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)) // wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
2659
|
+
// js: ['app.js', 'app.ts'].map(item => resolve(item)),
|
|
2660
|
+
|
|
2437
2661
|
},
|
|
2438
2662
|
module: {
|
|
2439
2663
|
from: '',
|
|
@@ -2464,16 +2688,17 @@ var compile = function (tmsConfig, {
|
|
|
2464
2688
|
}
|
|
2465
2689
|
|
|
2466
2690
|
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
2691
|
+
const modulePath = adaptPath(module.path);
|
|
2467
2692
|
const glob = {
|
|
2468
|
-
js: [`${
|
|
2469
|
-
json: [`${
|
|
2470
|
-
wxss: [`${
|
|
2471
|
-
wxml: [`${
|
|
2472
|
-
image: [`${
|
|
2693
|
+
js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
2694
|
+
json: [`${modulePath}/**/*.json`, ...excludes],
|
|
2695
|
+
wxss: [`${modulePath}/**/*.{less,wxss}`, ...excludes],
|
|
2696
|
+
wxml: [`${modulePath}/**/*.wxml`, ...excludes],
|
|
2697
|
+
image: [`${modulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
|
|
2473
2698
|
};
|
|
2474
2699
|
compile$1(tmsConfig, {
|
|
2475
2700
|
glob: { ...glob,
|
|
2476
|
-
other: [`${
|
|
2701
|
+
other: [`${modulePath}/**/*`, ...excludeGlob(glob)]
|
|
2477
2702
|
},
|
|
2478
2703
|
destPath: resolve(tmsConfig.outputDir, module.root),
|
|
2479
2704
|
module: {
|
|
@@ -2490,14 +2715,32 @@ var compile = function (tmsConfig, {
|
|
|
2490
2715
|
|
|
2491
2716
|
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
|
|
2492
2717
|
for (const item of tmsConfig.static) {
|
|
2493
|
-
|
|
2494
|
-
|
|
2718
|
+
item.from = adaptPath(item.from);
|
|
2719
|
+
item.to = adaptPath(item.to);
|
|
2720
|
+
let glob = {};
|
|
2721
|
+
const ext = path.extname(item.from).slice(1);
|
|
2722
|
+
|
|
2723
|
+
if (ext) {
|
|
2724
|
+
glob[ext] = [item.from];
|
|
2725
|
+
} else {
|
|
2726
|
+
glob = {
|
|
2727
|
+
js: [`${item.from}/**/*.{js,ts,wxs}`],
|
|
2728
|
+
json: [`${item.from}/**/*.json`],
|
|
2729
|
+
wxss: [`${item.from}/**/*.{less,wxss}`],
|
|
2730
|
+
wxml: [`${item.from}/**/*.wxml`],
|
|
2731
|
+
image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`]
|
|
2732
|
+
};
|
|
2733
|
+
glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
|
|
2495
2737
|
compile$1(tmsConfig, {
|
|
2496
|
-
glob
|
|
2497
|
-
|
|
2738
|
+
glob,
|
|
2739
|
+
destPath: item.to,
|
|
2740
|
+
module: {
|
|
2741
|
+
from,
|
|
2742
|
+
to: item.to
|
|
2498
2743
|
},
|
|
2499
|
-
destPath: to,
|
|
2500
|
-
module: item,
|
|
2501
2744
|
srcOption: {
|
|
2502
2745
|
allowEmpty: true
|
|
2503
2746
|
},
|
|
@@ -2508,13 +2751,13 @@ var compile = function (tmsConfig, {
|
|
|
2508
2751
|
};
|
|
2509
2752
|
})(dev$3);
|
|
2510
2753
|
|
|
2511
|
-
const fs$1 = require$$0__default$
|
|
2512
|
-
const semver$1 = require$$1__default$
|
|
2754
|
+
const fs$1 = require$$0__default$2;
|
|
2755
|
+
const semver$1 = require$$1__default$8;
|
|
2513
2756
|
const {
|
|
2514
|
-
resolve: resolve$
|
|
2757
|
+
resolve: resolve$3
|
|
2515
2758
|
} = widgets;
|
|
2516
2759
|
const path = require$$3__default;
|
|
2517
|
-
const shelljs$2 = require$$
|
|
2760
|
+
const shelljs$2 = require$$0__default$3;
|
|
2518
2761
|
const {
|
|
2519
2762
|
handleError
|
|
2520
2763
|
} = handleError_1;
|
|
@@ -2523,23 +2766,23 @@ const getLatestVersion = npmName => {
|
|
|
2523
2766
|
const data = shelljs$2.exec(`npm view ${npmName} version`);
|
|
2524
2767
|
return data.stdout || '0.0.0';
|
|
2525
2768
|
};
|
|
2526
|
-
/**
|
|
2527
|
-
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
2528
|
-
* @param {*} modules 模块
|
|
2529
|
-
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
2530
|
-
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
2531
|
-
* @returns
|
|
2769
|
+
/**
|
|
2770
|
+
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
2771
|
+
* @param {*} modules 模块
|
|
2772
|
+
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
2773
|
+
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
2774
|
+
* @returns
|
|
2532
2775
|
*/
|
|
2533
2776
|
|
|
2534
2777
|
|
|
2535
|
-
const checkDependencies$1 = (modules, cwd, outputDir
|
|
2778
|
+
const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
2536
2779
|
// 步骤1. 收集package.json
|
|
2537
2780
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
2538
2781
|
// 1.1根目录的package.json
|
|
2539
2782
|
|
|
2540
2783
|
const packageArr = [{
|
|
2541
2784
|
srcPackageDir: path.join(cwd, packageJsonName),
|
|
2542
|
-
destNpmDir: resolve$
|
|
2785
|
+
destNpmDir: resolve$3(outputDir, 'node_modules')
|
|
2543
2786
|
}]; // 1.2模块的package.json
|
|
2544
2787
|
|
|
2545
2788
|
modules.forEach(item => {
|
|
@@ -2548,7 +2791,7 @@ const checkDependencies$1 = (modules, cwd, outputDir, isDev) => {
|
|
|
2548
2791
|
if (fs$1.existsSync(srcPackageDir)) {
|
|
2549
2792
|
packageArr.push({
|
|
2550
2793
|
srcPackageDir,
|
|
2551
|
-
destNpmDir: resolve$
|
|
2794
|
+
destNpmDir: resolve$3(outputDir, item.root, 'node_modules')
|
|
2552
2795
|
});
|
|
2553
2796
|
}
|
|
2554
2797
|
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
@@ -2561,7 +2804,7 @@ const checkDependencies$1 = (modules, cwd, outputDir, isDev) => {
|
|
|
2561
2804
|
const json = JSON.parse(packageJson);
|
|
2562
2805
|
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
2563
2806
|
} catch (e) {
|
|
2564
|
-
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json
|
|
2807
|
+
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
2565
2808
|
}
|
|
2566
2809
|
|
|
2567
2810
|
const dependenciesKeys = Object.keys(dependencies);
|
|
@@ -2600,27 +2843,53 @@ var checkDependencies_1 = {
|
|
|
2600
2843
|
checkDependencies: checkDependencies$1
|
|
2601
2844
|
};
|
|
2602
2845
|
|
|
2603
|
-
const
|
|
2604
|
-
const fs = require$$0__default$1;
|
|
2846
|
+
const fs = require$$0__default$2;
|
|
2605
2847
|
const {
|
|
2606
|
-
resolve: resolve$
|
|
2848
|
+
resolve: resolve$2
|
|
2607
2849
|
} = widgets;
|
|
2608
|
-
const init$4 = init_1;
|
|
2609
2850
|
const {
|
|
2610
|
-
MODULE_CONFIG_FILENAME
|
|
2611
|
-
|
|
2851
|
+
MODULE_CONFIG_FILENAME,
|
|
2852
|
+
MODULE_CODE_DIR
|
|
2853
|
+
} = require$$4;
|
|
2612
2854
|
const {
|
|
2613
|
-
|
|
2614
|
-
} =
|
|
2855
|
+
checkRemoteModGitUrlBranch
|
|
2856
|
+
} = cloneModules_1;
|
|
2615
2857
|
const {
|
|
2616
2858
|
checkDependencies
|
|
2617
2859
|
} = checkDependencies_1;
|
|
2618
2860
|
const {
|
|
2619
2861
|
fail
|
|
2620
|
-
} = log$
|
|
2621
|
-
|
|
2862
|
+
} = log$1;
|
|
2863
|
+
|
|
2864
|
+
function checkModule(targetModules, contextDir) {
|
|
2865
|
+
// 判断\源码\dist\是否存在用户指定的模块
|
|
2866
|
+
for (const item of targetModules) {
|
|
2867
|
+
// 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
|
|
2868
|
+
if (!item.root) {
|
|
2869
|
+
return true;
|
|
2870
|
+
} // 判断dist目录是否有该模块
|
|
2871
|
+
|
|
2872
|
+
|
|
2873
|
+
if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
|
|
2874
|
+
return true;
|
|
2875
|
+
} // 判断第三方远程模块git地址与branch是否有更新
|
|
2876
|
+
|
|
2877
|
+
|
|
2878
|
+
if (checkRemoteModGitUrlBranch(MODULE_CODE_DIR, item)) {
|
|
2879
|
+
return true;
|
|
2880
|
+
} // 判断源码目录是否有该模块
|
|
2881
|
+
|
|
2882
|
+
|
|
2883
|
+
if (item.path && !fs.existsSync(resolve$2(item.path))) {
|
|
2884
|
+
fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2885
|
+
process.exit(1);
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
return false;
|
|
2890
|
+
}
|
|
2622
2891
|
|
|
2623
|
-
function isInit(tmsConfig, targetModules, contextDir
|
|
2892
|
+
function isInit$1(tmsConfig, targetModules, contextDir) {
|
|
2624
2893
|
// 判断是否存在dist目录
|
|
2625
2894
|
if (!fs.existsSync(contextDir)) {
|
|
2626
2895
|
return true;
|
|
@@ -2639,31 +2908,43 @@ function isInit(tmsConfig, targetModules, contextDir, isDev) {
|
|
|
2639
2908
|
|
|
2640
2909
|
if (!fs.existsSync(`${contextDir}/app.json`)) {
|
|
2641
2910
|
return true;
|
|
2642
|
-
} //
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
for (const item of targetModules) {
|
|
2646
|
-
// 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
|
|
2647
|
-
if (!item.root) {
|
|
2648
|
-
return true;
|
|
2649
|
-
} // 判断dist目录是否有该模块
|
|
2911
|
+
} // 判断模块信息
|
|
2650
2912
|
|
|
2651
2913
|
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2914
|
+
if (checkModule(targetModules, contextDir)) {
|
|
2915
|
+
return true;
|
|
2916
|
+
} // 判断package.json的版本是否有新的版本
|
|
2655
2917
|
|
|
2656
2918
|
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
}
|
|
2661
|
-
} // 判断package.json的版本是否有新的版本
|
|
2919
|
+
if (checkDependencies(targetModules, resolve$2('./'), tmsConfig.outputDir)) {
|
|
2920
|
+
return true;
|
|
2921
|
+
}
|
|
2662
2922
|
|
|
2923
|
+
return false;
|
|
2924
|
+
}
|
|
2663
2925
|
|
|
2664
|
-
|
|
2665
|
-
|
|
2926
|
+
var isInIt = {
|
|
2927
|
+
isInit: isInit$1
|
|
2928
|
+
};
|
|
2666
2929
|
|
|
2930
|
+
const shelljs$1 = require$$0__default$3;
|
|
2931
|
+
const compileDev = dev$3.exports;
|
|
2932
|
+
const {
|
|
2933
|
+
resolve: resolve$1
|
|
2934
|
+
} = widgets;
|
|
2935
|
+
const init$4 = init_1;
|
|
2936
|
+
const {
|
|
2937
|
+
isInit
|
|
2938
|
+
} = isInIt;
|
|
2939
|
+
const {
|
|
2940
|
+
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
|
|
2941
|
+
} = tmsMpconfig;
|
|
2942
|
+
const {
|
|
2943
|
+
info: info$2
|
|
2944
|
+
} = log$1;
|
|
2945
|
+
const {
|
|
2946
|
+
global: global$1
|
|
2947
|
+
} = global_1; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
2667
2948
|
|
|
2668
2949
|
function delOtherModule(tmsConfig, targetModules) {
|
|
2669
2950
|
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
|
|
@@ -2681,17 +2962,17 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
2681
2962
|
|
|
2682
2963
|
async function dev$2(tmsConfig, targetModules, env) {
|
|
2683
2964
|
let newModules = targetModules;
|
|
2684
|
-
const
|
|
2965
|
+
const isLatest = global$1.getData('cmd').latest; // 判断是否进行init命令
|
|
2685
2966
|
|
|
2686
|
-
if (isInit(tmsConfig, targetModules, resolve$1('dist')
|
|
2967
|
+
if (isLatest || isInit(tmsConfig, targetModules, resolve$1('dist'))) {
|
|
2687
2968
|
// init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
|
|
2688
|
-
const initData = await init$4(tmsConfig, newModules
|
|
2969
|
+
const initData = await init$4(tmsConfig, newModules);
|
|
2689
2970
|
newModules = initData.targetModules;
|
|
2690
2971
|
}
|
|
2691
2972
|
|
|
2692
|
-
|
|
2973
|
+
info$2('当前dev启动的有效模块', newModules.map(item => item.name).sort());
|
|
2693
2974
|
delOtherModule(tmsConfig, newModules);
|
|
2694
|
-
|
|
2975
|
+
compileDev(tmsConfig, newModules, env);
|
|
2695
2976
|
}
|
|
2696
2977
|
|
|
2697
2978
|
var dev_1 = dev$2;
|
|
@@ -2702,21 +2983,20 @@ var build$2 = async (tmsConfig, newModules) => {
|
|
|
2702
2983
|
dev$1(tmsConfig, newModules, false);
|
|
2703
2984
|
};
|
|
2704
2985
|
|
|
2705
|
-
const shelljs = require$$
|
|
2986
|
+
const shelljs = require$$0__default$3;
|
|
2706
2987
|
const {
|
|
2707
2988
|
resolve
|
|
2708
2989
|
} = widgets;
|
|
2709
2990
|
const init$3 = init_1;
|
|
2710
|
-
const
|
|
2991
|
+
const compileBuild = build$2;
|
|
2711
2992
|
|
|
2712
2993
|
async function build$1(tmsConfig, targetModules, env) {
|
|
2713
2994
|
// 开始构建前,清理输出目录
|
|
2714
2995
|
await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
2715
|
-
const isDev = false;
|
|
2716
2996
|
const {
|
|
2717
2997
|
targetModules: newModules
|
|
2718
|
-
} = await init$3(tmsConfig, targetModules
|
|
2719
|
-
|
|
2998
|
+
} = await init$3(tmsConfig, targetModules);
|
|
2999
|
+
compileBuild(tmsConfig, newModules, env);
|
|
2720
3000
|
}
|
|
2721
3001
|
|
|
2722
3002
|
var build_1 = build$1;
|
|
@@ -2726,63 +3006,77 @@ const dev = dev_1;
|
|
|
2726
3006
|
const build = build_1;
|
|
2727
3007
|
const install = install_1;
|
|
2728
3008
|
const {
|
|
2729
|
-
|
|
2730
|
-
} =
|
|
2731
|
-
const {
|
|
2732
|
-
MODE
|
|
2733
|
-
} = require$$3;
|
|
3009
|
+
global
|
|
3010
|
+
} = global_1;
|
|
2734
3011
|
const {
|
|
2735
3012
|
readTmsConfig,
|
|
2736
3013
|
readTmsPrivateCf,
|
|
2737
|
-
checkModules
|
|
2738
|
-
} = tkitUtils;
|
|
2739
|
-
const {
|
|
3014
|
+
checkModules,
|
|
2740
3015
|
tmsModulesMergeLocalModuleCfg,
|
|
2741
3016
|
subModulesMergeDepModules
|
|
2742
|
-
} =
|
|
3017
|
+
} = tmsMpconfig;
|
|
2743
3018
|
|
|
2744
|
-
const
|
|
3019
|
+
const handleModuleArg = cmd => {
|
|
2745
3020
|
// 单模块或多模块开发-用户通过脚手架参数指定的模块
|
|
2746
|
-
if (cmd.module) {
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
3021
|
+
if (typeof cmd.module === 'string') {
|
|
3022
|
+
return cmd.module.split(',');
|
|
3023
|
+
}
|
|
3024
|
+
|
|
3025
|
+
return [];
|
|
3026
|
+
};
|
|
3027
|
+
/**
|
|
3028
|
+
* 获取用户指定要跑的模块
|
|
3029
|
+
* @param {Array} moduleArg 参数指定的模块
|
|
3030
|
+
* @param {Object} modulePrivateCfg 私有配置里的模块
|
|
3031
|
+
* @param {Array} moduleAll 当前小程序全部模块
|
|
3032
|
+
*/
|
|
3033
|
+
|
|
3034
|
+
|
|
3035
|
+
const getSpecificModules = (moduleArg, modulePrivateCfg, moduleAll) => {
|
|
3036
|
+
if (moduleArg.length > 0) {
|
|
3037
|
+
return moduleArg;
|
|
2752
3038
|
} // 单模块或多模块开发-用户在tms.private.js指定的模块
|
|
2753
3039
|
|
|
2754
3040
|
|
|
2755
|
-
if (
|
|
2756
|
-
|
|
2757
|
-
|
|
3041
|
+
if (modulePrivateCfg) {
|
|
3042
|
+
var _modulePrivateCfg$inc, _modulePrivateCfg$exc;
|
|
3043
|
+
|
|
3044
|
+
if (((_modulePrivateCfg$inc = modulePrivateCfg.include) === null || _modulePrivateCfg$inc === void 0 ? void 0 : _modulePrivateCfg$inc.length) > 0) {
|
|
3045
|
+
return modulePrivateCfg.include;
|
|
3046
|
+
}
|
|
3047
|
+
|
|
3048
|
+
if (((_modulePrivateCfg$exc = modulePrivateCfg.exclude) === null || _modulePrivateCfg$exc === void 0 ? void 0 : _modulePrivateCfg$exc.length) > 0) {
|
|
3049
|
+
return moduleAll.filter(module => !modulePrivateCfg.exclude.includes(module.name)).map(item => item.name);
|
|
3050
|
+
}
|
|
2758
3051
|
|
|
3052
|
+
if (modulePrivateCfg.blockRemote === true) {
|
|
3053
|
+
return moduleAll.filter(module => module.repoInfo === undefined).map(item => item.name);
|
|
3054
|
+
}
|
|
3055
|
+
}
|
|
2759
3056
|
|
|
2760
|
-
return
|
|
3057
|
+
return moduleAll.map(item => item.name);
|
|
2761
3058
|
};
|
|
2762
3059
|
|
|
2763
3060
|
async function run(commandName, cmd) {
|
|
2764
3061
|
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
2765
|
-
const
|
|
2766
|
-
|
|
2767
|
-
const moduleArg = handleModulesArg(cmd, tmsPrivateCg);
|
|
3062
|
+
const tmsPrivateCf = readTmsPrivateCf();
|
|
2768
3063
|
const {
|
|
2769
|
-
env =
|
|
3064
|
+
env = tmsPrivateCf === null || tmsPrivateCf === void 0 ? void 0 : tmsPrivateCf.env
|
|
2770
3065
|
} = cmd;
|
|
2771
|
-
const tmsConfig =
|
|
2772
|
-
let modules;
|
|
2773
|
-
|
|
2774
|
-
if (moduleArg === MODE.all) {
|
|
2775
|
-
// 全量模块
|
|
2776
|
-
modules = tmsConfig.modules;
|
|
2777
|
-
} else {
|
|
2778
|
-
// 检查用户输入modules的有效性
|
|
2779
|
-
modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...moduleArg])]);
|
|
2780
|
-
} // tms.config.js的modules 合并 module.config.json的配置项
|
|
3066
|
+
const tmsConfig = readTmsConfig(env); // 处理module参数
|
|
2781
3067
|
|
|
3068
|
+
const specificModules = getSpecificModules(handleModuleArg(cmd), tmsPrivateCf.modules, tmsConfig.modules);
|
|
3069
|
+
const modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...specificModules])]); // tms.config.js的modules 合并 module.config.json的配置项
|
|
2782
3070
|
|
|
2783
3071
|
let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
2784
3072
|
|
|
2785
|
-
newModules = subModulesMergeDepModules(tmsConfig, newModules);
|
|
3073
|
+
newModules = subModulesMergeDepModules(tmsConfig, newModules); // 缓存数据
|
|
3074
|
+
|
|
3075
|
+
global.setData({
|
|
3076
|
+
env,
|
|
3077
|
+
cmd,
|
|
3078
|
+
tmsPrivateCf
|
|
3079
|
+
});
|
|
2786
3080
|
|
|
2787
3081
|
switch (commandName) {
|
|
2788
3082
|
case 'init':
|
|
@@ -2790,6 +3084,7 @@ async function run(commandName, cmd) {
|
|
|
2790
3084
|
return;
|
|
2791
3085
|
|
|
2792
3086
|
case 'dev':
|
|
3087
|
+
global.setData('isDev', true);
|
|
2793
3088
|
dev(tmsConfig, newModules, env);
|
|
2794
3089
|
return;
|
|
2795
3090
|
|
|
@@ -2798,6 +3093,7 @@ async function run(commandName, cmd) {
|
|
|
2798
3093
|
return;
|
|
2799
3094
|
|
|
2800
3095
|
case 'build':
|
|
3096
|
+
global.setData('isDev', false);
|
|
2801
3097
|
build(tmsConfig, newModules, env);
|
|
2802
3098
|
return;
|
|
2803
3099
|
|
|
@@ -2828,7 +3124,7 @@ var entry = [{
|
|
|
2828
3124
|
}, {
|
|
2829
3125
|
command: 'dev',
|
|
2830
3126
|
description: 'dev 打包编译',
|
|
2831
|
-
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
3127
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量'], ['-latest, --latest', '下载最新第三方模块代码、安装最新依赖']],
|
|
2832
3128
|
action: cmd => {
|
|
2833
3129
|
run_1('dev', cmd);
|
|
2834
3130
|
}
|
|
@@ -2839,21 +3135,26 @@ var entry = [{
|
|
|
2839
3135
|
action: cmd => {
|
|
2840
3136
|
run_1('build', cmd);
|
|
2841
3137
|
}
|
|
2842
|
-
}
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
3138
|
+
} // 对外暂不暴露该命令
|
|
3139
|
+
// {
|
|
3140
|
+
// command: 'init',
|
|
3141
|
+
// description: '模块配置初始化项目(eg: 下载第三方模块代码、安装依赖、生成app.json等)',
|
|
3142
|
+
// options: [
|
|
3143
|
+
// ['-m, --module [moduleName]', '模块名称'],
|
|
3144
|
+
// ['-e, --env [env]', '环境变量'],
|
|
3145
|
+
// ],
|
|
3146
|
+
// action: (cmd) => {
|
|
3147
|
+
// require('./scripts/run/index')('init', cmd);
|
|
3148
|
+
// },
|
|
3149
|
+
// },
|
|
3150
|
+
]
|
|
2850
3151
|
}];
|
|
2851
3152
|
|
|
2852
|
-
var require$$
|
|
3153
|
+
var require$$7 = {
|
|
2853
3154
|
name: "@tmsfe/tmskit",
|
|
2854
|
-
version: "0.0.
|
|
3155
|
+
version: "0.0.9-beta.1",
|
|
2855
3156
|
description: "tmskit",
|
|
2856
|
-
main: "
|
|
3157
|
+
main: "dist/index.cjs",
|
|
2857
3158
|
bin: {
|
|
2858
3159
|
tmskit: "main.js"
|
|
2859
3160
|
},
|
|
@@ -2890,13 +3191,11 @@ var require$$6 = {
|
|
|
2890
3191
|
chalk: "^4.1.0",
|
|
2891
3192
|
commander: "^8.3.0",
|
|
2892
3193
|
"copy-webpack-plugin": "^9.1.0",
|
|
2893
|
-
"download-git-repo": "^3.0.2",
|
|
2894
3194
|
ejs: "^3.1.5",
|
|
2895
3195
|
"fs-extra": "^10.0.1",
|
|
2896
3196
|
"glob-ignore": "^1.0.2",
|
|
2897
3197
|
gulp: "^4.0.2",
|
|
2898
3198
|
"gulp-cache": "^1.1.3",
|
|
2899
|
-
"gulp-image": "^5.1.0",
|
|
2900
3199
|
"gulp-postcss": "^9.0.1",
|
|
2901
3200
|
"gulp-px-to-rpx": "^1.0.7",
|
|
2902
3201
|
"gulp-watch": "^5.0.1",
|
|
@@ -2925,32 +3224,32 @@ var require$$6 = {
|
|
|
2925
3224
|
}
|
|
2926
3225
|
};
|
|
2927
3226
|
|
|
2928
|
-
const semver = require$$1__default$
|
|
2929
|
-
const packageJson = require$$
|
|
2930
|
-
const chalk$1 = require$$0__default
|
|
3227
|
+
const semver = require$$1__default$8;
|
|
3228
|
+
const packageJson = require$$7;
|
|
3229
|
+
const chalk$1 = require$$0__default;
|
|
2931
3230
|
const {
|
|
2932
|
-
|
|
2933
|
-
} =
|
|
3231
|
+
info: info$1
|
|
3232
|
+
} = log$1;
|
|
2934
3233
|
const requiredVersion = packageJson.engines.node;
|
|
2935
3234
|
const packName = packageJson.name;
|
|
2936
|
-
/**
|
|
2937
|
-
* 检查node版本
|
|
2938
|
-
* @param {String} wanted 希望的node版本
|
|
2939
|
-
* @param {String} id 某node特性
|
|
2940
|
-
* @returns {Undefined} 无需返回值
|
|
3235
|
+
/**
|
|
3236
|
+
* 检查node版本
|
|
3237
|
+
* @param {String} wanted 希望的node版本
|
|
3238
|
+
* @param {String} id 某node特性
|
|
3239
|
+
* @returns {Undefined} 无需返回值
|
|
2941
3240
|
*/
|
|
2942
3241
|
|
|
2943
3242
|
const checkNodeVersion = (wanted, id) => {
|
|
2944
3243
|
if (!semver.satisfies(process.version, wanted, {
|
|
2945
3244
|
includePrerelease: true
|
|
2946
3245
|
})) {
|
|
2947
|
-
|
|
3246
|
+
info$1(chalk$1.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id} 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
|
|
2948
3247
|
process.exit(1);
|
|
2949
3248
|
}
|
|
2950
3249
|
};
|
|
2951
|
-
/**
|
|
2952
|
-
* 检查运行环境
|
|
2953
|
-
* @returns {Undefined} 无需返回值
|
|
3250
|
+
/**
|
|
3251
|
+
* 检查运行环境
|
|
3252
|
+
* @returns {Undefined} 无需返回值
|
|
2954
3253
|
*/
|
|
2955
3254
|
|
|
2956
3255
|
|
|
@@ -2962,20 +3261,22 @@ function initCliContext() {
|
|
|
2962
3261
|
|
|
2963
3262
|
var init$1 = initCliContext;
|
|
2964
3263
|
|
|
2965
|
-
const chalk = require$$0__default
|
|
2966
|
-
const commander = require$$0__default;
|
|
3264
|
+
const chalk = require$$0__default;
|
|
3265
|
+
const commander = require$$0__default$1;
|
|
2967
3266
|
const {
|
|
2968
|
-
log,
|
|
2969
3267
|
suggestCommands
|
|
2970
3268
|
} = widgets;
|
|
3269
|
+
const {
|
|
3270
|
+
info
|
|
3271
|
+
} = log$1;
|
|
2971
3272
|
const {
|
|
2972
3273
|
TMS_NAME
|
|
2973
|
-
} = require$$
|
|
3274
|
+
} = require$$4;
|
|
2974
3275
|
const commands = entry;
|
|
2975
3276
|
const init = init$1;
|
|
2976
3277
|
init();
|
|
2977
3278
|
const program = new commander.Command(TMS_NAME);
|
|
2978
|
-
program.version(`${TMS_NAME} ${require$$
|
|
3279
|
+
program.version(`${TMS_NAME} ${require$$7.version}`, '-v, -V, --version');
|
|
2979
3280
|
|
|
2980
3281
|
function registerCommand(program, commands) {
|
|
2981
3282
|
commands.forEach(cmd => {
|
|
@@ -2999,15 +3300,15 @@ function registerCommand(program, commands) {
|
|
|
2999
3300
|
|
|
3000
3301
|
registerCommand(program, commands);
|
|
3001
3302
|
program.on('--help', () => {
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3303
|
+
info();
|
|
3304
|
+
info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
3305
|
+
info();
|
|
3005
3306
|
}); // 捕获未注册的命令
|
|
3006
3307
|
|
|
3007
3308
|
program.arguments('<command>').action(cmd => {
|
|
3008
3309
|
program.outputHelp();
|
|
3009
|
-
|
|
3010
|
-
|
|
3310
|
+
info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
|
|
3311
|
+
info();
|
|
3011
3312
|
suggestCommands(cmd);
|
|
3012
3313
|
process.exitCode = 1;
|
|
3013
3314
|
});
|