@tmsfe/tmskit 0.0.5 → 0.0.6
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 +18 -2
- package/dist/index.cjs.js +1852 -1050
- package/package.json +24 -6
- package/src/config/constant.js +5 -2
- package/src/config/defaultTmsConfig.js +9 -10
- package/src/entry.js +48 -8
- package/src/gulp/build.js +5 -0
- package/src/gulp/compile.js +87 -0
- package/src/gulp/dev.js +102 -0
- package/src/gulp/plugins/less.js +116 -0
- package/src/gulp/plugins/mpCommonDep.js +131 -0
- package/src/gulp/plugins/mpJsonDep.js +108 -0
- package/src/gulp/plugins/mpWxmlDep.js +194 -0
- package/src/gulp/plugins/postcss-font-base64.js +72 -0
- package/src/gulp/plugins/replaceEnv.js +29 -0
- package/src/gulp/plugins/utils/pluginError.js +25 -0
- package/src/index.js +24 -9
- package/src/init.js +0 -5
- package/src/scripts/run/build/index.js +5 -4
- package/src/scripts/run/dev/index.js +30 -13
- package/src/scripts/run/index.js +30 -25
- package/src/scripts/run/init/index.js +31 -41
- package/src/scripts/run/install/index.js +19 -29
- package/src/utils/buildAppJson.js +100 -23
- package/src/utils/checkDependencies.js +6 -6
- package/src/utils/cloneModules.js +39 -13
- package/src/utils/findCssImport.js +30 -0
- package/src/utils/handleError.js +16 -0
- package/src/utils/io.js +85 -0
- package/src/utils/mpCiUtils.js +0 -1
- package/src/utils/npmUtils.js +77 -37
- package/src/utils/tkitUtils.js +90 -16
- package/src/utils/widgets.js +11 -14
- package/CHANGELOG.md +0 -0
- package/rollup.config.js +0 -179
- package/src/webpack/base.js +0 -65
- package/src/webpack/build.js +0 -21
- package/src/webpack/buildServer.js +0 -34
- package/src/webpack/dev.js +0 -31
- package/src/webpack/devServer.js +0 -37
- package/src/webpack/plugins/entryExtractPlugin/index.js +0 -28
- package/src/webpack/utils.js +0 -244
package/dist/index.cjs.js
CHANGED
|
@@ -3,48 +3,60 @@
|
|
|
3
3
|
var require$$0 = require('commander');
|
|
4
4
|
var require$$1 = require('leven');
|
|
5
5
|
var require$$2 = require('ora');
|
|
6
|
-
var require$$
|
|
6
|
+
var require$$3$1 = require('path');
|
|
7
7
|
var require$$0$1 = require('fs');
|
|
8
|
-
var require$$
|
|
8
|
+
var require$$4 = require('shelljs');
|
|
9
9
|
var require$$6$1 = require('download-git-repo');
|
|
10
|
-
var require$$0$
|
|
11
|
-
var require$$0$
|
|
12
|
-
var require$$1$
|
|
13
|
-
var require$$1$
|
|
14
|
-
var require$$0$
|
|
10
|
+
var require$$0$2 = require('chalk');
|
|
11
|
+
var require$$0$3 = require('async');
|
|
12
|
+
var require$$1$1 = require('ejs');
|
|
13
|
+
var require$$1$2 = require('inquirer');
|
|
14
|
+
var require$$0$4 = require('metalsmith');
|
|
15
|
+
var require$$0$5 = require('lodash');
|
|
15
16
|
var require$$0$6 = require('miniprogram-ci');
|
|
16
|
-
var require$$
|
|
17
|
-
var require$$
|
|
18
|
-
var require$$
|
|
19
|
-
var require$$0$
|
|
20
|
-
var require$$0$
|
|
21
|
-
var require$$
|
|
22
|
-
var require$$1$
|
|
23
|
-
var require$$
|
|
17
|
+
var require$$5 = require('glob-ignore');
|
|
18
|
+
var require$$1$3 = require('fs-extra');
|
|
19
|
+
var require$$2$1 = require('crypto');
|
|
20
|
+
var require$$0$7 = require('through2');
|
|
21
|
+
var require$$0$8 = require('strip-comments');
|
|
22
|
+
var require$$1$4 = require('precinct');
|
|
23
|
+
var require$$1$5 = require('htmlparser2');
|
|
24
|
+
var require$$0$9 = require('postcss');
|
|
25
|
+
var require$$0$a = require('gulp');
|
|
26
|
+
var require$$1$6 = require('gulp-px-to-rpx');
|
|
27
|
+
var require$$2$2 = require('gulp-postcss');
|
|
28
|
+
var require$$3$2 = require('gulp-watch');
|
|
29
|
+
var require$$1$7 = require('semver');
|
|
24
30
|
|
|
25
31
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
26
32
|
|
|
27
33
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
28
34
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
29
35
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
30
|
-
var require$$
|
|
36
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
|
|
31
37
|
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
32
|
-
var require$$
|
|
38
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
33
39
|
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
|
|
40
|
+
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
34
41
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
35
|
-
var require$$
|
|
42
|
+
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
36
43
|
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
37
|
-
var require$$
|
|
44
|
+
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
38
45
|
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
39
46
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
47
|
+
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
48
|
+
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
49
|
+
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
40
50
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
41
|
-
var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
|
|
42
51
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
52
|
+
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
53
|
+
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
43
54
|
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
44
55
|
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
45
|
-
var require$$
|
|
46
|
-
var require$$
|
|
56
|
+
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
57
|
+
var require$$2__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$2$2);
|
|
47
58
|
var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
|
|
59
|
+
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
48
60
|
|
|
49
61
|
function getAugmentedNamespace(n) {
|
|
50
62
|
if (n.__esModule) return n;
|
|
@@ -61,24 +73,24 @@ function getAugmentedNamespace(n) {
|
|
|
61
73
|
return a;
|
|
62
74
|
}
|
|
63
75
|
|
|
64
|
-
var src$
|
|
76
|
+
var src$2 = {};
|
|
65
77
|
|
|
66
78
|
const program$1 = require$$0__default;
|
|
67
79
|
const leven = require$$1__default;
|
|
68
80
|
const ora = require$$2__default;
|
|
69
|
-
const path$
|
|
70
|
-
const fs$
|
|
71
|
-
const shelljs$6 = require$$
|
|
81
|
+
const path$b = require$$3__default;
|
|
82
|
+
const fs$e = require$$0__default$1;
|
|
83
|
+
const shelljs$6 = require$$4__default;
|
|
72
84
|
const download = require$$6__default;
|
|
73
|
-
const chalk$3 = require$$0__default$
|
|
74
|
-
const
|
|
85
|
+
const chalk$3 = require$$0__default$2;
|
|
86
|
+
const shelljsOptions = {
|
|
75
87
|
slient: true
|
|
76
88
|
}; // 获取当前目录
|
|
77
89
|
|
|
78
90
|
const cwd = process.cwd();
|
|
79
91
|
|
|
80
|
-
function resolve$
|
|
81
|
-
return path$
|
|
92
|
+
function resolve$d(...args) {
|
|
93
|
+
return path$b.resolve(cwd, ...args);
|
|
82
94
|
}
|
|
83
95
|
/**
|
|
84
96
|
* 封装logs
|
|
@@ -147,7 +159,7 @@ function downloadRepo(dest, downloadOptions = {
|
|
|
147
159
|
branch
|
|
148
160
|
} = downloadOptions;
|
|
149
161
|
|
|
150
|
-
if (fs$
|
|
162
|
+
if (fs$e.existsSync(dest)) {
|
|
151
163
|
shelljs$6.rm('-rf', dest);
|
|
152
164
|
}
|
|
153
165
|
|
|
@@ -177,15 +189,20 @@ function downloadRepo(dest, downloadOptions = {
|
|
|
177
189
|
|
|
178
190
|
function downloadRepoForGit$2(url, dest, branch) {
|
|
179
191
|
const cwd = process.cwd();
|
|
180
|
-
return new Promise(resolve => {
|
|
192
|
+
return new Promise((resolve, reject) => {
|
|
181
193
|
// 如果目标目录不存在
|
|
182
|
-
if (fs$
|
|
183
|
-
shelljs$6.rm('-rf', path$
|
|
194
|
+
if (fs$e.existsSync(dest)) {
|
|
195
|
+
shelljs$6.rm('-rf', path$b.join(dest));
|
|
184
196
|
}
|
|
185
197
|
|
|
186
198
|
shelljs$6.mkdir('-p', dest);
|
|
187
199
|
shelljs$6.cd(dest);
|
|
188
|
-
shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`,
|
|
200
|
+
const gitCloneRes = shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptions);
|
|
201
|
+
|
|
202
|
+
if (gitCloneRes.code !== 0) {
|
|
203
|
+
reject(gitCloneRes.stderr);
|
|
204
|
+
}
|
|
205
|
+
|
|
189
206
|
shelljs$6.cd(cwd);
|
|
190
207
|
resolve();
|
|
191
208
|
});
|
|
@@ -207,24 +224,15 @@ const cost = start => Date.now() - start;
|
|
|
207
224
|
*/
|
|
208
225
|
|
|
209
226
|
|
|
210
|
-
function createTask$
|
|
227
|
+
function createTask$4(task, startText, endText) {
|
|
211
228
|
return async (...args) => {
|
|
212
229
|
const start = Date.now();
|
|
213
|
-
let result;
|
|
214
230
|
const spinner = ora(startText);
|
|
215
231
|
spinner.start();
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
result = e;
|
|
221
|
-
console.log(chalk$3.red(e));
|
|
222
|
-
process.exit(-1);
|
|
223
|
-
} finally {
|
|
224
|
-
endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
|
|
225
|
-
spinner.stop();
|
|
226
|
-
}
|
|
227
|
-
|
|
232
|
+
console.log('\n');
|
|
233
|
+
const result = await task(...args);
|
|
234
|
+
endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
|
|
235
|
+
spinner.stop();
|
|
228
236
|
return result;
|
|
229
237
|
};
|
|
230
238
|
}
|
|
@@ -237,46 +245,46 @@ function createTask$5(task, startText, endText) {
|
|
|
237
245
|
const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
|
|
238
246
|
|
|
239
247
|
var widgets = {
|
|
240
|
-
resolve: resolve$
|
|
248
|
+
resolve: resolve$d,
|
|
241
249
|
log: log$3,
|
|
242
250
|
isObject: isObject$2,
|
|
243
251
|
isArray: isArray$1,
|
|
244
|
-
createTask: createTask$
|
|
252
|
+
createTask: createTask$4,
|
|
245
253
|
downloadRepo,
|
|
246
254
|
downloadRepoForGit: downloadRepoForGit$2,
|
|
247
255
|
suggestCommands: suggestCommands$1,
|
|
248
256
|
camelize
|
|
249
257
|
};
|
|
250
258
|
|
|
251
|
-
const path$
|
|
259
|
+
const path$a = require('path'); // 用户目录
|
|
252
260
|
|
|
253
261
|
|
|
254
262
|
const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
|
|
255
263
|
|
|
256
|
-
const CACHE_DIR$1 = path$
|
|
264
|
+
const CACHE_DIR$1 = path$a.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
257
265
|
|
|
258
|
-
const TEMPLATE_DIR$1 = path$
|
|
266
|
+
const TEMPLATE_DIR$1 = path$a.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
259
267
|
|
|
260
|
-
const MODULE_CODE_DIR$1 = path$
|
|
268
|
+
const MODULE_CODE_DIR$1 = path$a.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
|
|
261
269
|
|
|
262
|
-
const TEMPLATE_PATH$1 = path$
|
|
270
|
+
const TEMPLATE_PATH$1 = path$a.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
|
|
263
271
|
|
|
264
272
|
const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
|
|
265
273
|
|
|
266
|
-
const TMS_CONFIG_FILENAME$1 = 'tms.config.js';
|
|
274
|
+
const TMS_CONFIG_FILENAME$1 = 'tms.config.js';
|
|
275
|
+
const TMS_PRIVATE_FILENAME$1 = 'tms.private.config.js'; // 模块代码的默认在modules子目录
|
|
267
276
|
|
|
268
|
-
const DEFAULT_MODULE_DIR
|
|
277
|
+
const DEFAULT_MODULE_DIR = 'modules'; // 模块的配置文件的名称
|
|
269
278
|
|
|
270
|
-
const MODULE_CONFIG_FILENAME$
|
|
279
|
+
const MODULE_CONFIG_FILENAME$3 = 'module.config.json'; // 默认的webpack entry
|
|
271
280
|
|
|
272
|
-
const DEFAULT_WEBPACK_ENTRY
|
|
273
|
-
app: path$
|
|
281
|
+
const DEFAULT_WEBPACK_ENTRY = {
|
|
282
|
+
app: path$a.resolve(process.cwd(), 'app')
|
|
274
283
|
}; // 默认从源码拷贝到编译后的配置
|
|
275
284
|
|
|
276
|
-
const DEFAULT_COPY_CONFIG$
|
|
285
|
+
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json']; // 开发模式
|
|
277
286
|
|
|
278
287
|
const MODE$1 = {
|
|
279
|
-
main: 'tkitmain',
|
|
280
288
|
all: 'all',
|
|
281
289
|
multi: 'multi'
|
|
282
290
|
};
|
|
@@ -285,6 +293,7 @@ const ENV = {
|
|
|
285
293
|
prod: 'production'
|
|
286
294
|
};
|
|
287
295
|
const TEMPLATE_TKIT_DIR$2 = '_tmskit';
|
|
296
|
+
const MODULE_CONFIG_INVALID_KEY$1 = ['entranceDeclare', 'entryPagePath'];
|
|
288
297
|
|
|
289
298
|
var constant = /*#__PURE__*/Object.freeze({
|
|
290
299
|
__proto__: null,
|
|
@@ -294,26 +303,39 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
294
303
|
TEMPLATE_PATH: TEMPLATE_PATH$1,
|
|
295
304
|
TMS_NAME: TMS_NAME$2,
|
|
296
305
|
TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
306
|
+
TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME$1,
|
|
307
|
+
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
|
|
308
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$3,
|
|
309
|
+
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
310
|
+
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
301
311
|
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
302
312
|
MODE: MODE$1,
|
|
303
313
|
ENV: ENV,
|
|
304
|
-
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2
|
|
314
|
+
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
315
|
+
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1
|
|
305
316
|
});
|
|
306
317
|
|
|
307
318
|
var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
308
319
|
|
|
309
|
-
const fs$
|
|
320
|
+
const fs$d = require$$0__default$1;
|
|
321
|
+
const path$9 = require$$3__default;
|
|
310
322
|
/**
|
|
311
323
|
* 判断目录是否为空
|
|
312
324
|
* @param {string} dirname 目录名
|
|
313
325
|
* @returns
|
|
314
326
|
*/
|
|
315
327
|
|
|
316
|
-
const isDirEmpty = dirname => fs$
|
|
328
|
+
const isDirEmpty = dirname => fs$d.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
const isFile = pathName => {
|
|
332
|
+
try {
|
|
333
|
+
const stat = fs$d.lstatSync(pathName);
|
|
334
|
+
return stat.isFile();
|
|
335
|
+
} catch {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
317
339
|
/**
|
|
318
340
|
* 确保目录存在,不存在就创建一个
|
|
319
341
|
* @param {*} dirname 目录名
|
|
@@ -321,19 +343,99 @@ const isDirEmpty = dirname => fs$a.promises.readdir(dirname).then(files => files
|
|
|
321
343
|
|
|
322
344
|
|
|
323
345
|
const ensureDirExist = dirname => {
|
|
324
|
-
if (!fs$
|
|
325
|
-
fs$
|
|
346
|
+
if (!fs$d.existsSync(dirname)) {
|
|
347
|
+
fs$d.mkdirSync(dirname, {
|
|
326
348
|
recursive: true
|
|
327
349
|
});
|
|
328
350
|
}
|
|
351
|
+
}; // 复制文件
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
const copyFile = function (src, dest) {
|
|
355
|
+
if (fs$d.existsSync(dest)) {
|
|
356
|
+
fs$d.unlinkSync(dest);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const dir = path$9.dirname(dest);
|
|
360
|
+
ensureDirExist(dir);
|
|
361
|
+
fs$d.copyFileSync(src, dest);
|
|
362
|
+
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
function diffContentCopyFile$3(originFile, destFile) {
|
|
366
|
+
if (fs$d.existsSync(destFile)) {
|
|
367
|
+
const depDestContent = fs$d.readFileSync(destFile, 'utf8');
|
|
368
|
+
const depOriginContent = fs$d.readFileSync(originFile, 'utf8');
|
|
369
|
+
|
|
370
|
+
if (depDestContent !== depOriginContent) {
|
|
371
|
+
console.log(`拷贝${originFile}内容到${destFile}`);
|
|
372
|
+
copyFile(originFile, destFile);
|
|
373
|
+
}
|
|
374
|
+
} else {
|
|
375
|
+
console.log(`拷贝${originFile}内容到${destFile}`);
|
|
376
|
+
copyFile(originFile, destFile);
|
|
377
|
+
}
|
|
378
|
+
} // 添加后缀
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
function ext$3(filePath, extensions) {
|
|
382
|
+
let newFilePath = filePath;
|
|
383
|
+
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
384
|
+
|
|
385
|
+
try {
|
|
386
|
+
const stat = fs$d.lstatSync(newFilePath);
|
|
387
|
+
|
|
388
|
+
if (stat.isDirectory()) {
|
|
389
|
+
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
390
|
+
newFilePath += extPath;
|
|
391
|
+
}
|
|
392
|
+
} catch (e) {}
|
|
393
|
+
|
|
394
|
+
for (const ext of extensions) {
|
|
395
|
+
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
396
|
+
|
|
397
|
+
if (fs$d.existsSync(file)) {
|
|
398
|
+
return {
|
|
399
|
+
ext,
|
|
400
|
+
extPath: extPath + ext,
|
|
401
|
+
file
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return {
|
|
407
|
+
ext: '',
|
|
408
|
+
extPath,
|
|
409
|
+
file: filePath
|
|
410
|
+
};
|
|
411
|
+
} // 判断文件是否在某个目录
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
const fileInDir$3 = (dir, file) => {
|
|
415
|
+
if (!fs$d.existsSync(dir) || !fs$d.existsSync(file)) {
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const relativePath = path$9.relative(dir, file);
|
|
420
|
+
|
|
421
|
+
if (relativePath.startsWith('..')) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return true;
|
|
329
426
|
};
|
|
330
427
|
|
|
331
428
|
var io$2 = {
|
|
332
429
|
isDirEmpty,
|
|
333
|
-
|
|
430
|
+
copyFile,
|
|
431
|
+
diffContentCopyFile: diffContentCopyFile$3,
|
|
432
|
+
ensureDirExist,
|
|
433
|
+
ext: ext$3,
|
|
434
|
+
fileInDir: fileInDir$3,
|
|
435
|
+
isFile
|
|
334
436
|
};
|
|
335
437
|
|
|
336
|
-
const chalk$2 = require$$0__default$
|
|
438
|
+
const chalk$2 = require$$0__default$2;
|
|
337
439
|
/**
|
|
338
440
|
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
339
441
|
*/
|
|
@@ -384,8 +486,8 @@ var log$2 = {
|
|
|
384
486
|
warn
|
|
385
487
|
};
|
|
386
488
|
|
|
387
|
-
const async = require$$0__default$
|
|
388
|
-
const ejs = require$$1__default$
|
|
489
|
+
const async = require$$0__default$3;
|
|
490
|
+
const ejs = require$$1__default$1;
|
|
389
491
|
|
|
390
492
|
const render$1 = (files, metalsmith, next) => {
|
|
391
493
|
const keys = Object.keys(files);
|
|
@@ -404,10 +506,10 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
404
506
|
|
|
405
507
|
var render_1 = render$1;
|
|
406
508
|
|
|
407
|
-
const fs$
|
|
408
|
-
const inquirer = require$$1__default$
|
|
509
|
+
const fs$c = require$$0__default$1;
|
|
510
|
+
const inquirer = require$$1__default$2;
|
|
409
511
|
const {
|
|
410
|
-
resolve: resolve$
|
|
512
|
+
resolve: resolve$c
|
|
411
513
|
} = widgets;
|
|
412
514
|
const {
|
|
413
515
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
@@ -421,12 +523,12 @@ const {
|
|
|
421
523
|
const parseTemplateQuestions = dir => {
|
|
422
524
|
let prompts = [];
|
|
423
525
|
|
|
424
|
-
if (!fs$
|
|
526
|
+
if (!fs$c.existsSync(`${dir}/questions.json`)) {
|
|
425
527
|
return prompts;
|
|
426
528
|
}
|
|
427
529
|
|
|
428
530
|
try {
|
|
429
|
-
const json = JSON.parse(fs$
|
|
531
|
+
const json = JSON.parse(fs$c.readFileSync(`${dir}/questions.json`));
|
|
430
532
|
|
|
431
533
|
if (Array.isArray(json) && json.length > 0) {
|
|
432
534
|
json.forEach((item, index) => {
|
|
@@ -459,7 +561,7 @@ const isQuestionType = result => {
|
|
|
459
561
|
};
|
|
460
562
|
|
|
461
563
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
462
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
564
|
+
const prompts = parseTemplateQuestions(resolve$c(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
463
565
|
const metadata = metalsmith.metadata();
|
|
464
566
|
const filteredPrompts = prompts.filter(prompt => {
|
|
465
567
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -484,7 +586,7 @@ var ask_1 = ask$1;
|
|
|
484
586
|
const FILES_TO_IGNORE$1 = ['node_modules'];
|
|
485
587
|
var ignoreFiles = FILES_TO_IGNORE$1;
|
|
486
588
|
|
|
487
|
-
const Metalsmith = require$$0__default$
|
|
589
|
+
const Metalsmith = require$$0__default$4;
|
|
488
590
|
const render = render_1;
|
|
489
591
|
const ask = ask_1;
|
|
490
592
|
const FILES_TO_IGNORE = ignoreFiles;
|
|
@@ -501,9 +603,9 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
501
603
|
|
|
502
604
|
var generator_1 = generator$1;
|
|
503
605
|
|
|
504
|
-
const path$
|
|
505
|
-
const fs$
|
|
506
|
-
const shelljs$5 = require$$
|
|
606
|
+
const path$8 = require$$3__default;
|
|
607
|
+
const fs$b = require$$0__default$1;
|
|
608
|
+
const shelljs$5 = require$$4__default;
|
|
507
609
|
const {
|
|
508
610
|
TEMPLATE_DIR,
|
|
509
611
|
TEMPLATE_PATH,
|
|
@@ -511,8 +613,8 @@ const {
|
|
|
511
613
|
} = require$$3;
|
|
512
614
|
const {
|
|
513
615
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
514
|
-
createTask: createTask$
|
|
515
|
-
resolve: resolve$
|
|
616
|
+
createTask: createTask$3,
|
|
617
|
+
resolve: resolve$b
|
|
516
618
|
} = widgets;
|
|
517
619
|
const io$1 = io$2;
|
|
518
620
|
const {
|
|
@@ -528,7 +630,7 @@ const generator = generator_1;
|
|
|
528
630
|
|
|
529
631
|
async function createAppDir(targetDir) {
|
|
530
632
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
531
|
-
if (fs$
|
|
633
|
+
if (fs$b.existsSync(targetDir)) {
|
|
532
634
|
if (!(await io$1.isDirEmpty(targetDir))) {
|
|
533
635
|
fail$9('该目录名已经存在,换个项目名字吧~');
|
|
534
636
|
process.exit(1);
|
|
@@ -546,21 +648,21 @@ async function createAppDir(targetDir) {
|
|
|
546
648
|
|
|
547
649
|
async function create(appName) {
|
|
548
650
|
const cwd = process.cwd();
|
|
549
|
-
const targetDir = path$
|
|
651
|
+
const targetDir = path$8.resolve(cwd, appName);
|
|
550
652
|
const appType = 'mp';
|
|
551
653
|
await createAppDir(targetDir); // 创建缓存目录
|
|
552
654
|
|
|
553
655
|
io$1.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
|
|
554
656
|
|
|
555
|
-
await createTask$
|
|
657
|
+
await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
556
658
|
|
|
557
|
-
generator(path$
|
|
659
|
+
generator(path$8.join(TEMPLATE_PATH, appType), targetDir, {
|
|
558
660
|
appName,
|
|
559
661
|
appType
|
|
560
662
|
}).then(() => {
|
|
561
663
|
shelljs$5.cd(appName);
|
|
562
664
|
|
|
563
|
-
const hooks = require(resolve$
|
|
665
|
+
const hooks = require(resolve$b(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
564
666
|
|
|
565
667
|
if (hooks.afterCreate) {
|
|
566
668
|
hooks.afterCreate.forEach(item => {
|
|
@@ -574,7 +676,7 @@ async function create(appName) {
|
|
|
574
676
|
});
|
|
575
677
|
}
|
|
576
678
|
|
|
577
|
-
shelljs$5.rm('-rf', resolve$
|
|
679
|
+
shelljs$5.rm('-rf', resolve$b(appName, TEMPLATE_TKIT_DIR));
|
|
578
680
|
succeed('项目创建完成.');
|
|
579
681
|
}).catch(err => {
|
|
580
682
|
fail$9(err.message);
|
|
@@ -584,38 +686,55 @@ async function create(appName) {
|
|
|
584
686
|
|
|
585
687
|
var create_1 = create;
|
|
586
688
|
|
|
587
|
-
const fs$7 = require$$0__default$1;
|
|
588
689
|
const {
|
|
589
|
-
|
|
590
|
-
|
|
690
|
+
fail: fail$8
|
|
691
|
+
} = log$2;
|
|
692
|
+
|
|
693
|
+
function handleError$3(error, isDev = false) {
|
|
694
|
+
const errMsg = typeof error === 'object' ? error.message : error;
|
|
695
|
+
|
|
696
|
+
if (isDev) {
|
|
697
|
+
fail$8(errMsg);
|
|
698
|
+
} else {
|
|
699
|
+
fail$8(errMsg);
|
|
700
|
+
process.exit(1);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
var handleError_1 = {
|
|
705
|
+
handleError: handleError$3
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
const fs$a = require$$0__default$1;
|
|
709
|
+
const {
|
|
710
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
|
|
711
|
+
MODULE_CONFIG_INVALID_KEY
|
|
591
712
|
} = require$$3;
|
|
592
713
|
const {
|
|
593
|
-
fail: fail$
|
|
714
|
+
fail: fail$7
|
|
594
715
|
} = log$2;
|
|
595
716
|
const {
|
|
596
|
-
resolve: resolve$
|
|
717
|
+
resolve: resolve$a,
|
|
597
718
|
isObject: isObject$1,
|
|
598
719
|
isArray
|
|
599
720
|
} = widgets;
|
|
721
|
+
const {
|
|
722
|
+
handleError: handleError$2
|
|
723
|
+
} = handleError_1;
|
|
600
724
|
/**
|
|
601
725
|
* 获取每个模块下面的信息,并且收集,后续更新到appJson里面
|
|
602
726
|
* @param { object } file 操作目录下面所有的文件
|
|
603
727
|
* @param { string } appName 小程序的名称
|
|
604
728
|
*/
|
|
605
729
|
|
|
606
|
-
function setModuleConfig$1(file, appName
|
|
730
|
+
function setModuleConfig$1(file, appName) {
|
|
607
731
|
const content = file.contents ? JSON.parse(file.contents.toString()) : JSON.parse(file);
|
|
608
732
|
|
|
609
|
-
if (isObject$1(content)) {
|
|
610
|
-
content.root = content.root.indexOf(moduleDir) > -1 ? content.root : `${moduleDir}/${content.root}`;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
733
|
if (isArray(content)) {
|
|
614
734
|
let i = content.length - 1;
|
|
615
735
|
|
|
616
736
|
while (i >= 0) {
|
|
617
737
|
let current = content[i];
|
|
618
|
-
current.root = current.root.indexOf(moduleDir) > -1 ? current.root : `${moduleDir}/${current.root}`;
|
|
619
738
|
|
|
620
739
|
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
621
740
|
current = { ...current,
|
|
@@ -637,16 +756,16 @@ function setModuleConfig$1(file, appName, moduleDir) {
|
|
|
637
756
|
*/
|
|
638
757
|
|
|
639
758
|
|
|
640
|
-
function getLocalModuleConfig(modules = [], appName,
|
|
759
|
+
function getLocalModuleConfig(modules = [], appName, moduleConfigFilename) {
|
|
641
760
|
const modulesConfig = {};
|
|
642
761
|
modules.forEach(({
|
|
643
762
|
path
|
|
644
763
|
}) => {
|
|
645
|
-
const moduleConfigPath = resolve$
|
|
764
|
+
const moduleConfigPath = resolve$a(path, moduleConfigFilename);
|
|
646
765
|
|
|
647
|
-
if (fs$
|
|
648
|
-
const content = fs$
|
|
649
|
-
modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName
|
|
766
|
+
if (fs$a.existsSync(moduleConfigPath)) {
|
|
767
|
+
const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
|
|
768
|
+
modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName);
|
|
650
769
|
}
|
|
651
770
|
});
|
|
652
771
|
return modulesConfig;
|
|
@@ -670,7 +789,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
670
789
|
|
|
671
790
|
foundMainPackages.forEach(subpackage => {
|
|
672
791
|
if (!subpackage.pages || !subpackage.pages.length) {
|
|
673
|
-
fail$
|
|
792
|
+
fail$7(`主包 ${subpackage} 不能没有 pages`);
|
|
674
793
|
process.exit(-1);
|
|
675
794
|
}
|
|
676
795
|
|
|
@@ -696,16 +815,16 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
696
815
|
|
|
697
816
|
|
|
698
817
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
699
|
-
if (!fs$
|
|
700
|
-
fail$
|
|
818
|
+
if (!fs$a.existsSync(sourceAppJsonPath)) {
|
|
819
|
+
fail$7(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
701
820
|
process.exit(1);
|
|
702
821
|
}
|
|
703
822
|
|
|
704
|
-
const appJson = JSON.parse(fs$
|
|
823
|
+
const appJson = JSON.parse(fs$a.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
705
824
|
|
|
706
825
|
appJson.subpackages = [];
|
|
707
|
-
appJson.pages = [];
|
|
708
|
-
|
|
826
|
+
appJson.pages = []; // appJson.plugins = {};
|
|
827
|
+
|
|
709
828
|
delete appJson.entranceDeclare;
|
|
710
829
|
return appJson;
|
|
711
830
|
};
|
|
@@ -719,11 +838,93 @@ const getAppJsonContent = sourceAppJsonPath => {
|
|
|
719
838
|
const updateSubpackages = (appJson, modulesConfig) => {
|
|
720
839
|
// eslint-disable-next-line
|
|
721
840
|
for (const name in modulesConfig) {
|
|
722
|
-
const moduleInfo = isObject$1(modulesConfig[name]) ? [modulesConfig[name]] : modulesConfig[name]; //
|
|
841
|
+
const moduleInfo = isObject$1(modulesConfig[name]) ? [modulesConfig[name]] : modulesConfig[name]; // 过滤 pages 为空的情况
|
|
842
|
+
|
|
843
|
+
const validModules = getValidModules$1(moduleInfo); // eslint-disable-next-line
|
|
723
844
|
|
|
724
|
-
appJson.subpackages = appJson.subpackages.concat(
|
|
845
|
+
appJson.subpackages = appJson.subpackages.concat(validModules);
|
|
725
846
|
}
|
|
726
847
|
};
|
|
848
|
+
/**
|
|
849
|
+
* 过滤页面为空的分包
|
|
850
|
+
* @param {Array} moduleCfg 模块配置内容
|
|
851
|
+
* @returns pages不为空的分包
|
|
852
|
+
*/
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
const getValidModules$1 = moduleCfg => {
|
|
856
|
+
// 过滤 pages 为空的情况
|
|
857
|
+
const validModules = moduleCfg.filter(item => item.pages.length > 0);
|
|
858
|
+
return validModules;
|
|
859
|
+
};
|
|
860
|
+
/**
|
|
861
|
+
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
862
|
+
* @param {Object} appJson appjson
|
|
863
|
+
*/
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
const processAppJson = appJson => {
|
|
867
|
+
const {
|
|
868
|
+
subpackages
|
|
869
|
+
} = appJson;
|
|
870
|
+
const pluginsMap = {};
|
|
871
|
+
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
872
|
+
const subps = subpackages.map(subp => {
|
|
873
|
+
const invalidKeys = [];
|
|
874
|
+
Object.keys(subp).forEach(key => {
|
|
875
|
+
if (key === 'dependencies') {
|
|
876
|
+
// eslint-disable-next-line
|
|
877
|
+
delete subp.dependencies;
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if (key === 'plugins') {
|
|
882
|
+
Object.keys(subp.plugins).forEach(pk => {
|
|
883
|
+
pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
|
|
884
|
+
});
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
if (MODULE_CONFIG_INVALID_KEY.indexOf(key) > -1) {
|
|
889
|
+
// 如果分包配置中有不支持的key,则错误提醒
|
|
890
|
+
invalidKeys.push(key);
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
if (['requiredBackgroundModes', 'embeddedAppIdList'].indexOf(key) > -1) {
|
|
895
|
+
// 提到appjson最上层处理
|
|
896
|
+
const preVal = appJson[key]; // eslint-disable-next-line
|
|
897
|
+
|
|
898
|
+
preVal ? appJson[key] = Array.from(new Set(preVal // eslint-disable-next-line
|
|
899
|
+
.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
if (invalidKeys.length) {
|
|
905
|
+
fail$7(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
906
|
+
} // eslint-disable-next-line
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
invalidKeys.concat(['requiredBackgroundModes', 'embeddedAppIdList']).forEach(k => delete subp[k]);
|
|
910
|
+
return subp;
|
|
911
|
+
}); // 如果plugins重复,则错误提示
|
|
912
|
+
|
|
913
|
+
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
914
|
+
if (pluginsMap[pk].length > 1) {
|
|
915
|
+
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
return '';
|
|
919
|
+
}).reduce((pre, cur) => pre + cur, '');
|
|
920
|
+
|
|
921
|
+
if (pluginsErrMsg) {
|
|
922
|
+
fail$7(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
923
|
+
} // eslint-disable-next-line
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
appJson.subpackages = subps;
|
|
927
|
+
};
|
|
727
928
|
/**
|
|
728
929
|
* 动态生成编译后的app.json
|
|
729
930
|
* @param {object} tmsConfig
|
|
@@ -732,283 +933,279 @@ const updateSubpackages = (appJson, modulesConfig) => {
|
|
|
732
933
|
*/
|
|
733
934
|
|
|
734
935
|
|
|
735
|
-
function buildOutputAppJson$
|
|
736
|
-
|
|
737
|
-
|
|
936
|
+
function buildOutputAppJson$1(tmsConfig, modules, isDev) {
|
|
937
|
+
try {
|
|
938
|
+
// 获取当前 modules 下的所有子模块的配置内容
|
|
939
|
+
const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME$2); // 获取app.json的配置
|
|
940
|
+
|
|
941
|
+
const appJson = getAppJsonContent(resolve$a('./app.json')); // 更新app.json中的subpackages
|
|
738
942
|
|
|
739
|
-
|
|
943
|
+
updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
|
|
740
944
|
|
|
741
|
-
|
|
945
|
+
processAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
742
946
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
947
|
+
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
948
|
+
fs$a.writeFileSync(resolve$a(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
949
|
+
return appJson;
|
|
950
|
+
} catch (e) {
|
|
951
|
+
handleError$2(`生成app.json出现错误: ${e}`, isDev);
|
|
952
|
+
}
|
|
746
953
|
}
|
|
747
954
|
|
|
748
955
|
var buildAppJson = {
|
|
749
956
|
setModuleConfig: setModuleConfig$1,
|
|
750
|
-
|
|
957
|
+
getValidModules: getValidModules$1,
|
|
958
|
+
buildOutputAppJson: buildOutputAppJson$1
|
|
751
959
|
};
|
|
752
960
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
const fs$6 = require$$0__default$1;
|
|
757
|
-
const path$4 = require$$1__default$1;
|
|
758
|
-
const shell = require$$0__default$2;
|
|
759
|
-
const LOG = log$2;
|
|
760
|
-
const dirpath = process.cwd(); // 项目根目录
|
|
761
|
-
|
|
762
|
-
const getTarNpmFilename = targetDir => `${targetDir.replaceAll('/', '-')}.tar.gz`; // 缓存npm包
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
const npmCache = function (targetDir, cacheDir) {
|
|
766
|
-
if (!fs$6.existsSync(cacheDir)) {
|
|
767
|
-
fs$6.mkdirSync(cacheDir);
|
|
961
|
+
class Globale {
|
|
962
|
+
constructor() {
|
|
963
|
+
this.moduleCache = {};
|
|
768
964
|
}
|
|
769
965
|
|
|
770
|
-
|
|
771
|
-
|
|
966
|
+
setModuleCache(url, branch, dest) {
|
|
967
|
+
const instance = getGlobalInstance$1();
|
|
968
|
+
const key = `${branch}:${url}`;
|
|
969
|
+
instance.moduleCache[key] = {
|
|
970
|
+
dest
|
|
971
|
+
};
|
|
972
|
+
return instance.moduleCache[key];
|
|
973
|
+
}
|
|
772
974
|
|
|
773
|
-
|
|
774
|
-
|
|
975
|
+
getModuleCache(url, branch) {
|
|
976
|
+
const instance = getGlobalInstance$1();
|
|
977
|
+
return instance.moduleCache[`${branch}:${url}`];
|
|
775
978
|
}
|
|
776
979
|
|
|
777
|
-
|
|
778
|
-
shell.exec(cmd, {
|
|
779
|
-
async: true,
|
|
780
|
-
silent: true
|
|
781
|
-
}); // tar -zcvf /Users/odile/.tmskit/node_modules.tar.gz ./node_modules
|
|
782
|
-
}; // 获取缓存npm包
|
|
980
|
+
}
|
|
783
981
|
|
|
982
|
+
let instance;
|
|
784
983
|
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
984
|
+
function getGlobalInstance$1() {
|
|
985
|
+
if (instance) {
|
|
986
|
+
return instance;
|
|
987
|
+
}
|
|
788
988
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
shell.exec(cmd, {
|
|
792
|
-
async: false,
|
|
793
|
-
silent: true
|
|
794
|
-
});
|
|
795
|
-
} // tar -zxvf /Users/odile/.tmskit/node_modules.tar.gz -C ./
|
|
989
|
+
return instance = new Globale();
|
|
990
|
+
}
|
|
796
991
|
|
|
797
|
-
|
|
992
|
+
var global = {
|
|
993
|
+
getGlobalInstance: getGlobalInstance$1
|
|
994
|
+
};
|
|
798
995
|
|
|
996
|
+
var defaultTmsConfig$1 = {
|
|
997
|
+
// 全局的环境配置项
|
|
998
|
+
envData: {},
|
|
999
|
+
// 模块配置信息
|
|
1000
|
+
modules: [],
|
|
1001
|
+
cloudDir: 'cloud',
|
|
1002
|
+
// 第三方依赖代码需要拷贝到本项目的
|
|
1003
|
+
dependencies: {},
|
|
799
1004
|
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
|
|
803
|
-
const dir = path$4.dirname(file);
|
|
804
|
-
shell.cd(dir);
|
|
1005
|
+
/** 编译输出文件夹位置 */
|
|
1006
|
+
outputDir: 'dist',
|
|
805
1007
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
}
|
|
1008
|
+
/** 源码监听路径 */
|
|
1009
|
+
sourceDir: './',
|
|
809
1010
|
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
});
|
|
813
|
-
resolve();
|
|
814
|
-
npmCache(dir, cacheDir);
|
|
815
|
-
})));
|
|
1011
|
+
/** 静态资源目录 */
|
|
1012
|
+
static: []
|
|
816
1013
|
};
|
|
1014
|
+
|
|
1015
|
+
const loadash = require$$0__default$5;
|
|
1016
|
+
const fs$9 = require$$0__default$1;
|
|
1017
|
+
const {
|
|
1018
|
+
TMS_NAME: TMS_NAME$1,
|
|
1019
|
+
TMS_CONFIG_FILENAME,
|
|
1020
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
1021
|
+
TMS_PRIVATE_FILENAME
|
|
1022
|
+
} = require$$3;
|
|
1023
|
+
const {
|
|
1024
|
+
resolve: resolve$9,
|
|
1025
|
+
isObject
|
|
1026
|
+
} = widgets;
|
|
1027
|
+
const {
|
|
1028
|
+
setModuleConfig,
|
|
1029
|
+
getValidModules
|
|
1030
|
+
} = buildAppJson;
|
|
1031
|
+
const defaultTmsConfig = defaultTmsConfig$1;
|
|
1032
|
+
const {
|
|
1033
|
+
fail: fail$6
|
|
1034
|
+
} = log$2;
|
|
1035
|
+
const path$7 = require$$3__default;
|
|
817
1036
|
/**
|
|
818
|
-
*
|
|
819
|
-
* @param {
|
|
820
|
-
* @param {String} filter 匹配的字符串
|
|
821
|
-
* @returns {Array<String>} 查找到的文件路径列表
|
|
1037
|
+
* 读取tms.config.js
|
|
1038
|
+
* @param env {string} 环境变量
|
|
822
1039
|
*/
|
|
823
1040
|
|
|
1041
|
+
const readTmsConfig$1 = function (env) {
|
|
1042
|
+
const tmsConfigPath = resolve$9(TMS_CONFIG_FILENAME);
|
|
824
1043
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
* @param {String} startPath 开始查找的文件夹路径
|
|
830
|
-
* @param {String} filter 筛选器
|
|
831
|
-
* @returns {Undefined} 无需返回值
|
|
832
|
-
*/
|
|
1044
|
+
if (!fs$9.existsSync(tmsConfigPath)) {
|
|
1045
|
+
fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
1046
|
+
process.exit(1);
|
|
1047
|
+
}
|
|
833
1048
|
|
|
834
|
-
const
|
|
835
|
-
// 目录不存在
|
|
836
|
-
if (!fs$6.existsSync(startPath)) {
|
|
837
|
-
LOG.fail(`${startPath}目录不存在`);
|
|
838
|
-
process.exit(-1);
|
|
839
|
-
return;
|
|
840
|
-
} // 当前目录下的所有文件 / 文件夹
|
|
1049
|
+
const tmsConfigFn = require(tmsConfigPath);
|
|
841
1050
|
|
|
1051
|
+
const tmsConfig = tmsConfigFn({
|
|
1052
|
+
env
|
|
1053
|
+
}); // 合并默认值
|
|
842
1054
|
|
|
843
|
-
|
|
1055
|
+
loadash.mergeWith(tmsConfig, defaultTmsConfig); // modules兼容处理
|
|
844
1056
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
1057
|
+
tmsConfig.modules = convertModules(tmsConfig.modules);
|
|
1058
|
+
return tmsConfig;
|
|
1059
|
+
}; // convertModules 处理默认值
|
|
848
1060
|
|
|
849
|
-
const files = fs$6.readdirSync(startPath);
|
|
850
|
-
files.forEach(file => {
|
|
851
|
-
const filename = path$4.join(startPath, file);
|
|
852
|
-
const stat = fs$6.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
853
1061
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1062
|
+
const convertModules = modules => {
|
|
1063
|
+
const newModules = [];
|
|
1064
|
+
modules.forEach((module, index) => {
|
|
1065
|
+
const newModule = {};
|
|
1066
|
+
|
|
1067
|
+
if (typeof module === 'string') {
|
|
1068
|
+
// 路径字符串
|
|
1069
|
+
Object.assign(newModule, {
|
|
1070
|
+
name: path$7.basename(module),
|
|
1071
|
+
path: module
|
|
1072
|
+
});
|
|
1073
|
+
} else if (typeof module === 'object') {
|
|
1074
|
+
Object.assign(newModule, module);
|
|
1075
|
+
|
|
1076
|
+
if (module.name === undefined) {
|
|
1077
|
+
newModule.name = path$7.basename(module.path);
|
|
859
1078
|
}
|
|
860
|
-
}
|
|
861
|
-
};
|
|
1079
|
+
}
|
|
862
1080
|
|
|
863
|
-
|
|
864
|
-
|
|
1081
|
+
newModules.push(newModule);
|
|
1082
|
+
});
|
|
1083
|
+
return newModules;
|
|
865
1084
|
};
|
|
866
1085
|
/**
|
|
867
|
-
*
|
|
868
|
-
* @param {Array<String>} subRoots 需要安装npm依赖的路径
|
|
869
|
-
* @param {String} contextDir 命令运行的目录
|
|
870
|
-
* @returns {Array<String>} 找到的所有package.json文件的路径
|
|
1086
|
+
* 读取tms.private.js
|
|
871
1087
|
*/
|
|
872
1088
|
|
|
873
1089
|
|
|
874
|
-
const
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
const cwd = contextDir || dirpath;
|
|
878
|
-
const result = [path$4.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1090
|
+
const readTmsPrivateCf$2 = function () {
|
|
1091
|
+
let tmsPrivateCg;
|
|
1092
|
+
const tmsPrivatePath = resolve$9(TMS_PRIVATE_FILENAME);
|
|
879
1093
|
|
|
880
|
-
|
|
881
|
-
|
|
1094
|
+
if (fs$9.existsSync(tmsPrivatePath)) {
|
|
1095
|
+
tmsPrivateCg = require(tmsPrivatePath);
|
|
1096
|
+
}
|
|
882
1097
|
|
|
883
|
-
|
|
884
|
-
result.push(...list);
|
|
885
|
-
});
|
|
886
|
-
return result;
|
|
1098
|
+
return tmsPrivateCg;
|
|
887
1099
|
};
|
|
888
|
-
|
|
889
|
-
var npmUtils = {
|
|
890
|
-
npmInstallAll: npmInstallAll$1,
|
|
891
|
-
findAllPackageJson: findAllPackageJson$1
|
|
892
|
-
};
|
|
893
|
-
|
|
894
|
-
/* eslint-disable require-jsdoc */
|
|
895
|
-
const ci = require$$0__default$6;
|
|
896
|
-
const path$3 = require$$1__default$1;
|
|
897
1100
|
/**
|
|
898
|
-
*
|
|
899
|
-
* @
|
|
1101
|
+
* 从tms.config.json中检索用户传入的有效modules
|
|
1102
|
+
* @param { object } tmsConfig
|
|
1103
|
+
* @param { array } modules
|
|
1104
|
+
* @returns
|
|
900
1105
|
*/
|
|
901
1106
|
|
|
902
|
-
const getMpCi = ({
|
|
903
|
-
appId,
|
|
904
|
-
projectPath,
|
|
905
|
-
type = 'miniProgram',
|
|
906
|
-
privateKey = 'TODO'
|
|
907
|
-
}) => {
|
|
908
|
-
var _cfgJsonContent$packO;
|
|
909
|
-
|
|
910
|
-
const cfgJsonContent = require(path$3.join(projectPath, 'project.config.json'));
|
|
911
1107
|
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
privateKey,
|
|
918
|
-
type,
|
|
919
|
-
projectPath,
|
|
920
|
-
ignores: ['node_modules/**/*', ...ignores]
|
|
1108
|
+
const checkModules$1 = function (tmsConfig, modules) {
|
|
1109
|
+
const targetModules = [];
|
|
1110
|
+
modules.forEach(moduleName => {
|
|
1111
|
+
const module = tmsConfig.modules.find(module => module.name === moduleName);
|
|
1112
|
+
module && targetModules.push(module);
|
|
921
1113
|
});
|
|
922
|
-
}; // 用小程序ci工具构建小程序
|
|
923
1114
|
|
|
1115
|
+
if (targetModules.length === 0) {
|
|
1116
|
+
fail$6(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
|
|
1117
|
+
process.exit(1);
|
|
1118
|
+
}
|
|
924
1119
|
|
|
925
|
-
|
|
926
|
-
await ci.packNpm(project, {
|
|
927
|
-
ignores: ['cloud/**/*']
|
|
928
|
-
});
|
|
1120
|
+
return targetModules;
|
|
929
1121
|
};
|
|
930
1122
|
/**
|
|
931
|
-
*
|
|
932
|
-
* @param {
|
|
933
|
-
* @
|
|
1123
|
+
* tms.config.js的modules 合并 module.config.json的配置项
|
|
1124
|
+
* @param {array} modules
|
|
1125
|
+
* @param {string} appName
|
|
1126
|
+
* @param {string} moduleDir
|
|
1127
|
+
* @returns
|
|
934
1128
|
*/
|
|
935
1129
|
|
|
936
1130
|
|
|
937
|
-
const
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1131
|
+
const tmsModulesMergeLocalModuleCfg$3 = (modules, appName) => {
|
|
1132
|
+
const newModules = [];
|
|
1133
|
+
modules.forEach(({
|
|
1134
|
+
path: relativePath,
|
|
1135
|
+
name: moduleName
|
|
1136
|
+
}, moduleIndex) => {
|
|
1137
|
+
const moduleConfigPath = resolve$9(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
1138
|
+
|
|
1139
|
+
if (fs$9.existsSync(moduleConfigPath)) {
|
|
1140
|
+
try {
|
|
1141
|
+
let moduleConfigContent = fs$9.readFileSync(moduleConfigPath, 'utf-8');
|
|
1142
|
+
moduleConfigContent = setModuleConfig(moduleConfigContent, appName);
|
|
1143
|
+
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
1144
|
+
getValidModules(moduleContentArr).forEach(({
|
|
1145
|
+
name
|
|
1146
|
+
}, moduleContentArrIndex) => {
|
|
1147
|
+
if (name === moduleName) {
|
|
1148
|
+
newModules.push({ ...modules[moduleIndex],
|
|
1149
|
+
...moduleContentArr[moduleContentArrIndex]
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
} catch (e) {
|
|
1154
|
+
fail$6(`${moduleConfigPath}配置错误: ${e}`);
|
|
1155
|
+
newModules.push({ ...modules[moduleIndex]
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
} else {
|
|
1159
|
+
newModules.push({ ...modules[moduleIndex]
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
return newModules;
|
|
945
1164
|
};
|
|
946
1165
|
/**
|
|
947
|
-
*
|
|
948
|
-
*
|
|
1166
|
+
* 分包依赖了分包的模块 合并所依赖的modules
|
|
1167
|
+
* @param { object } tmsConfig
|
|
1168
|
+
* @param {array} modules
|
|
1169
|
+
* @param {string} moduleDir
|
|
1170
|
+
* @returns
|
|
949
1171
|
*/
|
|
950
1172
|
|
|
951
1173
|
|
|
952
|
-
const
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
}) => {
|
|
957
|
-
|
|
958
|
-
appId,
|
|
959
|
-
projectPath,
|
|
960
|
-
privateKey
|
|
1174
|
+
const subModulesMergeDepModules$2 = (tmsConfig, modules) => {
|
|
1175
|
+
const moduleNames = [];
|
|
1176
|
+
modules.forEach(({
|
|
1177
|
+
name: moduleName
|
|
1178
|
+
}) => {
|
|
1179
|
+
moduleNames.push(moduleName);
|
|
961
1180
|
});
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1181
|
+
let mergeModules = modules;
|
|
1182
|
+
let isOver = true;
|
|
1183
|
+
modules.forEach(({
|
|
1184
|
+
dependencies: dependencyModules
|
|
1185
|
+
}) => {
|
|
1186
|
+
dependencyModules === null || dependencyModules === void 0 ? void 0 : dependencyModules.forEach(item => {
|
|
1187
|
+
// 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
|
|
1188
|
+
// 否则递归处理,根据name找到相关配置加到modules里
|
|
1189
|
+
if (moduleNames.indexOf(item) === -1) {
|
|
1190
|
+
isOver = false;
|
|
1191
|
+
const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
|
|
1192
|
+
mergeModules = [...mergeModules, ...tmpModules];
|
|
1193
|
+
mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
});
|
|
1197
|
+
return isOver ? mergeModules : subModulesMergeDepModules$2(tmsConfig, mergeModules);
|
|
974
1198
|
};
|
|
975
1199
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
const instance = getGlobalInstance$1();
|
|
983
|
-
const key = `${branch}:${url}`;
|
|
984
|
-
instance.moduleCache[key] = {
|
|
985
|
-
dest
|
|
986
|
-
};
|
|
987
|
-
return instance.moduleCache[key];
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
getModuleCache(url, branch) {
|
|
991
|
-
const instance = getGlobalInstance$1();
|
|
992
|
-
return instance.moduleCache[`${branch}:${url}`];
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
let instance;
|
|
998
|
-
|
|
999
|
-
function getGlobalInstance$1() {
|
|
1000
|
-
if (instance) {
|
|
1001
|
-
return instance;
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
return instance = new Globale();
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
var global = {
|
|
1008
|
-
getGlobalInstance: getGlobalInstance$1
|
|
1200
|
+
var tkitUtils = {
|
|
1201
|
+
readTmsConfig: readTmsConfig$1,
|
|
1202
|
+
readTmsPrivateCf: readTmsPrivateCf$2,
|
|
1203
|
+
checkModules: checkModules$1,
|
|
1204
|
+
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
|
|
1205
|
+
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
1009
1206
|
};
|
|
1010
1207
|
|
|
1011
|
-
const MetalSmith = require$$0__default$
|
|
1208
|
+
const MetalSmith = require$$0__default$4;
|
|
1012
1209
|
const {
|
|
1013
1210
|
getGlobalInstance
|
|
1014
1211
|
} = global;
|
|
@@ -1017,10 +1214,39 @@ const {
|
|
|
1017
1214
|
resolve: resolve$8
|
|
1018
1215
|
} = widgets;
|
|
1019
1216
|
const {
|
|
1020
|
-
|
|
1217
|
+
readTmsPrivateCf: readTmsPrivateCf$1
|
|
1218
|
+
} = tkitUtils;
|
|
1219
|
+
const {
|
|
1220
|
+
fail: fail$5
|
|
1021
1221
|
} = log$2;
|
|
1022
|
-
const fs$
|
|
1023
|
-
const shelljs$4 = require$$
|
|
1222
|
+
const fs$8 = require$$0__default$1;
|
|
1223
|
+
const shelljs$4 = require$$4__default;
|
|
1224
|
+
const {
|
|
1225
|
+
handleError: handleError$1
|
|
1226
|
+
} = handleError_1;
|
|
1227
|
+
/**
|
|
1228
|
+
* 处理用户没有clone git仓库权限问题——拼接账号信息
|
|
1229
|
+
* @param {*} httpRepoUrl
|
|
1230
|
+
* @param {*} moduleName
|
|
1231
|
+
* @returns
|
|
1232
|
+
*/
|
|
1233
|
+
|
|
1234
|
+
function replaceGitUrlAccount(httpRepoUrl, moduleName, privateCf) {
|
|
1235
|
+
var _privateCf$gitAccout;
|
|
1236
|
+
|
|
1237
|
+
let gitUrl = httpRepoUrl;
|
|
1238
|
+
const {
|
|
1239
|
+
username = '',
|
|
1240
|
+
pass = ''
|
|
1241
|
+
} = (privateCf === null || privateCf === void 0 ? void 0 : (_privateCf$gitAccout = privateCf.gitAccout) === null || _privateCf$gitAccout === void 0 ? void 0 : _privateCf$gitAccout[moduleName]) || {};
|
|
1242
|
+
const urlPrefixReg = /http(s)?:\/\//;
|
|
1243
|
+
|
|
1244
|
+
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
1245
|
+
gitUrl = gitUrl.replace(urlPrefixReg, val => `${val}${encodeURIComponent(username)}:${pass}@`);
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
return gitUrl;
|
|
1249
|
+
}
|
|
1024
1250
|
/**
|
|
1025
1251
|
* 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
|
|
1026
1252
|
* @param { string } sourceDir 缓存文件夹
|
|
@@ -1029,14 +1255,14 @@ const shelljs$4 = require$$0__default$2;
|
|
|
1029
1255
|
* @returns { undefined } no return
|
|
1030
1256
|
*/
|
|
1031
1257
|
|
|
1258
|
+
|
|
1032
1259
|
function moveFile(sourceDir, targetDir, ignore = []) {
|
|
1033
1260
|
// 删除不是文件夹的文件
|
|
1034
|
-
return new Promise(resolve => {
|
|
1261
|
+
return new Promise((resolve, reject) => {
|
|
1035
1262
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1036
1263
|
if (e) {
|
|
1037
|
-
fail$
|
|
1038
|
-
|
|
1039
|
-
console.log('MetalSmith 详细的错误信息:', e);
|
|
1264
|
+
fail$5(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
|
|
1265
|
+
reject(e);
|
|
1040
1266
|
}
|
|
1041
1267
|
|
|
1042
1268
|
resolve();
|
|
@@ -1047,16 +1273,18 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
1047
1273
|
* 下载目标模块
|
|
1048
1274
|
* @param { string } sourceDir 缓存文件夹
|
|
1049
1275
|
* @param { string } targetDir 目标文件夹
|
|
1276
|
+
* @param { boolean } isDev 是否是dev
|
|
1050
1277
|
* @returns { array } modules 描述模块的列表
|
|
1051
1278
|
*/
|
|
1052
1279
|
|
|
1053
1280
|
|
|
1054
|
-
async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
1055
|
-
//
|
|
1281
|
+
async function cloneModules$1(sourceDir, targetDir, modules, isDev) {
|
|
1282
|
+
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1283
|
+
const privateCf = readTmsPrivateCf$1(); // 根据小程序的配置文件下载模块, 并且处理信息
|
|
1284
|
+
|
|
1056
1285
|
for (const moduleInfo of modules) {
|
|
1057
|
-
// eslint-disable-line
|
|
1058
1286
|
if (moduleInfo.repoInfo) {
|
|
1059
|
-
await downLoadAndMoveModule(sourceDir, targetDir, moduleInfo);
|
|
1287
|
+
await downLoadAndMoveModule(sourceDir, targetDir, moduleInfo, privateCf, isDev);
|
|
1060
1288
|
}
|
|
1061
1289
|
}
|
|
1062
1290
|
}
|
|
@@ -1064,20 +1292,22 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1064
1292
|
* 下载模块信息并且将它移动到对应的位置
|
|
1065
1293
|
* @param { string } sourceDir 代码缓存文件夹
|
|
1066
1294
|
* @param { string } targetDir 代码要放到的目标文件夹
|
|
1295
|
+
* @param { boolean } isDev 是否是dev
|
|
1067
1296
|
* @returns { array } moduleInfo 描述模块的信息
|
|
1068
1297
|
*/
|
|
1069
1298
|
|
|
1070
1299
|
|
|
1071
|
-
async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
|
|
1300
|
+
async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo, privateCf, isDev) {
|
|
1072
1301
|
const {
|
|
1073
1302
|
repoInfo: {
|
|
1074
1303
|
buildGitTag,
|
|
1075
1304
|
httpRepoUrl
|
|
1076
1305
|
},
|
|
1077
|
-
path
|
|
1306
|
+
path,
|
|
1307
|
+
name
|
|
1078
1308
|
} = moduleInfo; // 源码临时存在的源目录
|
|
1079
1309
|
|
|
1080
|
-
let sourcePath = resolve$8(sourceDir,
|
|
1310
|
+
let sourcePath = resolve$8(sourceDir, name); // 源码要放到目标目录
|
|
1081
1311
|
|
|
1082
1312
|
const targetPath = resolve$8(targetDir, path); // 设置模块的构建分支
|
|
1083
1313
|
|
|
@@ -1088,21 +1318,21 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
|
|
|
1088
1318
|
|
|
1089
1319
|
try {
|
|
1090
1320
|
if (!moduleInCache) {
|
|
1091
|
-
|
|
1321
|
+
// 处理仓库权限问题
|
|
1322
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, name, privateCf);
|
|
1323
|
+
await downloadRepoForGit(gitUrl, sourcePath, cloneBranch);
|
|
1092
1324
|
globalInstance.setModuleCache(httpRepoUrl, cloneBranch, sourcePath);
|
|
1093
1325
|
} else {
|
|
1094
1326
|
sourcePath = globalInstance.getModuleCache(httpRepoUrl, cloneBranch).dest;
|
|
1095
1327
|
}
|
|
1096
1328
|
|
|
1097
|
-
if (fs$
|
|
1098
|
-
shelljs$4.rm('-rf', targetPath);
|
|
1329
|
+
if (fs$8.existsSync(targetPath)) {
|
|
1330
|
+
shelljs$4.rm('-rf', `${targetPath}/*`);
|
|
1099
1331
|
}
|
|
1100
1332
|
|
|
1101
1333
|
await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
|
|
1102
1334
|
} catch (e) {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
process.exit(-1);
|
|
1335
|
+
handleError$1(e, isDev);
|
|
1106
1336
|
}
|
|
1107
1337
|
}
|
|
1108
1338
|
|
|
@@ -1110,165 +1340,323 @@ var cloneModules_1 = {
|
|
|
1110
1340
|
cloneModules: cloneModules$1
|
|
1111
1341
|
};
|
|
1112
1342
|
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
/** 编译输出文件夹位置 */
|
|
1120
|
-
outputDir: 'dist',
|
|
1343
|
+
const ci = require$$0__default$6;
|
|
1344
|
+
const path$6 = require$$3__default;
|
|
1345
|
+
/**
|
|
1346
|
+
* 获取小程序ci的Project对象
|
|
1347
|
+
* @returns {Object} 小程序ci对象
|
|
1348
|
+
*/
|
|
1121
1349
|
|
|
1122
|
-
|
|
1123
|
-
|
|
1350
|
+
const getMpCi = ({
|
|
1351
|
+
appId,
|
|
1352
|
+
projectPath,
|
|
1353
|
+
type = 'miniProgram',
|
|
1354
|
+
privateKey = 'TODO'
|
|
1355
|
+
}) => {
|
|
1356
|
+
var _cfgJsonContent$packO;
|
|
1124
1357
|
|
|
1125
|
-
|
|
1126
|
-
sourceMap: 'none',
|
|
1358
|
+
const cfgJsonContent = require(path$6.join(projectPath, 'project.config.json'));
|
|
1127
1359
|
|
|
1128
|
-
|
|
1129
|
-
|
|
1360
|
+
const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
|
|
1361
|
+
value
|
|
1362
|
+
}) => value)) || [];
|
|
1363
|
+
return new ci.Project({
|
|
1364
|
+
appid: appId,
|
|
1365
|
+
privateKey,
|
|
1366
|
+
type,
|
|
1367
|
+
projectPath,
|
|
1368
|
+
ignores: ['node_modules/**/*', ...ignores]
|
|
1369
|
+
});
|
|
1370
|
+
}; // 用小程序ci工具构建小程序
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
const packMpProject = async project => {
|
|
1374
|
+
await ci.packNpm(project, {
|
|
1375
|
+
ignores: ['cloud/**/*']
|
|
1376
|
+
});
|
|
1377
|
+
};
|
|
1378
|
+
/**
|
|
1379
|
+
* 格式化构建npm结果信息
|
|
1380
|
+
* @param {Array<String>} warning 构建时的告警信息
|
|
1381
|
+
* @returns {String} npm构建错误信息
|
|
1382
|
+
*/
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
const formatPackNpmWarning = warning => {
|
|
1386
|
+
if (!warning) {
|
|
1387
|
+
return '';
|
|
1130
1388
|
}
|
|
1389
|
+
|
|
1390
|
+
const result = warning.map((it, index) => `${index + 1}. ${it.msg}
|
|
1391
|
+
\t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
|
|
1392
|
+
return result;
|
|
1393
|
+
};
|
|
1394
|
+
/**
|
|
1395
|
+
* 构建miniprogram_npm
|
|
1396
|
+
* @returns {Object} 小程序ci对象
|
|
1397
|
+
*/
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
const buildMpNpm$1 = async ({
|
|
1401
|
+
appId,
|
|
1402
|
+
projectPath,
|
|
1403
|
+
privateKey
|
|
1404
|
+
}) => {
|
|
1405
|
+
const mpCi = await getMpCi({
|
|
1406
|
+
appId,
|
|
1407
|
+
projectPath,
|
|
1408
|
+
privateKey
|
|
1409
|
+
});
|
|
1410
|
+
const packNpmWarning = await packMpProject(mpCi);
|
|
1411
|
+
const packNpmMsg = formatPackNpmWarning(packNpmWarning);
|
|
1412
|
+
|
|
1413
|
+
if (packNpmMsg) {
|
|
1414
|
+
return Promise.reject(packNpmMsg);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
return Promise.resolve();
|
|
1418
|
+
};
|
|
1419
|
+
|
|
1420
|
+
var mpCiUtils = {
|
|
1421
|
+
buildMpNpm: buildMpNpm$1
|
|
1131
1422
|
};
|
|
1132
1423
|
|
|
1133
|
-
const loadash = require$$0__default$7;
|
|
1134
|
-
const fs$4 = require$$0__default$1;
|
|
1135
|
-
const {
|
|
1136
|
-
TMS_NAME: TMS_NAME$1,
|
|
1137
|
-
TMS_CONFIG_FILENAME,
|
|
1138
|
-
MODULE_CONFIG_FILENAME
|
|
1139
|
-
} = require$$3;
|
|
1140
|
-
const {
|
|
1141
|
-
resolve: resolve$7,
|
|
1142
|
-
isObject
|
|
1143
|
-
} = widgets;
|
|
1144
|
-
const {
|
|
1145
|
-
setModuleConfig
|
|
1146
|
-
} = buildAppJson;
|
|
1147
|
-
const defaultTmsConfig = defaultTmsConfig$1;
|
|
1148
|
-
const {
|
|
1149
|
-
fail: fail$6
|
|
1150
|
-
} = log$2;
|
|
1151
1424
|
/**
|
|
1152
|
-
*
|
|
1153
|
-
* @param env {string} 环境变量
|
|
1425
|
+
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1154
1426
|
*/
|
|
1427
|
+
const fs$7 = require$$0__default$1;
|
|
1428
|
+
const fsExtra = require$$1__default$3;
|
|
1429
|
+
const crypto = require$$2__default$1;
|
|
1430
|
+
const path$5 = require$$3__default;
|
|
1431
|
+
const shell = require$$4__default;
|
|
1432
|
+
const glob = require$$5__default;
|
|
1433
|
+
const LOG = log$2;
|
|
1434
|
+
const shellJsOption = {
|
|
1435
|
+
async: false,
|
|
1436
|
+
silent: true
|
|
1437
|
+
};
|
|
1438
|
+
const dirPath = process.cwd(); // 项目根目录
|
|
1155
1439
|
|
|
1156
|
-
const
|
|
1157
|
-
const
|
|
1440
|
+
const install$3 = async (packageJsonPath = '', retry = true, cacheDir) => {
|
|
1441
|
+
const obj = {};
|
|
1442
|
+
const packageContent = fs$7.readFileSync(packageJsonPath);
|
|
1443
|
+
const packageJson = JSON.parse(packageContent);
|
|
1444
|
+
obj.dependencies = packageJson.dependencies || {}; // obj.devDependencies = packageJson.devDependencies || {};
|
|
1445
|
+
// dependencies和devDependencies字段为空,没有需要安装的npm包,直接return
|
|
1446
|
+
// if (Object.keys(obj.dependencies).length === 0 && Object.keys(obj.devDependencies).length === 0) {
|
|
1158
1447
|
|
|
1159
|
-
if (
|
|
1160
|
-
|
|
1161
|
-
|
|
1448
|
+
if (Object.keys(obj.dependencies).length === 0) {
|
|
1449
|
+
return;
|
|
1450
|
+
} // 以package.json中dependencies字段stringify后的md5值作为缓存key
|
|
1451
|
+
// 任意包名或者版本号的差异,将导致md5后的差异,从而导致缓存失效,重新下载
|
|
1452
|
+
// 如此来保证npm缓存的准确性
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
const str = JSON.stringify(obj);
|
|
1456
|
+
const key = crypto.createHash('md5').update(str).digest('hex');
|
|
1457
|
+
const keyPath = path$5.join(cacheDir, key);
|
|
1458
|
+
const tarFile = path$5.join(keyPath, 'node_modules.tar.gz'); // npm缓存路径不存在
|
|
1459
|
+
// 或者缓存的包大小小于512byte,认为缓存不合法
|
|
1460
|
+
// 清空缓存目录,重新下载npm包缓存
|
|
1461
|
+
|
|
1462
|
+
const missCache = !fsExtra.pathExistsSync(keyPath) || !fsExtra.existsSync(tarFile) || fsExtra.statSync(tarFile).size < 512;
|
|
1463
|
+
|
|
1464
|
+
if (missCache) {
|
|
1465
|
+
console.log(`未命中缓存,下载${packageJsonPath}依赖`);
|
|
1466
|
+
fsExtra.emptydirSync(keyPath);
|
|
1467
|
+
shell.cp('-f', packageJsonPath, keyPath);
|
|
1468
|
+
shell.cd(keyPath);
|
|
1469
|
+
|
|
1470
|
+
try {
|
|
1471
|
+
shell.exec('npx yarn --production --registry http://mirrors.tencent.com/npm/', shellJsOption);
|
|
1472
|
+
} catch (err) {
|
|
1473
|
+
console.log('err', err);
|
|
1474
|
+
|
|
1475
|
+
if (retry) {
|
|
1476
|
+
return await install$3(packageJsonPath, false);
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
throw err;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
shell.exec('tar -zcvf ./node_modules.tar.gz ./node_modules', shellJsOption);
|
|
1483
|
+
shell.exec('rm -rf ./node_modules', shellJsOption);
|
|
1162
1484
|
}
|
|
1163
1485
|
|
|
1164
|
-
|
|
1486
|
+
shell.cp('-Rf', tarFile, `${path$5.dirname(packageJsonPath)}/`);
|
|
1487
|
+
shell.cd(path$5.dirname(packageJsonPath));
|
|
1488
|
+
shell.exec('tar -xzvf ./node_modules.tar.gz -C ./', shellJsOption);
|
|
1489
|
+
shell.exec('rm -rf ./node_modules.tar.gz', shellJsOption);
|
|
1490
|
+
return {
|
|
1491
|
+
missCache,
|
|
1492
|
+
key
|
|
1493
|
+
};
|
|
1494
|
+
}; // 遍历安装指定目录下所有项目的npm依赖
|
|
1165
1495
|
|
|
1166
|
-
const tmsConfig = tmsConfigFn({
|
|
1167
|
-
env
|
|
1168
|
-
}); // 合并默认值
|
|
1169
1496
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1497
|
+
const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
1498
|
+
const packageJsonFiles = await findAllPackageJson(modules, contextDir);
|
|
1499
|
+
await Promise.all(packageJsonFiles.map(file => install$3(file, true, cacheDir)));
|
|
1172
1500
|
};
|
|
1173
1501
|
/**
|
|
1174
|
-
*
|
|
1175
|
-
* @param {
|
|
1176
|
-
* @param {
|
|
1177
|
-
* @returns
|
|
1502
|
+
* 递归查找指定条件的文件
|
|
1503
|
+
* @param {String} startPath 开始查找的根路径
|
|
1504
|
+
* @param {String} filter 匹配的字符串
|
|
1505
|
+
* @returns {Array<String>} 查找到的文件路径列表
|
|
1178
1506
|
*/
|
|
1179
1507
|
|
|
1180
1508
|
|
|
1181
|
-
const
|
|
1182
|
-
const
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1509
|
+
const findFilesByFilter = (startPath, filter) => {
|
|
1510
|
+
const result = [];
|
|
1511
|
+
/**
|
|
1512
|
+
* 根据指定的筛选器查找文件
|
|
1513
|
+
* @param {String} startPath 开始查找的文件夹路径
|
|
1514
|
+
* @param {String} filter 筛选器
|
|
1515
|
+
* @returns {Undefined} 无需返回值
|
|
1516
|
+
*/
|
|
1187
1517
|
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1518
|
+
const find = (startPath, filter) => {
|
|
1519
|
+
// 目录不存在
|
|
1520
|
+
if (!fs$7.existsSync(startPath)) {
|
|
1521
|
+
LOG.fail(`${startPath}目录不存在`);
|
|
1522
|
+
process.exit(-1);
|
|
1523
|
+
return;
|
|
1524
|
+
} // 当前目录下的所有文件 / 文件夹
|
|
1192
1525
|
|
|
1193
|
-
|
|
1526
|
+
|
|
1527
|
+
const exceptDir = ['node_modules', 'miniprogram_npm'];
|
|
1528
|
+
|
|
1529
|
+
if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
const files = fs$7.readdirSync(startPath);
|
|
1534
|
+
files.forEach(file => {
|
|
1535
|
+
const filename = path$5.join(startPath, file);
|
|
1536
|
+
const stat = fs$7.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1537
|
+
|
|
1538
|
+
if (stat.isDirectory()) {
|
|
1539
|
+
find(filename, filter);
|
|
1540
|
+
} else if (filename.indexOf(filter) >= 0) {
|
|
1541
|
+
// 文件类型
|
|
1542
|
+
result.push(filename);
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
};
|
|
1546
|
+
|
|
1547
|
+
find(startPath, filter);
|
|
1548
|
+
return result;
|
|
1194
1549
|
};
|
|
1195
1550
|
/**
|
|
1196
|
-
*
|
|
1197
|
-
* @param {
|
|
1198
|
-
* @param {
|
|
1199
|
-
* @
|
|
1200
|
-
* @returns
|
|
1551
|
+
* 找到项目中所有的package.json文件
|
|
1552
|
+
* @param {Array<String>} subRoots 需要安装npm依赖的路径
|
|
1553
|
+
* @param {String} contextDir 命令运行的目录
|
|
1554
|
+
* @returns {Array<String>} 找到的所有package.json文件的路径
|
|
1201
1555
|
*/
|
|
1202
1556
|
|
|
1203
1557
|
|
|
1204
|
-
const
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
moduleConfigContent = setModuleConfig(moduleConfigContent, appName, moduleDir);
|
|
1215
|
-
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
1216
|
-
moduleContentArr.forEach(({
|
|
1217
|
-
name
|
|
1218
|
-
}, moduleContentArrIndex) => {
|
|
1219
|
-
if (name === moduleName) {
|
|
1220
|
-
newModules.push({ ...modules[moduleIndex],
|
|
1221
|
-
...moduleContentArr[moduleContentArrIndex]
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
});
|
|
1225
|
-
} else {
|
|
1226
|
-
newModules.push({ ...modules[moduleIndex]
|
|
1227
|
-
});
|
|
1558
|
+
const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
1559
|
+
const packageJsonName = 'package.json'; // 查找文件名
|
|
1560
|
+
|
|
1561
|
+
const cwd = contextDir || dirPath;
|
|
1562
|
+
const result = [path$5.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1563
|
+
|
|
1564
|
+
subRoots.forEach(subRoot => {
|
|
1565
|
+
if (!subRoot.root) {
|
|
1566
|
+
LOG.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
|
|
1567
|
+
process.exit(1);
|
|
1228
1568
|
}
|
|
1569
|
+
|
|
1570
|
+
const toppath = path$5.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1571
|
+
|
|
1572
|
+
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1573
|
+
result.push(...list);
|
|
1229
1574
|
});
|
|
1230
|
-
return
|
|
1575
|
+
return result;
|
|
1231
1576
|
};
|
|
1232
1577
|
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1578
|
+
function cloudNpmInstall$1(contextDir) {
|
|
1579
|
+
return new Promise((resolve, reject) => {
|
|
1580
|
+
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
1581
|
+
if (err) {
|
|
1582
|
+
reject(err);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
files.forEach(file => {
|
|
1586
|
+
const dir = path$5.dirname(file);
|
|
1587
|
+
shell.cd(dir);
|
|
1588
|
+
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1589
|
+
silent: false
|
|
1590
|
+
});
|
|
1591
|
+
});
|
|
1592
|
+
resolve();
|
|
1593
|
+
});
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
var npmUtils = {
|
|
1598
|
+
cloudNpmInstall: cloudNpmInstall$1,
|
|
1599
|
+
mpNpmInstallAll: mpNpmInstallAll$1,
|
|
1600
|
+
findAllPackageJson
|
|
1237
1601
|
};
|
|
1238
1602
|
|
|
1239
|
-
const shelljs$3 = require$$0__default$2;
|
|
1240
|
-
const fs$3 = require$$0__default$1;
|
|
1241
|
-
const io = io$2;
|
|
1242
1603
|
const {
|
|
1243
|
-
|
|
1244
|
-
|
|
1604
|
+
createTask: createTask$2,
|
|
1605
|
+
resolve: resolve$7
|
|
1245
1606
|
} = widgets;
|
|
1246
1607
|
const {
|
|
1247
|
-
|
|
1248
|
-
} =
|
|
1608
|
+
buildMpNpm
|
|
1609
|
+
} = mpCiUtils;
|
|
1610
|
+
const {
|
|
1611
|
+
CACHE_DIR
|
|
1612
|
+
} = require$$3;
|
|
1249
1613
|
const {
|
|
1250
|
-
|
|
1614
|
+
cloudNpmInstall,
|
|
1615
|
+
mpNpmInstallAll
|
|
1251
1616
|
} = npmUtils;
|
|
1617
|
+
|
|
1618
|
+
async function install$2(tmsConfig, modules, isCloud = false) {
|
|
1619
|
+
// 小程序npm install
|
|
1620
|
+
await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(modules, resolve$7(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
|
|
1621
|
+
|
|
1622
|
+
await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
|
|
1623
|
+
appId: tmsConfig.appId,
|
|
1624
|
+
projectPath: resolve$7('./'),
|
|
1625
|
+
privateKey: tmsConfig.privateKey
|
|
1626
|
+
}); // 安装云函数的
|
|
1627
|
+
|
|
1628
|
+
isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$7(tmsConfig.cloudDir));
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
var install_1 = install$2;
|
|
1632
|
+
|
|
1633
|
+
const shelljs$3 = require$$4__default;
|
|
1634
|
+
const fs$6 = require$$0__default$1;
|
|
1635
|
+
const io = io$2;
|
|
1252
1636
|
const {
|
|
1253
|
-
|
|
1254
|
-
|
|
1637
|
+
resolve: resolve$6,
|
|
1638
|
+
createTask: createTask$1
|
|
1639
|
+
} = widgets;
|
|
1640
|
+
const {
|
|
1641
|
+
buildOutputAppJson
|
|
1642
|
+
} = buildAppJson;
|
|
1255
1643
|
const {
|
|
1256
1644
|
MODULE_CODE_DIR,
|
|
1257
|
-
|
|
1258
|
-
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
|
|
1259
|
-
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3
|
|
1645
|
+
DEFAULT_COPY_CONFIG
|
|
1260
1646
|
} = require$$3;
|
|
1261
1647
|
const {
|
|
1262
1648
|
cloneModules
|
|
1263
1649
|
} = cloneModules_1;
|
|
1264
1650
|
const {
|
|
1265
|
-
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2
|
|
1651
|
+
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2,
|
|
1652
|
+
subModulesMergeDepModules: subModulesMergeDepModules$1
|
|
1266
1653
|
} = tkitUtils;
|
|
1267
1654
|
const {
|
|
1268
|
-
fail: fail$
|
|
1655
|
+
fail: fail$4
|
|
1269
1656
|
} = log$2;
|
|
1657
|
+
const install$1 = install_1;
|
|
1270
1658
|
/**
|
|
1271
|
-
*
|
|
1659
|
+
* 拷贝相关配置文件到编译输出目录
|
|
1272
1660
|
* @param { object } tmsConfig
|
|
1273
1661
|
* @param { array } modules
|
|
1274
1662
|
* @param { array } defaultFiles 默认需要拷贝的配置项
|
|
@@ -1276,504 +1664,935 @@ const {
|
|
|
1276
1664
|
*/
|
|
1277
1665
|
|
|
1278
1666
|
const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
1279
|
-
const outputDir = resolve$6(tmsConfig.
|
|
1667
|
+
const outputDir = resolve$6(tmsConfig.outputDir);
|
|
1280
1668
|
io.ensureDirExist(outputDir);
|
|
1281
1669
|
defaultFiles.forEach(item => {
|
|
1282
|
-
if (fs$
|
|
1283
|
-
shelljs$3.cp('-rf', resolve$6(item), resolve$6(tmsConfig.
|
|
1670
|
+
if (fs$6.existsSync(resolve$6(item))) {
|
|
1671
|
+
shelljs$3.cp('-rf', resolve$6(item), resolve$6(tmsConfig.outputDir, item));
|
|
1284
1672
|
}
|
|
1285
|
-
}); //
|
|
1673
|
+
}); // 拷贝模块的package.json到编译输出目录
|
|
1286
1674
|
|
|
1287
1675
|
targetModules.forEach(item => {
|
|
1288
|
-
const outputModuleDir = resolve$6(`${tmsConfig.
|
|
1676
|
+
const outputModuleDir = resolve$6(`${tmsConfig.outputDir}/${item.root}`);
|
|
1289
1677
|
|
|
1290
|
-
if (!fs$
|
|
1291
|
-
fail$
|
|
1678
|
+
if (!fs$6.existsSync(resolve$6(item.path))) {
|
|
1679
|
+
fail$4(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1292
1680
|
process.exit(1);
|
|
1293
1681
|
}
|
|
1294
1682
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
// 删除除了node_modules、miniprogram_npm 的其他文件
|
|
1299
|
-
// eslint-disable-next-line
|
|
1300
|
-
shelljs$3.exec('find . -not \( -name node_modules -or -name miniprogram_npm \) -delete', {
|
|
1301
|
-
silent: true
|
|
1302
|
-
});
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
shelljs$3.cp('-Rf', `${resolve$6(item.path)}/*`, outputModuleDir);
|
|
1683
|
+
io.ensureDirExist(outputModuleDir);
|
|
1684
|
+
const modulePackagePath = resolve$6(item.path, 'package.json');
|
|
1685
|
+
if (fs$6.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1306
1686
|
});
|
|
1307
1687
|
};
|
|
1308
1688
|
|
|
1309
|
-
async function task(tmsConfig, targetModules) {
|
|
1689
|
+
async function task(tmsConfig, targetModules, isDev) {
|
|
1310
1690
|
// 下载和移动代码
|
|
1311
|
-
await createTask$
|
|
1691
|
+
await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules, isDev); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1312
1692
|
|
|
1313
|
-
|
|
1314
|
-
console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
|
|
1693
|
+
let newModules = tmsModulesMergeLocalModuleCfg$2(targetModules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
1315
1694
|
|
|
1316
|
-
|
|
1695
|
+
newModules = subModulesMergeDepModules$1(tmsConfig, newModules); // 拷贝相关配置文件到输出目录
|
|
1317
1696
|
|
|
1318
|
-
await createTask$
|
|
1697
|
+
await createTask$1(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
|
|
1319
1698
|
|
|
1320
|
-
await
|
|
1321
|
-
appId: tmsConfig.appId,
|
|
1322
|
-
projectPath: resolve$6('./'),
|
|
1323
|
-
privateKey: tmsConfig.privateKey
|
|
1324
|
-
}); // 动态生成编译后的app.json;
|
|
1699
|
+
await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
|
|
1325
1700
|
|
|
1326
|
-
await createTask$
|
|
1701
|
+
await createTask$1(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules, isDev);
|
|
1327
1702
|
return newModules;
|
|
1328
1703
|
}
|
|
1329
1704
|
|
|
1330
|
-
async function
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1705
|
+
async function init$5(tmsConfig, targetModules, isDev) {
|
|
1706
|
+
try {
|
|
1707
|
+
const newModules = await task(tmsConfig, targetModules, isDev);
|
|
1708
|
+
return {
|
|
1709
|
+
targetModules: newModules
|
|
1710
|
+
};
|
|
1711
|
+
} catch (error) {
|
|
1712
|
+
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1713
|
+
fail$4(`init流程出现错误${errMsg}`);
|
|
1714
|
+
process.exit(1);
|
|
1715
|
+
}
|
|
1335
1716
|
}
|
|
1336
1717
|
|
|
1337
|
-
var init$5
|
|
1718
|
+
var init_1 = init$5;
|
|
1338
1719
|
|
|
1339
|
-
|
|
1340
|
-
|
|
1720
|
+
var dev$3 = {exports: {}};
|
|
1721
|
+
|
|
1722
|
+
const through$3 = require$$0__default$7;
|
|
1723
|
+
|
|
1724
|
+
function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
|
|
1725
|
+
const stream = through$3.obj(function (file, enc, cb) {
|
|
1726
|
+
if (file.isBuffer()) {
|
|
1727
|
+
let contents = String(file.contents);
|
|
1728
|
+
let resReg; // eslint-disable-next-line
|
|
1729
|
+
|
|
1730
|
+
while ((resReg = reg.exec(contents)) !== null) {
|
|
1731
|
+
const [reg1, reg2, reg3] = resReg;
|
|
1732
|
+
|
|
1733
|
+
if (reg1 && reg2 && reg3) {
|
|
1734
|
+
const value = typeof envData[reg3] === 'object' ? JSON.stringify(envData[reg3]) : envData[reg3];
|
|
1735
|
+
contents = contents.replace(reg1, value);
|
|
1736
|
+
} else if (reg1 && !reg2 && !reg3) {
|
|
1737
|
+
contents = contents.replace(reg1, JSON.stringify(envData));
|
|
1738
|
+
}
|
|
1739
|
+
} // eslint-disable-next-line
|
|
1740
|
+
|
|
1741
|
+
|
|
1742
|
+
file.contents = Buffer.from(contents);
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
this.push(file);
|
|
1746
|
+
cb();
|
|
1747
|
+
});
|
|
1748
|
+
return stream;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
var replaceEnv_1 = replaceEnv$1;
|
|
1752
|
+
|
|
1753
|
+
/* eslint-disable no-param-reassign */
|
|
1754
|
+
const strip = require$$0__default$8; // 匹配规则
|
|
1755
|
+
|
|
1756
|
+
const MATCH_RULE = new RegExp(/@import *(?:url\(['"]?([^'")]+)['"]?\)|['"]([^'"]+)['"]);?/g);
|
|
1757
|
+
/**
|
|
1758
|
+
* 获取样式文件中的@import语句
|
|
1759
|
+
* @param code 代码片段
|
|
1760
|
+
* @returns 结果数组
|
|
1761
|
+
*/
|
|
1762
|
+
|
|
1763
|
+
const findCssImports$1 = code => {
|
|
1764
|
+
// 将buffer转成字符串
|
|
1765
|
+
code = code.toString(); // 去除注释
|
|
1766
|
+
|
|
1767
|
+
code = strip.block(code); // 定义最后返回的结果
|
|
1768
|
+
|
|
1769
|
+
const result = [];
|
|
1770
|
+
let matchList; // 循环遍历代码段,直至匹配结果为空
|
|
1771
|
+
|
|
1772
|
+
while (matchList = MATCH_RULE.exec(code)) {
|
|
1773
|
+
var _matchList, _matchList2;
|
|
1774
|
+
|
|
1775
|
+
// 存入结果数组
|
|
1776
|
+
result.push(((_matchList = matchList) === null || _matchList === void 0 ? void 0 : _matchList[1]) || ((_matchList2 = matchList) === null || _matchList2 === void 0 ? void 0 : _matchList2[2]));
|
|
1777
|
+
} // 返回结果
|
|
1778
|
+
|
|
1779
|
+
|
|
1780
|
+
return result;
|
|
1781
|
+
};
|
|
1782
|
+
|
|
1783
|
+
var findCssImport = {
|
|
1784
|
+
findCssImports: findCssImports$1
|
|
1785
|
+
};
|
|
1786
|
+
|
|
1787
|
+
/* eslint-disable no-param-reassign */
|
|
1341
1788
|
const {
|
|
1342
|
-
|
|
1343
|
-
} =
|
|
1789
|
+
fail: fail$3
|
|
1790
|
+
} = log$2;
|
|
1791
|
+
|
|
1792
|
+
function pluginError$3(error, isWatch) {
|
|
1793
|
+
const errMsg = error.message;
|
|
1794
|
+
|
|
1795
|
+
if (isWatch) {
|
|
1796
|
+
fail$3(errMsg);
|
|
1797
|
+
} else {
|
|
1798
|
+
fail$3(errMsg);
|
|
1799
|
+
process.exit(1);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
var pluginError_1 = {
|
|
1804
|
+
pluginError: pluginError$3
|
|
1805
|
+
};
|
|
1806
|
+
|
|
1807
|
+
/* eslint-disable no-param-reassign */
|
|
1808
|
+
const through$2 = require$$0__default$7;
|
|
1809
|
+
const precinct = require$$1__default$4;
|
|
1810
|
+
const path$4 = require$$3__default;
|
|
1344
1811
|
const {
|
|
1345
|
-
|
|
1346
|
-
} =
|
|
1812
|
+
findCssImports
|
|
1813
|
+
} = findCssImport;
|
|
1347
1814
|
const {
|
|
1348
|
-
|
|
1349
|
-
|
|
1815
|
+
ext: ext$2,
|
|
1816
|
+
fileInDir: fileInDir$2,
|
|
1817
|
+
diffContentCopyFile: diffContentCopyFile$2
|
|
1818
|
+
} = io$2;
|
|
1350
1819
|
const {
|
|
1351
|
-
|
|
1352
|
-
} =
|
|
1820
|
+
resolve: resolve$5
|
|
1821
|
+
} = widgets;
|
|
1822
|
+
const fs$5 = require$$0__default$1;
|
|
1353
1823
|
const {
|
|
1354
|
-
|
|
1355
|
-
} =
|
|
1356
|
-
const
|
|
1357
|
-
const extensions = ['.ts', '.js'];
|
|
1824
|
+
pluginError: pluginError$2
|
|
1825
|
+
} = pluginError_1;
|
|
1826
|
+
const cssFilter = ['.less', '.wxss'];
|
|
1358
1827
|
|
|
1359
|
-
function
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
try {
|
|
1363
|
-
const stat = fs$2.lstatSync(newEntry);
|
|
1828
|
+
const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensions, isWatch = true) {
|
|
1829
|
+
const resDep = new Map();
|
|
1364
1830
|
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
}
|
|
1368
|
-
} catch (e) {}
|
|
1831
|
+
function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
|
|
1832
|
+
let contents = '';
|
|
1369
1833
|
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
return {
|
|
1375
|
-
file,
|
|
1376
|
-
ext
|
|
1377
|
-
};
|
|
1834
|
+
try {
|
|
1835
|
+
contents = fs$5.readFileSync(anaFileOriginFile, 'utf8');
|
|
1836
|
+
} catch (e) {
|
|
1837
|
+
pluginError$2(e, isWatch);
|
|
1378
1838
|
}
|
|
1379
|
-
}
|
|
1380
1839
|
|
|
1381
|
-
|
|
1382
|
-
|
|
1840
|
+
const deps = cssFilter.indexOf(path$4.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
1841
|
+
deps.forEach(depItem => {
|
|
1842
|
+
if (depItem.startsWith('.')) {
|
|
1843
|
+
// 被依赖文件的存在的绝对路径
|
|
1844
|
+
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
1845
|
+
|
|
1846
|
+
const {
|
|
1847
|
+
ext: extAlias,
|
|
1848
|
+
file: depOriginFile,
|
|
1849
|
+
extPath
|
|
1850
|
+
} = ext$2(depOriginPath, extensions);
|
|
1851
|
+
|
|
1852
|
+
if (!fs$5.existsSync(depOriginFile)) {
|
|
1853
|
+
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
1854
|
+
return;
|
|
1855
|
+
}
|
|
1383
1856
|
|
|
1857
|
+
const depDestPath = resolve$5(path$4.dirname(anaFileDestFile), depItem);
|
|
1858
|
+
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
1384
1859
|
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1860
|
+
if (!resDep.has(depDestFile)) {
|
|
1861
|
+
resDep.set(depDestFile, {
|
|
1862
|
+
anaFileOriginFile,
|
|
1863
|
+
anaFileDestFile,
|
|
1864
|
+
depDestFile,
|
|
1865
|
+
depOriginFile
|
|
1866
|
+
});
|
|
1867
|
+
dfs(depOriginFile, depDestFile, extensions);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1395
1870
|
});
|
|
1396
|
-
}
|
|
1397
|
-
return alias;
|
|
1398
|
-
} // 根据用户选择的modules,找到module.config.json的配置信息,找到所有的page
|
|
1399
|
-
|
|
1871
|
+
}
|
|
1400
1872
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1873
|
+
dfs(anaFileOriginFile, anaFileDestFile, extensions);
|
|
1874
|
+
return resDep;
|
|
1875
|
+
};
|
|
1403
1876
|
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1877
|
+
function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
1878
|
+
const stream = through$2.obj(function (file, enc, cb) {
|
|
1879
|
+
// 依赖分析的文件
|
|
1880
|
+
const anaFileOriginFile = file.history[0];
|
|
1881
|
+
const anaFileRelativeModule = path$4.relative(resolve$5(module.from), anaFileOriginFile);
|
|
1882
|
+
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
1883
|
+
|
|
1884
|
+
if (file.isBuffer()) {
|
|
1885
|
+
let contents = String(file.contents);
|
|
1886
|
+
const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
1887
|
+
const copyModules = new Map();
|
|
1888
|
+
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
1889
|
+
const includePath = tmsConfig.dependencies[includeName];
|
|
1890
|
+
deps.forEach(depItem => {
|
|
1891
|
+
if (depItem.indexOf(includeName) > -1) {
|
|
1892
|
+
// 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
|
|
1893
|
+
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
1894
|
+
|
|
1895
|
+
const {
|
|
1896
|
+
ext: extAlias,
|
|
1897
|
+
file: depOriginFile,
|
|
1898
|
+
extPath
|
|
1899
|
+
} = ext$2(depOriginPath, extensions);
|
|
1900
|
+
|
|
1901
|
+
if (!fileInDir$2(includePath, depOriginFile)) {
|
|
1902
|
+
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
1903
|
+
return;
|
|
1904
|
+
} // eslint-disable-next-line
|
|
1905
|
+
|
|
1906
|
+
|
|
1907
|
+
const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
1908
|
+
const regRes = depItem.match(reg) || [];
|
|
1909
|
+
|
|
1910
|
+
if (regRes[2]) {
|
|
1911
|
+
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
1912
|
+
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
1913
|
+
|
|
1914
|
+
if (!copyModules.has(depDestFile)) {
|
|
1915
|
+
copyModules.set(depDestFile, {
|
|
1916
|
+
depOriginFile,
|
|
1917
|
+
depDestFile,
|
|
1918
|
+
beforeDepPath: depItem,
|
|
1919
|
+
afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
});
|
|
1925
|
+
}); // console.log('mpCommonDep copyModules', copyModules);
|
|
1926
|
+
|
|
1927
|
+
copyModules.forEach(({
|
|
1928
|
+
depOriginFile,
|
|
1929
|
+
depDestFile,
|
|
1930
|
+
beforeDepPath,
|
|
1931
|
+
afterDepPath
|
|
1932
|
+
}) => {
|
|
1933
|
+
diffContentCopyFile$2(depOriginFile, depDestFile);
|
|
1934
|
+
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
1935
|
+
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
1936
|
+
const defs = dfsFindCommonDep$2(depOriginFile, depDestFile, extensions, isWatch);
|
|
1937
|
+
defs.forEach(item => {
|
|
1938
|
+
diffContentCopyFile$2(item.depOriginFile, item.depDestFile);
|
|
1939
|
+
}); // console.log('mpCommonDep defs', defs);
|
|
1940
|
+
});
|
|
1941
|
+
file.contents = Buffer.from(contents);
|
|
1942
|
+
}
|
|
1412
1943
|
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1944
|
+
this.push(file);
|
|
1945
|
+
cb();
|
|
1946
|
+
});
|
|
1947
|
+
return stream;
|
|
1948
|
+
}
|
|
1416
1949
|
|
|
1417
|
-
|
|
1950
|
+
var mpCommonDep_1 = {
|
|
1951
|
+
mpCommonDep: mpCommonDep$1,
|
|
1952
|
+
dfsFindCommonDep: dfsFindCommonDep$2
|
|
1953
|
+
};
|
|
1418
1954
|
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1955
|
+
/* eslint-disable no-param-reassign */
|
|
1956
|
+
const through$1 = require$$0__default$7;
|
|
1957
|
+
const path$3 = require$$3__default;
|
|
1958
|
+
const {
|
|
1959
|
+
ext: ext$1,
|
|
1960
|
+
fileInDir: fileInDir$1,
|
|
1961
|
+
diffContentCopyFile: diffContentCopyFile$1
|
|
1962
|
+
} = io$2;
|
|
1963
|
+
const {
|
|
1964
|
+
resolve: resolve$4
|
|
1965
|
+
} = widgets;
|
|
1966
|
+
const fs$4 = require$$0__default$1;
|
|
1967
|
+
const {
|
|
1968
|
+
pluginError: pluginError$1
|
|
1969
|
+
} = pluginError_1;
|
|
1970
|
+
const {
|
|
1971
|
+
dfsFindCommonDep: dfsFindCommonDep$1
|
|
1972
|
+
} = mpCommonDep_1;
|
|
1973
|
+
|
|
1974
|
+
function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch) {
|
|
1975
|
+
const stream = through$1.obj(function (file, enc, cb) {
|
|
1976
|
+
// 当前分析的文件的路径
|
|
1977
|
+
const anaFileOriginFile = file.history[0];
|
|
1978
|
+
const anaFileRelativeModule = path$3.relative(resolve$4(module.from), anaFileOriginFile);
|
|
1979
|
+
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
1980
|
+
|
|
1981
|
+
if (file.isBuffer()) {
|
|
1982
|
+
const copyModules = new Map();
|
|
1983
|
+
let contents = String(file.contents);
|
|
1984
|
+
|
|
1985
|
+
try {
|
|
1986
|
+
contents = JSON.parse(contents);
|
|
1987
|
+
|
|
1988
|
+
if (contents.usingComponents) {
|
|
1989
|
+
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
1990
|
+
const includePath = tmsConfig.dependencies[includeName];
|
|
1991
|
+
Object.keys(contents.usingComponents).forEach(componentKey => {
|
|
1992
|
+
const componentPath = contents.usingComponents[componentKey];
|
|
1993
|
+
|
|
1994
|
+
if (componentPath.indexOf(includeName) > -1) {
|
|
1995
|
+
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
|
|
1996
|
+
|
|
1997
|
+
const {
|
|
1998
|
+
ext: extAlias,
|
|
1999
|
+
file: depOriginFile,
|
|
2000
|
+
extPath
|
|
2001
|
+
} = ext$1(depOriginPath, extensions);
|
|
2002
|
+
const isFileInDir = fileInDir$1(includePath, depOriginFile);
|
|
2003
|
+
|
|
2004
|
+
if (!isFileInDir) {
|
|
2005
|
+
pluginError$1(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
2006
|
+
return;
|
|
2007
|
+
} // eslint-disable-next-line
|
|
2008
|
+
|
|
2009
|
+
|
|
2010
|
+
const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2011
|
+
const regRes = componentPath.match(reg) || [];
|
|
2012
|
+
|
|
2013
|
+
if (regRes[2]) {
|
|
2014
|
+
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2015
|
+
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2016
|
+
|
|
2017
|
+
if (!copyModules.has(depDestFile)) {
|
|
2018
|
+
copyModules.set(depDestFile, {
|
|
2019
|
+
depOriginFile,
|
|
2020
|
+
depOriginExt: extAlias,
|
|
2021
|
+
depDestFile,
|
|
2022
|
+
beforeDepPath: componentPath,
|
|
2023
|
+
afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
});
|
|
2029
|
+
});
|
|
1422
2030
|
}
|
|
2031
|
+
} catch (e) {
|
|
2032
|
+
pluginError$1(e, isWatch);
|
|
2033
|
+
} // console.log('json copyModules', copyModules);
|
|
2034
|
+
|
|
2035
|
+
|
|
2036
|
+
copyModules.forEach(({
|
|
2037
|
+
depOriginFile,
|
|
2038
|
+
depOriginExt,
|
|
2039
|
+
depDestFile,
|
|
2040
|
+
beforeDepPath,
|
|
2041
|
+
afterDepPath
|
|
2042
|
+
}) => {
|
|
2043
|
+
// 拷贝当前依赖组件几个部分 wxml、wxss、wxs、json
|
|
2044
|
+
filesExt.forEach(extKey => {
|
|
2045
|
+
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2046
|
+
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2047
|
+
|
|
2048
|
+
if (fs$4.existsSync(originFile)) {
|
|
2049
|
+
diffContentCopyFile$1(originFile, destFile);
|
|
2050
|
+
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2051
|
+
|
|
2052
|
+
if (extensionsFilter.indexOf(extKey) > -1) {
|
|
2053
|
+
const defs = dfsFindCommonDep$1(originFile, destFile, extensionsFilter); // console.log('json defs', defs);
|
|
2054
|
+
|
|
2055
|
+
defs.forEach(item => {
|
|
2056
|
+
diffContentCopyFile$1(item.depOriginFile, item.depDestFile);
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
});
|
|
2061
|
+
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
2062
|
+
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2063
|
+
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
2064
|
+
});
|
|
2065
|
+
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
2066
|
+
file.contents = Buffer.from(contents);
|
|
2067
|
+
}
|
|
1423
2068
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
[entryKey]: extValue.file
|
|
1427
|
-
}, getComponentEntry(pageJsonContent, pageDir, path$2.dirname(entryKey)));
|
|
1428
|
-
}
|
|
1429
|
-
});
|
|
2069
|
+
this.push(file);
|
|
2070
|
+
cb();
|
|
1430
2071
|
});
|
|
1431
|
-
return
|
|
1432
|
-
}
|
|
2072
|
+
return stream;
|
|
2073
|
+
}
|
|
1433
2074
|
|
|
2075
|
+
var mpJsonDep_1 = {
|
|
2076
|
+
mpJsonDep: mpJsonDep$1
|
|
2077
|
+
};
|
|
1434
2078
|
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
2079
|
+
/* eslint-disable no-param-reassign */
|
|
2080
|
+
const through = require$$0__default$7;
|
|
2081
|
+
const htmlparser2 = require$$1__default$5;
|
|
2082
|
+
const fs$3 = require$$0__default$1;
|
|
2083
|
+
const path$2 = require$$3__default;
|
|
2084
|
+
const {
|
|
2085
|
+
diffContentCopyFile,
|
|
2086
|
+
ext,
|
|
2087
|
+
fileInDir
|
|
2088
|
+
} = io$2;
|
|
2089
|
+
const {
|
|
2090
|
+
resolve: resolve$3
|
|
2091
|
+
} = widgets;
|
|
2092
|
+
const {
|
|
2093
|
+
dfsFindCommonDep
|
|
2094
|
+
} = mpCommonDep_1;
|
|
2095
|
+
const {
|
|
2096
|
+
pluginError
|
|
2097
|
+
} = pluginError_1; // 处理后缀(源码引入依赖时,不带后缀的情况)
|
|
2098
|
+
|
|
2099
|
+
const extFile = function (name, file) {
|
|
2100
|
+
const extMap = {
|
|
2101
|
+
import: '.wxml',
|
|
2102
|
+
include: '.wxml',
|
|
2103
|
+
wxs: '.wxs'
|
|
1443
2104
|
};
|
|
1444
|
-
|
|
2105
|
+
let extObj = {};
|
|
1445
2106
|
|
|
2107
|
+
if (Object.keys(extMap).indexOf(name) > -1 && !file.endsWith(extMap[name])) {
|
|
2108
|
+
extObj = ext(file, [extMap[name]]);
|
|
2109
|
+
}
|
|
1446
2110
|
|
|
1447
|
-
|
|
1448
|
-
|
|
2111
|
+
return {
|
|
2112
|
+
extPath: extObj.extPath || '',
|
|
2113
|
+
ext: extObj.ext || '',
|
|
2114
|
+
file: extObj.file || file
|
|
2115
|
+
};
|
|
2116
|
+
};
|
|
1449
2117
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
2118
|
+
const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = true) {
|
|
2119
|
+
const resDep = {
|
|
2120
|
+
image: new Map(),
|
|
2121
|
+
wxml: new Map(),
|
|
2122
|
+
wxs: new Map()
|
|
2123
|
+
};
|
|
2124
|
+
|
|
2125
|
+
function dfs(anaFileOriginFile, anaFileDestFile) {
|
|
2126
|
+
let contents = '';
|
|
1454
2127
|
|
|
1455
|
-
|
|
2128
|
+
try {
|
|
2129
|
+
contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
|
|
2130
|
+
} catch (e) {
|
|
2131
|
+
pluginError(e, isWatch);
|
|
2132
|
+
}
|
|
1456
2133
|
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
const comValue = path$2.join(dir, json.usingComponents[key]);
|
|
1461
|
-
const extValue = ext(comValue, extensions);
|
|
1462
|
-
const comKey = path$2.resolve('/', rootKey, json.usingComponents[key]);
|
|
2134
|
+
const parser = new htmlparser2.Parser({
|
|
2135
|
+
onopentag(name, attributes) {
|
|
2136
|
+
var _attributes$src;
|
|
1463
2137
|
|
|
1464
|
-
if (
|
|
1465
|
-
|
|
1466
|
-
process.exit(1);
|
|
1467
|
-
}
|
|
2138
|
+
if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
|
|
2139
|
+
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
|
|
1468
2140
|
|
|
1469
|
-
|
|
1470
|
-
|
|
2141
|
+
const {
|
|
2142
|
+
ext,
|
|
2143
|
+
file: depOriginFile,
|
|
2144
|
+
extPath
|
|
2145
|
+
} = extFile(name, depOriginPath);
|
|
1471
2146
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
2147
|
+
if (!fs$3.existsSync(depOriginFile)) {
|
|
2148
|
+
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
1475
2151
|
|
|
1476
|
-
|
|
2152
|
+
const depDestPath = path$2.join(path$2.dirname(anaFileDestFile), attributes.src);
|
|
2153
|
+
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
|
|
2154
|
+
|
|
2155
|
+
if (['import', 'include'].indexOf(name) > -1) {
|
|
2156
|
+
resDep.wxml.set(depDestFile, {
|
|
2157
|
+
anaFileOriginFile,
|
|
2158
|
+
anaFileDestFile,
|
|
2159
|
+
depDestFile,
|
|
2160
|
+
depOriginFile
|
|
2161
|
+
});
|
|
2162
|
+
dfs(depOriginFile, depDestFile);
|
|
2163
|
+
} // 收集image依赖
|
|
2164
|
+
// if (name === 'image') {
|
|
2165
|
+
// resDep.image.set(attributes.src, {
|
|
2166
|
+
// anaFileOriginFile,
|
|
2167
|
+
// anaFileDestFile,
|
|
2168
|
+
// depDestFile,
|
|
2169
|
+
// depOriginFile,
|
|
2170
|
+
// });
|
|
2171
|
+
// dfs(depOriginFile, depDestFile);
|
|
2172
|
+
// }
|
|
2173
|
+
// 收集wxs依赖
|
|
2174
|
+
|
|
2175
|
+
|
|
2176
|
+
if (name === 'wxs') {
|
|
2177
|
+
resDep.wxs.set(depDestFile, {
|
|
2178
|
+
anaFileOriginFile,
|
|
2179
|
+
anaFileDestFile,
|
|
2180
|
+
depDestFile,
|
|
2181
|
+
depOriginFile
|
|
2182
|
+
});
|
|
2183
|
+
const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs']);
|
|
2184
|
+
defs.forEach((item, key) => {
|
|
2185
|
+
resDep.wxs.set(key, item);
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
1477
2188
|
}
|
|
1478
2189
|
}
|
|
2190
|
+
|
|
1479
2191
|
});
|
|
2192
|
+
parser.write(contents);
|
|
2193
|
+
parser.end();
|
|
1480
2194
|
}
|
|
1481
2195
|
|
|
1482
|
-
|
|
1483
|
-
return
|
|
1484
|
-
}
|
|
2196
|
+
dfs(anaFileOriginFile, anaFileDestFile);
|
|
2197
|
+
return resDep;
|
|
2198
|
+
};
|
|
1485
2199
|
|
|
2200
|
+
function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
2201
|
+
const stream = through.obj(function (file, enc, cb) {
|
|
2202
|
+
// 依赖分析的文件
|
|
2203
|
+
const anaFileOriginFile = file.history[0];
|
|
2204
|
+
const anaFileRelativeModule = path$2.relative(resolve$3(module.from), anaFileOriginFile);
|
|
2205
|
+
const anaFileDestFile = resolve$3(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2206
|
+
|
|
2207
|
+
if (file.isBuffer()) {
|
|
2208
|
+
let contents = String(file.contents);
|
|
2209
|
+
const copyModules = new Map();
|
|
2210
|
+
const parser = new htmlparser2.Parser({
|
|
2211
|
+
onopentag(name, attributes) {
|
|
2212
|
+
const nameFilter = ['import', 'include', 'wxs'];
|
|
2213
|
+
|
|
2214
|
+
if (nameFilter.indexOf(name) > -1 && attributes.src) {
|
|
2215
|
+
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
|
|
2216
|
+
|
|
2217
|
+
const {
|
|
2218
|
+
ext,
|
|
2219
|
+
file: depOriginFile,
|
|
2220
|
+
extPath
|
|
2221
|
+
} = extFile(name, depOriginPath);
|
|
2222
|
+
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2223
|
+
if (attributes.src.indexOf(includeName) > -1) {
|
|
2224
|
+
const includePath = tmsConfig.dependencies[includeName];
|
|
2225
|
+
|
|
2226
|
+
if (!fileInDir(includePath, depOriginFile)) {
|
|
2227
|
+
pluginError(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
2228
|
+
return;
|
|
2229
|
+
} // eslint-disable-next-line
|
|
2230
|
+
|
|
2231
|
+
|
|
2232
|
+
const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2233
|
+
const regRes = attributes.src.match(reg) || [];
|
|
2234
|
+
|
|
2235
|
+
if (regRes[2]) {
|
|
2236
|
+
const depDestPath = resolve$3(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2237
|
+
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2238
|
+
|
|
2239
|
+
if (!copyModules.has(depDestFile)) {
|
|
2240
|
+
copyModules.set(depDestFile, {
|
|
2241
|
+
depOriginFile,
|
|
2242
|
+
depDestFile,
|
|
2243
|
+
beforeDepPath: attributes.src,
|
|
2244
|
+
afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
});
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
1486
2252
|
|
|
1487
|
-
|
|
1488
|
-
|
|
2253
|
+
});
|
|
2254
|
+
parser.write(contents);
|
|
2255
|
+
parser.end(); // console.log('wxml copyModules', copyModules);
|
|
2256
|
+
|
|
2257
|
+
copyModules.forEach(({
|
|
2258
|
+
depOriginFile,
|
|
2259
|
+
depDestFile,
|
|
2260
|
+
beforeDepPath,
|
|
2261
|
+
afterDepPath
|
|
2262
|
+
}) => {
|
|
2263
|
+
if (fs$3.existsSync(depOriginFile)) {
|
|
2264
|
+
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2265
|
+
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2266
|
+
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
2267
|
+
}
|
|
1489
2268
|
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
}
|
|
2269
|
+
if (depOriginFile.endsWith('.wxml')) {
|
|
2270
|
+
const defs = dfsFindWxmlDep(depOriginFile, depDestFile, isWatch); // console.log('wxml defs', defs);
|
|
2271
|
+
|
|
2272
|
+
[...defs.wxml, ...defs.wxs].forEach(([, item]) => {
|
|
2273
|
+
diffContentCopyFile(item.depOriginFile, item.depDestFile);
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
1498
2276
|
|
|
1499
|
-
|
|
2277
|
+
if (depOriginFile.endsWith('.wxs')) {
|
|
2278
|
+
const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs'], isWatch); // console.log('wxs defs', defs);
|
|
1500
2279
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
from: resolve$5(item),
|
|
1505
|
-
to: resolve$5(`./${toPath}/${item}`),
|
|
1506
|
-
transform: {
|
|
1507
|
-
cache: true
|
|
2280
|
+
defs.forEach(item => {
|
|
2281
|
+
diffContentCopyFile(item.depOriginFile, item.depDestFile);
|
|
2282
|
+
});
|
|
1508
2283
|
}
|
|
1509
2284
|
});
|
|
2285
|
+
file.contents = Buffer.from(contents);
|
|
1510
2286
|
}
|
|
1511
|
-
}); // 拷贝模块的代码
|
|
1512
|
-
|
|
1513
|
-
modules.forEach(item => {
|
|
1514
|
-
patterns.push({
|
|
1515
|
-
from: resolve$5(item.path),
|
|
1516
|
-
to: resolve$5(`./${toPath}/${item.root}`),
|
|
1517
|
-
globOptions: {
|
|
1518
|
-
ignore: ['**/*.js', '*.js', '**/*.ts', '*.ts']
|
|
1519
|
-
},
|
|
1520
|
-
transform: {
|
|
1521
|
-
cache: true,
|
|
1522
|
-
transformer: env === 'dev' ? (content, absoluteFrom) => {
|
|
1523
|
-
// 监听module.config.json的修改, 自动生成编译后的app.json
|
|
1524
|
-
if (absoluteFrom.indexOf('module.config.json') > -1) {
|
|
1525
|
-
generatorAppJson(tmsConfig, modules);
|
|
1526
|
-
}
|
|
1527
2287
|
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
}
|
|
1531
|
-
});
|
|
2288
|
+
this.push(file);
|
|
2289
|
+
cb();
|
|
1532
2290
|
});
|
|
2291
|
+
return stream;
|
|
2292
|
+
}
|
|
1533
2293
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
2294
|
+
var mpWxmlDep_1 = {
|
|
2295
|
+
mpWxmlDep: mpWxmlDep$1,
|
|
2296
|
+
dfsFindWxmlDep
|
|
2297
|
+
};
|
|
2298
|
+
|
|
2299
|
+
/* eslint-disable no-param-reassign */
|
|
2300
|
+
const postcss$1 = require$$0__default$9;
|
|
2301
|
+
const fs$2 = require$$0__default$1;
|
|
2302
|
+
const path$1 = require$$3__default;
|
|
2303
|
+
const {
|
|
2304
|
+
fail: fail$2
|
|
2305
|
+
} = log$2;
|
|
2306
|
+
var postcssFontBase64 = postcss$1.plugin('postcss-font-base64', options => {
|
|
2307
|
+
options = { ...options,
|
|
2308
|
+
...{
|
|
2309
|
+
match: {
|
|
2310
|
+
Scrabble: ['fakefont']
|
|
2311
|
+
},
|
|
2312
|
+
format: ['eot', 'woff', 'woff2', 'ttf']
|
|
2313
|
+
}
|
|
2314
|
+
};
|
|
2315
|
+
return function (css, result) {
|
|
2316
|
+
css.walkAtRules('font-face', fontFace => {
|
|
2317
|
+
const fileTypeRegex = getRegexStringForFileTypes(options.format);
|
|
2318
|
+
fontFace.replaceValues(new RegExp(`url\\(["']?.+\\.${fileTypeRegex}["']?\\)`), attr => {
|
|
2319
|
+
const fontRePath = attr.replace(/(url|'|"|\(|\)|\?#iefix)/g, '');
|
|
2320
|
+
const fontAbPath = path$1.join(path$1.dirname(result.opts.from), fontRePath);
|
|
2321
|
+
const res64 = base64Encode(fontAbPath);
|
|
2322
|
+
const newUrlStr = 'url(data:'.concat(getMimeType(attr)).concat(';charset=utf-8;base64,').concat(res64).concat(')');
|
|
2323
|
+
return res64 ? newUrlStr : attr;
|
|
1548
2324
|
});
|
|
1549
2325
|
});
|
|
1550
|
-
}
|
|
1551
2326
|
|
|
1552
|
-
|
|
1553
|
-
|
|
2327
|
+
function getRegexStringForFileTypes(fileTypes) {
|
|
2328
|
+
const regex = fileTypes.map(fileType => fileType === 'eot' ? fileType.concat('(\\?#iefix)?') : fileType).join('|');
|
|
2329
|
+
return regex ? `(${regex})` : '';
|
|
2330
|
+
} // helper functions
|
|
1554
2331
|
|
|
1555
2332
|
|
|
1556
|
-
|
|
1557
|
-
|
|
2333
|
+
function getMimeType(attribute) {
|
|
2334
|
+
const formats = {
|
|
2335
|
+
'.woff': 'application/font-woff',
|
|
2336
|
+
'.woff2': 'font/woff2',
|
|
2337
|
+
'.ttf': 'application/font-sfnt',
|
|
2338
|
+
'.eot': 'application/vnd.ms-fontobject',
|
|
2339
|
+
'.otf': 'application/font-sfnt'
|
|
2340
|
+
};
|
|
2341
|
+
let match = '';
|
|
2342
|
+
const extension = attribute.match(/\.[a-z]{3,4}/)[0];
|
|
1558
2343
|
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
2344
|
+
if (extension in formats) {
|
|
2345
|
+
match = formats[extension];
|
|
2346
|
+
}
|
|
2347
|
+
return match;
|
|
2348
|
+
}
|
|
1563
2349
|
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
process.nextTick(() => {
|
|
1568
|
-
const {
|
|
1569
|
-
stats
|
|
1570
|
-
} = context;
|
|
1571
|
-
if (!stats) return;
|
|
1572
|
-
|
|
1573
|
-
if (tempFirstDone) {
|
|
1574
|
-
tempFirstDone = false;
|
|
1575
|
-
firstDone();
|
|
2350
|
+
function base64Encode(file) {
|
|
2351
|
+
if (fs$2.existsSync(file)) {
|
|
2352
|
+
return readAndEncodeFile(file);
|
|
1576
2353
|
}
|
|
1577
|
-
});
|
|
1578
|
-
};
|
|
1579
2354
|
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
compiler.hooks.watchRun.tap('miniprogram-dev', invalid);
|
|
1584
|
-
compiler.hooks.invalid.tap('miniprogram-dev', invalid);
|
|
1585
|
-
compiler.hooks.done.tap('miniprogram-dev', done);
|
|
1586
|
-
};
|
|
2355
|
+
fail$2(`${file} does not exist.`);
|
|
2356
|
+
return '';
|
|
2357
|
+
}
|
|
1587
2358
|
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
}, {})
|
|
2359
|
+
function readAndEncodeFile(file) {
|
|
2360
|
+
const bitmap = fs$2.readFileSync(file);
|
|
2361
|
+
return Buffer.from(bitmap).toString('base64');
|
|
2362
|
+
}
|
|
2363
|
+
};
|
|
1594
2364
|
});
|
|
1595
2365
|
|
|
1596
|
-
var utils = {
|
|
1597
|
-
getCopyPlugin: getCopyPlugin$2,
|
|
1598
|
-
setupDevWebPackHooks: setupDevWebPackHooks$1,
|
|
1599
|
-
getEntry: getEntry$2,
|
|
1600
|
-
stringified: stringified$1,
|
|
1601
|
-
getAlias: getAlias$1
|
|
1602
|
-
};
|
|
1603
|
-
|
|
1604
|
-
const WebpackChain = require$$0__default$8;
|
|
1605
|
-
const webpack$2 = require$$0__default$9;
|
|
1606
2366
|
const {
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
} =
|
|
2367
|
+
src: src$1,
|
|
2368
|
+
dest,
|
|
2369
|
+
lastRun
|
|
2370
|
+
} = require$$0__default$a;
|
|
2371
|
+
const px2rpx = require$$1__default$6;
|
|
2372
|
+
const postcss = require$$2__default$2;
|
|
2373
|
+
const watch = require$$3__default$1; // const cache = require('gulp-cache');
|
|
2374
|
+
// const image = require('gulp-image');
|
|
2375
|
+
|
|
2376
|
+
const replaceEnv = replaceEnv_1;
|
|
1611
2377
|
const {
|
|
1612
|
-
|
|
1613
|
-
} =
|
|
2378
|
+
mpCommonDep
|
|
2379
|
+
} = mpCommonDep_1;
|
|
1614
2380
|
const {
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
2381
|
+
mpJsonDep
|
|
2382
|
+
} = mpJsonDep_1;
|
|
2383
|
+
const {
|
|
2384
|
+
mpWxmlDep
|
|
2385
|
+
} = mpWxmlDep_1;
|
|
2386
|
+
const base64 = postcssFontBase64;
|
|
2387
|
+
const {
|
|
2388
|
+
fail: fail$1
|
|
2389
|
+
} = log$2;
|
|
1618
2390
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
// type: 'filesystem',
|
|
1637
|
-
// cacheDirectory: resolve(`./${tmsConfig.webpack.outputDir}/node_modules/.cache`),
|
|
1638
|
-
// },
|
|
1639
|
-
resolve: {
|
|
1640
|
-
extensions: ['.tsx', '.ts', '.js'],
|
|
1641
|
-
alias: Object.assign(tmsWebpack.alias, alias)
|
|
1642
|
-
},
|
|
1643
|
-
devtool: tmsWebpack.sourceMap ? 'source-map' : false
|
|
1644
|
-
});
|
|
1645
|
-
webpackConfig.module.rule('ts-loader').test(/\.ts$/).use('ts-loader').loader(require.resolve('ts-loader')).options({
|
|
1646
|
-
configFile: resolve$4('./tsconfig.json'),
|
|
1647
|
-
// 只进行语法转换,不进行类型校验,提高构建速度
|
|
1648
|
-
transpileOnly: true
|
|
1649
|
-
}).end(); // webpackConfig.module
|
|
1650
|
-
// .rule('babel')
|
|
1651
|
-
// .test(/\.(js|mjs|jsx|ts|tsx)$/)
|
|
1652
|
-
// .pre()
|
|
1653
|
-
// .exclude.add(/(node_modules|miniprogram_npm)/).end()
|
|
1654
|
-
// .use(require.resolve('babel-loader'))
|
|
1655
|
-
// .loader(require.resolve('babel-loader'));
|
|
1656
|
-
|
|
1657
|
-
webpackConfig.plugin('definePlugin').use(webpack$2.DefinePlugin, [stringified(envData)]).end(); // 执行tms.config.js自定义的webpackChain
|
|
1658
|
-
|
|
1659
|
-
if (tmsWebpack.webpackChain) {
|
|
1660
|
-
webpackConfig = tmsWebpack.webpackChain(webpackConfig, {
|
|
1661
|
-
modules
|
|
2391
|
+
const since = task => file => lastRun(task) > file.stat.ctime ? lastRun(task) : 0;
|
|
2392
|
+
|
|
2393
|
+
var compile = function (tmsConfig, {
|
|
2394
|
+
glob,
|
|
2395
|
+
destPath,
|
|
2396
|
+
srcOption,
|
|
2397
|
+
module,
|
|
2398
|
+
watchOption = {
|
|
2399
|
+
events: ['change', 'add', 'unlink']
|
|
2400
|
+
},
|
|
2401
|
+
isWatch
|
|
2402
|
+
}) {
|
|
2403
|
+
Object.keys(glob).forEach(globKey => {
|
|
2404
|
+
const globValue = glob[globKey];
|
|
2405
|
+
|
|
2406
|
+
const task = () => src$1(globValue, { ...srcOption,
|
|
2407
|
+
since: since(task)
|
|
1662
2408
|
});
|
|
1663
|
-
}
|
|
1664
2409
|
|
|
1665
|
-
|
|
1666
|
-
};
|
|
2410
|
+
let srcPipe = task();
|
|
1667
2411
|
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$1
|
|
1672
|
-
} = require$$3;
|
|
1673
|
-
const {
|
|
1674
|
-
getEntry
|
|
1675
|
-
} = utils;
|
|
2412
|
+
if (isWatch) {
|
|
2413
|
+
srcPipe = srcPipe.pipe(watch(globValue, watchOption));
|
|
2414
|
+
}
|
|
1676
2415
|
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
2416
|
+
switch (globKey) {
|
|
2417
|
+
case 'js':
|
|
2418
|
+
srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch)).pipe(dest(destPath)).on('error', err => {
|
|
2419
|
+
fail$1(`js编译报错${err}`);
|
|
2420
|
+
});
|
|
2421
|
+
break;
|
|
2422
|
+
|
|
2423
|
+
case 'wxss':
|
|
2424
|
+
srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).pipe(postcss([base64()])).on('error', err => {
|
|
2425
|
+
fail$1(`postcss编译报错${err}`);
|
|
2426
|
+
}).pipe(px2rpx({
|
|
2427
|
+
designWidth: 375,
|
|
2428
|
+
// 设计稿宽度,默认为750
|
|
2429
|
+
precision: 2 // 小数最大精度,默认为6
|
|
2430
|
+
|
|
2431
|
+
})).pipe(dest(destPath));
|
|
2432
|
+
break;
|
|
2433
|
+
|
|
2434
|
+
case 'json':
|
|
2435
|
+
srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch)).on('error', err => {
|
|
2436
|
+
fail$1(`json编译报错${err}`);
|
|
2437
|
+
}).pipe(dest(destPath));
|
|
2438
|
+
break;
|
|
2439
|
+
|
|
2440
|
+
case 'wxml':
|
|
2441
|
+
srcPipe.pipe(mpWxmlDep(tmsConfig, module, isWatch)).pipe(dest(destPath));
|
|
2442
|
+
break;
|
|
2443
|
+
|
|
2444
|
+
case 'image':
|
|
2445
|
+
srcPipe // .pipe(cache(image()))
|
|
2446
|
+
// .on('error', (err) => {
|
|
2447
|
+
// fail(`image编译报错${err}`);
|
|
2448
|
+
// })
|
|
2449
|
+
.pipe(dest(destPath));
|
|
2450
|
+
break;
|
|
2451
|
+
|
|
2452
|
+
case 'other':
|
|
2453
|
+
srcPipe.pipe(dest(destPath));
|
|
2454
|
+
break;
|
|
2455
|
+
}
|
|
2456
|
+
});
|
|
2457
|
+
};
|
|
1681
2458
|
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
}
|
|
2459
|
+
(function (module) {
|
|
2460
|
+
const watch = require$$3__default$1;
|
|
2461
|
+
const {
|
|
2462
|
+
resolve
|
|
2463
|
+
} = widgets;
|
|
2464
|
+
const {
|
|
2465
|
+
buildOutputAppJson
|
|
2466
|
+
} = buildAppJson;
|
|
2467
|
+
const {
|
|
2468
|
+
DEFAULT_COPY_CONFIG
|
|
2469
|
+
} = require$$3;
|
|
2470
|
+
const compile$1 = compile;
|
|
2471
|
+
|
|
2472
|
+
function excludeGlob(glob) {
|
|
2473
|
+
const otherArr = new Set();
|
|
2474
|
+
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
2475
|
+
Object.keys(glob).forEach(globKey => {
|
|
2476
|
+
if (typeof glob[globKey] === 'string') {
|
|
2477
|
+
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
2478
|
+
otherArr.add(data);
|
|
2479
|
+
}
|
|
1690
2480
|
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
2481
|
+
if (Array.isArray(glob[globKey])) {
|
|
2482
|
+
glob[globKey].forEach(value => {
|
|
2483
|
+
if (typeof value === 'string') {
|
|
2484
|
+
const data = value.startsWith('!') ? value : `!${value}`;
|
|
2485
|
+
otherArr.add(data);
|
|
2486
|
+
}
|
|
2487
|
+
});
|
|
2488
|
+
}
|
|
1699
2489
|
});
|
|
2490
|
+
return Array.from(otherArr);
|
|
1700
2491
|
}
|
|
1701
2492
|
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
2493
|
+
module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
2494
|
+
// 监听app.json
|
|
2495
|
+
if (isWatch) {
|
|
2496
|
+
watch(resolve('app.json'), {
|
|
2497
|
+
ignoreInitial: false,
|
|
2498
|
+
events: ['add', 'change']
|
|
2499
|
+
}, () => {
|
|
2500
|
+
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
2501
|
+
});
|
|
2502
|
+
} else {
|
|
2503
|
+
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
2504
|
+
} // 监听根目录的文件
|
|
1705
2505
|
|
|
1706
|
-
const webpackConfig$1 = base;
|
|
1707
|
-
const {
|
|
1708
|
-
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
|
|
1709
|
-
} = require$$3;
|
|
1710
|
-
const {
|
|
1711
|
-
getCopyPlugin: getCopyPlugin$1
|
|
1712
|
-
} = utils;
|
|
1713
|
-
|
|
1714
|
-
var dev$2 = (...args) => {
|
|
1715
|
-
const [tmsConfig, modules] = args;
|
|
1716
|
-
const webpackDevConfig = webpackConfig$1(...args);
|
|
1717
|
-
webpackDevConfig.devtool('source-map');
|
|
1718
|
-
webpackDevConfig.mode('development');
|
|
1719
|
-
const copyPluginParams = getCopyPlugin$1(DEFAULT_COPY_CONFIG$1, modules, tmsConfig, 'dev'); // console.log('copyPluginParams', copyPluginParams);
|
|
1720
|
-
|
|
1721
|
-
webpackDevConfig.plugin('copy-webpack-plugin').use(require$$3__default, [{
|
|
1722
|
-
patterns: copyPluginParams
|
|
1723
|
-
}]).end();
|
|
1724
|
-
webpackDevConfig.plugin('ExtractPlugin').use(entryExtractPlugin, [{
|
|
1725
|
-
tmsConfig,
|
|
1726
|
-
modules
|
|
1727
|
-
}]).end();
|
|
1728
|
-
return webpackDevConfig;
|
|
1729
|
-
};
|
|
1730
2506
|
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
2507
|
+
compile$1(tmsConfig, {
|
|
2508
|
+
glob: {
|
|
2509
|
+
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
2510
|
+
wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
2511
|
+
js: ['app.js', 'app.ts'].map(item => resolve(item))
|
|
2512
|
+
},
|
|
2513
|
+
module: {
|
|
2514
|
+
from: '',
|
|
2515
|
+
to: ''
|
|
2516
|
+
},
|
|
2517
|
+
destPath: resolve(tmsConfig.outputDir),
|
|
2518
|
+
srcOption: {
|
|
2519
|
+
allowEmpty: true
|
|
2520
|
+
},
|
|
2521
|
+
isWatch
|
|
2522
|
+
}); // 监听模块的文件
|
|
2523
|
+
|
|
2524
|
+
for (let module of newModules) {
|
|
2525
|
+
// 处理默认参数
|
|
2526
|
+
module = { ...{
|
|
2527
|
+
exclude: []
|
|
2528
|
+
},
|
|
2529
|
+
...module
|
|
2530
|
+
};
|
|
1739
2531
|
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
compiler.watch({
|
|
1749
|
-
aggregateTimeout: 1000,
|
|
1750
|
-
poll: undefined
|
|
1751
|
-
}, (err, stats) => {
|
|
1752
|
-
if (err) {
|
|
1753
|
-
fail$3(err);
|
|
1754
|
-
console.log('详细的错误信息:', err);
|
|
1755
|
-
}
|
|
2532
|
+
if (isWatch) {
|
|
2533
|
+
// 监听模块配置文件
|
|
2534
|
+
watch(`${resolve(module.path)}/**/module.config.json`, {
|
|
2535
|
+
events: ['change']
|
|
2536
|
+
}, () => {
|
|
2537
|
+
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
1756
2540
|
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
2541
|
+
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
2542
|
+
const glob = {
|
|
2543
|
+
js: [`${resolve(module.path)}/**/*.{js,ts,wxs}`, ...excludes],
|
|
2544
|
+
json: [`${resolve(module.path)}/**/*.json`, ...excludes],
|
|
2545
|
+
wxss: [`${resolve(module.path)}/**/*.{less,wxss}`, ...excludes],
|
|
2546
|
+
wxml: [`${resolve(module.path)}/**/*.wxml`, ...excludes],
|
|
2547
|
+
image: [`${resolve(module.path)}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
|
|
2548
|
+
};
|
|
2549
|
+
compile$1(tmsConfig, {
|
|
2550
|
+
glob: { ...glob,
|
|
2551
|
+
other: [`${resolve(module.path)}/**/*`, ...excludeGlob(glob)]
|
|
2552
|
+
},
|
|
2553
|
+
destPath: resolve(tmsConfig.outputDir, module.root),
|
|
2554
|
+
module: {
|
|
2555
|
+
from: module.path,
|
|
2556
|
+
to: module.root
|
|
2557
|
+
},
|
|
2558
|
+
srcOption: {
|
|
2559
|
+
allowEmpty: true
|
|
2560
|
+
},
|
|
2561
|
+
isWatch
|
|
2562
|
+
});
|
|
2563
|
+
} // 静态资源目录-拷贝
|
|
2564
|
+
|
|
2565
|
+
|
|
2566
|
+
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
|
|
2567
|
+
for (const item of tmsConfig.static) {
|
|
2568
|
+
const from = item !== null && item !== void 0 && item.from.startsWith('/') ? item.from : resolve(item.from);
|
|
2569
|
+
const to = item !== null && item !== void 0 && item.to.startsWith('/') ? item.to : resolve(item.to);
|
|
2570
|
+
compile$1(tmsConfig, {
|
|
2571
|
+
glob: {
|
|
2572
|
+
other: [from]
|
|
2573
|
+
},
|
|
2574
|
+
destPath: to,
|
|
2575
|
+
module: item,
|
|
2576
|
+
srcOption: {
|
|
2577
|
+
allowEmpty: true
|
|
2578
|
+
},
|
|
2579
|
+
isWatch
|
|
2580
|
+
});
|
|
2581
|
+
}
|
|
1762
2582
|
}
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
};
|
|
2583
|
+
};
|
|
2584
|
+
})(dev$3);
|
|
1766
2585
|
|
|
1767
2586
|
const fs$1 = require$$0__default$1;
|
|
1768
|
-
const semver$1 = require$$1__default$
|
|
2587
|
+
const semver$1 = require$$1__default$7;
|
|
1769
2588
|
const {
|
|
1770
|
-
resolve: resolve$
|
|
2589
|
+
resolve: resolve$2
|
|
1771
2590
|
} = widgets;
|
|
1772
|
-
const path
|
|
2591
|
+
const path = require$$3__default;
|
|
2592
|
+
const shelljs$2 = require$$4__default;
|
|
1773
2593
|
const {
|
|
1774
|
-
|
|
1775
|
-
} =
|
|
1776
|
-
const shelljs$2 = require$$0__default$2;
|
|
2594
|
+
handleError
|
|
2595
|
+
} = handleError_1;
|
|
1777
2596
|
|
|
1778
2597
|
const getLatestVersion = npmName => {
|
|
1779
2598
|
const data = shelljs$2.exec(`npm view ${npmName} version`);
|
|
@@ -1788,48 +2607,48 @@ const getLatestVersion = npmName => {
|
|
|
1788
2607
|
*/
|
|
1789
2608
|
|
|
1790
2609
|
|
|
1791
|
-
const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
2610
|
+
const checkDependencies$1 = (modules, cwd, outputDir, isDev) => {
|
|
1792
2611
|
// 步骤1. 收集package.json
|
|
1793
2612
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1794
2613
|
// 1.1根目录的package.json
|
|
1795
2614
|
|
|
1796
2615
|
const packageArr = [{
|
|
1797
|
-
srcPackageDir: path
|
|
1798
|
-
destNpmDir: resolve$
|
|
2616
|
+
srcPackageDir: path.join(cwd, packageJsonName),
|
|
2617
|
+
destNpmDir: resolve$2(outputDir, 'node_modules')
|
|
1799
2618
|
}]; // 1.2模块的package.json
|
|
1800
2619
|
|
|
1801
2620
|
modules.forEach(item => {
|
|
1802
|
-
const srcPackageDir = path
|
|
2621
|
+
const srcPackageDir = path.join(cwd, item.path, 'package.json');
|
|
1803
2622
|
|
|
1804
2623
|
if (fs$1.existsSync(srcPackageDir)) {
|
|
1805
2624
|
packageArr.push({
|
|
1806
2625
|
srcPackageDir,
|
|
1807
|
-
destNpmDir: resolve$
|
|
2626
|
+
destNpmDir: resolve$2(outputDir, item.root, 'node_modules')
|
|
1808
2627
|
});
|
|
1809
2628
|
}
|
|
1810
2629
|
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1811
2630
|
|
|
1812
2631
|
for (const item of packageArr) {
|
|
1813
2632
|
const packageJson = fs$1.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1814
|
-
let dependencies;
|
|
2633
|
+
let dependencies = {};
|
|
1815
2634
|
|
|
1816
2635
|
try {
|
|
1817
|
-
|
|
2636
|
+
const json = JSON.parse(packageJson);
|
|
2637
|
+
dependencies = json !== null && json !== void 0 && json.dependencies ? json === null || json === void 0 ? void 0 : json.dependencies : {};
|
|
1818
2638
|
} catch (e) {
|
|
1819
|
-
|
|
1820
|
-
process.exit(1);
|
|
2639
|
+
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项`, isDev);
|
|
1821
2640
|
}
|
|
1822
2641
|
|
|
1823
2642
|
const dependenciesKeys = Object.keys(dependencies);
|
|
1824
2643
|
|
|
1825
2644
|
for (const key of dependenciesKeys) {
|
|
1826
|
-
const depPath = path
|
|
2645
|
+
const depPath = path.join(item.destNpmDir, key);
|
|
1827
2646
|
|
|
1828
2647
|
if (!fs$1.existsSync(depPath)) {
|
|
1829
2648
|
return true;
|
|
1830
2649
|
}
|
|
1831
2650
|
|
|
1832
|
-
const depPackagePath = path
|
|
2651
|
+
const depPackagePath = path.join(depPath, 'package.json');
|
|
1833
2652
|
|
|
1834
2653
|
if (fs$1.existsSync(depPackagePath)) {
|
|
1835
2654
|
const packageData = require(depPackagePath);
|
|
@@ -1856,26 +2675,27 @@ var checkDependencies_1 = {
|
|
|
1856
2675
|
checkDependencies: checkDependencies$1
|
|
1857
2676
|
};
|
|
1858
2677
|
|
|
1859
|
-
const
|
|
2678
|
+
const gulpDev = dev$3.exports;
|
|
1860
2679
|
const fs = require$$0__default$1;
|
|
1861
2680
|
const {
|
|
1862
|
-
resolve: resolve$
|
|
2681
|
+
resolve: resolve$1
|
|
1863
2682
|
} = widgets;
|
|
1864
|
-
const init$4 =
|
|
2683
|
+
const init$4 = init_1;
|
|
1865
2684
|
const {
|
|
1866
|
-
|
|
2685
|
+
MODULE_CONFIG_FILENAME
|
|
1867
2686
|
} = require$$3;
|
|
1868
2687
|
const {
|
|
1869
|
-
tmsModulesMergeLocalModuleCfg
|
|
2688
|
+
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
|
|
1870
2689
|
} = tkitUtils;
|
|
1871
2690
|
const {
|
|
1872
2691
|
checkDependencies
|
|
1873
2692
|
} = checkDependencies_1;
|
|
1874
2693
|
const {
|
|
1875
|
-
fail
|
|
2694
|
+
fail
|
|
1876
2695
|
} = log$2;
|
|
2696
|
+
const shelljs$1 = require$$4__default; // const io = require('../../../utils/io');
|
|
1877
2697
|
|
|
1878
|
-
function isInit(tmsConfig, targetModules, contextDir) {
|
|
2698
|
+
function isInit(tmsConfig, targetModules, contextDir, isDev) {
|
|
1879
2699
|
// 判断是否存在dist目录
|
|
1880
2700
|
if (!fs.existsSync(contextDir)) {
|
|
1881
2701
|
return true;
|
|
@@ -1901,188 +2721,114 @@ function isInit(tmsConfig, targetModules, contextDir) {
|
|
|
1901
2721
|
// 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
|
|
1902
2722
|
if (!item.root) {
|
|
1903
2723
|
return true;
|
|
1904
|
-
} //
|
|
2724
|
+
} // 判断dist目录是否有该模块
|
|
1905
2725
|
|
|
1906
2726
|
|
|
1907
|
-
if (!fs.existsSync(`${contextDir}/${item.root}`)) {
|
|
2727
|
+
if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
|
|
1908
2728
|
return true;
|
|
1909
2729
|
} // 判断源码目录是否有该模块
|
|
1910
2730
|
|
|
1911
2731
|
|
|
1912
|
-
if (item.path && !fs.existsSync(resolve$
|
|
1913
|
-
fail
|
|
2732
|
+
if (item.path && !fs.existsSync(resolve$1(item.path))) {
|
|
2733
|
+
fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1914
2734
|
process.exit(1);
|
|
1915
2735
|
}
|
|
1916
2736
|
} // 判断package.json的版本是否有新的版本
|
|
1917
2737
|
|
|
1918
2738
|
|
|
1919
|
-
return checkDependencies(targetModules, resolve$
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
async function dev$1(tmsConfig, targetModules, env) {
|
|
1923
|
-
// tms.config.js的modules 合并 module.config.json的配置项
|
|
1924
|
-
let newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR); // 判断是否进行init命令
|
|
2739
|
+
return checkDependencies(targetModules, resolve$1('./'), tmsConfig.outputDir, isDev);
|
|
2740
|
+
} // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
1925
2741
|
|
|
1926
|
-
if (isInit(tmsConfig, newModules, resolve$2('dist'))) {
|
|
1927
|
-
// init函数会将 最新的tms.config.js的modules 合并 module.config.json的配置项 返回,不需要再做重复工作
|
|
1928
|
-
const initData = await init$4(tmsConfig, targetModules);
|
|
1929
|
-
newModules = initData.targetModules;
|
|
1930
|
-
}
|
|
1931
2742
|
|
|
1932
|
-
|
|
1933
|
-
|
|
2743
|
+
function delOtherModule(tmsConfig, targetModules) {
|
|
2744
|
+
const modules = tmsModulesMergeLocalModuleCfg$1(tmsConfig.modules, tmsConfig.appName);
|
|
2745
|
+
const targetModulesName = targetModules.map(item => item.name);
|
|
2746
|
+
modules.forEach(item => {
|
|
2747
|
+
if (item.root && targetModulesName.indexOf(item.name) === -1) {
|
|
2748
|
+
const moduleRootDir = resolve$1(`dist/${item.root}`);
|
|
2749
|
+
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
2750
|
+
silent: true
|
|
2751
|
+
}); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
2752
|
+
// io.ensureDirExist(moduleRootDir);
|
|
2753
|
+
}
|
|
2754
|
+
});
|
|
1934
2755
|
}
|
|
1935
2756
|
|
|
1936
|
-
|
|
2757
|
+
async function dev$2(tmsConfig, targetModules, env) {
|
|
2758
|
+
let newModules = targetModules;
|
|
2759
|
+
const isDev = true; // 判断是否进行init命令
|
|
1937
2760
|
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
getCopyPlugin
|
|
1944
|
-
} = utils;
|
|
1945
|
-
|
|
1946
|
-
var build$2 = (...args) => {
|
|
1947
|
-
const [tmsConfig, modules] = args;
|
|
1948
|
-
const webpackBuildConfig = webpackConfig(...args);
|
|
1949
|
-
webpackBuildConfig.mode('production');
|
|
1950
|
-
const copyPluginParams = getCopyPlugin(DEFAULT_COPY_CONFIG, modules, tmsConfig, 'build'); // console.log('copyPluginParams', copyPluginParams);
|
|
1951
|
-
|
|
1952
|
-
webpackBuildConfig.plugin('copy-webpack-plugin').use(require$$3__default, [{
|
|
1953
|
-
patterns: copyPluginParams
|
|
1954
|
-
}]).end();
|
|
1955
|
-
return webpackBuildConfig;
|
|
1956
|
-
};
|
|
1957
|
-
|
|
1958
|
-
const webpack = require$$0__default$9;
|
|
1959
|
-
const webBuildConfig = build$2;
|
|
1960
|
-
const {
|
|
1961
|
-
createTask: createTask$2
|
|
1962
|
-
} = widgets;
|
|
1963
|
-
const {
|
|
1964
|
-
fail
|
|
1965
|
-
} = log$2;
|
|
2761
|
+
if (isInit(tmsConfig, targetModules, resolve$1('dist'), isDev)) {
|
|
2762
|
+
// init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
|
|
2763
|
+
const initData = await init$4(tmsConfig, newModules, isDev);
|
|
2764
|
+
newModules = initData.targetModules;
|
|
2765
|
+
}
|
|
1966
2766
|
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
resolve({
|
|
1971
|
-
err,
|
|
1972
|
-
stats
|
|
1973
|
-
});
|
|
1974
|
-
});
|
|
1975
|
-
});
|
|
2767
|
+
console.log('当前dev启动的有效模块', newModules.map(item => item.name).sort());
|
|
2768
|
+
delOtherModule(tmsConfig, newModules);
|
|
2769
|
+
gulpDev(tmsConfig, newModules, env);
|
|
1976
2770
|
}
|
|
1977
2771
|
|
|
1978
|
-
var
|
|
1979
|
-
const config = webBuildConfig(...args);
|
|
1980
|
-
const compiler = webpack(config.toConfig());
|
|
1981
|
-
const {
|
|
1982
|
-
err,
|
|
1983
|
-
stats
|
|
1984
|
-
} = await createTask$2(compilerRun, '开始webpack打包编译', 'webpack打包编译完成')(compiler);
|
|
2772
|
+
var dev_1 = dev$2;
|
|
1985
2773
|
|
|
1986
|
-
|
|
1987
|
-
fail(err);
|
|
1988
|
-
console.log('详细的错误信息:', err);
|
|
1989
|
-
}
|
|
2774
|
+
const dev$1 = dev$3.exports;
|
|
1990
2775
|
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
// 增加控制台颜色开关
|
|
1994
|
-
colors: true,
|
|
1995
|
-
errorDetails: true
|
|
1996
|
-
}));
|
|
1997
|
-
}
|
|
1998
|
-
return compiler;
|
|
2776
|
+
var build$2 = async (tmsConfig, newModules) => {
|
|
2777
|
+
dev$1(tmsConfig, newModules, false);
|
|
1999
2778
|
};
|
|
2000
2779
|
|
|
2001
|
-
const shelljs
|
|
2002
|
-
const webpackBuildServer = buildServer;
|
|
2780
|
+
const shelljs = require$$4__default;
|
|
2003
2781
|
const {
|
|
2004
|
-
resolve
|
|
2782
|
+
resolve
|
|
2005
2783
|
} = widgets;
|
|
2006
|
-
const init$3 =
|
|
2784
|
+
const init$3 = init_1;
|
|
2785
|
+
const gulpBuild = build$2;
|
|
2007
2786
|
|
|
2008
2787
|
async function build$1(tmsConfig, targetModules, env) {
|
|
2009
2788
|
// 开始构建前,清理输出目录
|
|
2010
|
-
await shelljs
|
|
2789
|
+
await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
2790
|
+
const isDev = false;
|
|
2011
2791
|
const {
|
|
2012
2792
|
targetModules: newModules
|
|
2013
|
-
} = await init$3(tmsConfig, targetModules);
|
|
2014
|
-
|
|
2793
|
+
} = await init$3(tmsConfig, targetModules, isDev);
|
|
2794
|
+
gulpBuild(tmsConfig, newModules, env);
|
|
2015
2795
|
}
|
|
2016
2796
|
|
|
2017
2797
|
var build_1 = build$1;
|
|
2018
2798
|
|
|
2019
|
-
const
|
|
2020
|
-
const {
|
|
2021
|
-
createTask: createTask$1
|
|
2022
|
-
} = widgets;
|
|
2023
|
-
const {
|
|
2024
|
-
buildMpNpm
|
|
2025
|
-
} = mpCiUtils;
|
|
2026
|
-
const glob = require$$3__default$1;
|
|
2027
|
-
const path = require$$1__default$1;
|
|
2028
|
-
|
|
2029
|
-
function npmInstall(contextDir) {
|
|
2030
|
-
return new Promise((resolve, reject) => {
|
|
2031
|
-
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
2032
|
-
if (err) {
|
|
2033
|
-
reject(err);
|
|
2034
|
-
}
|
|
2035
|
-
|
|
2036
|
-
files.forEach(file => {
|
|
2037
|
-
const dir = path.dirname(file);
|
|
2038
|
-
shelljs.cd(dir);
|
|
2039
|
-
shelljs.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
|
|
2040
|
-
silent: false
|
|
2041
|
-
});
|
|
2042
|
-
});
|
|
2043
|
-
resolve();
|
|
2044
|
-
});
|
|
2045
|
-
});
|
|
2046
|
-
}
|
|
2047
|
-
|
|
2048
|
-
async function install$1(contextDir) {
|
|
2049
|
-
// npm install
|
|
2050
|
-
await createTask$1(npmInstall, '开始npm install', 'npm install完成')(contextDir); // 构建miniprograme_npm
|
|
2051
|
-
|
|
2052
|
-
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
2053
|
-
appId: 'null',
|
|
2054
|
-
projectPath: contextDir,
|
|
2055
|
-
privateKey: 'null'
|
|
2056
|
-
});
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
var install_1 = install$1;
|
|
2060
|
-
|
|
2061
|
-
const init$2 = init$5;
|
|
2799
|
+
const init$2 = init_1;
|
|
2062
2800
|
const dev = dev_1;
|
|
2063
2801
|
const build = build_1;
|
|
2064
2802
|
const install = install_1;
|
|
2065
2803
|
const {
|
|
2066
|
-
createTask
|
|
2067
|
-
resolve
|
|
2804
|
+
createTask
|
|
2068
2805
|
} = widgets;
|
|
2069
2806
|
const {
|
|
2070
2807
|
MODE
|
|
2071
2808
|
} = require$$3;
|
|
2072
2809
|
const {
|
|
2073
2810
|
readTmsConfig,
|
|
2811
|
+
readTmsPrivateCf,
|
|
2074
2812
|
checkModules
|
|
2075
2813
|
} = tkitUtils;
|
|
2814
|
+
const {
|
|
2815
|
+
tmsModulesMergeLocalModuleCfg,
|
|
2816
|
+
subModulesMergeDepModules
|
|
2817
|
+
} = tkitUtils;
|
|
2076
2818
|
|
|
2077
|
-
const handleModulesArg = cmd => {
|
|
2078
|
-
//
|
|
2079
|
-
if (cmd.module
|
|
2080
|
-
|
|
2081
|
-
|
|
2819
|
+
const handleModulesArg = (cmd, tmsPrivateCg) => {
|
|
2820
|
+
// 单模块或多模块开发-用户通过脚手架参数指定的模块
|
|
2821
|
+
if (cmd.module) {
|
|
2822
|
+
const {
|
|
2823
|
+
argv
|
|
2824
|
+
} = process;
|
|
2825
|
+
const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
|
|
2826
|
+
return [cmd.module, ...reset];
|
|
2827
|
+
} // 单模块或多模块开发-用户在tms.private.js指定的模块
|
|
2082
2828
|
|
|
2083
2829
|
|
|
2084
|
-
if (
|
|
2085
|
-
return
|
|
2830
|
+
if (tmsPrivateCg !== null && tmsPrivateCg !== void 0 && tmsPrivateCg.modules && (tmsPrivateCg === null || tmsPrivateCg === void 0 ? void 0 : tmsPrivateCg.modules.length) > 0) {
|
|
2831
|
+
return tmsPrivateCg === null || tmsPrivateCg === void 0 ? void 0 : tmsPrivateCg.modules;
|
|
2086
2832
|
} // 全量模块
|
|
2087
2833
|
|
|
2088
2834
|
|
|
@@ -2090,39 +2836,44 @@ const handleModulesArg = cmd => {
|
|
|
2090
2836
|
};
|
|
2091
2837
|
|
|
2092
2838
|
async function run(commandName, cmd) {
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
return;
|
|
2096
|
-
}
|
|
2839
|
+
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
2840
|
+
const tmsPrivateCg = readTmsPrivateCf(); // 处理module参数
|
|
2097
2841
|
|
|
2098
|
-
const moduleArg = handleModulesArg(cmd);
|
|
2842
|
+
const moduleArg = handleModulesArg(cmd, tmsPrivateCg);
|
|
2099
2843
|
const {
|
|
2100
|
-
env
|
|
2844
|
+
env = tmsPrivateCg === null || tmsPrivateCg === void 0 ? void 0 : tmsPrivateCg.env
|
|
2101
2845
|
} = cmd;
|
|
2102
2846
|
const tmsConfig = await createTask(readTmsConfig, '开始读取脚手架的配置项', '读取脚手架的配置项完成')(env);
|
|
2103
|
-
let modules;
|
|
2847
|
+
let modules;
|
|
2104
2848
|
|
|
2105
|
-
if (moduleArg === MODE.
|
|
2106
|
-
modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages])]);
|
|
2107
|
-
} else if (moduleArg === MODE.all) {
|
|
2849
|
+
if (moduleArg === MODE.all) {
|
|
2108
2850
|
// 全量模块
|
|
2109
2851
|
modules = tmsConfig.modules;
|
|
2110
2852
|
} else {
|
|
2111
2853
|
// 检查用户输入modules的有效性
|
|
2112
2854
|
modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...moduleArg])]);
|
|
2113
|
-
}
|
|
2855
|
+
} // tms.config.js的modules 合并 module.config.json的配置项
|
|
2856
|
+
|
|
2857
|
+
|
|
2858
|
+
let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName); // A分包依赖了B分包的代码, merge B分包进行编译;
|
|
2859
|
+
|
|
2860
|
+
newModules = subModulesMergeDepModules(tmsConfig, newModules);
|
|
2114
2861
|
|
|
2115
2862
|
switch (commandName) {
|
|
2116
2863
|
case 'init':
|
|
2117
|
-
init$2(tmsConfig,
|
|
2864
|
+
init$2(tmsConfig, newModules, env);
|
|
2118
2865
|
return;
|
|
2119
2866
|
|
|
2120
2867
|
case 'dev':
|
|
2121
|
-
dev(tmsConfig,
|
|
2868
|
+
dev(tmsConfig, newModules, env);
|
|
2869
|
+
return;
|
|
2870
|
+
|
|
2871
|
+
case 'install':
|
|
2872
|
+
install(tmsConfig, newModules, env);
|
|
2122
2873
|
return;
|
|
2123
2874
|
|
|
2124
2875
|
case 'build':
|
|
2125
|
-
build(tmsConfig,
|
|
2876
|
+
build(tmsConfig, newModules, env);
|
|
2126
2877
|
return;
|
|
2127
2878
|
|
|
2128
2879
|
default:
|
|
@@ -2139,22 +2890,54 @@ var entry = [{
|
|
|
2139
2890
|
create_1(appName, cmd);
|
|
2140
2891
|
}
|
|
2141
2892
|
}, {
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
description: '
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2893
|
+
name: 'run',
|
|
2894
|
+
type: 'child',
|
|
2895
|
+
description: '项目开发使用的命令',
|
|
2896
|
+
commands: [{
|
|
2897
|
+
command: 'install',
|
|
2898
|
+
description: '安装依赖',
|
|
2899
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
2900
|
+
action: cmd => {
|
|
2901
|
+
run_1('install', cmd);
|
|
2902
|
+
}
|
|
2903
|
+
}, {
|
|
2904
|
+
command: 'dev',
|
|
2905
|
+
description: 'dev 打包编译',
|
|
2906
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
2907
|
+
action: cmd => {
|
|
2908
|
+
run_1('dev', cmd);
|
|
2909
|
+
}
|
|
2910
|
+
}, {
|
|
2911
|
+
command: 'build',
|
|
2912
|
+
description: 'prod 打包编译',
|
|
2913
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
2914
|
+
action: cmd => {
|
|
2915
|
+
run_1('build', cmd);
|
|
2916
|
+
}
|
|
2917
|
+
}, {
|
|
2918
|
+
command: 'init',
|
|
2919
|
+
description: '根据模块配置初始化项目(eg: 动态拷贝模块、下载依赖、生成app.json等)',
|
|
2920
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
2921
|
+
action: cmd => {
|
|
2922
|
+
run_1('init', cmd);
|
|
2923
|
+
}
|
|
2924
|
+
}]
|
|
2148
2925
|
}];
|
|
2149
2926
|
|
|
2150
2927
|
var require$$6 = {
|
|
2151
2928
|
name: "@tmsfe/tmskit",
|
|
2152
|
-
version: "0.0.
|
|
2929
|
+
version: "0.0.6",
|
|
2153
2930
|
description: "tmskit",
|
|
2154
2931
|
main: "main.js",
|
|
2155
2932
|
bin: {
|
|
2156
2933
|
tmskit: "main.js"
|
|
2157
2934
|
},
|
|
2935
|
+
files: [
|
|
2936
|
+
"src",
|
|
2937
|
+
"dist",
|
|
2938
|
+
"main.js",
|
|
2939
|
+
"package.json"
|
|
2940
|
+
],
|
|
2158
2941
|
scripts: {
|
|
2159
2942
|
dev: "rollup -wc --environment TARGET:tmskit",
|
|
2160
2943
|
build: "rollup -c --environment TARGET:tmskit"
|
|
@@ -2180,37 +2963,46 @@ var require$$6 = {
|
|
|
2180
2963
|
dependencies: {
|
|
2181
2964
|
async: "^3.2.2",
|
|
2182
2965
|
chalk: "^4.1.0",
|
|
2183
|
-
commander: "^
|
|
2966
|
+
commander: "^8.3.0",
|
|
2184
2967
|
"copy-webpack-plugin": "^9.1.0",
|
|
2185
2968
|
"download-git-repo": "^3.0.2",
|
|
2186
2969
|
ejs: "^3.1.5",
|
|
2970
|
+
"fs-extra": "^10.0.1",
|
|
2187
2971
|
"glob-ignore": "^1.0.2",
|
|
2972
|
+
gulp: "^4.0.2",
|
|
2973
|
+
"gulp-cache": "^1.1.3",
|
|
2974
|
+
"gulp-image": "^5.1.0",
|
|
2975
|
+
"gulp-postcss": "^9.0.1",
|
|
2976
|
+
"gulp-px-to-rpx": "^1.0.7",
|
|
2977
|
+
"gulp-watch": "^5.0.1",
|
|
2978
|
+
htmlparser2: "^7.2.0",
|
|
2188
2979
|
inquirer: "^7.3.3",
|
|
2189
2980
|
leven: "3.1.0",
|
|
2190
2981
|
lodash: "^4.17.21",
|
|
2191
2982
|
metalsmith: "^2.3.0",
|
|
2192
2983
|
"miniprogram-ci": "1.4.13",
|
|
2984
|
+
"object-assign": "^4.0.1",
|
|
2193
2985
|
ora: "^5.1.0",
|
|
2986
|
+
"plugin-error": "^1.0.0",
|
|
2987
|
+
postcss: "^8.4.6",
|
|
2988
|
+
precinct: "^8.3.1",
|
|
2194
2989
|
"replace-ext": "^2.0.0",
|
|
2195
2990
|
shelljs: "^0.8.4",
|
|
2196
|
-
"
|
|
2197
|
-
|
|
2198
|
-
"
|
|
2991
|
+
"strip-comments": "^2.0.1",
|
|
2992
|
+
through2: "^4.0.2",
|
|
2993
|
+
"vinyl-sourcemaps-apply": "^0.2.0"
|
|
2199
2994
|
},
|
|
2200
2995
|
engines: {
|
|
2201
|
-
node: "^12.17.0 || >= 14.
|
|
2996
|
+
node: "^12.17.0 || >= 14.13.1"
|
|
2202
2997
|
},
|
|
2203
2998
|
jest: {
|
|
2204
2999
|
testEnvironment: "jest-environment-node"
|
|
2205
3000
|
}
|
|
2206
3001
|
};
|
|
2207
3002
|
|
|
2208
|
-
const
|
|
2209
|
-
exec
|
|
2210
|
-
} = require$$0__default$2;
|
|
2211
|
-
const semver = require$$1__default$4;
|
|
3003
|
+
const semver = require$$1__default$7;
|
|
2212
3004
|
const packageJson = require$$6;
|
|
2213
|
-
const chalk$1 = require$$0__default$
|
|
3005
|
+
const chalk$1 = require$$0__default$2;
|
|
2214
3006
|
const {
|
|
2215
3007
|
log: log$1
|
|
2216
3008
|
} = widgets;
|
|
@@ -2240,17 +3032,13 @@ const checkNodeVersion = (wanted, id) => {
|
|
|
2240
3032
|
function initCliContext() {
|
|
2241
3033
|
// 执行操作前检查node版本
|
|
2242
3034
|
// 旧版本node直接提示升级,退出脚本
|
|
2243
|
-
checkNodeVersion(requiredVersion, packName);
|
|
2244
|
-
|
|
2245
|
-
exec('npm config set registry https://mirrors.tencent.com/npm/ --global', {
|
|
2246
|
-
silent: true
|
|
2247
|
-
});
|
|
3035
|
+
checkNodeVersion(requiredVersion, packName);
|
|
2248
3036
|
}
|
|
2249
3037
|
|
|
2250
3038
|
var init$1 = initCliContext;
|
|
2251
3039
|
|
|
2252
|
-
const chalk = require$$0__default$
|
|
2253
|
-
const
|
|
3040
|
+
const chalk = require$$0__default$2;
|
|
3041
|
+
const commander = require$$0__default;
|
|
2254
3042
|
const {
|
|
2255
3043
|
log,
|
|
2256
3044
|
suggestCommands
|
|
@@ -2261,16 +3049,30 @@ const {
|
|
|
2261
3049
|
const commands = entry;
|
|
2262
3050
|
const init = init$1;
|
|
2263
3051
|
init();
|
|
2264
|
-
program.
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
3052
|
+
const program = new commander.Command(TMS_NAME);
|
|
3053
|
+
program.version(`${TMS_NAME} ${require$$6.version}`, '-v, -V, --version');
|
|
3054
|
+
|
|
3055
|
+
function registerCommand(program, commands) {
|
|
3056
|
+
commands.forEach(cmd => {
|
|
3057
|
+
if (cmd.type === 'child') {
|
|
3058
|
+
const childProgram = new commander.Command(cmd.name);
|
|
3059
|
+
cmd.usage && childProgram.usage(cmd.usage);
|
|
3060
|
+
cmd.description && childProgram.description(cmd.description);
|
|
3061
|
+
registerCommand(childProgram, cmd.commands);
|
|
3062
|
+
program.addCommand(childProgram);
|
|
3063
|
+
} else {
|
|
3064
|
+
var _cmd$options;
|
|
3065
|
+
|
|
3066
|
+
const command = program.command(cmd.command);
|
|
3067
|
+
cmd.usage && command.usage(cmd.usage);
|
|
3068
|
+
cmd.description && command.description(cmd.description);
|
|
3069
|
+
(_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
|
|
3070
|
+
command.action(cmd.action);
|
|
3071
|
+
}
|
|
3072
|
+
});
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
registerCommand(program, commands);
|
|
2274
3076
|
program.on('--help', () => {
|
|
2275
3077
|
log();
|
|
2276
3078
|
log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
@@ -2291,6 +3093,6 @@ if (!process.argv.slice(2).length) {
|
|
|
2291
3093
|
}
|
|
2292
3094
|
|
|
2293
3095
|
program.parse(process.argv);
|
|
2294
|
-
var src = src$
|
|
3096
|
+
var src = src$2;
|
|
2295
3097
|
|
|
2296
3098
|
module.exports = src;
|