@tmsfe/tmskit 0.0.3 → 0.0.5-beta.2
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 +5 -17
- package/dist/index.cjs.js +1074 -944
- package/package.json +11 -22
- package/src/config/constant.js +1 -1
- package/src/config/defaultTmsConfig.js +5 -4
- package/src/entry.js +48 -8
- package/src/gulp/build.js +6 -0
- package/src/gulp/compile.js +68 -0
- package/src/gulp/dev.js +107 -0
- package/src/gulp/jsDep.js +150 -0
- package/src/gulp/mpJsonDep.js +122 -0
- package/src/gulp/replaceEnv.js +29 -0
- package/src/index.js +26 -10
- package/src/init.js +0 -5
- package/src/scripts/create/generator.js +0 -1
- package/src/scripts/create/index.js +3 -4
- package/src/scripts/run/build/index.js +3 -3
- package/src/scripts/run/dev/index.js +3 -3
- package/src/scripts/run/index.js +7 -7
- package/src/scripts/run/init/index.js +12 -29
- package/src/scripts/run/install/index.js +21 -30
- package/src/utils/buildAppJson.js +1 -1
- package/src/utils/io.js +45 -0
- package/src/utils/npmUtils.js +26 -4
- 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
|
@@ -4,23 +4,26 @@ var require$$0 = require('commander');
|
|
|
4
4
|
var require$$1 = require('leven');
|
|
5
5
|
var require$$2 = require('ora');
|
|
6
6
|
var require$$1$1 = require('path');
|
|
7
|
-
var require$$1
|
|
8
|
-
var require$$
|
|
7
|
+
var require$$0$1 = require('fs');
|
|
8
|
+
var require$$5 = require('shelljs');
|
|
9
9
|
var require$$6$1 = require('download-git-repo');
|
|
10
10
|
var require$$0$2 = require('chalk');
|
|
11
11
|
var require$$0$3 = require('async');
|
|
12
|
-
var require$$1$
|
|
13
|
-
var require$$1$
|
|
12
|
+
var require$$1$2 = require('ejs');
|
|
13
|
+
var require$$1$3 = require('inquirer');
|
|
14
14
|
var require$$0$4 = require('metalsmith');
|
|
15
|
-
var require$$0$5 = require('
|
|
16
|
-
var require$$0$6 = require('
|
|
17
|
-
var require$$
|
|
18
|
-
var require$$0$7 = require('
|
|
19
|
-
var require$$
|
|
20
|
-
var require$$0$
|
|
21
|
-
var require$$
|
|
22
|
-
var require$$1
|
|
23
|
-
var require$$3$2 = require('
|
|
15
|
+
var require$$0$5 = require('lodash');
|
|
16
|
+
var require$$0$6 = require('miniprogram-ci');
|
|
17
|
+
var require$$3$1 = require('glob-ignore');
|
|
18
|
+
var require$$0$7 = require('through2');
|
|
19
|
+
var require$$1$4 = require('precinct');
|
|
20
|
+
var require$$0$8 = require('gulp');
|
|
21
|
+
var require$$1$5 = require('gulp-px-to-rpx');
|
|
22
|
+
var require$$2$1 = require('gulp-less');
|
|
23
|
+
var require$$3$2 = require('gulp-rename');
|
|
24
|
+
var require$$4 = require('gulp-watch');
|
|
25
|
+
var require$$5$1 = require('gulp-image');
|
|
26
|
+
var require$$1$6 = require('semver');
|
|
24
27
|
|
|
25
28
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
26
29
|
|
|
@@ -28,23 +31,26 @@ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
|
28
31
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
29
32
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
30
33
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
31
|
-
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
32
34
|
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
35
|
+
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
33
36
|
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
|
|
34
37
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
35
38
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
39
|
+
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
36
40
|
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
37
|
-
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
38
41
|
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
39
42
|
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
40
43
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
41
|
-
var require$$
|
|
44
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
|
|
42
45
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
46
|
+
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
43
47
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
44
|
-
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
45
|
-
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
|
|
46
48
|
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
49
|
+
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
47
50
|
var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
|
|
51
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
52
|
+
var require$$5__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
|
|
53
|
+
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
48
54
|
|
|
49
55
|
function getAugmentedNamespace(n) {
|
|
50
56
|
if (n.__esModule) return n;
|
|
@@ -61,14 +67,14 @@ function getAugmentedNamespace(n) {
|
|
|
61
67
|
return a;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
var src$
|
|
70
|
+
var src$2 = {};
|
|
65
71
|
|
|
66
72
|
const program$1 = require$$0__default;
|
|
67
73
|
const leven = require$$1__default;
|
|
68
74
|
const ora = require$$2__default;
|
|
69
|
-
const path$
|
|
70
|
-
const fs$
|
|
71
|
-
const shelljs$
|
|
75
|
+
const path$8 = require$$1__default$1;
|
|
76
|
+
const fs$c = require$$0__default$1;
|
|
77
|
+
const shelljs$5 = require$$5__default;
|
|
72
78
|
const download = require$$6__default;
|
|
73
79
|
const chalk$3 = require$$0__default$2;
|
|
74
80
|
const shelljsOptons = {
|
|
@@ -78,7 +84,7 @@ const shelljsOptons = {
|
|
|
78
84
|
const cwd = process.cwd();
|
|
79
85
|
|
|
80
86
|
function resolve$c(...args) {
|
|
81
|
-
return path$
|
|
87
|
+
return path$8.resolve(cwd, ...args);
|
|
82
88
|
}
|
|
83
89
|
/**
|
|
84
90
|
* 封装logs
|
|
@@ -147,11 +153,11 @@ function downloadRepo(dest, downloadOptions = {
|
|
|
147
153
|
branch
|
|
148
154
|
} = downloadOptions;
|
|
149
155
|
|
|
150
|
-
if (fs$
|
|
151
|
-
shelljs$
|
|
156
|
+
if (fs$c.existsSync(dest)) {
|
|
157
|
+
shelljs$5.rm('-rf', dest);
|
|
152
158
|
}
|
|
153
159
|
|
|
154
|
-
shelljs$
|
|
160
|
+
shelljs$5.mkdir('-p', dest);
|
|
155
161
|
return new Promise(resolve => {
|
|
156
162
|
download(`${repoUrl}#${branch}`, dest, {
|
|
157
163
|
clone: true
|
|
@@ -179,14 +185,14 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
179
185
|
const cwd = process.cwd();
|
|
180
186
|
return new Promise(resolve => {
|
|
181
187
|
// 如果目标目录不存在
|
|
182
|
-
if (fs$
|
|
183
|
-
shelljs$
|
|
188
|
+
if (fs$c.existsSync(dest)) {
|
|
189
|
+
shelljs$5.rm('-rf', path$8.join(dest));
|
|
184
190
|
}
|
|
185
191
|
|
|
186
|
-
shelljs$
|
|
187
|
-
shelljs$
|
|
188
|
-
shelljs$
|
|
189
|
-
shelljs$
|
|
192
|
+
shelljs$5.mkdir('-p', dest);
|
|
193
|
+
shelljs$5.cd(dest);
|
|
194
|
+
shelljs$5.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptons);
|
|
195
|
+
shelljs$5.cd(cwd);
|
|
190
196
|
resolve();
|
|
191
197
|
});
|
|
192
198
|
}
|
|
@@ -207,7 +213,7 @@ const cost = start => Date.now() - start;
|
|
|
207
213
|
*/
|
|
208
214
|
|
|
209
215
|
|
|
210
|
-
function createTask$
|
|
216
|
+
function createTask$4(task, startText, endText) {
|
|
211
217
|
return async (...args) => {
|
|
212
218
|
const start = Date.now();
|
|
213
219
|
let result;
|
|
@@ -241,39 +247,39 @@ var widgets = {
|
|
|
241
247
|
log: log$3,
|
|
242
248
|
isObject: isObject$2,
|
|
243
249
|
isArray: isArray$1,
|
|
244
|
-
createTask: createTask$
|
|
250
|
+
createTask: createTask$4,
|
|
245
251
|
downloadRepo,
|
|
246
252
|
downloadRepoForGit: downloadRepoForGit$2,
|
|
247
253
|
suggestCommands: suggestCommands$1,
|
|
248
254
|
camelize
|
|
249
255
|
};
|
|
250
256
|
|
|
251
|
-
const path$
|
|
257
|
+
const path$7 = require('path'); // 用户目录
|
|
252
258
|
|
|
253
259
|
|
|
254
260
|
const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
|
|
255
261
|
|
|
256
|
-
const CACHE_DIR$1 = path$
|
|
262
|
+
const CACHE_DIR$1 = path$7.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
257
263
|
|
|
258
|
-
const TEMPLATE_DIR$1 = path$
|
|
264
|
+
const TEMPLATE_DIR$1 = path$7.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
259
265
|
|
|
260
|
-
const MODULE_CODE_DIR$1 = path$
|
|
266
|
+
const MODULE_CODE_DIR$1 = path$7.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
|
|
261
267
|
|
|
262
|
-
const TEMPLATE_PATH$1 = path$
|
|
268
|
+
const TEMPLATE_PATH$1 = path$7.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
|
|
263
269
|
|
|
264
270
|
const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
|
|
265
271
|
|
|
266
272
|
const TMS_CONFIG_FILENAME$1 = 'tms.config.js'; // 模块代码的默认在modules子目录
|
|
267
273
|
|
|
268
|
-
const DEFAULT_MODULE_DIR$
|
|
274
|
+
const DEFAULT_MODULE_DIR$4 = 'modules'; // 模块的配置文件的名称
|
|
269
275
|
|
|
270
276
|
const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
|
|
271
277
|
|
|
272
|
-
const DEFAULT_WEBPACK_ENTRY
|
|
273
|
-
app: path$
|
|
278
|
+
const DEFAULT_WEBPACK_ENTRY = {
|
|
279
|
+
app: path$7.resolve(process.cwd(), 'app')
|
|
274
280
|
}; // 默认从源码拷贝到编译后的配置
|
|
275
281
|
|
|
276
|
-
const DEFAULT_COPY_CONFIG$
|
|
282
|
+
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json']; // 开发模式
|
|
277
283
|
|
|
278
284
|
const MODE$1 = {
|
|
279
285
|
main: 'tkitmain',
|
|
@@ -294,10 +300,10 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
294
300
|
TEMPLATE_PATH: TEMPLATE_PATH$1,
|
|
295
301
|
TMS_NAME: TMS_NAME$2,
|
|
296
302
|
TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME$1,
|
|
297
|
-
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$
|
|
303
|
+
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$4,
|
|
298
304
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$2,
|
|
299
|
-
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY
|
|
300
|
-
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$
|
|
305
|
+
DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
|
|
306
|
+
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1,
|
|
301
307
|
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
302
308
|
MODE: MODE$1,
|
|
303
309
|
ENV: ENV,
|
|
@@ -306,14 +312,15 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
306
312
|
|
|
307
313
|
var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
308
314
|
|
|
309
|
-
const fs$
|
|
315
|
+
const fs$b = require$$0__default$1;
|
|
316
|
+
const path$6 = require$$1__default$1;
|
|
310
317
|
/**
|
|
311
318
|
* 判断目录是否为空
|
|
312
319
|
* @param {string} dirname 目录名
|
|
313
320
|
* @returns
|
|
314
321
|
*/
|
|
315
322
|
|
|
316
|
-
const isDirEmpty = dirname => fs$
|
|
323
|
+
const isDirEmpty = dirname => fs$b.promises.readdir(dirname).then(files => files.length === 0);
|
|
317
324
|
/**
|
|
318
325
|
* 确保目录存在,不存在就创建一个
|
|
319
326
|
* @param {*} dirname 目录名
|
|
@@ -321,16 +328,67 @@ const isDirEmpty = dirname => fs$a.promises.readdir(dirname).then(files => files
|
|
|
321
328
|
|
|
322
329
|
|
|
323
330
|
const ensureDirExist = dirname => {
|
|
324
|
-
if (!fs$
|
|
325
|
-
fs$
|
|
331
|
+
if (!fs$b.existsSync(dirname)) {
|
|
332
|
+
fs$b.mkdirSync(dirname, {
|
|
326
333
|
recursive: true
|
|
327
334
|
});
|
|
328
335
|
}
|
|
336
|
+
}; // 复制文件
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
const copyFile$2 = function (src, dest) {
|
|
340
|
+
if (fs$b.existsSync(dest)) {
|
|
341
|
+
fs$b.unlinkSync(dest);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const dir = dest.substr(0, dest.lastIndexOf('/'));
|
|
345
|
+
ensureDirExist(dir);
|
|
346
|
+
fs$b.copyFileSync(src, dest);
|
|
347
|
+
}; // 添加后缀
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
function ext$2(filePath, extensions) {
|
|
351
|
+
let newFilePath = filePath;
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
const stat = fs$b.lstatSync(newFilePath);
|
|
355
|
+
|
|
356
|
+
if (stat.isDirectory()) {
|
|
357
|
+
newFilePath += newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
358
|
+
}
|
|
359
|
+
} catch (e) {}
|
|
360
|
+
|
|
361
|
+
for (const ext of extensions) {
|
|
362
|
+
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
363
|
+
|
|
364
|
+
if (fs$b.existsSync(file)) {
|
|
365
|
+
return {
|
|
366
|
+
file,
|
|
367
|
+
ext
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return null;
|
|
373
|
+
} // 判断文件是否在某个目录
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
const fileInDir$2 = (dir, file) => {
|
|
377
|
+
const relativePath = path$6.relative(dir, file);
|
|
378
|
+
|
|
379
|
+
if (relativePath.startsWith('..')) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return true;
|
|
329
384
|
};
|
|
330
385
|
|
|
331
386
|
var io$2 = {
|
|
332
387
|
isDirEmpty,
|
|
333
|
-
|
|
388
|
+
copyFile: copyFile$2,
|
|
389
|
+
ensureDirExist,
|
|
390
|
+
ext: ext$2,
|
|
391
|
+
fileInDir: fileInDir$2
|
|
334
392
|
};
|
|
335
393
|
|
|
336
394
|
const chalk$2 = require$$0__default$2;
|
|
@@ -346,7 +404,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
|
|
|
346
404
|
* @returns {undefined} 无
|
|
347
405
|
*/
|
|
348
406
|
|
|
349
|
-
const fail$
|
|
407
|
+
const fail$9 = (message = '') => {
|
|
350
408
|
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
351
409
|
|
|
352
410
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
@@ -379,13 +437,13 @@ const warn = message => {
|
|
|
379
437
|
};
|
|
380
438
|
|
|
381
439
|
var log$2 = {
|
|
382
|
-
fail: fail$
|
|
440
|
+
fail: fail$9,
|
|
383
441
|
succeed: succeed$1,
|
|
384
442
|
warn
|
|
385
443
|
};
|
|
386
444
|
|
|
387
445
|
const async = require$$0__default$3;
|
|
388
|
-
const ejs = require$$1__default$
|
|
446
|
+
const ejs = require$$1__default$2;
|
|
389
447
|
|
|
390
448
|
const render$1 = (files, metalsmith, next) => {
|
|
391
449
|
const keys = Object.keys(files);
|
|
@@ -404,8 +462,8 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
404
462
|
|
|
405
463
|
var render_1 = render$1;
|
|
406
464
|
|
|
407
|
-
const fs$
|
|
408
|
-
const inquirer = require$$1__default$
|
|
465
|
+
const fs$a = require$$0__default$1;
|
|
466
|
+
const inquirer = require$$1__default$3;
|
|
409
467
|
const {
|
|
410
468
|
resolve: resolve$b
|
|
411
469
|
} = widgets;
|
|
@@ -421,12 +479,12 @@ const {
|
|
|
421
479
|
const parseTemplateQuestions = dir => {
|
|
422
480
|
let prompts = [];
|
|
423
481
|
|
|
424
|
-
if (!fs$
|
|
482
|
+
if (!fs$a.existsSync(`${dir}/questions.json`)) {
|
|
425
483
|
return prompts;
|
|
426
484
|
}
|
|
427
485
|
|
|
428
486
|
try {
|
|
429
|
-
const json = JSON.parse(fs$
|
|
487
|
+
const json = JSON.parse(fs$a.readFileSync(`${dir}/questions.json`));
|
|
430
488
|
|
|
431
489
|
if (Array.isArray(json) && json.length > 0) {
|
|
432
490
|
json.forEach((item, index) => {
|
|
@@ -502,8 +560,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
502
560
|
var generator_1 = generator$1;
|
|
503
561
|
|
|
504
562
|
const path$5 = require$$1__default$1;
|
|
505
|
-
const fs$
|
|
506
|
-
const shelljs$
|
|
563
|
+
const fs$9 = require$$0__default$1;
|
|
564
|
+
const shelljs$4 = require$$5__default;
|
|
507
565
|
const {
|
|
508
566
|
TEMPLATE_DIR,
|
|
509
567
|
TEMPLATE_PATH,
|
|
@@ -511,12 +569,12 @@ const {
|
|
|
511
569
|
} = require$$3;
|
|
512
570
|
const {
|
|
513
571
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
514
|
-
createTask: createTask$
|
|
572
|
+
createTask: createTask$3,
|
|
515
573
|
resolve: resolve$a
|
|
516
574
|
} = widgets;
|
|
517
575
|
const io$1 = io$2;
|
|
518
576
|
const {
|
|
519
|
-
fail: fail$
|
|
577
|
+
fail: fail$8,
|
|
520
578
|
succeed
|
|
521
579
|
} = log$2;
|
|
522
580
|
const generator = generator_1;
|
|
@@ -528,13 +586,13 @@ const generator = generator_1;
|
|
|
528
586
|
|
|
529
587
|
async function createAppDir(targetDir) {
|
|
530
588
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
531
|
-
if (fs$
|
|
589
|
+
if (fs$9.existsSync(targetDir)) {
|
|
532
590
|
if (!(await io$1.isDirEmpty(targetDir))) {
|
|
533
|
-
fail$
|
|
591
|
+
fail$8('该目录名已经存在,换个项目名字吧~');
|
|
534
592
|
process.exit(1);
|
|
535
593
|
}
|
|
536
594
|
} else {
|
|
537
|
-
shelljs$
|
|
595
|
+
shelljs$4.mkdir('-p', targetDir);
|
|
538
596
|
}
|
|
539
597
|
}
|
|
540
598
|
/**
|
|
@@ -548,49 +606,49 @@ async function create(appName) {
|
|
|
548
606
|
const cwd = process.cwd();
|
|
549
607
|
const targetDir = path$5.resolve(cwd, appName);
|
|
550
608
|
const appType = 'mp';
|
|
551
|
-
createAppDir(targetDir); // 创建缓存目录
|
|
609
|
+
await createAppDir(targetDir); // 创建缓存目录
|
|
552
610
|
|
|
553
611
|
io$1.ensureDirExist(TEMPLATE_DIR); // 拉取git模板
|
|
554
612
|
|
|
555
|
-
await createTask$
|
|
613
|
+
await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
556
614
|
|
|
557
615
|
generator(path$5.join(TEMPLATE_PATH, appType), targetDir, {
|
|
558
616
|
appName,
|
|
559
617
|
appType
|
|
560
618
|
}).then(() => {
|
|
561
|
-
|
|
562
|
-
shelljs$5.cd(appName);
|
|
619
|
+
shelljs$4.cd(appName);
|
|
563
620
|
|
|
564
621
|
const hooks = require(resolve$a(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
565
622
|
|
|
566
623
|
if (hooks.afterCreate) {
|
|
567
624
|
hooks.afterCreate.forEach(item => {
|
|
568
625
|
if (typeof item === 'function') {
|
|
569
|
-
item.call(null, shelljs$
|
|
626
|
+
item.call(null, shelljs$4, {
|
|
570
627
|
appName
|
|
571
628
|
});
|
|
572
629
|
} else {
|
|
573
|
-
shelljs$
|
|
630
|
+
shelljs$4.exec(item);
|
|
574
631
|
}
|
|
575
632
|
});
|
|
576
633
|
}
|
|
577
634
|
|
|
578
|
-
shelljs$
|
|
635
|
+
shelljs$4.rm('-rf', resolve$a(appName, TEMPLATE_TKIT_DIR));
|
|
636
|
+
succeed('项目创建完成.');
|
|
579
637
|
}).catch(err => {
|
|
580
|
-
fail$
|
|
638
|
+
fail$8(err.message);
|
|
581
639
|
console.log('详细的错误信息:', err);
|
|
582
640
|
});
|
|
583
641
|
}
|
|
584
642
|
|
|
585
643
|
var create_1 = create;
|
|
586
644
|
|
|
587
|
-
const fs$
|
|
645
|
+
const fs$8 = require$$0__default$1;
|
|
588
646
|
const {
|
|
589
|
-
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$
|
|
647
|
+
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3,
|
|
590
648
|
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1
|
|
591
649
|
} = require$$3;
|
|
592
650
|
const {
|
|
593
|
-
fail: fail$
|
|
651
|
+
fail: fail$7
|
|
594
652
|
} = log$2;
|
|
595
653
|
const {
|
|
596
654
|
resolve: resolve$9,
|
|
@@ -644,8 +702,8 @@ function getLocalModuleConfig(modules = [], appName, moduleDir, moduleConfigFile
|
|
|
644
702
|
}) => {
|
|
645
703
|
const moduleConfigPath = resolve$9(path, moduleConfigFilename);
|
|
646
704
|
|
|
647
|
-
if (fs$
|
|
648
|
-
const content = fs$
|
|
705
|
+
if (fs$8.existsSync(moduleConfigPath)) {
|
|
706
|
+
const content = fs$8.readFileSync(moduleConfigPath, 'utf-8');
|
|
649
707
|
modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName, moduleDir);
|
|
650
708
|
}
|
|
651
709
|
});
|
|
@@ -670,7 +728,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
670
728
|
|
|
671
729
|
foundMainPackages.forEach(subpackage => {
|
|
672
730
|
if (!subpackage.pages || !subpackage.pages.length) {
|
|
673
|
-
fail$
|
|
731
|
+
fail$7(`主包 ${subpackage} 不能没有 pages`);
|
|
674
732
|
process.exit(-1);
|
|
675
733
|
}
|
|
676
734
|
|
|
@@ -696,12 +754,12 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
696
754
|
|
|
697
755
|
|
|
698
756
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
699
|
-
if (!fs$
|
|
700
|
-
fail$
|
|
757
|
+
if (!fs$8.existsSync(sourceAppJsonPath)) {
|
|
758
|
+
fail$7(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
701
759
|
process.exit(1);
|
|
702
760
|
}
|
|
703
761
|
|
|
704
|
-
const appJson = JSON.parse(fs$
|
|
762
|
+
const appJson = JSON.parse(fs$8.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
705
763
|
|
|
706
764
|
appJson.subpackages = [];
|
|
707
765
|
appJson.pages = [];
|
|
@@ -732,245 +790,22 @@ const updateSubpackages = (appJson, modulesConfig) => {
|
|
|
732
790
|
*/
|
|
733
791
|
|
|
734
792
|
|
|
735
|
-
function buildOutputAppJson$
|
|
793
|
+
function buildOutputAppJson$1(tmsConfig, modules) {
|
|
736
794
|
// 获取当前 modules 下的所有子模块的配置内容
|
|
737
|
-
const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$
|
|
795
|
+
const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$3, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
|
|
738
796
|
|
|
739
797
|
const appJson = getAppJsonContent(resolve$9('./app.json')); // 更新app.json中的subpackages
|
|
740
798
|
|
|
741
799
|
updateSubpackages(appJson, modulesConfig); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
742
800
|
|
|
743
801
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
744
|
-
fs$
|
|
802
|
+
fs$8.writeFileSync(resolve$9(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
745
803
|
return appJson;
|
|
746
804
|
}
|
|
747
805
|
|
|
748
806
|
var buildAppJson = {
|
|
749
807
|
setModuleConfig: setModuleConfig$1,
|
|
750
|
-
buildOutputAppJson: buildOutputAppJson$
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
/**
|
|
754
|
-
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
755
|
-
*/
|
|
756
|
-
const fs$6 = require$$1__default$2;
|
|
757
|
-
const path$4 = require$$1__default$1;
|
|
758
|
-
const shell = require$$0__default$1;
|
|
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);
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
const tarNpmFilename = getTarNpmFilename(targetDir);
|
|
771
|
-
const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
|
|
772
|
-
|
|
773
|
-
if (fs$6.existsSync(tarNpmFilePath)) {
|
|
774
|
-
shell.rm('-rf', tarNpmFilePath);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
const cmd = `tar -zcvf ${tarNpmFilePath} ./node_modules`;
|
|
778
|
-
shell.exec(cmd, {
|
|
779
|
-
async: true,
|
|
780
|
-
silent: true
|
|
781
|
-
}); // tar -zcvf /Users/odile/.tmskit/node_modules.tar.gz ./node_modules
|
|
782
|
-
}; // 获取缓存npm包
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
const getNpmCache = function (targetDir, cacheDir) {
|
|
786
|
-
const tarNpmFilename = getTarNpmFilename(targetDir);
|
|
787
|
-
const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
|
|
788
|
-
|
|
789
|
-
if (fs$6.existsSync(tarNpmFilePath)) {
|
|
790
|
-
const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
|
|
791
|
-
shell.exec(cmd, {
|
|
792
|
-
async: false,
|
|
793
|
-
silent: true
|
|
794
|
-
});
|
|
795
|
-
} // tar -zxvf /Users/odile/.tmskit/node_modules.tar.gz -C ./
|
|
796
|
-
|
|
797
|
-
}; // 遍历安装指定目录下所有项目的npm依赖
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
const npmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
801
|
-
const packageJsonFiles = await findAllPackageJson$1(modules, contextDir);
|
|
802
|
-
await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
|
|
803
|
-
const dir = path$4.dirname(file);
|
|
804
|
-
shell.cd(dir);
|
|
805
|
-
|
|
806
|
-
if (!fs$6.existsSync(`${dir}/node_modules`)) {
|
|
807
|
-
getNpmCache(dir, cacheDir);
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
shell.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
|
|
811
|
-
silent: false
|
|
812
|
-
});
|
|
813
|
-
resolve();
|
|
814
|
-
npmCache(dir, cacheDir);
|
|
815
|
-
})));
|
|
816
|
-
};
|
|
817
|
-
/**
|
|
818
|
-
* 递归查找指定条件的文件
|
|
819
|
-
* @param {String} startPath 开始查找的根路径
|
|
820
|
-
* @param {String} filter 匹配的字符串
|
|
821
|
-
* @returns {Array<String>} 查找到的文件路径列表
|
|
822
|
-
*/
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
const findFilesByFilter = (startPath, filter) => {
|
|
826
|
-
const result = [];
|
|
827
|
-
/**
|
|
828
|
-
* 根据指定的筛选器查找文件
|
|
829
|
-
* @param {String} startPath 开始查找的文件夹路径
|
|
830
|
-
* @param {String} filter 筛选器
|
|
831
|
-
* @returns {Undefined} 无需返回值
|
|
832
|
-
*/
|
|
833
|
-
|
|
834
|
-
const find = (startPath, filter) => {
|
|
835
|
-
// 目录不存在
|
|
836
|
-
if (!fs$6.existsSync(startPath)) {
|
|
837
|
-
LOG.fail(`${startPath}目录不存在`);
|
|
838
|
-
process.exit(-1);
|
|
839
|
-
return;
|
|
840
|
-
} // 当前目录下的所有文件 / 文件夹
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
const exceptDir = ['node_modules', 'miniprogram_npm'];
|
|
844
|
-
|
|
845
|
-
if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
|
|
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
|
-
|
|
854
|
-
if (stat.isDirectory()) {
|
|
855
|
-
find(filename, filter);
|
|
856
|
-
} else if (filename.indexOf(filter) >= 0) {
|
|
857
|
-
// 文件类型
|
|
858
|
-
result.push(filename);
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
};
|
|
862
|
-
|
|
863
|
-
find(startPath, filter);
|
|
864
|
-
return result;
|
|
865
|
-
};
|
|
866
|
-
/**
|
|
867
|
-
* 找到项目中所有的package.json文件
|
|
868
|
-
* @param {Array<String>} subRoots 需要安装npm依赖的路径
|
|
869
|
-
* @param {String} contextDir 命令运行的目录
|
|
870
|
-
* @returns {Array<String>} 找到的所有package.json文件的路径
|
|
871
|
-
*/
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
const findAllPackageJson$1 = (subRoots = [], contextDir) => {
|
|
875
|
-
const packageJsonName = 'package.json'; // 查找文件名
|
|
876
|
-
|
|
877
|
-
const cwd = contextDir || dirpath;
|
|
878
|
-
const result = [path$4.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
879
|
-
|
|
880
|
-
subRoots.forEach(subRoot => {
|
|
881
|
-
const toppath = path$4.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
882
|
-
|
|
883
|
-
const list = findFilesByFilter(toppath, packageJsonName);
|
|
884
|
-
result.push(...list);
|
|
885
|
-
});
|
|
886
|
-
return result;
|
|
887
|
-
};
|
|
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$5;
|
|
896
|
-
const path$3 = require$$1__default$1;
|
|
897
|
-
/**
|
|
898
|
-
* 获取小程序ci的Project对象
|
|
899
|
-
* @returns {Object} 小程序ci对象
|
|
900
|
-
*/
|
|
901
|
-
|
|
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
|
-
|
|
912
|
-
const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
|
|
913
|
-
value
|
|
914
|
-
}) => value)) || [];
|
|
915
|
-
return new ci.Project({
|
|
916
|
-
appid: appId,
|
|
917
|
-
privateKey,
|
|
918
|
-
type,
|
|
919
|
-
projectPath,
|
|
920
|
-
ignores: ['node_modules/**/*', ...ignores]
|
|
921
|
-
});
|
|
922
|
-
}; // 用小程序ci工具构建小程序
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
const packMpProject = async project => {
|
|
926
|
-
await ci.packNpm(project, {
|
|
927
|
-
ignores: ['cloud/**/*']
|
|
928
|
-
});
|
|
929
|
-
};
|
|
930
|
-
/**
|
|
931
|
-
* 格式化构建npm结果信息
|
|
932
|
-
* @param {Array<String>} warning 构建时的告警信息
|
|
933
|
-
* @returns {String} npm构建错误信息
|
|
934
|
-
*/
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
const formatPackNpmWarning = warning => {
|
|
938
|
-
if (!warning) {
|
|
939
|
-
return '';
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
const result = warning.map((it, index) => `${index + 1}. ${it.msg}
|
|
943
|
-
\t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
|
|
944
|
-
return result;
|
|
945
|
-
};
|
|
946
|
-
/**
|
|
947
|
-
* 构建miniprogram_npm
|
|
948
|
-
* @returns {Object} 小程序ci对象
|
|
949
|
-
*/
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
const buildMpNpm$2 = async ({
|
|
953
|
-
appId,
|
|
954
|
-
projectPath,
|
|
955
|
-
privateKey
|
|
956
|
-
}) => {
|
|
957
|
-
const mpCi = await getMpCi({
|
|
958
|
-
appId,
|
|
959
|
-
projectPath,
|
|
960
|
-
privateKey
|
|
961
|
-
});
|
|
962
|
-
const packNpmWarning = await packMpProject(mpCi);
|
|
963
|
-
const packNpmMsg = formatPackNpmWarning(packNpmWarning);
|
|
964
|
-
|
|
965
|
-
if (packNpmMsg) {
|
|
966
|
-
return Promise.reject(packNpmMsg);
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
return Promise.resolve();
|
|
970
|
-
};
|
|
971
|
-
|
|
972
|
-
var mpCiUtils = {
|
|
973
|
-
buildMpNpm: buildMpNpm$2
|
|
808
|
+
buildOutputAppJson: buildOutputAppJson$1
|
|
974
809
|
};
|
|
975
810
|
|
|
976
811
|
class Globale {
|
|
@@ -1017,10 +852,10 @@ const {
|
|
|
1017
852
|
resolve: resolve$8
|
|
1018
853
|
} = widgets;
|
|
1019
854
|
const {
|
|
1020
|
-
fail: fail$
|
|
855
|
+
fail: fail$6
|
|
1021
856
|
} = log$2;
|
|
1022
|
-
const fs$
|
|
1023
|
-
const shelljs$
|
|
857
|
+
const fs$7 = require$$0__default$1;
|
|
858
|
+
const shelljs$3 = require$$5__default;
|
|
1024
859
|
/**
|
|
1025
860
|
* 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
|
|
1026
861
|
* @param { string } sourceDir 缓存文件夹
|
|
@@ -1034,7 +869,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
1034
869
|
return new Promise(resolve => {
|
|
1035
870
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1036
871
|
if (e) {
|
|
1037
|
-
fail$
|
|
872
|
+
fail$6(e); // eslint-disable-line
|
|
1038
873
|
|
|
1039
874
|
console.log('MetalSmith 详细的错误信息:', e);
|
|
1040
875
|
}
|
|
@@ -1094,13 +929,13 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
|
|
|
1094
929
|
sourcePath = globalInstance.getModuleCache(httpRepoUrl, cloneBranch).dest;
|
|
1095
930
|
}
|
|
1096
931
|
|
|
1097
|
-
if (fs$
|
|
1098
|
-
shelljs$
|
|
932
|
+
if (fs$7.existsSync(targetPath)) {
|
|
933
|
+
shelljs$3.rm('-rf', targetPath);
|
|
1099
934
|
}
|
|
1100
935
|
|
|
1101
936
|
await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
|
|
1102
937
|
} catch (e) {
|
|
1103
|
-
fail$
|
|
938
|
+
fail$6(`downLoadAndMoveModule ${e}`); // eslint-disable-line
|
|
1104
939
|
|
|
1105
940
|
process.exit(-1);
|
|
1106
941
|
}
|
|
@@ -1115,7 +950,11 @@ var defaultTmsConfig$1 = {
|
|
|
1115
950
|
envData: {},
|
|
1116
951
|
// 模块配置信息
|
|
1117
952
|
modules: [],
|
|
1118
|
-
|
|
953
|
+
cloudDir: 'cloud',
|
|
954
|
+
gulp: {
|
|
955
|
+
// 第三方依赖代码需要拷贝到本项目的
|
|
956
|
+
dependencies: {},
|
|
957
|
+
|
|
1119
958
|
/** 编译输出文件夹位置 */
|
|
1120
959
|
outputDir: 'dist',
|
|
1121
960
|
|
|
@@ -1123,15 +962,12 @@ var defaultTmsConfig$1 = {
|
|
|
1123
962
|
sourceDir: './',
|
|
1124
963
|
|
|
1125
964
|
/** 源码Map */
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
/** 别名 */
|
|
1129
|
-
alias: {}
|
|
965
|
+
copyDir: []
|
|
1130
966
|
}
|
|
1131
967
|
};
|
|
1132
968
|
|
|
1133
|
-
const loadash = require$$0__default$
|
|
1134
|
-
const fs$
|
|
969
|
+
const loadash = require$$0__default$5;
|
|
970
|
+
const fs$6 = require$$0__default$1;
|
|
1135
971
|
const {
|
|
1136
972
|
TMS_NAME: TMS_NAME$1,
|
|
1137
973
|
TMS_CONFIG_FILENAME,
|
|
@@ -1146,7 +982,7 @@ const {
|
|
|
1146
982
|
} = buildAppJson;
|
|
1147
983
|
const defaultTmsConfig = defaultTmsConfig$1;
|
|
1148
984
|
const {
|
|
1149
|
-
fail: fail$
|
|
985
|
+
fail: fail$5
|
|
1150
986
|
} = log$2;
|
|
1151
987
|
/**
|
|
1152
988
|
* 读取tms.config.json
|
|
@@ -1156,8 +992,8 @@ const {
|
|
|
1156
992
|
const readTmsConfig$1 = function (env) {
|
|
1157
993
|
const tmsConfigPath = resolve$7(TMS_CONFIG_FILENAME);
|
|
1158
994
|
|
|
1159
|
-
if (!fs$
|
|
1160
|
-
fail$
|
|
995
|
+
if (!fs$6.existsSync(tmsConfigPath)) {
|
|
996
|
+
fail$5('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
1161
997
|
process.exit(1);
|
|
1162
998
|
}
|
|
1163
999
|
|
|
@@ -1186,7 +1022,7 @@ const checkModules$1 = function (tmsConfig, modules) {
|
|
|
1186
1022
|
});
|
|
1187
1023
|
|
|
1188
1024
|
if (targetModules.length === 0) {
|
|
1189
|
-
fail$
|
|
1025
|
+
fail$5(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
|
|
1190
1026
|
process.exit(1);
|
|
1191
1027
|
}
|
|
1192
1028
|
|
|
@@ -1209,8 +1045,8 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName, moduleDir) => {
|
|
|
1209
1045
|
}, moduleIndex) => {
|
|
1210
1046
|
const moduleConfigPath = resolve$7(relativePath, MODULE_CONFIG_FILENAME);
|
|
1211
1047
|
|
|
1212
|
-
if (fs$
|
|
1213
|
-
let moduleConfigContent = fs$
|
|
1048
|
+
if (fs$6.existsSync(moduleConfigPath)) {
|
|
1049
|
+
let moduleConfigContent = fs$6.readFileSync(moduleConfigPath, 'utf-8');
|
|
1214
1050
|
moduleConfigContent = setModuleConfig(moduleConfigContent, appName, moduleDir);
|
|
1215
1051
|
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
1216
1052
|
moduleContentArr.forEach(({
|
|
@@ -1236,547 +1072,917 @@ var tkitUtils = {
|
|
|
1236
1072
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3
|
|
1237
1073
|
};
|
|
1238
1074
|
|
|
1239
|
-
|
|
1240
|
-
const
|
|
1241
|
-
const
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1075
|
+
/* eslint-disable require-jsdoc */
|
|
1076
|
+
const ci = require$$0__default$6;
|
|
1077
|
+
const path$4 = require$$1__default$1;
|
|
1078
|
+
/**
|
|
1079
|
+
* 获取小程序ci的Project对象
|
|
1080
|
+
* @returns {Object} 小程序ci对象
|
|
1081
|
+
*/
|
|
1082
|
+
|
|
1083
|
+
const getMpCi = ({
|
|
1084
|
+
appId,
|
|
1085
|
+
projectPath,
|
|
1086
|
+
type = 'miniProgram',
|
|
1087
|
+
privateKey = 'TODO'
|
|
1088
|
+
}) => {
|
|
1089
|
+
var _cfgJsonContent$packO;
|
|
1090
|
+
|
|
1091
|
+
const cfgJsonContent = require(path$4.join(projectPath, 'project.config.json'));
|
|
1092
|
+
|
|
1093
|
+
const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
|
|
1094
|
+
value
|
|
1095
|
+
}) => value)) || [];
|
|
1096
|
+
return new ci.Project({
|
|
1097
|
+
appid: appId,
|
|
1098
|
+
privateKey,
|
|
1099
|
+
type,
|
|
1100
|
+
projectPath,
|
|
1101
|
+
ignores: ['node_modules/**/*', ...ignores]
|
|
1102
|
+
});
|
|
1103
|
+
}; // 用小程序ci工具构建小程序
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
const packMpProject = async project => {
|
|
1107
|
+
await ci.packNpm(project, {
|
|
1108
|
+
ignores: ['cloud/**/*']
|
|
1109
|
+
});
|
|
1110
|
+
};
|
|
1111
|
+
/**
|
|
1112
|
+
* 格式化构建npm结果信息
|
|
1113
|
+
* @param {Array<String>} warning 构建时的告警信息
|
|
1114
|
+
* @returns {String} npm构建错误信息
|
|
1115
|
+
*/
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
const formatPackNpmWarning = warning => {
|
|
1119
|
+
if (!warning) {
|
|
1120
|
+
return '';
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
const result = warning.map((it, index) => `${index + 1}. ${it.msg}
|
|
1124
|
+
\t@ ${it.jsPath}:${it.tips}`).join('---------------\n');
|
|
1125
|
+
return result;
|
|
1126
|
+
};
|
|
1127
|
+
/**
|
|
1128
|
+
* 构建miniprogram_npm
|
|
1129
|
+
* @returns {Object} 小程序ci对象
|
|
1130
|
+
*/
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
const buildMpNpm$1 = async ({
|
|
1134
|
+
appId,
|
|
1135
|
+
projectPath,
|
|
1136
|
+
privateKey
|
|
1137
|
+
}) => {
|
|
1138
|
+
const mpCi = await getMpCi({
|
|
1139
|
+
appId,
|
|
1140
|
+
projectPath,
|
|
1141
|
+
privateKey
|
|
1142
|
+
});
|
|
1143
|
+
const packNpmWarning = await packMpProject(mpCi);
|
|
1144
|
+
const packNpmMsg = formatPackNpmWarning(packNpmWarning);
|
|
1145
|
+
|
|
1146
|
+
if (packNpmMsg) {
|
|
1147
|
+
return Promise.reject(packNpmMsg);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
return Promise.resolve();
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
var mpCiUtils = {
|
|
1253
1154
|
buildMpNpm: buildMpNpm$1
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
MODULE_CODE_DIR,
|
|
1257
|
-
CACHE_DIR,
|
|
1258
|
-
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
|
|
1259
|
-
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3
|
|
1260
|
-
} = require$$3;
|
|
1261
|
-
const {
|
|
1262
|
-
cloneModules
|
|
1263
|
-
} = cloneModules_1;
|
|
1264
|
-
const {
|
|
1265
|
-
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2
|
|
1266
|
-
} = tkitUtils;
|
|
1267
|
-
const {
|
|
1268
|
-
fail: fail$5
|
|
1269
|
-
} = log$2;
|
|
1155
|
+
};
|
|
1156
|
+
|
|
1270
1157
|
/**
|
|
1271
|
-
*
|
|
1272
|
-
* @param { object } tmsConfig
|
|
1273
|
-
* @param { array } modules
|
|
1274
|
-
* @param { array } defaultFiles 默认需要拷贝的配置项
|
|
1275
|
-
* @returns
|
|
1158
|
+
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1276
1159
|
*/
|
|
1160
|
+
const fs$5 = require$$0__default$1;
|
|
1161
|
+
const path$3 = require$$1__default$1;
|
|
1162
|
+
const shell = require$$5__default;
|
|
1163
|
+
const glob = require$$3__default;
|
|
1164
|
+
const LOG = log$2;
|
|
1165
|
+
const dirpath = process.cwd(); // 项目根目录
|
|
1277
1166
|
|
|
1278
|
-
const
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1167
|
+
const getTarNpmFilename = targetDir => `${targetDir.replace(/\//g, '-')}.tar.gz`; // 缓存npm包
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
const npmCache = function (targetDir, cacheDir) {
|
|
1171
|
+
if (!fs$5.existsSync(cacheDir)) {
|
|
1172
|
+
fs$5.mkdirSync(cacheDir);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
const tarNpmFilename = getTarNpmFilename(targetDir);
|
|
1176
|
+
const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
|
|
1177
|
+
|
|
1178
|
+
if (fs$5.existsSync(tarNpmFilePath)) {
|
|
1179
|
+
shell.rm('-rf', tarNpmFilePath);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
const cmd = `tar -zcvf ${tarNpmFilePath} ./node_modules`;
|
|
1183
|
+
shell.exec(cmd, {
|
|
1184
|
+
async: true,
|
|
1185
|
+
silent: true
|
|
1186
|
+
}); // tar -zcvf /Users/odile/.tmskit/node_modules.tar.gz ./node_modules
|
|
1187
|
+
}; // 获取缓存npm包
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
const getNpmCache = function (targetDir, cacheDir) {
|
|
1191
|
+
const tarNpmFilename = getTarNpmFilename(targetDir);
|
|
1192
|
+
const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
|
|
1193
|
+
|
|
1194
|
+
if (fs$5.existsSync(tarNpmFilePath)) {
|
|
1195
|
+
const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
|
|
1196
|
+
shell.exec(cmd, {
|
|
1197
|
+
async: false,
|
|
1198
|
+
silent: true
|
|
1199
|
+
});
|
|
1200
|
+
} // tar -zxvf /Users/odile/.tmskit/node_modules.tar.gz -C ./
|
|
1201
|
+
|
|
1202
|
+
}; // 遍历安装指定目录下所有项目的npm依赖
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
1206
|
+
const packageJsonFiles = await findAllPackageJson(modules, contextDir);
|
|
1207
|
+
await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
|
|
1208
|
+
const dir = path$3.dirname(file);
|
|
1209
|
+
shell.cd(dir);
|
|
1210
|
+
|
|
1211
|
+
if (!fs$5.existsSync(`${dir}/node_modules`)) {
|
|
1212
|
+
getNpmCache(dir, cacheDir);
|
|
1284
1213
|
}
|
|
1285
|
-
}); // 拷贝模块的代码到编译输出目录
|
|
1286
1214
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1215
|
+
shell.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
|
|
1216
|
+
silent: false
|
|
1217
|
+
});
|
|
1218
|
+
resolve();
|
|
1219
|
+
npmCache(dir, cacheDir);
|
|
1220
|
+
})));
|
|
1221
|
+
};
|
|
1222
|
+
/**
|
|
1223
|
+
* 递归查找指定条件的文件
|
|
1224
|
+
* @param {String} startPath 开始查找的根路径
|
|
1225
|
+
* @param {String} filter 匹配的字符串
|
|
1226
|
+
* @returns {Array<String>} 查找到的文件路径列表
|
|
1227
|
+
*/
|
|
1289
1228
|
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1229
|
+
|
|
1230
|
+
const findFilesByFilter = (startPath, filter) => {
|
|
1231
|
+
const result = [];
|
|
1232
|
+
/**
|
|
1233
|
+
* 根据指定的筛选器查找文件
|
|
1234
|
+
* @param {String} startPath 开始查找的文件夹路径
|
|
1235
|
+
* @param {String} filter 筛选器
|
|
1236
|
+
* @returns {Undefined} 无需返回值
|
|
1237
|
+
*/
|
|
1238
|
+
|
|
1239
|
+
const find = (startPath, filter) => {
|
|
1240
|
+
// 目录不存在
|
|
1241
|
+
if (!fs$5.existsSync(startPath)) {
|
|
1242
|
+
LOG.fail(`${startPath}目录不存在`);
|
|
1243
|
+
process.exit(-1);
|
|
1244
|
+
return;
|
|
1245
|
+
} // 当前目录下的所有文件 / 文件夹
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
const exceptDir = ['node_modules', 'miniprogram_npm'];
|
|
1249
|
+
|
|
1250
|
+
if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
|
|
1251
|
+
return;
|
|
1293
1252
|
}
|
|
1294
1253
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
//
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
})
|
|
1254
|
+
const files = fs$5.readdirSync(startPath);
|
|
1255
|
+
files.forEach(file => {
|
|
1256
|
+
const filename = path$3.join(startPath, file);
|
|
1257
|
+
const stat = fs$5.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1258
|
+
|
|
1259
|
+
if (stat.isDirectory()) {
|
|
1260
|
+
find(filename, filter);
|
|
1261
|
+
} else if (filename.indexOf(filter) >= 0) {
|
|
1262
|
+
// 文件类型
|
|
1263
|
+
result.push(filename);
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
find(startPath, filter);
|
|
1269
|
+
return result;
|
|
1270
|
+
};
|
|
1271
|
+
/**
|
|
1272
|
+
* 找到项目中所有的package.json文件
|
|
1273
|
+
* @param {Array<String>} subRoots 需要安装npm依赖的路径
|
|
1274
|
+
* @param {String} contextDir 命令运行的目录
|
|
1275
|
+
* @returns {Array<String>} 找到的所有package.json文件的路径
|
|
1276
|
+
*/
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
1280
|
+
const packageJsonName = 'package.json'; // 查找文件名
|
|
1281
|
+
|
|
1282
|
+
const cwd = contextDir || dirpath;
|
|
1283
|
+
const result = [path$3.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1284
|
+
|
|
1285
|
+
subRoots.forEach(subRoot => {
|
|
1286
|
+
if (!subRoot.root) {
|
|
1287
|
+
LOG.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
|
|
1288
|
+
process.exit(1);
|
|
1303
1289
|
}
|
|
1304
1290
|
|
|
1305
|
-
|
|
1291
|
+
const toppath = path$3.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1292
|
+
|
|
1293
|
+
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1294
|
+
result.push(...list);
|
|
1306
1295
|
});
|
|
1296
|
+
return result;
|
|
1307
1297
|
};
|
|
1308
1298
|
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1299
|
+
function cloudNpmInstall$1(contextDir) {
|
|
1300
|
+
return new Promise((resolve, reject) => {
|
|
1301
|
+
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
1302
|
+
if (err) {
|
|
1303
|
+
reject(err);
|
|
1304
|
+
}
|
|
1312
1305
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1306
|
+
files.forEach(file => {
|
|
1307
|
+
const dir = path$3.dirname(file);
|
|
1308
|
+
shell.cd(dir);
|
|
1309
|
+
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1310
|
+
silent: false
|
|
1311
|
+
});
|
|
1312
|
+
});
|
|
1313
|
+
resolve();
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1315
1317
|
|
|
1316
|
-
|
|
1318
|
+
var npmUtils = {
|
|
1319
|
+
cloudNpmInstall: cloudNpmInstall$1,
|
|
1320
|
+
mpNpmInstallAll: mpNpmInstallAll$1,
|
|
1321
|
+
findAllPackageJson
|
|
1322
|
+
};
|
|
1317
1323
|
|
|
1318
|
-
|
|
1324
|
+
const {
|
|
1325
|
+
createTask: createTask$2,
|
|
1326
|
+
resolve: resolve$6
|
|
1327
|
+
} = widgets;
|
|
1328
|
+
const {
|
|
1329
|
+
buildMpNpm
|
|
1330
|
+
} = mpCiUtils;
|
|
1331
|
+
const {
|
|
1332
|
+
CACHE_DIR,
|
|
1333
|
+
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$2
|
|
1334
|
+
} = require$$3;
|
|
1335
|
+
const {
|
|
1336
|
+
cloudNpmInstall,
|
|
1337
|
+
mpNpmInstallAll
|
|
1338
|
+
} = npmUtils;
|
|
1339
|
+
const {
|
|
1340
|
+
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$2
|
|
1341
|
+
} = tkitUtils;
|
|
1342
|
+
|
|
1343
|
+
async function install$2(tmsConfig, modules, isCloud = true) {
|
|
1344
|
+
const newModules = tmsModulesMergeLocalModuleCfg$2(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$2); // 小程序npm install
|
|
1345
|
+
|
|
1346
|
+
await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$6(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
|
|
1319
1347
|
|
|
1320
|
-
await createTask$
|
|
1348
|
+
await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
|
|
1321
1349
|
appId: tmsConfig.appId,
|
|
1322
1350
|
projectPath: resolve$6('./'),
|
|
1323
1351
|
privateKey: tmsConfig.privateKey
|
|
1324
|
-
}); //
|
|
1352
|
+
}); // 安装云函数的
|
|
1325
1353
|
|
|
1326
|
-
|
|
1327
|
-
return newModules;
|
|
1354
|
+
isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$6(tmsConfig.cloudDir));
|
|
1328
1355
|
}
|
|
1329
1356
|
|
|
1330
|
-
|
|
1331
|
-
const newModules = await task(tmsConfig, targetModules);
|
|
1332
|
-
return {
|
|
1333
|
-
targetModules: newModules
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
var init$5 = bootstrap;
|
|
1357
|
+
var install_1 = install$2;
|
|
1338
1358
|
|
|
1339
|
-
const
|
|
1340
|
-
const fs$
|
|
1359
|
+
const shelljs$2 = require$$5__default;
|
|
1360
|
+
const fs$4 = require$$0__default$1;
|
|
1361
|
+
const io = io$2;
|
|
1341
1362
|
const {
|
|
1342
|
-
resolve: resolve$5
|
|
1363
|
+
resolve: resolve$5,
|
|
1364
|
+
createTask: createTask$1
|
|
1343
1365
|
} = widgets;
|
|
1344
1366
|
const {
|
|
1345
1367
|
buildOutputAppJson
|
|
1346
1368
|
} = buildAppJson;
|
|
1369
|
+
const {
|
|
1370
|
+
MODULE_CODE_DIR,
|
|
1371
|
+
DEFAULT_COPY_CONFIG,
|
|
1372
|
+
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$1
|
|
1373
|
+
} = require$$3;
|
|
1374
|
+
const {
|
|
1375
|
+
cloneModules
|
|
1376
|
+
} = cloneModules_1;
|
|
1347
1377
|
const {
|
|
1348
1378
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
|
|
1349
1379
|
} = tkitUtils;
|
|
1350
|
-
const {
|
|
1351
|
-
findAllPackageJson
|
|
1352
|
-
} = npmUtils;
|
|
1353
1380
|
const {
|
|
1354
1381
|
fail: fail$4
|
|
1355
1382
|
} = log$2;
|
|
1356
|
-
const
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1383
|
+
const install$1 = install_1;
|
|
1384
|
+
/**
|
|
1385
|
+
* 拷贝相关配置文件到编译输出目录
|
|
1386
|
+
* @param { object } tmsConfig
|
|
1387
|
+
* @param { array } modules
|
|
1388
|
+
* @param { array } defaultFiles 默认需要拷贝的配置项
|
|
1389
|
+
* @returns
|
|
1390
|
+
*/
|
|
1364
1391
|
|
|
1365
|
-
|
|
1366
|
-
|
|
1392
|
+
const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
1393
|
+
const outputDir = resolve$5(tmsConfig.gulp.outputDir);
|
|
1394
|
+
io.ensureDirExist(outputDir);
|
|
1395
|
+
defaultFiles.forEach(item => {
|
|
1396
|
+
if (fs$4.existsSync(resolve$5(item))) {
|
|
1397
|
+
shelljs$2.cp('-rf', resolve$5(item), resolve$5(tmsConfig.gulp.outputDir, item));
|
|
1367
1398
|
}
|
|
1368
|
-
}
|
|
1399
|
+
}); // 拷贝模块的package.json到编译输出目录
|
|
1369
1400
|
|
|
1370
|
-
|
|
1371
|
-
const
|
|
1401
|
+
targetModules.forEach(item => {
|
|
1402
|
+
const outputModuleDir = resolve$5(`${tmsConfig.gulp.outputDir}/${item.root}`);
|
|
1372
1403
|
|
|
1373
|
-
if (fs$
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
ext
|
|
1377
|
-
};
|
|
1404
|
+
if (!fs$4.existsSync(resolve$5(item.path))) {
|
|
1405
|
+
fail$4(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1406
|
+
process.exit(1);
|
|
1378
1407
|
}
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
return null;
|
|
1382
|
-
} // 获取所有的package.json里的依赖包Dir
|
|
1383
|
-
|
|
1384
1408
|
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
allPackages.forEach(packageFilePath => {
|
|
1389
|
-
const {
|
|
1390
|
-
dependencies
|
|
1391
|
-
} = require(packageFilePath);
|
|
1392
|
-
|
|
1393
|
-
Object.keys(dependencies).forEach(dependence => {
|
|
1394
|
-
alias[dependence] = path$2.join(path$2.dirname(packageFilePath), `./miniprogram_npm/${dependence}`);
|
|
1395
|
-
});
|
|
1409
|
+
io.ensureDirExist(outputModuleDir);
|
|
1410
|
+
const modulePackagePath = resolve$5(item.path, 'package.json');
|
|
1411
|
+
if (fs$4.existsSync(modulePackagePath)) shelljs$2.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1396
1412
|
});
|
|
1397
|
-
|
|
1398
|
-
} // 根据用户选择的modules,找到module.config.json的配置信息,找到所有的page
|
|
1413
|
+
};
|
|
1399
1414
|
|
|
1415
|
+
async function task(tmsConfig, targetModules) {
|
|
1416
|
+
// 下载和移动代码
|
|
1417
|
+
await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$5('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1400
1418
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1419
|
+
const newModules = tmsModulesMergeLocalModuleCfg$1(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR$1);
|
|
1420
|
+
console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
|
|
1403
1421
|
|
|
1404
|
-
|
|
1405
|
-
newModules.forEach(({
|
|
1406
|
-
path: relativePath,
|
|
1407
|
-
pages,
|
|
1408
|
-
root
|
|
1409
|
-
}) => {
|
|
1410
|
-
pages.forEach(page => {
|
|
1411
|
-
const pageJsonPath = `${resolve$5(relativePath, page)}.json`;
|
|
1422
|
+
await createTask$1(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, newModules, DEFAULT_COPY_CONFIG); // install
|
|
1412
1423
|
|
|
1413
|
-
|
|
1414
|
-
const pageJsonContent = JSON.parse(fs$2.readFileSync(pageJsonPath, 'utf-8'));
|
|
1415
|
-
const pageDir = path$2.dirname(pageJsonPath); // 该页面所在的目录
|
|
1424
|
+
await install$1(tmsConfig, newModules, false); // 动态生成编译后的app.json;
|
|
1416
1425
|
|
|
1417
|
-
|
|
1426
|
+
await createTask$1(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
1427
|
+
return newModules;
|
|
1428
|
+
}
|
|
1418
1429
|
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1430
|
+
async function bootstrap(tmsConfig, targetModules) {
|
|
1431
|
+
const newModules = await task(tmsConfig, targetModules);
|
|
1432
|
+
return {
|
|
1433
|
+
targetModules: newModules
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1423
1436
|
|
|
1424
|
-
|
|
1425
|
-
Object.assign(entry, {
|
|
1426
|
-
[entryKey]: extValue.file
|
|
1427
|
-
}, getComponentEntry(pageJsonContent, pageDir, path$2.dirname(entryKey)));
|
|
1428
|
-
}
|
|
1429
|
-
});
|
|
1430
|
-
});
|
|
1431
|
-
return entry;
|
|
1432
|
-
} // 根据appJson,获取所有的page
|
|
1437
|
+
var init$5 = bootstrap;
|
|
1433
1438
|
|
|
1439
|
+
var dev$3 = {exports: {}};
|
|
1434
1440
|
|
|
1435
|
-
|
|
1436
|
-
const defaultEntry = {};
|
|
1437
|
-
Object.keys(defaultWebpackEntry).forEach(key => {
|
|
1438
|
-
const extValue = ext(defaultWebpackEntry[key], extensions);
|
|
1439
|
-
defaultEntry[key + extValue.ext] = extValue.file;
|
|
1440
|
-
});
|
|
1441
|
-
return { ...defaultEntry,
|
|
1442
|
-
...getPageEntry(modules, tmsConfig, moduleDir)
|
|
1443
|
-
};
|
|
1444
|
-
} // 根据pageJson,filePath,获取页面引入的所有component
|
|
1441
|
+
const through$2 = require$$0__default$7;
|
|
1445
1442
|
|
|
1443
|
+
function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
|
|
1444
|
+
const stream = through$2.obj(function (file, enc, cb) {
|
|
1445
|
+
if (file.isBuffer()) {
|
|
1446
|
+
let contents = String(file.contents);
|
|
1447
|
+
let resReg; // eslint-disable-next-line
|
|
1446
1448
|
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
+
while ((resReg = reg.exec(contents)) !== null) {
|
|
1450
|
+
const [reg1, reg2, reg3] = resReg;
|
|
1449
1451
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1452
|
+
if (reg1 && reg2 && reg3) {
|
|
1453
|
+
const value = typeof envData[reg3] === 'object' ? JSON.stringify(envData[reg3]) : envData[reg3];
|
|
1454
|
+
contents = contents.replace(reg1, value);
|
|
1455
|
+
} else if (reg1 && !reg2 && !reg3) {
|
|
1456
|
+
contents = contents.replace(reg1, JSON.stringify(envData));
|
|
1457
|
+
}
|
|
1458
|
+
} // eslint-disable-next-line
|
|
1454
1459
|
|
|
1455
|
-
const componentKeys = Object.keys(json.usingComponents); // 如果存在依赖的组件
|
|
1456
1460
|
|
|
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]);
|
|
1461
|
+
file.contents = new Buffer(contents);
|
|
1462
|
+
}
|
|
1463
1463
|
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1464
|
+
this.push(file);
|
|
1465
|
+
cb();
|
|
1466
|
+
});
|
|
1467
|
+
return stream;
|
|
1468
|
+
}
|
|
1468
1469
|
|
|
1469
|
-
|
|
1470
|
-
const comJsonPath = `${comValue}.json`;
|
|
1470
|
+
var replaceEnv_1 = replaceEnv$1;
|
|
1471
1471
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1472
|
+
const through$1 = require$$0__default$7;
|
|
1473
|
+
const precinct = require$$1__default$4;
|
|
1474
|
+
const path$2 = require$$1__default$1;
|
|
1475
|
+
const {
|
|
1476
|
+
copyFile: copyFile$1,
|
|
1477
|
+
ext: ext$1,
|
|
1478
|
+
fileInDir: fileInDir$1
|
|
1479
|
+
} = io$2;
|
|
1480
|
+
const {
|
|
1481
|
+
resolve: resolve$4
|
|
1482
|
+
} = widgets;
|
|
1483
|
+
const fs$3 = require$$0__default$1;
|
|
1484
|
+
const {
|
|
1485
|
+
fail: fail$3
|
|
1486
|
+
} = log$2;
|
|
1475
1487
|
|
|
1476
|
-
|
|
1488
|
+
const dfsFindJsDep$1 = function (anaFileOriginFile, anaFileDestFile, extensions) {
|
|
1489
|
+
const resDep = new Map();
|
|
1490
|
+
|
|
1491
|
+
function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
|
|
1492
|
+
const contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
|
|
1493
|
+
const deps = precinct(contents);
|
|
1494
|
+
deps.forEach(depItem => {
|
|
1495
|
+
if (depItem.startsWith('.')) {
|
|
1496
|
+
// 被依赖文件的存在的绝对路径
|
|
1497
|
+
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
1498
|
+
|
|
1499
|
+
const depOriginPathExt = ext$1(depOriginPath, extensions);
|
|
1500
|
+
|
|
1501
|
+
if (!depOriginPathExt) {
|
|
1502
|
+
fail$3(`${anaFileOriginFile}的${depItem}引用路径存找不到文件,请检查引用路径`);
|
|
1503
|
+
} // 被依赖文件是否存在 include的path中 (只处理include的文件)
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
if (depOriginPathExt) {
|
|
1507
|
+
const depOriginFile = depOriginPathExt.file;
|
|
1508
|
+
const depDestPath = resolve$4(path$2.dirname(anaFileDestFile), depItem);
|
|
1509
|
+
const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext;
|
|
1510
|
+
|
|
1511
|
+
if (!resDep.has(depDestFile)) {
|
|
1512
|
+
resDep.set(depDestFile, {
|
|
1513
|
+
anaFileOriginFile,
|
|
1514
|
+
anaFileDestFile,
|
|
1515
|
+
depDestFile,
|
|
1516
|
+
depOriginFile
|
|
1517
|
+
});
|
|
1518
|
+
dfs(depOriginFile, depDestFile, extensions);
|
|
1519
|
+
}
|
|
1477
1520
|
}
|
|
1478
1521
|
}
|
|
1479
1522
|
});
|
|
1480
1523
|
}
|
|
1481
1524
|
|
|
1482
|
-
|
|
1483
|
-
return
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1525
|
+
dfs(anaFileOriginFile, anaFileDestFile, extensions);
|
|
1526
|
+
return resDep;
|
|
1527
|
+
};
|
|
1486
1528
|
|
|
1487
|
-
function
|
|
1488
|
-
|
|
1529
|
+
function handleCopyFile$1(depDestFile, depOriginFile) {
|
|
1530
|
+
if (fs$3.existsSync(depDestFile)) {
|
|
1531
|
+
const depDestContent = fs$3.readFileSync(depDestFile, 'utf8');
|
|
1532
|
+
const depOriginContent = fs$3.readFileSync(depOriginFile, 'utf8');
|
|
1489
1533
|
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
} catch (e) {
|
|
1494
|
-
fail$4(`动态生成app.json出现错误${e} 请检查你的配置项`);
|
|
1495
|
-
return {};
|
|
1534
|
+
if (depDestContent !== depOriginContent) {
|
|
1535
|
+
console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
|
|
1536
|
+
copyFile$1(depOriginFile, depDestFile);
|
|
1496
1537
|
}
|
|
1538
|
+
} else {
|
|
1539
|
+
console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
|
|
1540
|
+
copyFile$1(depOriginFile, depDestFile);
|
|
1497
1541
|
}
|
|
1542
|
+
}
|
|
1498
1543
|
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1544
|
+
function jsDep$1(tmsConfig, module, extensions = ['.js', '.ts', '.wxs']) {
|
|
1545
|
+
const stream = through$1.obj(function (file, enc, cb) {
|
|
1546
|
+
// 依赖分析的文件
|
|
1547
|
+
const anaFileOriginFile = file.history[0];
|
|
1548
|
+
const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
|
|
1549
|
+
const anaFileDestFile = resolve$4(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
|
|
1550
|
+
|
|
1551
|
+
if (file.isBuffer()) {
|
|
1552
|
+
let contents = String(file.contents);
|
|
1553
|
+
const deps = precinct(contents);
|
|
1554
|
+
const copyModules = new Map();
|
|
1555
|
+
Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
|
|
1556
|
+
const includePath = tmsConfig.gulp.dependencies[includeName];
|
|
1557
|
+
deps.forEach(depItem => {
|
|
1558
|
+
if (depItem.indexOf(includeName) > -1) {
|
|
1559
|
+
// 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
|
|
1560
|
+
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
1561
|
+
|
|
1562
|
+
const depOriginPathExt = ext$1(depOriginPath, extensions);
|
|
1563
|
+
|
|
1564
|
+
if (!depOriginPathExt) {
|
|
1565
|
+
fail$3(`${anaFileOriginFile}的${depItem}引用路径存找不到文件,请检查引用路径`);
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
const isFileInDir = fileInDir$1(includePath, depOriginPathExt.file);
|
|
1569
|
+
|
|
1570
|
+
if (!isFileInDir) {
|
|
1571
|
+
fail$3(`${depOriginPathExt.file}不在${includePath}不在文件夹内, 请检查应用路径`);
|
|
1572
|
+
} // 被依赖文件是否存在 include的path中 (只处理include的文件)
|
|
1573
|
+
|
|
1574
|
+
|
|
1575
|
+
if (depOriginPathExt && isFileInDir) {
|
|
1576
|
+
// eslint-disable-next-line
|
|
1577
|
+
const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
1578
|
+
const regRes = depItem.match(reg) || [];
|
|
1579
|
+
|
|
1580
|
+
if (regRes[2]) {
|
|
1581
|
+
const depDestPath = resolve$4(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
|
|
1582
|
+
const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext; // {
|
|
1583
|
+
// depOriginFile: '/Users/odile/workspace/tms-frontend1/miniprogram/thirdparty/libs/timer.js',
|
|
1584
|
+
// depDestFile: `/Users/odile/workspace/tms-frontend1/tools/demo1/dist/modules/
|
|
1585
|
+
// aggredriving/thirdparty/libs/timer.js`,
|
|
1586
|
+
// beforeDepPath: '../../../../thirdparty/libs/timer',
|
|
1587
|
+
// afterDepPath: '../../thirdparty/libs/timer'
|
|
1588
|
+
// }
|
|
1589
|
+
|
|
1590
|
+
if (!copyModules.has(depDestFile)) {
|
|
1591
|
+
copyModules.set(depDestFile, {
|
|
1592
|
+
depOriginFile: depOriginPathExt.file,
|
|
1593
|
+
depDestFile,
|
|
1594
|
+
beforeDepPath: depItem,
|
|
1595
|
+
afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestPath)
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
});
|
|
1509
1602
|
});
|
|
1510
|
-
|
|
1511
|
-
|
|
1603
|
+
copyModules.forEach(({
|
|
1604
|
+
depOriginFile,
|
|
1605
|
+
depDestFile,
|
|
1606
|
+
beforeDepPath,
|
|
1607
|
+
afterDepPath
|
|
1608
|
+
}) => {
|
|
1609
|
+
handleCopyFile$1(depDestFile, depOriginFile);
|
|
1610
|
+
contents = contents.replace(beforeDepPath, afterDepPath);
|
|
1611
|
+
const defs = dfsFindJsDep$1(depOriginFile, depDestFile, extensions);
|
|
1612
|
+
defs.forEach(item => {
|
|
1613
|
+
handleCopyFile$1(item.depDestFile, item.depOriginFile);
|
|
1614
|
+
});
|
|
1615
|
+
}); // eslint-disable-next-line
|
|
1512
1616
|
|
|
1513
|
-
|
|
1514
|
-
|
|
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
|
-
}
|
|
1617
|
+
file.contents = new Buffer(contents);
|
|
1618
|
+
}
|
|
1527
1619
|
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
}
|
|
1531
|
-
});
|
|
1620
|
+
this.push(file);
|
|
1621
|
+
cb();
|
|
1532
1622
|
});
|
|
1623
|
+
return stream;
|
|
1624
|
+
}
|
|
1533
1625
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
patterns.push({
|
|
1539
|
-
from: resolve$5(item),
|
|
1540
|
-
to: resolve$5(`./${toPath}/${item}`),
|
|
1541
|
-
transform: {
|
|
1542
|
-
cache: true,
|
|
1543
|
-
transformer: () => {
|
|
1544
|
-
const appJson = generatorAppJson(tmsConfig, modules);
|
|
1545
|
-
return JSON.stringify(appJson, null, 2);
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
});
|
|
1549
|
-
});
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
return patterns;
|
|
1553
|
-
} // dev时,给webpack注入相应的事件
|
|
1626
|
+
var jsDep_1 = {
|
|
1627
|
+
jsDep: jsDep$1,
|
|
1628
|
+
dfsFindJsDep: dfsFindJsDep$1
|
|
1629
|
+
};
|
|
1554
1630
|
|
|
1631
|
+
const through = require$$0__default$7;
|
|
1632
|
+
const path$1 = require$$1__default$1;
|
|
1633
|
+
const {
|
|
1634
|
+
copyFile,
|
|
1635
|
+
ext,
|
|
1636
|
+
fileInDir
|
|
1637
|
+
} = io$2;
|
|
1638
|
+
const {
|
|
1639
|
+
resolve: resolve$3
|
|
1640
|
+
} = widgets;
|
|
1641
|
+
const fs$2 = require$$0__default$1;
|
|
1642
|
+
const {
|
|
1643
|
+
fail: fail$2
|
|
1644
|
+
} = log$2;
|
|
1645
|
+
const {
|
|
1646
|
+
dfsFindJsDep
|
|
1647
|
+
} = jsDep_1;
|
|
1555
1648
|
|
|
1556
|
-
|
|
1557
|
-
|
|
1649
|
+
function handleCopyFile(depDestFile, depOriginFile) {
|
|
1650
|
+
if (fs$2.existsSync(depDestFile)) {
|
|
1651
|
+
const depDestContent = fs$2.readFileSync(depDestFile, 'utf8');
|
|
1652
|
+
const depOriginContent = fs$2.readFileSync(depOriginFile, 'utf8');
|
|
1558
1653
|
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1654
|
+
if (depDestContent !== depOriginContent) {
|
|
1655
|
+
console.log(`json拷贝${depOriginFile}内容到${depDestFile}`);
|
|
1656
|
+
copyFile(depOriginFile, depDestFile);
|
|
1657
|
+
}
|
|
1658
|
+
} else {
|
|
1659
|
+
console.log(`json拷贝${depOriginFile}内容到${depDestFile}`);
|
|
1660
|
+
copyFile(depOriginFile, depDestFile);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1563
1663
|
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1664
|
+
function mpJsonDep$1(tmsConfig, module, extensions = ['.wxml'], filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less']) {
|
|
1665
|
+
const stream = through.obj(function (file, enc, cb) {
|
|
1666
|
+
// 当前分析的文件的路径
|
|
1667
|
+
const anaFileOriginFile = file.history[0];
|
|
1668
|
+
const anaFileRelativeModule = path$1.relative(resolve$3(module.from), anaFileOriginFile);
|
|
1669
|
+
const anaFileDestFile = resolve$3(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
|
|
1670
|
+
|
|
1671
|
+
if (file.isBuffer()) {
|
|
1672
|
+
const copyModules = new Map();
|
|
1673
|
+
let contents = String(file.contents);
|
|
1674
|
+
|
|
1675
|
+
try {
|
|
1676
|
+
contents = JSON.parse(contents);
|
|
1677
|
+
|
|
1678
|
+
if (contents.usingComponents) {
|
|
1679
|
+
Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
|
|
1680
|
+
const includePath = tmsConfig.gulp.dependencies[includeName];
|
|
1681
|
+
Object.keys(contents.usingComponents).forEach(componentKey => {
|
|
1682
|
+
const componentPath = contents.usingComponents[componentKey];
|
|
1683
|
+
|
|
1684
|
+
if (componentPath.indexOf(includeName) > -1) {
|
|
1685
|
+
const depOriginPath = path$1.join(path$1.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
|
|
1686
|
+
|
|
1687
|
+
const depOriginPathExt = ext(depOriginPath, extensions);
|
|
1688
|
+
|
|
1689
|
+
if (!depOriginPathExt) {
|
|
1690
|
+
fail$2(`${anaFileOriginFile}的${componentPath}引用路径存找不到文件,请检查引用路径`);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
const isFileInDir = fileInDir(includePath, depOriginPathExt.file);
|
|
1694
|
+
|
|
1695
|
+
if (!isFileInDir) {
|
|
1696
|
+
fail$2(`${depOriginPathExt.file}不在${includePath}不在文件夹内, 请检查应用路径`);
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
if (depOriginPathExt && isFileInDir) {
|
|
1700
|
+
// eslint-disable-next-line
|
|
1701
|
+
const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
1702
|
+
const regRes = componentPath.match(reg) || [];
|
|
1703
|
+
|
|
1704
|
+
if (regRes[2]) {
|
|
1705
|
+
const depDestPath = resolve$3(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
|
|
1706
|
+
const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext;
|
|
1707
|
+
|
|
1708
|
+
if (!copyModules.has(depDestFile)) {
|
|
1709
|
+
copyModules.set(depDestFile, {
|
|
1710
|
+
depOriginFile: depOriginPathExt.file,
|
|
1711
|
+
depOriginExt: depOriginPathExt.ext,
|
|
1712
|
+
depDestFile,
|
|
1713
|
+
beforeDepPath: componentPath,
|
|
1714
|
+
afterDepPath: path$1.relative(path$1.dirname(anaFileDestFile), depDestPath)
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
});
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
} catch (e) {
|
|
1724
|
+
fail$2(`解析jsonDep出现错误:${e}`);
|
|
1576
1725
|
}
|
|
1577
|
-
});
|
|
1578
|
-
};
|
|
1579
1726
|
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
}
|
|
1727
|
+
copyModules.forEach(({
|
|
1728
|
+
depOriginFile,
|
|
1729
|
+
depOriginExt,
|
|
1730
|
+
depDestFile,
|
|
1731
|
+
beforeDepPath,
|
|
1732
|
+
afterDepPath
|
|
1733
|
+
}) => {
|
|
1734
|
+
filesExt.forEach(extKey => {
|
|
1735
|
+
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
1736
|
+
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
1737
|
+
|
|
1738
|
+
if (fs$2.existsSync(originFile)) {
|
|
1739
|
+
handleCopyFile(destFile, originFile);
|
|
1740
|
+
const jsExtensions = ['.js', '.ts'];
|
|
1741
|
+
|
|
1742
|
+
if (jsExtensions.indexOf(extKey) > -1) {
|
|
1743
|
+
const defs = dfsFindJsDep(originFile, destFile, jsExtensions);
|
|
1744
|
+
defs.forEach(item => {
|
|
1745
|
+
handleCopyFile(item.depDestFile, item.depOriginFile);
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
1751
|
+
contents = contents.replace(beforeDepPath, afterDepPath);
|
|
1752
|
+
});
|
|
1753
|
+
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents; // eslint-disable-next-line
|
|
1587
1754
|
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
// eslint-disable-next-line
|
|
1591
|
-
env[key] = JSON.stringify(raw[key]);
|
|
1592
|
-
return env;
|
|
1593
|
-
}, {})
|
|
1594
|
-
});
|
|
1755
|
+
file.contents = new Buffer(contents);
|
|
1756
|
+
}
|
|
1595
1757
|
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1758
|
+
this.push(file);
|
|
1759
|
+
cb();
|
|
1760
|
+
});
|
|
1761
|
+
return stream;
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
var mpJsonDep_1 = {
|
|
1765
|
+
mpJsonDep: mpJsonDep$1
|
|
1602
1766
|
};
|
|
1603
1767
|
|
|
1604
|
-
const WebpackChain = require$$0__default$7;
|
|
1605
|
-
const webpack$2 = require$$0__default$8;
|
|
1606
1768
|
const {
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1769
|
+
src: src$1,
|
|
1770
|
+
dest
|
|
1771
|
+
} = require$$0__default$8;
|
|
1772
|
+
const px2rpx = require$$1__default$5;
|
|
1773
|
+
const less = require$$2__default$1;
|
|
1774
|
+
const rename = require$$3__default$1;
|
|
1775
|
+
const watch = require$$4__default;
|
|
1776
|
+
const image = require$$5__default$1;
|
|
1777
|
+
const replaceEnv = replaceEnv_1;
|
|
1611
1778
|
const {
|
|
1612
|
-
|
|
1613
|
-
} =
|
|
1779
|
+
jsDep
|
|
1780
|
+
} = jsDep_1;
|
|
1614
1781
|
const {
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1782
|
+
mpJsonDep
|
|
1783
|
+
} = mpJsonDep_1;
|
|
1784
|
+
|
|
1785
|
+
var compile = function (tmsConfig, {
|
|
1786
|
+
glob,
|
|
1787
|
+
destPath,
|
|
1788
|
+
srcOption,
|
|
1789
|
+
module,
|
|
1790
|
+
watchOption = {
|
|
1791
|
+
events: ['change', 'add', 'unlink']
|
|
1792
|
+
},
|
|
1793
|
+
isWatch
|
|
1794
|
+
}) {
|
|
1795
|
+
Object.keys(glob).forEach(globKey => {
|
|
1796
|
+
const globValue = glob[globKey];
|
|
1797
|
+
let srcPipe = src$1(globValue, srcOption);
|
|
1618
1798
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
webpack: tmsWebpack
|
|
1623
|
-
} = tmsConfig;
|
|
1624
|
-
let webpackConfig = new WebpackChain();
|
|
1625
|
-
const alias = getAlias(modules);
|
|
1626
|
-
const entry = getEntry$1(DEFAULT_WEBPACK_ENTRY$1, modules, tmsConfig, DEFAULT_MODULE_DIR$2);
|
|
1627
|
-
webpackConfig.merge({
|
|
1628
|
-
entry,
|
|
1629
|
-
output: {
|
|
1630
|
-
path: resolve$4(`./${tmsWebpack.outputDir}`),
|
|
1631
|
-
libraryTarget: 'commonjs2',
|
|
1632
|
-
filename: '[name]'
|
|
1633
|
-
},
|
|
1634
|
-
// TODO 有报错,先注释掉
|
|
1635
|
-
// cache: {
|
|
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
|
|
1662
|
-
});
|
|
1663
|
-
}
|
|
1799
|
+
if (isWatch) {
|
|
1800
|
+
srcPipe = srcPipe.pipe(watch(globValue, watchOption));
|
|
1801
|
+
}
|
|
1664
1802
|
|
|
1665
|
-
|
|
1803
|
+
switch (globKey) {
|
|
1804
|
+
case 'js':
|
|
1805
|
+
srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(jsDep(tmsConfig, module)).pipe(dest(destPath));
|
|
1806
|
+
break;
|
|
1807
|
+
|
|
1808
|
+
case 'css':
|
|
1809
|
+
srcPipe.pipe(less()).pipe(px2rpx({
|
|
1810
|
+
designWidth: 375,
|
|
1811
|
+
// 设计稿宽度,默认为750
|
|
1812
|
+
precision: 2 // 小数最大精度,默认为6
|
|
1813
|
+
|
|
1814
|
+
})).pipe(rename({
|
|
1815
|
+
extname: '.wxss'
|
|
1816
|
+
})).pipe(dest(destPath));
|
|
1817
|
+
break;
|
|
1818
|
+
|
|
1819
|
+
case 'json':
|
|
1820
|
+
srcPipe.pipe(mpJsonDep(tmsConfig, module)).pipe(dest(destPath));
|
|
1821
|
+
break;
|
|
1822
|
+
|
|
1823
|
+
case 'html':
|
|
1824
|
+
srcPipe.pipe(dest(destPath));
|
|
1825
|
+
break;
|
|
1826
|
+
|
|
1827
|
+
case 'image':
|
|
1828
|
+
srcPipe.pipe(image()).pipe(dest(destPath));
|
|
1829
|
+
break;
|
|
1830
|
+
|
|
1831
|
+
case 'other':
|
|
1832
|
+
srcPipe.pipe(dest(destPath));
|
|
1833
|
+
break;
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1666
1836
|
};
|
|
1667
1837
|
|
|
1668
|
-
|
|
1669
|
-
const
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
} =
|
|
1673
|
-
const {
|
|
1674
|
-
|
|
1675
|
-
} =
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1838
|
+
(function (module) {
|
|
1839
|
+
const watch = require$$4__default;
|
|
1840
|
+
const {
|
|
1841
|
+
resolve
|
|
1842
|
+
} = widgets;
|
|
1843
|
+
const {
|
|
1844
|
+
buildOutputAppJson
|
|
1845
|
+
} = buildAppJson;
|
|
1846
|
+
const {
|
|
1847
|
+
DEFAULT_COPY_CONFIG
|
|
1848
|
+
} = require$$3;
|
|
1849
|
+
const compile$1 = compile;
|
|
1850
|
+
|
|
1851
|
+
function handleOtherGlob(glob) {
|
|
1852
|
+
const otherArr = [];
|
|
1853
|
+
Object.keys(glob).forEach(globKey => {
|
|
1854
|
+
if (typeof glob[globKey] === 'string') {
|
|
1855
|
+
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
1856
|
+
otherArr.push(data);
|
|
1857
|
+
}
|
|
1681
1858
|
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1859
|
+
if (Array.isArray(glob[globKey])) {
|
|
1860
|
+
glob[globKey].forEach(value => {
|
|
1861
|
+
if (typeof value === 'string') {
|
|
1862
|
+
const data = value.startsWith('!') ? value : `!${value}`;
|
|
1863
|
+
otherArr.push(data);
|
|
1864
|
+
}
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1688
1867
|
});
|
|
1868
|
+
return otherArr;
|
|
1689
1869
|
}
|
|
1690
1870
|
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
tmsConfig = {},
|
|
1694
|
-
modules = []
|
|
1695
|
-
} = this.options;
|
|
1696
|
-
compiler.hooks.watchRun.tap('EntryExtraPlugin', () => {
|
|
1697
|
-
const entry = getEntry(DEFAULT_WEBPACK_ENTRY, modules, tmsConfig, DEFAULT_MODULE_DIR$1);
|
|
1698
|
-
this.applyEntry(compiler, entry);
|
|
1699
|
-
});
|
|
1700
|
-
}
|
|
1871
|
+
module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
1872
|
+
var _tmsConfig$gulp;
|
|
1701
1873
|
|
|
1702
|
-
|
|
1874
|
+
// 监听app.json
|
|
1875
|
+
if (isWatch) {
|
|
1876
|
+
watch(resolve('app.json'), {
|
|
1877
|
+
ignoreInitial: false,
|
|
1878
|
+
events: ['add', 'change']
|
|
1879
|
+
}, () => {
|
|
1880
|
+
buildOutputAppJson(tmsConfig, newModules);
|
|
1881
|
+
});
|
|
1882
|
+
} else {
|
|
1883
|
+
buildOutputAppJson(tmsConfig, newModules);
|
|
1884
|
+
} // 监听根目录的文件
|
|
1703
1885
|
|
|
1704
|
-
var entryExtractPlugin = EntryExtraPlugin;
|
|
1705
1886
|
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
};
|
|
1887
|
+
compile$1(tmsConfig, {
|
|
1888
|
+
glob: {
|
|
1889
|
+
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
1890
|
+
css: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
1891
|
+
js: ['app.js', 'app.ts'].map(item => resolve(item))
|
|
1892
|
+
},
|
|
1893
|
+
module: {
|
|
1894
|
+
from: '',
|
|
1895
|
+
to: ''
|
|
1896
|
+
},
|
|
1897
|
+
destPath: resolve(tmsConfig.gulp.outputDir),
|
|
1898
|
+
srcOption: {
|
|
1899
|
+
allowEmpty: true
|
|
1900
|
+
},
|
|
1901
|
+
isWatch
|
|
1902
|
+
}); // 监听模块的文件
|
|
1903
|
+
|
|
1904
|
+
for (let module of newModules) {
|
|
1905
|
+
// 处理默认参数
|
|
1906
|
+
module = { ...{
|
|
1907
|
+
excludes: []
|
|
1908
|
+
},
|
|
1909
|
+
...module
|
|
1910
|
+
};
|
|
1730
1911
|
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
}
|
|
1912
|
+
if (isWatch) {
|
|
1913
|
+
// 监听模块配置文件
|
|
1914
|
+
watch(`${resolve(module.path)}/**/module.config.json`, {
|
|
1915
|
+
events: ['change']
|
|
1916
|
+
}, () => {
|
|
1917
|
+
buildOutputAppJson(tmsConfig, newModules);
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1739
1920
|
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1921
|
+
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
1922
|
+
const glob = {
|
|
1923
|
+
js: [`${resolve(module.path)}/**/*.{js,ts,wxs}`, ...excludes],
|
|
1924
|
+
json: [`${resolve(module.path)}/**/*.json`, ...excludes],
|
|
1925
|
+
css: [`${resolve(module.path)}/**/*.{less,wxss}`, ...excludes],
|
|
1926
|
+
html: [`${resolve(module.path)}/**/*.wxml`, ...excludes],
|
|
1927
|
+
image: [`${resolve(module.path)}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
|
|
1928
|
+
};
|
|
1929
|
+
compile$1(tmsConfig, {
|
|
1930
|
+
glob: { ...glob,
|
|
1931
|
+
other: [`${resolve(module.path)}/**/*`, ...handleOtherGlob(glob)]
|
|
1932
|
+
},
|
|
1933
|
+
destPath: resolve(tmsConfig.gulp.outputDir, module.root),
|
|
1934
|
+
module: {
|
|
1935
|
+
from: module.path,
|
|
1936
|
+
to: module.root
|
|
1937
|
+
},
|
|
1938
|
+
srcOption: {
|
|
1939
|
+
allowEmpty: true
|
|
1940
|
+
},
|
|
1941
|
+
isWatch
|
|
1942
|
+
});
|
|
1943
|
+
} // 监听copy模块
|
|
1944
|
+
|
|
1945
|
+
|
|
1946
|
+
if ((tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gulp = tmsConfig.gulp) === null || _tmsConfig$gulp === void 0 ? void 0 : _tmsConfig$gulp.copyDir.length) > 0) {
|
|
1947
|
+
for (const item of (_tmsConfig$gulp2 = tmsConfig.gulp) === null || _tmsConfig$gulp2 === void 0 ? void 0 : _tmsConfig$gulp2.copyDir) {
|
|
1948
|
+
var _tmsConfig$gulp2;
|
|
1756
1949
|
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1950
|
+
const glob = {
|
|
1951
|
+
js: `${item.from}/**/*.{js,ts,wxs}`,
|
|
1952
|
+
json: `${item.from}/**/*.json`,
|
|
1953
|
+
css: `${item.from}/**/*.{less,wxss}`,
|
|
1954
|
+
html: `${item.from}/**/*.wxml`,
|
|
1955
|
+
image: `${item.from}/**/*.{png,jpg,jpeg,gif,svg}`
|
|
1956
|
+
};
|
|
1957
|
+
compile$1(tmsConfig, {
|
|
1958
|
+
glob: { ...glob,
|
|
1959
|
+
other: [`${item.from}/**/*`, ...handleOtherGlob(glob)]
|
|
1960
|
+
},
|
|
1961
|
+
destPath: item.to,
|
|
1962
|
+
module: item,
|
|
1963
|
+
srcOption: {
|
|
1964
|
+
allowEmpty: true
|
|
1965
|
+
},
|
|
1966
|
+
isWatch
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1762
1969
|
}
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
};
|
|
1970
|
+
};
|
|
1971
|
+
})(dev$3);
|
|
1766
1972
|
|
|
1767
|
-
const fs$1 = require$$
|
|
1768
|
-
const semver$1 = require$$1__default$
|
|
1973
|
+
const fs$1 = require$$0__default$1;
|
|
1974
|
+
const semver$1 = require$$1__default$6;
|
|
1769
1975
|
const {
|
|
1770
|
-
resolve: resolve$
|
|
1976
|
+
resolve: resolve$2
|
|
1771
1977
|
} = widgets;
|
|
1772
|
-
const path
|
|
1978
|
+
const path = require$$1__default$1;
|
|
1773
1979
|
const {
|
|
1774
|
-
fail: fail$
|
|
1980
|
+
fail: fail$1
|
|
1775
1981
|
} = log$2;
|
|
1776
|
-
const shelljs$
|
|
1982
|
+
const shelljs$1 = require$$5__default;
|
|
1777
1983
|
|
|
1778
1984
|
const getLatestVersion = npmName => {
|
|
1779
|
-
const data = shelljs$
|
|
1985
|
+
const data = shelljs$1.exec(`npm view ${npmName} version`);
|
|
1780
1986
|
return data.stdout || '0.0.0';
|
|
1781
1987
|
};
|
|
1782
1988
|
/**
|
|
@@ -1794,17 +2000,17 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
|
1794
2000
|
// 1.1根目录的package.json
|
|
1795
2001
|
|
|
1796
2002
|
const packageArr = [{
|
|
1797
|
-
srcPackageDir: path
|
|
1798
|
-
destNpmDir: resolve$
|
|
2003
|
+
srcPackageDir: path.join(cwd, packageJsonName),
|
|
2004
|
+
destNpmDir: resolve$2(outputDir, 'node_modules')
|
|
1799
2005
|
}]; // 1.2模块的package.json
|
|
1800
2006
|
|
|
1801
2007
|
modules.forEach(item => {
|
|
1802
|
-
const srcPackageDir = path
|
|
2008
|
+
const srcPackageDir = path.join(cwd, item.path, 'package.json');
|
|
1803
2009
|
|
|
1804
2010
|
if (fs$1.existsSync(srcPackageDir)) {
|
|
1805
2011
|
packageArr.push({
|
|
1806
2012
|
srcPackageDir,
|
|
1807
|
-
destNpmDir: resolve$
|
|
2013
|
+
destNpmDir: resolve$2(outputDir, item.root, 'node_modules')
|
|
1808
2014
|
});
|
|
1809
2015
|
}
|
|
1810
2016
|
}); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
@@ -1816,20 +2022,20 @@ const checkDependencies$1 = (modules, cwd, outputDir) => {
|
|
|
1816
2022
|
try {
|
|
1817
2023
|
dependencies = JSON.parse(packageJson).dependencies;
|
|
1818
2024
|
} catch (e) {
|
|
1819
|
-
fail$
|
|
2025
|
+
fail$1(`解析${packageJson}报错,请检查是否是正确的json配置项`);
|
|
1820
2026
|
process.exit(1);
|
|
1821
2027
|
}
|
|
1822
2028
|
|
|
1823
2029
|
const dependenciesKeys = Object.keys(dependencies);
|
|
1824
2030
|
|
|
1825
2031
|
for (const key of dependenciesKeys) {
|
|
1826
|
-
const depPath = path
|
|
2032
|
+
const depPath = path.join(item.destNpmDir, key);
|
|
1827
2033
|
|
|
1828
2034
|
if (!fs$1.existsSync(depPath)) {
|
|
1829
2035
|
return true;
|
|
1830
2036
|
}
|
|
1831
2037
|
|
|
1832
|
-
const depPackagePath = path
|
|
2038
|
+
const depPackagePath = path.join(depPath, 'package.json');
|
|
1833
2039
|
|
|
1834
2040
|
if (fs$1.existsSync(depPackagePath)) {
|
|
1835
2041
|
const packageData = require(depPackagePath);
|
|
@@ -1856,10 +2062,10 @@ var checkDependencies_1 = {
|
|
|
1856
2062
|
checkDependencies: checkDependencies$1
|
|
1857
2063
|
};
|
|
1858
2064
|
|
|
1859
|
-
const
|
|
1860
|
-
const fs = require$$
|
|
2065
|
+
const gulpDev = dev$3.exports;
|
|
2066
|
+
const fs = require$$0__default$1;
|
|
1861
2067
|
const {
|
|
1862
|
-
resolve: resolve$
|
|
2068
|
+
resolve: resolve$1
|
|
1863
2069
|
} = widgets;
|
|
1864
2070
|
const init$4 = init$5;
|
|
1865
2071
|
const {
|
|
@@ -1872,7 +2078,7 @@ const {
|
|
|
1872
2078
|
checkDependencies
|
|
1873
2079
|
} = checkDependencies_1;
|
|
1874
2080
|
const {
|
|
1875
|
-
fail
|
|
2081
|
+
fail
|
|
1876
2082
|
} = log$2;
|
|
1877
2083
|
|
|
1878
2084
|
function isInit(tmsConfig, targetModules, contextDir) {
|
|
@@ -1909,164 +2115,62 @@ function isInit(tmsConfig, targetModules, contextDir) {
|
|
|
1909
2115
|
} // 判断源码目录是否有该模块
|
|
1910
2116
|
|
|
1911
2117
|
|
|
1912
|
-
if (item.path && !fs.existsSync(resolve$
|
|
1913
|
-
fail
|
|
2118
|
+
if (item.path && !fs.existsSync(resolve$1(item.path))) {
|
|
2119
|
+
fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1914
2120
|
process.exit(1);
|
|
1915
2121
|
}
|
|
1916
2122
|
} // 判断package.json的版本是否有新的版本
|
|
1917
2123
|
|
|
1918
2124
|
|
|
1919
|
-
return checkDependencies(targetModules, resolve$
|
|
2125
|
+
return checkDependencies(targetModules, resolve$1('./'), tmsConfig.gulp.outputDir);
|
|
1920
2126
|
}
|
|
1921
2127
|
|
|
1922
|
-
async function dev$
|
|
2128
|
+
async function dev$2(tmsConfig, targetModules, env) {
|
|
1923
2129
|
// tms.config.js的modules 合并 module.config.json的配置项
|
|
1924
2130
|
let newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR); // 判断是否进行init命令
|
|
1925
2131
|
|
|
1926
|
-
if (isInit(tmsConfig, newModules, resolve$
|
|
2132
|
+
if (isInit(tmsConfig, newModules, resolve$1('dist'))) {
|
|
1927
2133
|
// init函数会将 最新的tms.config.js的modules 合并 module.config.json的配置项 返回,不需要再做重复工作
|
|
1928
2134
|
const initData = await init$4(tmsConfig, targetModules);
|
|
1929
2135
|
newModules = initData.targetModules;
|
|
1930
2136
|
}
|
|
1931
2137
|
|
|
1932
2138
|
console.log('当前dev启动的有效模块', newModules.map(item => item.name));
|
|
1933
|
-
|
|
1934
|
-
}
|
|
1935
|
-
|
|
1936
|
-
var dev_1 = dev$1;
|
|
1937
|
-
|
|
1938
|
-
const webpackConfig = base;
|
|
1939
|
-
const {
|
|
1940
|
-
DEFAULT_COPY_CONFIG
|
|
1941
|
-
} = require$$3;
|
|
1942
|
-
const {
|
|
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$8;
|
|
1959
|
-
const webBuildConfig = build$2;
|
|
1960
|
-
const {
|
|
1961
|
-
createTask: createTask$2
|
|
1962
|
-
} = widgets;
|
|
1963
|
-
const {
|
|
1964
|
-
fail
|
|
1965
|
-
} = log$2;
|
|
1966
|
-
|
|
1967
|
-
function compilerRun(compiler) {
|
|
1968
|
-
return new Promise(resolve => {
|
|
1969
|
-
compiler.run((err, stats) => {
|
|
1970
|
-
resolve({
|
|
1971
|
-
err,
|
|
1972
|
-
stats
|
|
1973
|
-
});
|
|
1974
|
-
});
|
|
1975
|
-
});
|
|
2139
|
+
gulpDev(tmsConfig, newModules, env);
|
|
1976
2140
|
}
|
|
1977
2141
|
|
|
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);
|
|
2142
|
+
var dev_1 = dev$2;
|
|
1985
2143
|
|
|
1986
|
-
|
|
1987
|
-
fail(err);
|
|
1988
|
-
console.log('详细的错误信息:', err);
|
|
1989
|
-
}
|
|
2144
|
+
const dev$1 = dev$3.exports;
|
|
1990
2145
|
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
// 增加控制台颜色开关
|
|
1994
|
-
colors: true,
|
|
1995
|
-
errorDetails: true
|
|
1996
|
-
}));
|
|
1997
|
-
}
|
|
1998
|
-
return compiler;
|
|
2146
|
+
var build$2 = async (tmsConfig, newModules) => {
|
|
2147
|
+
dev$1(tmsConfig, newModules, false);
|
|
1999
2148
|
};
|
|
2000
2149
|
|
|
2001
|
-
const shelljs
|
|
2002
|
-
const webpackBuildServer = buildServer;
|
|
2150
|
+
const shelljs = require$$5__default;
|
|
2003
2151
|
const {
|
|
2004
|
-
resolve
|
|
2152
|
+
resolve
|
|
2005
2153
|
} = widgets;
|
|
2006
2154
|
const init$3 = init$5;
|
|
2155
|
+
const gulpBuild = build$2;
|
|
2007
2156
|
|
|
2008
2157
|
async function build$1(tmsConfig, targetModules, env) {
|
|
2009
2158
|
// 开始构建前,清理输出目录
|
|
2010
|
-
await shelljs
|
|
2159
|
+
await shelljs.rm('-rf', resolve(tmsConfig.gulp.outputDir));
|
|
2011
2160
|
const {
|
|
2012
2161
|
targetModules: newModules
|
|
2013
2162
|
} = await init$3(tmsConfig, targetModules);
|
|
2014
|
-
|
|
2163
|
+
gulpBuild(tmsConfig, newModules, env);
|
|
2015
2164
|
}
|
|
2016
2165
|
|
|
2017
2166
|
var build_1 = build$1;
|
|
2018
2167
|
|
|
2019
|
-
const shelljs = require$$0__default$1;
|
|
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
|
-
console.log('files', files);
|
|
2033
|
-
|
|
2034
|
-
if (err) {
|
|
2035
|
-
reject(err);
|
|
2036
|
-
}
|
|
2037
|
-
|
|
2038
|
-
files.forEach(file => {
|
|
2039
|
-
const dir = path.dirname(file);
|
|
2040
|
-
shelljs.cd(dir);
|
|
2041
|
-
shelljs.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', {
|
|
2042
|
-
silent: false
|
|
2043
|
-
});
|
|
2044
|
-
});
|
|
2045
|
-
resolve();
|
|
2046
|
-
});
|
|
2047
|
-
});
|
|
2048
|
-
}
|
|
2049
|
-
|
|
2050
|
-
async function install$1(contextDir) {
|
|
2051
|
-
// npm install
|
|
2052
|
-
await createTask$1(npmInstall, '开始npm install', 'npm install完成')(contextDir); // 构建miniprograme_npm
|
|
2053
|
-
|
|
2054
|
-
await createTask$1(buildMpNpm, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')({
|
|
2055
|
-
appId: 'null',
|
|
2056
|
-
projectPath: contextDir,
|
|
2057
|
-
privateKey: 'null'
|
|
2058
|
-
});
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
var install_1 = install$1;
|
|
2062
|
-
|
|
2063
2168
|
const init$2 = init$5;
|
|
2064
2169
|
const dev = dev_1;
|
|
2065
2170
|
const build = build_1;
|
|
2066
2171
|
const install = install_1;
|
|
2067
2172
|
const {
|
|
2068
|
-
createTask
|
|
2069
|
-
resolve
|
|
2173
|
+
createTask
|
|
2070
2174
|
} = widgets;
|
|
2071
2175
|
const {
|
|
2072
2176
|
MODE
|
|
@@ -2083,8 +2187,13 @@ const handleModulesArg = cmd => {
|
|
|
2083
2187
|
} // 单模块 或 多模块开发
|
|
2084
2188
|
|
|
2085
2189
|
|
|
2190
|
+
const {
|
|
2191
|
+
argv
|
|
2192
|
+
} = process;
|
|
2193
|
+
const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
|
|
2194
|
+
|
|
2086
2195
|
if (cmd.module) {
|
|
2087
|
-
return [cmd.module, ...
|
|
2196
|
+
return [cmd.module, ...reset];
|
|
2088
2197
|
} // 全量模块
|
|
2089
2198
|
|
|
2090
2199
|
|
|
@@ -2092,11 +2201,6 @@ const handleModulesArg = cmd => {
|
|
|
2092
2201
|
};
|
|
2093
2202
|
|
|
2094
2203
|
async function run(commandName, cmd) {
|
|
2095
|
-
if (commandName === 'install') {
|
|
2096
|
-
install(resolve('./'));
|
|
2097
|
-
return;
|
|
2098
|
-
}
|
|
2099
|
-
|
|
2100
2204
|
const moduleArg = handleModulesArg(cmd);
|
|
2101
2205
|
const {
|
|
2102
2206
|
env
|
|
@@ -2123,6 +2227,10 @@ async function run(commandName, cmd) {
|
|
|
2123
2227
|
dev(tmsConfig, modules, env);
|
|
2124
2228
|
return;
|
|
2125
2229
|
|
|
2230
|
+
case 'install':
|
|
2231
|
+
install(tmsConfig, modules, env);
|
|
2232
|
+
return;
|
|
2233
|
+
|
|
2126
2234
|
case 'build':
|
|
2127
2235
|
build(tmsConfig, modules, env);
|
|
2128
2236
|
return;
|
|
@@ -2141,17 +2249,43 @@ var entry = [{
|
|
|
2141
2249
|
create_1(appName, cmd);
|
|
2142
2250
|
}
|
|
2143
2251
|
}, {
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
description: '
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2252
|
+
name: 'run',
|
|
2253
|
+
type: 'child',
|
|
2254
|
+
description: '项目开发使用的命令',
|
|
2255
|
+
commands: [{
|
|
2256
|
+
command: 'install',
|
|
2257
|
+
description: '安装依赖',
|
|
2258
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
2259
|
+
action: cmd => {
|
|
2260
|
+
run_1('install', cmd);
|
|
2261
|
+
}
|
|
2262
|
+
}, {
|
|
2263
|
+
command: 'dev',
|
|
2264
|
+
description: 'dev 打包编译',
|
|
2265
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
2266
|
+
action: cmd => {
|
|
2267
|
+
run_1('dev', cmd);
|
|
2268
|
+
}
|
|
2269
|
+
}, {
|
|
2270
|
+
command: 'build',
|
|
2271
|
+
description: 'prod 打包编译',
|
|
2272
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
2273
|
+
action: cmd => {
|
|
2274
|
+
run_1('build', cmd);
|
|
2275
|
+
}
|
|
2276
|
+
}, {
|
|
2277
|
+
command: 'init',
|
|
2278
|
+
description: '根据模块配置初始化项目(eg: 动态拷贝模块、下载依赖、生成app.json等)',
|
|
2279
|
+
options: [['-m, --module [moduleName]', '模块名称'], ['-e, --env [env]', '环境变量']],
|
|
2280
|
+
action: cmd => {
|
|
2281
|
+
run_1('init', cmd);
|
|
2282
|
+
}
|
|
2283
|
+
}]
|
|
2150
2284
|
}];
|
|
2151
2285
|
|
|
2152
2286
|
var require$$6 = {
|
|
2153
2287
|
name: "@tmsfe/tmskit",
|
|
2154
|
-
version: "0.0.
|
|
2288
|
+
version: "0.0.5-beta.2",
|
|
2155
2289
|
description: "tmskit",
|
|
2156
2290
|
main: "main.js",
|
|
2157
2291
|
bin: {
|
|
@@ -2180,53 +2314,39 @@ var require$$6 = {
|
|
|
2180
2314
|
"rollup-plugin-typescript2": "0.27.0"
|
|
2181
2315
|
},
|
|
2182
2316
|
dependencies: {
|
|
2183
|
-
"@babel/core": "^7.15.0",
|
|
2184
|
-
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
|
|
2185
|
-
"@babel/preset-env": "^7.16.0",
|
|
2186
2317
|
async: "^3.2.2",
|
|
2187
|
-
axios: "^0.21.4",
|
|
2188
|
-
"babel-core": "^6.26.3",
|
|
2189
|
-
"babel-loader": "^8.2.3",
|
|
2190
2318
|
chalk: "^4.1.0",
|
|
2191
|
-
commander: "^
|
|
2319
|
+
commander: "^8.3.0",
|
|
2192
2320
|
"copy-webpack-plugin": "^9.1.0",
|
|
2193
|
-
"cross-env": "^7.0.3",
|
|
2194
2321
|
"download-git-repo": "^3.0.2",
|
|
2195
2322
|
ejs: "^3.1.5",
|
|
2196
|
-
"file-loader": "^6.2.0",
|
|
2197
|
-
"fs-extra": "^9.0.1",
|
|
2198
2323
|
"glob-ignore": "^1.0.2",
|
|
2324
|
+
gulp: "^4.0.2",
|
|
2325
|
+
"gulp-image": "^5.1.0",
|
|
2326
|
+
"gulp-less": "^5.0.0",
|
|
2327
|
+
"gulp-px-to-rpx": "^1.0.7",
|
|
2328
|
+
"gulp-rename": "^2.0.0",
|
|
2329
|
+
"gulp-watch": "^5.0.1",
|
|
2199
2330
|
inquirer: "^7.3.3",
|
|
2200
2331
|
leven: "3.1.0",
|
|
2201
2332
|
lodash: "^4.17.21",
|
|
2202
2333
|
metalsmith: "^2.3.0",
|
|
2203
|
-
"mini-css-extract-plugin": "^2.4.5",
|
|
2204
|
-
minimist: "^1.2.5",
|
|
2205
2334
|
"miniprogram-ci": "1.4.13",
|
|
2206
2335
|
ora: "^5.1.0",
|
|
2336
|
+
precinct: "^8.3.1",
|
|
2207
2337
|
"replace-ext": "^2.0.0",
|
|
2208
2338
|
shelljs: "^0.8.4",
|
|
2209
|
-
|
|
2210
|
-
tslib: "^1.14.1",
|
|
2211
|
-
typescript: "^3.8.3",
|
|
2212
|
-
"url-loader": "^4.1.1",
|
|
2213
|
-
username: "5.1.0",
|
|
2214
|
-
webpack: "^5.64.0",
|
|
2215
|
-
"webpack-chain": "^6.5.1",
|
|
2216
|
-
"webpack-cli": "^4.9.1"
|
|
2339
|
+
through2: "^4.0.2"
|
|
2217
2340
|
},
|
|
2218
2341
|
engines: {
|
|
2219
|
-
node: "^12.17.0 || >= 14.
|
|
2342
|
+
node: "^12.17.0 || >= 14.13.1"
|
|
2220
2343
|
},
|
|
2221
2344
|
jest: {
|
|
2222
2345
|
testEnvironment: "jest-environment-node"
|
|
2223
2346
|
}
|
|
2224
2347
|
};
|
|
2225
2348
|
|
|
2226
|
-
const
|
|
2227
|
-
exec
|
|
2228
|
-
} = require$$0__default$1;
|
|
2229
|
-
const semver = require$$1__default$5;
|
|
2349
|
+
const semver = require$$1__default$6;
|
|
2230
2350
|
const packageJson = require$$6;
|
|
2231
2351
|
const chalk$1 = require$$0__default$2;
|
|
2232
2352
|
const {
|
|
@@ -2258,17 +2378,13 @@ const checkNodeVersion = (wanted, id) => {
|
|
|
2258
2378
|
function initCliContext() {
|
|
2259
2379
|
// 执行操作前检查node版本
|
|
2260
2380
|
// 旧版本node直接提示升级,退出脚本
|
|
2261
|
-
checkNodeVersion(requiredVersion, packName);
|
|
2262
|
-
|
|
2263
|
-
exec('npm config set registry https://mirrors.tencent.com/npm/ --global', {
|
|
2264
|
-
silent: true
|
|
2265
|
-
});
|
|
2381
|
+
checkNodeVersion(requiredVersion, packName);
|
|
2266
2382
|
}
|
|
2267
2383
|
|
|
2268
2384
|
var init$1 = initCliContext;
|
|
2269
2385
|
|
|
2270
2386
|
const chalk = require$$0__default$2;
|
|
2271
|
-
const
|
|
2387
|
+
const commander = require$$0__default;
|
|
2272
2388
|
const {
|
|
2273
2389
|
log,
|
|
2274
2390
|
suggestCommands
|
|
@@ -2279,19 +2395,33 @@ const {
|
|
|
2279
2395
|
const commands = entry;
|
|
2280
2396
|
const init = init$1;
|
|
2281
2397
|
init();
|
|
2282
|
-
program.
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2398
|
+
const program = new commander.Command(TMS_NAME);
|
|
2399
|
+
program.version(`${TMS_NAME} ${require$$6.version}`, '-v, -V, --version');
|
|
2400
|
+
|
|
2401
|
+
function registerCommand(program, commands) {
|
|
2402
|
+
commands.forEach(cmd => {
|
|
2403
|
+
if (cmd.type === 'child') {
|
|
2404
|
+
const childProgram = new commander.Command(cmd.name);
|
|
2405
|
+
cmd.usage && childProgram.usage(cmd.usage);
|
|
2406
|
+
cmd.description && childProgram.description(cmd.description);
|
|
2407
|
+
registerCommand(childProgram, cmd.commands);
|
|
2408
|
+
program.addCommand(childProgram);
|
|
2409
|
+
} else {
|
|
2410
|
+
var _cmd$options;
|
|
2411
|
+
|
|
2412
|
+
const command = program.command(cmd.command);
|
|
2413
|
+
cmd.usage && command.usage(cmd.usage);
|
|
2414
|
+
cmd.description && command.description(cmd.description);
|
|
2415
|
+
(_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
|
|
2416
|
+
command.action(cmd.action);
|
|
2417
|
+
}
|
|
2418
|
+
});
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
registerCommand(program, commands);
|
|
2292
2422
|
program.on('--help', () => {
|
|
2293
2423
|
log();
|
|
2294
|
-
log(` Run ${chalk.cyan(
|
|
2424
|
+
log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
2295
2425
|
log();
|
|
2296
2426
|
}); // 捕获未注册的命令
|
|
2297
2427
|
|
|
@@ -2309,6 +2439,6 @@ if (!process.argv.slice(2).length) {
|
|
|
2309
2439
|
}
|
|
2310
2440
|
|
|
2311
2441
|
program.parse(process.argv);
|
|
2312
|
-
var src = src$
|
|
2442
|
+
var src = src$2;
|
|
2313
2443
|
|
|
2314
2444
|
module.exports = src;
|