@tmsfe/tmskit 0.0.5-beta.3 → 0.0.5-beta.4
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 +16 -2
- package/dist/index.cjs.js +802 -339
- package/package.json +11 -4
- package/src/config/constant.js +2 -0
- package/src/config/defaultTmsConfig.js +2 -2
- package/src/gulp/compile.js +33 -14
- package/src/gulp/dev.js +11 -10
- package/src/gulp/plugins/less.js +116 -0
- package/src/gulp/plugins/mpCommonDep.js +131 -0
- package/src/gulp/plugins/mpJsonDep.js +108 -0
- package/src/gulp/plugins/mpWxmlDep.js +194 -0
- package/src/gulp/plugins/postcss-font-base64.js +72 -0
- package/src/gulp/plugins/utils/pluginError.js +25 -0
- package/src/utils/buildAppJson.js +58 -2
- package/src/utils/findCssImport.js +30 -0
- package/src/utils/io.js +43 -3
- package/src/webpack/base.js +65 -0
- package/src/webpack/build.js +21 -0
- package/src/webpack/buildServer.js +34 -0
- package/src/webpack/dev.js +31 -0
- package/src/webpack/devServer.js +37 -0
- package/src/webpack/plugins/entryExtractPlugin/index.js +28 -0
- package/src/webpack/utils.js +244 -0
- package/CHANGELOG.md +0 -0
- package/rollup.config.js +0 -179
- package/src/gulp/jsDep.js +0 -150
- package/src/gulp/mpJsonDep.js +0 -122
package/dist/index.cjs.js
CHANGED
|
@@ -16,14 +16,17 @@ var require$$0$5 = require('lodash');
|
|
|
16
16
|
var require$$0$6 = require('miniprogram-ci');
|
|
17
17
|
var require$$3$1 = require('glob-ignore');
|
|
18
18
|
var require$$0$7 = require('through2');
|
|
19
|
+
var require$$0$8 = require('strip-comments');
|
|
19
20
|
var require$$1$4 = require('precinct');
|
|
20
|
-
var require$$
|
|
21
|
-
var require$$
|
|
22
|
-
var require$$
|
|
23
|
-
var require$$
|
|
24
|
-
var require$$
|
|
21
|
+
var require$$1$5 = require('htmlparser2');
|
|
22
|
+
var require$$0$9 = require('postcss');
|
|
23
|
+
var require$$0$a = require('gulp');
|
|
24
|
+
var require$$1$6 = require('gulp-px-to-rpx');
|
|
25
|
+
var require$$2$1 = require('gulp-postcss');
|
|
26
|
+
var require$$3$2 = require('gulp-watch');
|
|
27
|
+
var require$$4 = require('gulp-cache');
|
|
25
28
|
var require$$5$1 = require('gulp-image');
|
|
26
|
-
var require$$1$
|
|
29
|
+
var require$$1$7 = require('semver');
|
|
27
30
|
|
|
28
31
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
29
32
|
|
|
@@ -43,14 +46,17 @@ var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
|
43
46
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
44
47
|
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
|
|
45
48
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
46
|
-
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
47
49
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
50
|
+
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
48
51
|
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
52
|
+
var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
53
|
+
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
54
|
+
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
49
55
|
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
50
56
|
var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
|
|
51
57
|
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
52
58
|
var require$$5__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
|
|
53
|
-
var require$$1__default$
|
|
59
|
+
var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
|
|
54
60
|
|
|
55
61
|
function getAugmentedNamespace(n) {
|
|
56
62
|
if (n.__esModule) return n;
|
|
@@ -72,8 +78,8 @@ var src$2 = {};
|
|
|
72
78
|
const program$1 = require$$0__default;
|
|
73
79
|
const leven = require$$1__default;
|
|
74
80
|
const ora = require$$2__default;
|
|
75
|
-
const path$
|
|
76
|
-
const fs$
|
|
81
|
+
const path$a = require$$1__default$1;
|
|
82
|
+
const fs$e = require$$0__default$1;
|
|
77
83
|
const shelljs$6 = require$$5__default;
|
|
78
84
|
const download = require$$6__default;
|
|
79
85
|
const chalk$3 = require$$0__default$2;
|
|
@@ -83,8 +89,8 @@ const shelljsOptons = {
|
|
|
83
89
|
|
|
84
90
|
const cwd = process.cwd();
|
|
85
91
|
|
|
86
|
-
function resolve$
|
|
87
|
-
return path$
|
|
92
|
+
function resolve$d(...args) {
|
|
93
|
+
return path$a.resolve(cwd, ...args);
|
|
88
94
|
}
|
|
89
95
|
/**
|
|
90
96
|
* 封装logs
|
|
@@ -153,7 +159,7 @@ function downloadRepo(dest, downloadOptions = {
|
|
|
153
159
|
branch
|
|
154
160
|
} = downloadOptions;
|
|
155
161
|
|
|
156
|
-
if (fs$
|
|
162
|
+
if (fs$e.existsSync(dest)) {
|
|
157
163
|
shelljs$6.rm('-rf', dest);
|
|
158
164
|
}
|
|
159
165
|
|
|
@@ -185,8 +191,8 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
185
191
|
const cwd = process.cwd();
|
|
186
192
|
return new Promise(resolve => {
|
|
187
193
|
// 如果目标目录不存在
|
|
188
|
-
if (fs$
|
|
189
|
-
shelljs$6.rm('-rf', path$
|
|
194
|
+
if (fs$e.existsSync(dest)) {
|
|
195
|
+
shelljs$6.rm('-rf', path$a.join(dest));
|
|
190
196
|
}
|
|
191
197
|
|
|
192
198
|
shelljs$6.mkdir('-p', dest);
|
|
@@ -243,7 +249,7 @@ function createTask$4(task, startText, endText) {
|
|
|
243
249
|
const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
|
|
244
250
|
|
|
245
251
|
var widgets = {
|
|
246
|
-
resolve: resolve$
|
|
252
|
+
resolve: resolve$d,
|
|
247
253
|
log: log$3,
|
|
248
254
|
isObject: isObject$2,
|
|
249
255
|
isArray: isArray$1,
|
|
@@ -254,18 +260,18 @@ var widgets = {
|
|
|
254
260
|
camelize
|
|
255
261
|
};
|
|
256
262
|
|
|
257
|
-
const path$
|
|
263
|
+
const path$9 = require('path'); // 用户目录
|
|
258
264
|
|
|
259
265
|
|
|
260
266
|
const HOME_DIR = process.env.HOME; // 所有文件的缓存目录
|
|
261
267
|
|
|
262
|
-
const CACHE_DIR$1 = path$
|
|
268
|
+
const CACHE_DIR$1 = path$9.resolve(HOME_DIR, '.tmskit'); // 脚手架模板代码所在目录
|
|
263
269
|
|
|
264
|
-
const TEMPLATE_DIR$1 = path$
|
|
270
|
+
const TEMPLATE_DIR$1 = path$9.resolve(CACHE_DIR$1, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
265
271
|
|
|
266
|
-
const MODULE_CODE_DIR$1 = path$
|
|
272
|
+
const MODULE_CODE_DIR$1 = path$9.resolve(CACHE_DIR$1, 'modules_code'); // 脚手架模板代码的具体路径
|
|
267
273
|
|
|
268
|
-
const TEMPLATE_PATH$1 = path$
|
|
274
|
+
const TEMPLATE_PATH$1 = path$9.resolve(TEMPLATE_DIR$1, 'tools/tms-cli-template'); // 脚手架的名称
|
|
269
275
|
|
|
270
276
|
const TMS_NAME$2 = 'tmskit'; // 脚手架的配置名称
|
|
271
277
|
|
|
@@ -276,7 +282,7 @@ const DEFAULT_MODULE_DIR$4 = 'modules'; // 模块的配置文件的名称
|
|
|
276
282
|
const MODULE_CONFIG_FILENAME$2 = 'module.config.json'; // 默认的webpack entry
|
|
277
283
|
|
|
278
284
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
279
|
-
app: path$
|
|
285
|
+
app: path$9.resolve(process.cwd(), 'app')
|
|
280
286
|
}; // 默认从源码拷贝到编译后的配置
|
|
281
287
|
|
|
282
288
|
const DEFAULT_COPY_CONFIG$1 = ['package.json', 'sitemap.json']; // 开发模式
|
|
@@ -291,6 +297,7 @@ const ENV = {
|
|
|
291
297
|
prod: 'production'
|
|
292
298
|
};
|
|
293
299
|
const TEMPLATE_TKIT_DIR$2 = '_tmskit';
|
|
300
|
+
const MODULE_CONFIG_INVALID_KEY$1 = ['entranceDeclare', 'entryPagePath'];
|
|
294
301
|
|
|
295
302
|
var constant = /*#__PURE__*/Object.freeze({
|
|
296
303
|
__proto__: null,
|
|
@@ -307,20 +314,31 @@ var constant = /*#__PURE__*/Object.freeze({
|
|
|
307
314
|
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
308
315
|
MODE: MODE$1,
|
|
309
316
|
ENV: ENV,
|
|
310
|
-
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2
|
|
317
|
+
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
|
|
318
|
+
MODULE_CONFIG_INVALID_KEY: MODULE_CONFIG_INVALID_KEY$1
|
|
311
319
|
});
|
|
312
320
|
|
|
313
321
|
var require$$3 = /*@__PURE__*/getAugmentedNamespace(constant);
|
|
314
322
|
|
|
315
|
-
const fs$
|
|
316
|
-
const path$
|
|
323
|
+
const fs$d = require$$0__default$1;
|
|
324
|
+
const path$8 = require$$1__default$1;
|
|
317
325
|
/**
|
|
318
326
|
* 判断目录是否为空
|
|
319
327
|
* @param {string} dirname 目录名
|
|
320
328
|
* @returns
|
|
321
329
|
*/
|
|
322
330
|
|
|
323
|
-
const isDirEmpty = dirname => fs$
|
|
331
|
+
const isDirEmpty = dirname => fs$d.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
const isFile = pathName => {
|
|
335
|
+
try {
|
|
336
|
+
const stat = fs$d.lstatSync(pathName);
|
|
337
|
+
return stat.isFile();
|
|
338
|
+
} catch {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
324
342
|
/**
|
|
325
343
|
* 确保目录存在,不存在就创建一个
|
|
326
344
|
* @param {*} dirname 目录名
|
|
@@ -328,53 +346,80 @@ const isDirEmpty = dirname => fs$b.promises.readdir(dirname).then(files => files
|
|
|
328
346
|
|
|
329
347
|
|
|
330
348
|
const ensureDirExist = dirname => {
|
|
331
|
-
if (!fs$
|
|
332
|
-
fs$
|
|
349
|
+
if (!fs$d.existsSync(dirname)) {
|
|
350
|
+
fs$d.mkdirSync(dirname, {
|
|
333
351
|
recursive: true
|
|
334
352
|
});
|
|
335
353
|
}
|
|
336
354
|
}; // 复制文件
|
|
337
355
|
|
|
338
356
|
|
|
339
|
-
const copyFile
|
|
340
|
-
if (fs$
|
|
341
|
-
fs$
|
|
357
|
+
const copyFile = function (src, dest) {
|
|
358
|
+
if (fs$d.existsSync(dest)) {
|
|
359
|
+
fs$d.unlinkSync(dest);
|
|
342
360
|
}
|
|
343
361
|
|
|
344
362
|
const dir = dest.substr(0, dest.lastIndexOf('/'));
|
|
345
363
|
ensureDirExist(dir);
|
|
346
|
-
fs$
|
|
347
|
-
}; //
|
|
364
|
+
fs$d.copyFileSync(src, dest);
|
|
365
|
+
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
function diffContentCopyFile$3(originFile, destFile) {
|
|
369
|
+
if (fs$d.existsSync(destFile)) {
|
|
370
|
+
const depDestContent = fs$d.readFileSync(destFile, 'utf8');
|
|
371
|
+
const depOriginContent = fs$d.readFileSync(originFile, 'utf8');
|
|
372
|
+
|
|
373
|
+
if (depDestContent !== depOriginContent) {
|
|
374
|
+
console.log(`拷贝${originFile}内容到${destFile}`);
|
|
375
|
+
copyFile(originFile, destFile);
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
console.log(`拷贝${originFile}内容到${destFile}`);
|
|
379
|
+
copyFile(originFile, destFile);
|
|
380
|
+
}
|
|
381
|
+
} // 添加后缀
|
|
348
382
|
|
|
349
383
|
|
|
350
|
-
function ext$
|
|
384
|
+
function ext$3(filePath, extensions) {
|
|
351
385
|
let newFilePath = filePath;
|
|
386
|
+
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
352
387
|
|
|
353
388
|
try {
|
|
354
|
-
const stat = fs$
|
|
389
|
+
const stat = fs$d.lstatSync(newFilePath);
|
|
355
390
|
|
|
356
391
|
if (stat.isDirectory()) {
|
|
357
|
-
|
|
392
|
+
extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
|
|
393
|
+
newFilePath += extPath;
|
|
358
394
|
}
|
|
359
395
|
} catch (e) {}
|
|
360
396
|
|
|
361
397
|
for (const ext of extensions) {
|
|
362
398
|
const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
|
|
363
399
|
|
|
364
|
-
if (fs$
|
|
400
|
+
if (fs$d.existsSync(file)) {
|
|
365
401
|
return {
|
|
366
|
-
|
|
367
|
-
ext
|
|
402
|
+
ext,
|
|
403
|
+
extPath: extPath + ext,
|
|
404
|
+
file
|
|
368
405
|
};
|
|
369
406
|
}
|
|
370
407
|
}
|
|
371
408
|
|
|
372
|
-
return
|
|
409
|
+
return {
|
|
410
|
+
ext: '',
|
|
411
|
+
extPath,
|
|
412
|
+
file: filePath
|
|
413
|
+
};
|
|
373
414
|
} // 判断文件是否在某个目录
|
|
374
415
|
|
|
375
416
|
|
|
376
|
-
const fileInDir$
|
|
377
|
-
|
|
417
|
+
const fileInDir$3 = (dir, file) => {
|
|
418
|
+
if (!fs$d.existsSync(dir) || !fs$d.existsSync(file)) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const relativePath = path$8.relative(dir, file);
|
|
378
423
|
|
|
379
424
|
if (relativePath.startsWith('..')) {
|
|
380
425
|
return false;
|
|
@@ -385,10 +430,12 @@ const fileInDir$2 = (dir, file) => {
|
|
|
385
430
|
|
|
386
431
|
var io$2 = {
|
|
387
432
|
isDirEmpty,
|
|
388
|
-
copyFile
|
|
433
|
+
copyFile,
|
|
434
|
+
diffContentCopyFile: diffContentCopyFile$3,
|
|
389
435
|
ensureDirExist,
|
|
390
|
-
ext: ext$
|
|
391
|
-
fileInDir: fileInDir$
|
|
436
|
+
ext: ext$3,
|
|
437
|
+
fileInDir: fileInDir$3,
|
|
438
|
+
isFile
|
|
392
439
|
};
|
|
393
440
|
|
|
394
441
|
const chalk$2 = require$$0__default$2;
|
|
@@ -404,7 +451,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
|
|
|
404
451
|
* @returns {undefined} 无
|
|
405
452
|
*/
|
|
406
453
|
|
|
407
|
-
const fail$
|
|
454
|
+
const fail$a = (message = '') => {
|
|
408
455
|
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
409
456
|
|
|
410
457
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
@@ -437,7 +484,7 @@ const warn = message => {
|
|
|
437
484
|
};
|
|
438
485
|
|
|
439
486
|
var log$2 = {
|
|
440
|
-
fail: fail$
|
|
487
|
+
fail: fail$a,
|
|
441
488
|
succeed: succeed$1,
|
|
442
489
|
warn
|
|
443
490
|
};
|
|
@@ -462,10 +509,10 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
462
509
|
|
|
463
510
|
var render_1 = render$1;
|
|
464
511
|
|
|
465
|
-
const fs$
|
|
512
|
+
const fs$c = require$$0__default$1;
|
|
466
513
|
const inquirer = require$$1__default$3;
|
|
467
514
|
const {
|
|
468
|
-
resolve: resolve$
|
|
515
|
+
resolve: resolve$c
|
|
469
516
|
} = widgets;
|
|
470
517
|
const {
|
|
471
518
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
@@ -479,12 +526,12 @@ const {
|
|
|
479
526
|
const parseTemplateQuestions = dir => {
|
|
480
527
|
let prompts = [];
|
|
481
528
|
|
|
482
|
-
if (!fs$
|
|
529
|
+
if (!fs$c.existsSync(`${dir}/questions.json`)) {
|
|
483
530
|
return prompts;
|
|
484
531
|
}
|
|
485
532
|
|
|
486
533
|
try {
|
|
487
|
-
const json = JSON.parse(fs$
|
|
534
|
+
const json = JSON.parse(fs$c.readFileSync(`${dir}/questions.json`));
|
|
488
535
|
|
|
489
536
|
if (Array.isArray(json) && json.length > 0) {
|
|
490
537
|
json.forEach((item, index) => {
|
|
@@ -517,7 +564,7 @@ const isQuestionType = result => {
|
|
|
517
564
|
};
|
|
518
565
|
|
|
519
566
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
520
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
567
|
+
const prompts = parseTemplateQuestions(resolve$c(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
521
568
|
const metadata = metalsmith.metadata();
|
|
522
569
|
const filteredPrompts = prompts.filter(prompt => {
|
|
523
570
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -559,8 +606,8 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
559
606
|
|
|
560
607
|
var generator_1 = generator$1;
|
|
561
608
|
|
|
562
|
-
const path$
|
|
563
|
-
const fs$
|
|
609
|
+
const path$7 = require$$1__default$1;
|
|
610
|
+
const fs$b = require$$0__default$1;
|
|
564
611
|
const shelljs$5 = require$$5__default;
|
|
565
612
|
const {
|
|
566
613
|
TEMPLATE_DIR,
|
|
@@ -570,11 +617,11 @@ const {
|
|
|
570
617
|
const {
|
|
571
618
|
downloadRepoForGit: downloadRepoForGit$1,
|
|
572
619
|
createTask: createTask$3,
|
|
573
|
-
resolve: resolve$
|
|
620
|
+
resolve: resolve$b
|
|
574
621
|
} = widgets;
|
|
575
622
|
const io$1 = io$2;
|
|
576
623
|
const {
|
|
577
|
-
fail: fail$
|
|
624
|
+
fail: fail$9,
|
|
578
625
|
succeed
|
|
579
626
|
} = log$2;
|
|
580
627
|
const generator = generator_1;
|
|
@@ -586,9 +633,9 @@ const generator = generator_1;
|
|
|
586
633
|
|
|
587
634
|
async function createAppDir(targetDir) {
|
|
588
635
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
589
|
-
if (fs$
|
|
636
|
+
if (fs$b.existsSync(targetDir)) {
|
|
590
637
|
if (!(await io$1.isDirEmpty(targetDir))) {
|
|
591
|
-
fail$
|
|
638
|
+
fail$9('该目录名已经存在,换个项目名字吧~');
|
|
592
639
|
process.exit(1);
|
|
593
640
|
}
|
|
594
641
|
} else {
|
|
@@ -604,7 +651,7 @@ async function createAppDir(targetDir) {
|
|
|
604
651
|
|
|
605
652
|
async function create(appName) {
|
|
606
653
|
const cwd = process.cwd();
|
|
607
|
-
const targetDir = path$
|
|
654
|
+
const targetDir = path$7.resolve(cwd, appName);
|
|
608
655
|
const appType = 'mp';
|
|
609
656
|
await createAppDir(targetDir); // 创建缓存目录
|
|
610
657
|
|
|
@@ -612,13 +659,13 @@ async function create(appName) {
|
|
|
612
659
|
|
|
613
660
|
await createTask$3(downloadRepoForGit$1, '拉取模板仓库', '拉取模板仓库完成')('https://git.woa.com/tmsfe/tms-frontend.git', TEMPLATE_DIR, 'master'); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
614
661
|
|
|
615
|
-
generator(path$
|
|
662
|
+
generator(path$7.join(TEMPLATE_PATH, appType), targetDir, {
|
|
616
663
|
appName,
|
|
617
664
|
appType
|
|
618
665
|
}).then(() => {
|
|
619
666
|
shelljs$5.cd(appName);
|
|
620
667
|
|
|
621
|
-
const hooks = require(resolve$
|
|
668
|
+
const hooks = require(resolve$b(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
622
669
|
|
|
623
670
|
if (hooks.afterCreate) {
|
|
624
671
|
hooks.afterCreate.forEach(item => {
|
|
@@ -632,26 +679,27 @@ async function create(appName) {
|
|
|
632
679
|
});
|
|
633
680
|
}
|
|
634
681
|
|
|
635
|
-
shelljs$5.rm('-rf', resolve$
|
|
682
|
+
shelljs$5.rm('-rf', resolve$b(appName, TEMPLATE_TKIT_DIR));
|
|
636
683
|
succeed('项目创建完成.');
|
|
637
684
|
}).catch(err => {
|
|
638
|
-
fail$
|
|
685
|
+
fail$9(err.message);
|
|
639
686
|
console.log('详细的错误信息:', err);
|
|
640
687
|
});
|
|
641
688
|
}
|
|
642
689
|
|
|
643
690
|
var create_1 = create;
|
|
644
691
|
|
|
645
|
-
const fs$
|
|
692
|
+
const fs$a = require$$0__default$1;
|
|
646
693
|
const {
|
|
647
694
|
DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR$3,
|
|
648
|
-
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1
|
|
695
|
+
MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME$1,
|
|
696
|
+
MODULE_CONFIG_INVALID_KEY
|
|
649
697
|
} = require$$3;
|
|
650
698
|
const {
|
|
651
|
-
fail: fail$
|
|
699
|
+
fail: fail$8
|
|
652
700
|
} = log$2;
|
|
653
701
|
const {
|
|
654
|
-
resolve: resolve$
|
|
702
|
+
resolve: resolve$a,
|
|
655
703
|
isObject: isObject$1,
|
|
656
704
|
isArray
|
|
657
705
|
} = widgets;
|
|
@@ -700,10 +748,10 @@ function getLocalModuleConfig(modules = [], appName, moduleDir, moduleConfigFile
|
|
|
700
748
|
modules.forEach(({
|
|
701
749
|
path
|
|
702
750
|
}) => {
|
|
703
|
-
const moduleConfigPath = resolve$
|
|
751
|
+
const moduleConfigPath = resolve$a(path, moduleConfigFilename);
|
|
704
752
|
|
|
705
|
-
if (fs$
|
|
706
|
-
const content = fs$
|
|
753
|
+
if (fs$a.existsSync(moduleConfigPath)) {
|
|
754
|
+
const content = fs$a.readFileSync(moduleConfigPath, 'utf-8');
|
|
707
755
|
modulesConfig[moduleConfigPath] = setModuleConfig$1(content, appName, moduleDir);
|
|
708
756
|
}
|
|
709
757
|
});
|
|
@@ -728,7 +776,7 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
728
776
|
|
|
729
777
|
foundMainPackages.forEach(subpackage => {
|
|
730
778
|
if (!subpackage.pages || !subpackage.pages.length) {
|
|
731
|
-
fail$
|
|
779
|
+
fail$8(`主包 ${subpackage} 不能没有 pages`);
|
|
732
780
|
process.exit(-1);
|
|
733
781
|
}
|
|
734
782
|
|
|
@@ -754,16 +802,16 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
754
802
|
|
|
755
803
|
|
|
756
804
|
const getAppJsonContent = sourceAppJsonPath => {
|
|
757
|
-
if (!fs$
|
|
758
|
-
fail$
|
|
805
|
+
if (!fs$a.existsSync(sourceAppJsonPath)) {
|
|
806
|
+
fail$8(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
|
|
759
807
|
process.exit(1);
|
|
760
808
|
}
|
|
761
809
|
|
|
762
|
-
const appJson = JSON.parse(fs$
|
|
810
|
+
const appJson = JSON.parse(fs$a.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
|
|
763
811
|
|
|
764
812
|
appJson.subpackages = [];
|
|
765
|
-
appJson.pages = [];
|
|
766
|
-
|
|
813
|
+
appJson.pages = []; // appJson.plugins = {};
|
|
814
|
+
|
|
767
815
|
delete appJson.entranceDeclare;
|
|
768
816
|
return appJson;
|
|
769
817
|
};
|
|
@@ -782,6 +830,68 @@ const updateSubpackages = (appJson, modulesConfig) => {
|
|
|
782
830
|
appJson.subpackages = appJson.subpackages.concat(moduleInfo);
|
|
783
831
|
}
|
|
784
832
|
};
|
|
833
|
+
/**
|
|
834
|
+
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
835
|
+
* @param {Object} appJson appjson
|
|
836
|
+
*/
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
const processAppJson = appJson => {
|
|
840
|
+
const {
|
|
841
|
+
subpackages
|
|
842
|
+
} = appJson;
|
|
843
|
+
const pluginsMap = {};
|
|
844
|
+
Object.keys(appJson.plugins || {}).forEach(key => pluginsMap[key] = ['app.json']);
|
|
845
|
+
const subps = subpackages.map(subp => {
|
|
846
|
+
const invalidKeys = [];
|
|
847
|
+
Object.keys(subp).forEach(key => {
|
|
848
|
+
if (key === 'plugins') {
|
|
849
|
+
Object.keys(subp.plugins).forEach(pk => {
|
|
850
|
+
pluginsMap[pk] ? pluginsMap[pk].push(`分包${subp.name}`) : pluginsMap[pk] = [`分包${subp.name}`];
|
|
851
|
+
});
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
if (MODULE_CONFIG_INVALID_KEY.indexOf(key) > -1) {
|
|
856
|
+
// 如果分包配置中有不支持的key,则错误提醒
|
|
857
|
+
invalidKeys.push(key);
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
if (['requiredBackgroundModes', 'embeddedAppIdList'].indexOf(key) > -1) {
|
|
862
|
+
// 提到appjson最上层处理
|
|
863
|
+
const preVal = appJson[key]; // eslint-disable-next-line
|
|
864
|
+
|
|
865
|
+
preVal ? appJson[key] = Array.from(new Set(preVal // eslint-disable-next-line
|
|
866
|
+
.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
if (invalidKeys.length) {
|
|
872
|
+
fail$8(`不支持分包${subp === null || subp === void 0 ? void 0 : subp.name}配置${invalidKeys.join(',')}\n`);
|
|
873
|
+
} // eslint-disable-next-line
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
invalidKeys.concat(['requiredBackgroundModes', 'embeddedAppIdList']).forEach(k => delete subp[k]);
|
|
877
|
+
return subp;
|
|
878
|
+
}); // 如果plugins重复,则错误提示
|
|
879
|
+
|
|
880
|
+
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
881
|
+
if (pluginsMap[pk].length > 1) {
|
|
882
|
+
return `${pluginsMap[pk].join(',')}重复配置plugin(${pk});`;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
return '';
|
|
886
|
+
}).reduce((pre, cur) => pre + cur, '');
|
|
887
|
+
|
|
888
|
+
if (pluginsErrMsg) {
|
|
889
|
+
fail$8(pluginsErrMsg);
|
|
890
|
+
} // eslint-disable-next-line
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
appJson.subpackages = subps;
|
|
894
|
+
};
|
|
785
895
|
/**
|
|
786
896
|
* 动态生成编译后的app.json
|
|
787
897
|
* @param {object} tmsConfig
|
|
@@ -794,12 +904,14 @@ function buildOutputAppJson$1(tmsConfig, modules) {
|
|
|
794
904
|
// 获取当前 modules 下的所有子模块的配置内容
|
|
795
905
|
const modulesConfig = getLocalModuleConfig(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$3, MODULE_CONFIG_FILENAME$1); // 获取app.json的配置
|
|
796
906
|
|
|
797
|
-
const appJson = getAppJsonContent(resolve$
|
|
907
|
+
const appJson = getAppJsonContent(resolve$a('./app.json')); // 更新app.json中的subpackages
|
|
908
|
+
|
|
909
|
+
updateSubpackages(appJson, modulesConfig); // 处理appJson中重复||冲突的地方
|
|
798
910
|
|
|
799
|
-
|
|
911
|
+
processAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
800
912
|
|
|
801
913
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
802
|
-
fs$
|
|
914
|
+
fs$a.writeFileSync(resolve$a(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
803
915
|
return appJson;
|
|
804
916
|
}
|
|
805
917
|
|
|
@@ -849,12 +961,12 @@ const {
|
|
|
849
961
|
} = global;
|
|
850
962
|
const {
|
|
851
963
|
downloadRepoForGit,
|
|
852
|
-
resolve: resolve$
|
|
964
|
+
resolve: resolve$9
|
|
853
965
|
} = widgets;
|
|
854
966
|
const {
|
|
855
|
-
fail: fail$
|
|
967
|
+
fail: fail$7
|
|
856
968
|
} = log$2;
|
|
857
|
-
const fs$
|
|
969
|
+
const fs$9 = require$$0__default$1;
|
|
858
970
|
const shelljs$4 = require$$5__default;
|
|
859
971
|
/**
|
|
860
972
|
* 对克隆下来的模块进行相应的文件处理操作,比如收集处理模块信息,进行信息缓存等操作
|
|
@@ -869,7 +981,7 @@ function moveFile(sourceDir, targetDir, ignore = []) {
|
|
|
869
981
|
return new Promise(resolve => {
|
|
870
982
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
871
983
|
if (e) {
|
|
872
|
-
fail$
|
|
984
|
+
fail$7(e); // eslint-disable-line
|
|
873
985
|
|
|
874
986
|
console.log('MetalSmith 详细的错误信息:', e);
|
|
875
987
|
}
|
|
@@ -912,9 +1024,9 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
|
|
|
912
1024
|
path
|
|
913
1025
|
} = moduleInfo; // 源码临时存在的源目录
|
|
914
1026
|
|
|
915
|
-
let sourcePath = resolve$
|
|
1027
|
+
let sourcePath = resolve$9(sourceDir, path); // 源码要放到目标目录
|
|
916
1028
|
|
|
917
|
-
const targetPath = resolve$
|
|
1029
|
+
const targetPath = resolve$9(targetDir, path); // 设置模块的构建分支
|
|
918
1030
|
|
|
919
1031
|
const cloneBranch = buildGitTag && typeof buildGitTag === 'string' ? buildGitTag : 'master'; // 检查缓存中有没有
|
|
920
1032
|
|
|
@@ -929,13 +1041,13 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
|
|
|
929
1041
|
sourcePath = globalInstance.getModuleCache(httpRepoUrl, cloneBranch).dest;
|
|
930
1042
|
}
|
|
931
1043
|
|
|
932
|
-
if (fs$
|
|
1044
|
+
if (fs$9.existsSync(targetPath)) {
|
|
933
1045
|
shelljs$4.rm('-rf', targetPath);
|
|
934
1046
|
}
|
|
935
1047
|
|
|
936
1048
|
await moveFile(sourcePath, targetPath, ['node_modules', '.git']);
|
|
937
1049
|
} catch (e) {
|
|
938
|
-
fail$
|
|
1050
|
+
fail$7(`downLoadAndMoveModule ${e}`); // eslint-disable-line
|
|
939
1051
|
|
|
940
1052
|
process.exit(-1);
|
|
941
1053
|
}
|
|
@@ -961,20 +1073,20 @@ var defaultTmsConfig$1 = {
|
|
|
961
1073
|
/** 源码监听路径 */
|
|
962
1074
|
sourceDir: './',
|
|
963
1075
|
|
|
964
|
-
/**
|
|
965
|
-
|
|
1076
|
+
/** 静态资源目录 */
|
|
1077
|
+
static: []
|
|
966
1078
|
}
|
|
967
1079
|
};
|
|
968
1080
|
|
|
969
1081
|
const loadash = require$$0__default$5;
|
|
970
|
-
const fs$
|
|
1082
|
+
const fs$8 = require$$0__default$1;
|
|
971
1083
|
const {
|
|
972
1084
|
TMS_NAME: TMS_NAME$1,
|
|
973
1085
|
TMS_CONFIG_FILENAME,
|
|
974
1086
|
MODULE_CONFIG_FILENAME
|
|
975
1087
|
} = require$$3;
|
|
976
1088
|
const {
|
|
977
|
-
resolve: resolve$
|
|
1089
|
+
resolve: resolve$8,
|
|
978
1090
|
isObject
|
|
979
1091
|
} = widgets;
|
|
980
1092
|
const {
|
|
@@ -982,7 +1094,7 @@ const {
|
|
|
982
1094
|
} = buildAppJson;
|
|
983
1095
|
const defaultTmsConfig = defaultTmsConfig$1;
|
|
984
1096
|
const {
|
|
985
|
-
fail: fail$
|
|
1097
|
+
fail: fail$6
|
|
986
1098
|
} = log$2;
|
|
987
1099
|
/**
|
|
988
1100
|
* 读取tms.config.json
|
|
@@ -990,10 +1102,10 @@ const {
|
|
|
990
1102
|
*/
|
|
991
1103
|
|
|
992
1104
|
const readTmsConfig$1 = function (env) {
|
|
993
|
-
const tmsConfigPath = resolve$
|
|
1105
|
+
const tmsConfigPath = resolve$8(TMS_CONFIG_FILENAME);
|
|
994
1106
|
|
|
995
|
-
if (!fs$
|
|
996
|
-
fail$
|
|
1107
|
+
if (!fs$8.existsSync(tmsConfigPath)) {
|
|
1108
|
+
fail$6('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
997
1109
|
process.exit(1);
|
|
998
1110
|
}
|
|
999
1111
|
|
|
@@ -1022,7 +1134,7 @@ const checkModules$1 = function (tmsConfig, modules) {
|
|
|
1022
1134
|
});
|
|
1023
1135
|
|
|
1024
1136
|
if (targetModules.length === 0) {
|
|
1025
|
-
fail$
|
|
1137
|
+
fail$6(`你启动的模块无效,尝试 ${TMS_NAME$1} -m moduleName`);
|
|
1026
1138
|
process.exit(1);
|
|
1027
1139
|
}
|
|
1028
1140
|
|
|
@@ -1043,10 +1155,10 @@ const tmsModulesMergeLocalModuleCfg$3 = (modules, appName, moduleDir) => {
|
|
|
1043
1155
|
path: relativePath,
|
|
1044
1156
|
name: moduleName
|
|
1045
1157
|
}, moduleIndex) => {
|
|
1046
|
-
const moduleConfigPath = resolve$
|
|
1158
|
+
const moduleConfigPath = resolve$8(relativePath, MODULE_CONFIG_FILENAME);
|
|
1047
1159
|
|
|
1048
|
-
if (fs$
|
|
1049
|
-
let moduleConfigContent = fs$
|
|
1160
|
+
if (fs$8.existsSync(moduleConfigPath)) {
|
|
1161
|
+
let moduleConfigContent = fs$8.readFileSync(moduleConfigPath, 'utf-8');
|
|
1050
1162
|
moduleConfigContent = setModuleConfig(moduleConfigContent, appName, moduleDir);
|
|
1051
1163
|
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
1052
1164
|
moduleContentArr.forEach(({
|
|
@@ -1074,7 +1186,7 @@ var tkitUtils = {
|
|
|
1074
1186
|
|
|
1075
1187
|
/* eslint-disable require-jsdoc */
|
|
1076
1188
|
const ci = require$$0__default$6;
|
|
1077
|
-
const path$
|
|
1189
|
+
const path$6 = require$$1__default$1;
|
|
1078
1190
|
/**
|
|
1079
1191
|
* 获取小程序ci的Project对象
|
|
1080
1192
|
* @returns {Object} 小程序ci对象
|
|
@@ -1088,7 +1200,7 @@ const getMpCi = ({
|
|
|
1088
1200
|
}) => {
|
|
1089
1201
|
var _cfgJsonContent$packO;
|
|
1090
1202
|
|
|
1091
|
-
const cfgJsonContent = require(path$
|
|
1203
|
+
const cfgJsonContent = require(path$6.join(projectPath, 'project.config.json'));
|
|
1092
1204
|
|
|
1093
1205
|
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
1206
|
value
|
|
@@ -1157,8 +1269,8 @@ var mpCiUtils = {
|
|
|
1157
1269
|
/**
|
|
1158
1270
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1159
1271
|
*/
|
|
1160
|
-
const fs$
|
|
1161
|
-
const path$
|
|
1272
|
+
const fs$7 = require$$0__default$1;
|
|
1273
|
+
const path$5 = require$$1__default$1;
|
|
1162
1274
|
const shell = require$$5__default;
|
|
1163
1275
|
const glob = require$$3__default;
|
|
1164
1276
|
const LOG = log$2;
|
|
@@ -1168,14 +1280,14 @@ const getTarNpmFilename = targetDir => `${targetDir.replace(/\//g, '-')}.tar.gz`
|
|
|
1168
1280
|
|
|
1169
1281
|
|
|
1170
1282
|
const npmCache = function (targetDir, cacheDir) {
|
|
1171
|
-
if (!fs$
|
|
1172
|
-
fs$
|
|
1283
|
+
if (!fs$7.existsSync(cacheDir)) {
|
|
1284
|
+
fs$7.mkdirSync(cacheDir);
|
|
1173
1285
|
}
|
|
1174
1286
|
|
|
1175
1287
|
const tarNpmFilename = getTarNpmFilename(targetDir);
|
|
1176
1288
|
const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
|
|
1177
1289
|
|
|
1178
|
-
if (fs$
|
|
1290
|
+
if (fs$7.existsSync(tarNpmFilePath)) {
|
|
1179
1291
|
shell.rm('-rf', tarNpmFilePath);
|
|
1180
1292
|
}
|
|
1181
1293
|
|
|
@@ -1191,7 +1303,7 @@ const getNpmCache = function (targetDir, cacheDir) {
|
|
|
1191
1303
|
const tarNpmFilename = getTarNpmFilename(targetDir);
|
|
1192
1304
|
const tarNpmFilePath = `${cacheDir}/${tarNpmFilename}`;
|
|
1193
1305
|
|
|
1194
|
-
if (fs$
|
|
1306
|
+
if (fs$7.existsSync(tarNpmFilePath)) {
|
|
1195
1307
|
const cmd = `tar -zxvf ${tarNpmFilePath} -C ./`;
|
|
1196
1308
|
shell.exec(cmd, {
|
|
1197
1309
|
async: false,
|
|
@@ -1205,10 +1317,10 @@ const getNpmCache = function (targetDir, cacheDir) {
|
|
|
1205
1317
|
const mpNpmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
1206
1318
|
const packageJsonFiles = await findAllPackageJson(modules, contextDir);
|
|
1207
1319
|
await Promise.all(packageJsonFiles.map(file => new Promise(resolve => {
|
|
1208
|
-
const dir = path$
|
|
1320
|
+
const dir = path$5.dirname(file);
|
|
1209
1321
|
shell.cd(dir);
|
|
1210
1322
|
|
|
1211
|
-
if (!fs$
|
|
1323
|
+
if (!fs$7.existsSync(`${dir}/node_modules`)) {
|
|
1212
1324
|
getNpmCache(dir, cacheDir);
|
|
1213
1325
|
}
|
|
1214
1326
|
|
|
@@ -1238,7 +1350,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1238
1350
|
|
|
1239
1351
|
const find = (startPath, filter) => {
|
|
1240
1352
|
// 目录不存在
|
|
1241
|
-
if (!fs$
|
|
1353
|
+
if (!fs$7.existsSync(startPath)) {
|
|
1242
1354
|
LOG.fail(`${startPath}目录不存在`);
|
|
1243
1355
|
process.exit(-1);
|
|
1244
1356
|
return;
|
|
@@ -1251,10 +1363,10 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1251
1363
|
return;
|
|
1252
1364
|
}
|
|
1253
1365
|
|
|
1254
|
-
const files = fs$
|
|
1366
|
+
const files = fs$7.readdirSync(startPath);
|
|
1255
1367
|
files.forEach(file => {
|
|
1256
|
-
const filename = path$
|
|
1257
|
-
const stat = fs$
|
|
1368
|
+
const filename = path$5.join(startPath, file);
|
|
1369
|
+
const stat = fs$7.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1258
1370
|
|
|
1259
1371
|
if (stat.isDirectory()) {
|
|
1260
1372
|
find(filename, filter);
|
|
@@ -1280,7 +1392,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1280
1392
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1281
1393
|
|
|
1282
1394
|
const cwd = contextDir || dirpath;
|
|
1283
|
-
const result = [path$
|
|
1395
|
+
const result = [path$5.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1284
1396
|
|
|
1285
1397
|
subRoots.forEach(subRoot => {
|
|
1286
1398
|
if (!subRoot.root) {
|
|
@@ -1288,7 +1400,7 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1288
1400
|
process.exit(1);
|
|
1289
1401
|
}
|
|
1290
1402
|
|
|
1291
|
-
const toppath = path$
|
|
1403
|
+
const toppath = path$5.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1292
1404
|
|
|
1293
1405
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1294
1406
|
result.push(...list);
|
|
@@ -1304,7 +1416,7 @@ function cloudNpmInstall$1(contextDir) {
|
|
|
1304
1416
|
}
|
|
1305
1417
|
|
|
1306
1418
|
files.forEach(file => {
|
|
1307
|
-
const dir = path$
|
|
1419
|
+
const dir = path$5.dirname(file);
|
|
1308
1420
|
shell.cd(dir);
|
|
1309
1421
|
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1310
1422
|
silent: false
|
|
@@ -1323,7 +1435,7 @@ var npmUtils = {
|
|
|
1323
1435
|
|
|
1324
1436
|
const {
|
|
1325
1437
|
createTask: createTask$2,
|
|
1326
|
-
resolve: resolve$
|
|
1438
|
+
resolve: resolve$7
|
|
1327
1439
|
} = widgets;
|
|
1328
1440
|
const {
|
|
1329
1441
|
buildMpNpm
|
|
@@ -1343,24 +1455,24 @@ const {
|
|
|
1343
1455
|
async function install$2(tmsConfig, modules, isCloud = true) {
|
|
1344
1456
|
const newModules = tmsModulesMergeLocalModuleCfg$2(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$2); // 小程序npm install
|
|
1345
1457
|
|
|
1346
|
-
await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$
|
|
1458
|
+
await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$7(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
|
|
1347
1459
|
|
|
1348
1460
|
await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
|
|
1349
1461
|
appId: tmsConfig.appId,
|
|
1350
|
-
projectPath: resolve$
|
|
1462
|
+
projectPath: resolve$7('./'),
|
|
1351
1463
|
privateKey: tmsConfig.privateKey
|
|
1352
1464
|
}); // 安装云函数的
|
|
1353
1465
|
|
|
1354
|
-
isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$
|
|
1466
|
+
isCloud && createTask$2(cloudNpmInstall, '云函数npm install', '云函数npm install安装完毕')(resolve$7(tmsConfig.cloudDir));
|
|
1355
1467
|
}
|
|
1356
1468
|
|
|
1357
1469
|
var install_1 = install$2;
|
|
1358
1470
|
|
|
1359
1471
|
const shelljs$3 = require$$5__default;
|
|
1360
|
-
const fs$
|
|
1472
|
+
const fs$6 = require$$0__default$1;
|
|
1361
1473
|
const io = io$2;
|
|
1362
1474
|
const {
|
|
1363
|
-
resolve: resolve$
|
|
1475
|
+
resolve: resolve$6,
|
|
1364
1476
|
createTask: createTask$1
|
|
1365
1477
|
} = widgets;
|
|
1366
1478
|
const {
|
|
@@ -1378,7 +1490,7 @@ const {
|
|
|
1378
1490
|
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$1
|
|
1379
1491
|
} = tkitUtils;
|
|
1380
1492
|
const {
|
|
1381
|
-
fail: fail$
|
|
1493
|
+
fail: fail$5
|
|
1382
1494
|
} = log$2;
|
|
1383
1495
|
const install$1 = install_1;
|
|
1384
1496
|
/**
|
|
@@ -1390,31 +1502,31 @@ const install$1 = install_1;
|
|
|
1390
1502
|
*/
|
|
1391
1503
|
|
|
1392
1504
|
const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
1393
|
-
const outputDir = resolve$
|
|
1505
|
+
const outputDir = resolve$6(tmsConfig.gulp.outputDir);
|
|
1394
1506
|
io.ensureDirExist(outputDir);
|
|
1395
1507
|
defaultFiles.forEach(item => {
|
|
1396
|
-
if (fs$
|
|
1397
|
-
shelljs$3.cp('-rf', resolve$
|
|
1508
|
+
if (fs$6.existsSync(resolve$6(item))) {
|
|
1509
|
+
shelljs$3.cp('-rf', resolve$6(item), resolve$6(tmsConfig.gulp.outputDir, item));
|
|
1398
1510
|
}
|
|
1399
1511
|
}); // 拷贝模块的package.json到编译输出目录
|
|
1400
1512
|
|
|
1401
1513
|
targetModules.forEach(item => {
|
|
1402
|
-
const outputModuleDir = resolve$
|
|
1514
|
+
const outputModuleDir = resolve$6(`${tmsConfig.gulp.outputDir}/${item.root}`);
|
|
1403
1515
|
|
|
1404
|
-
if (!fs$
|
|
1405
|
-
fail$
|
|
1516
|
+
if (!fs$6.existsSync(resolve$6(item.path))) {
|
|
1517
|
+
fail$5(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
1406
1518
|
process.exit(1);
|
|
1407
1519
|
}
|
|
1408
1520
|
|
|
1409
1521
|
io.ensureDirExist(outputModuleDir);
|
|
1410
|
-
const modulePackagePath = resolve$
|
|
1411
|
-
if (fs$
|
|
1522
|
+
const modulePackagePath = resolve$6(item.path, 'package.json');
|
|
1523
|
+
if (fs$6.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
1412
1524
|
});
|
|
1413
1525
|
};
|
|
1414
1526
|
|
|
1415
1527
|
async function task(tmsConfig, targetModules) {
|
|
1416
1528
|
// 下载和移动代码
|
|
1417
|
-
await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$
|
|
1529
|
+
await createTask$1(cloneModules, '开始下载模块代码完成', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$6('./'), targetModules); // tms.config.js的modules 合并 module.config.json的配置项
|
|
1418
1530
|
|
|
1419
1531
|
const newModules = tmsModulesMergeLocalModuleCfg$1(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR$1);
|
|
1420
1532
|
console.log('当前init的有效模块', newModules.map(item => item.name)); // 拷贝相关配置文件到输出目录
|
|
@@ -1438,10 +1550,10 @@ var init$5 = bootstrap;
|
|
|
1438
1550
|
|
|
1439
1551
|
var dev$3 = {exports: {}};
|
|
1440
1552
|
|
|
1441
|
-
const through$
|
|
1553
|
+
const through$3 = require$$0__default$7;
|
|
1442
1554
|
|
|
1443
1555
|
function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
|
|
1444
|
-
const stream = through$
|
|
1556
|
+
const stream = through$3.obj(function (file, enc, cb) {
|
|
1445
1557
|
if (file.isBuffer()) {
|
|
1446
1558
|
let contents = String(file.contents);
|
|
1447
1559
|
let resReg; // eslint-disable-next-line
|
|
@@ -1469,54 +1581,121 @@ function replaceEnv$1(reg = /process\.env(\.(\w*))?/g, envData) {
|
|
|
1469
1581
|
|
|
1470
1582
|
var replaceEnv_1 = replaceEnv$1;
|
|
1471
1583
|
|
|
1472
|
-
|
|
1584
|
+
/* eslint-disable no-param-reassign */
|
|
1585
|
+
const strip = require$$0__default$8; // 匹配规则
|
|
1586
|
+
|
|
1587
|
+
const MATCH_RULE = new RegExp(/@import *(?:url\(['"]?([^'")]+)['"]?\)|['"]([^'"]+)['"]);?/g);
|
|
1588
|
+
/**
|
|
1589
|
+
* 获取样式文件中的@import语句
|
|
1590
|
+
* @param code 代码片段
|
|
1591
|
+
* @returns 结果数组
|
|
1592
|
+
*/
|
|
1593
|
+
|
|
1594
|
+
const findCssImports$1 = code => {
|
|
1595
|
+
// 将buffer转成字符串
|
|
1596
|
+
code = code.toString(); // 去除注释
|
|
1597
|
+
|
|
1598
|
+
code = strip.block(code); // 定义最后返回的结果
|
|
1599
|
+
|
|
1600
|
+
const result = [];
|
|
1601
|
+
let matchList; // 循环遍历代码段,直至匹配结果为空
|
|
1602
|
+
|
|
1603
|
+
while (matchList = MATCH_RULE.exec(code)) {
|
|
1604
|
+
var _matchList, _matchList2;
|
|
1605
|
+
|
|
1606
|
+
// 存入结果数组
|
|
1607
|
+
result.push(((_matchList = matchList) === null || _matchList === void 0 ? void 0 : _matchList[1]) || ((_matchList2 = matchList) === null || _matchList2 === void 0 ? void 0 : _matchList2[2]));
|
|
1608
|
+
} // 返回结果
|
|
1609
|
+
|
|
1610
|
+
|
|
1611
|
+
return result;
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
var findCssImport = {
|
|
1615
|
+
findCssImports: findCssImports$1
|
|
1616
|
+
};
|
|
1617
|
+
|
|
1618
|
+
/* eslint-disable no-param-reassign */
|
|
1619
|
+
const {
|
|
1620
|
+
fail: fail$4
|
|
1621
|
+
} = log$2;
|
|
1622
|
+
|
|
1623
|
+
function pluginError$3(error, isWatch) {
|
|
1624
|
+
const errMsg = error.message;
|
|
1625
|
+
|
|
1626
|
+
if (isWatch) {
|
|
1627
|
+
fail$4(errMsg);
|
|
1628
|
+
} else {
|
|
1629
|
+
fail$4(errMsg);
|
|
1630
|
+
process.exit(1);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
var pluginError_1 = {
|
|
1635
|
+
pluginError: pluginError$3
|
|
1636
|
+
};
|
|
1637
|
+
|
|
1638
|
+
/* eslint-disable no-param-reassign */
|
|
1639
|
+
const through$2 = require$$0__default$7;
|
|
1473
1640
|
const precinct = require$$1__default$4;
|
|
1474
|
-
const path$
|
|
1641
|
+
const path$4 = require$$1__default$1;
|
|
1475
1642
|
const {
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1643
|
+
findCssImports
|
|
1644
|
+
} = findCssImport;
|
|
1645
|
+
const {
|
|
1646
|
+
ext: ext$2,
|
|
1647
|
+
fileInDir: fileInDir$2,
|
|
1648
|
+
diffContentCopyFile: diffContentCopyFile$2
|
|
1479
1649
|
} = io$2;
|
|
1480
1650
|
const {
|
|
1481
|
-
resolve: resolve$
|
|
1651
|
+
resolve: resolve$5
|
|
1482
1652
|
} = widgets;
|
|
1483
|
-
const fs$
|
|
1653
|
+
const fs$5 = require$$0__default$1;
|
|
1484
1654
|
const {
|
|
1485
|
-
|
|
1486
|
-
} =
|
|
1655
|
+
pluginError: pluginError$2
|
|
1656
|
+
} = pluginError_1;
|
|
1657
|
+
const cssFilter = ['.less', '.wxss'];
|
|
1487
1658
|
|
|
1488
|
-
const
|
|
1659
|
+
const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensions, isWatch = true) {
|
|
1489
1660
|
const resDep = new Map();
|
|
1490
1661
|
|
|
1491
1662
|
function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
|
|
1492
|
-
|
|
1493
|
-
|
|
1663
|
+
let contents = '';
|
|
1664
|
+
|
|
1665
|
+
try {
|
|
1666
|
+
contents = fs$5.readFileSync(anaFileOriginFile, 'utf8');
|
|
1667
|
+
} catch (e) {
|
|
1668
|
+
pluginError$2(e, isWatch);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
const deps = cssFilter.indexOf(path$4.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
1494
1672
|
deps.forEach(depItem => {
|
|
1495
1673
|
if (depItem.startsWith('.')) {
|
|
1496
1674
|
// 被依赖文件的存在的绝对路径
|
|
1497
|
-
const depOriginPath = path$
|
|
1675
|
+
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
1498
1676
|
|
|
1499
|
-
const
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
}
|
|
1677
|
+
const {
|
|
1678
|
+
ext: extAlias,
|
|
1679
|
+
file: depOriginFile,
|
|
1680
|
+
extPath
|
|
1681
|
+
} = ext$2(depOriginPath, extensions);
|
|
1504
1682
|
|
|
1683
|
+
if (!fs$5.existsSync(depOriginFile)) {
|
|
1684
|
+
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1505
1687
|
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
const depDestPath = resolve$4(path$2.dirname(anaFileDestFile), depItem);
|
|
1509
|
-
const depDestFile = depDestPath.endsWith(depOriginPathExt.ext) ? depDestPath : depDestPath + depOriginPathExt.ext;
|
|
1688
|
+
const depDestPath = resolve$5(path$4.dirname(anaFileDestFile), depItem);
|
|
1689
|
+
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
1510
1690
|
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
}
|
|
1691
|
+
if (!resDep.has(depDestFile)) {
|
|
1692
|
+
resDep.set(depDestFile, {
|
|
1693
|
+
anaFileOriginFile,
|
|
1694
|
+
anaFileDestFile,
|
|
1695
|
+
depDestFile,
|
|
1696
|
+
depOriginFile
|
|
1697
|
+
});
|
|
1698
|
+
dfs(depOriginFile, depDestFile, extensions);
|
|
1520
1699
|
}
|
|
1521
1700
|
}
|
|
1522
1701
|
});
|
|
@@ -1526,94 +1705,70 @@ const dfsFindJsDep$1 = function (anaFileOriginFile, anaFileDestFile, extensions)
|
|
|
1526
1705
|
return resDep;
|
|
1527
1706
|
};
|
|
1528
1707
|
|
|
1529
|
-
function
|
|
1530
|
-
|
|
1531
|
-
const depDestContent = fs$3.readFileSync(depDestFile, 'utf8');
|
|
1532
|
-
const depOriginContent = fs$3.readFileSync(depOriginFile, 'utf8');
|
|
1533
|
-
|
|
1534
|
-
if (depDestContent !== depOriginContent) {
|
|
1535
|
-
console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
|
|
1536
|
-
copyFile$1(depOriginFile, depDestFile);
|
|
1537
|
-
}
|
|
1538
|
-
} else {
|
|
1539
|
-
console.log(`拷贝${depOriginFile}内容到${depDestFile}`);
|
|
1540
|
-
copyFile$1(depOriginFile, depDestFile);
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
function jsDep$1(tmsConfig, module, extensions = ['.js', '.ts', '.wxs']) {
|
|
1545
|
-
const stream = through$1.obj(function (file, enc, cb) {
|
|
1708
|
+
function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
1709
|
+
const stream = through$2.obj(function (file, enc, cb) {
|
|
1546
1710
|
// 依赖分析的文件
|
|
1547
1711
|
const anaFileOriginFile = file.history[0];
|
|
1548
|
-
const anaFileRelativeModule = path$
|
|
1549
|
-
const anaFileDestFile = resolve$
|
|
1712
|
+
const anaFileRelativeModule = path$4.relative(resolve$5(module.from), anaFileOriginFile);
|
|
1713
|
+
const anaFileDestFile = resolve$5(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
|
|
1550
1714
|
|
|
1551
1715
|
if (file.isBuffer()) {
|
|
1552
1716
|
let contents = String(file.contents);
|
|
1553
|
-
const deps = precinct(contents);
|
|
1717
|
+
const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
1554
1718
|
const copyModules = new Map();
|
|
1555
1719
|
Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
|
|
1556
1720
|
const includePath = tmsConfig.gulp.dependencies[includeName];
|
|
1557
1721
|
deps.forEach(depItem => {
|
|
1558
1722
|
if (depItem.indexOf(includeName) > -1) {
|
|
1559
1723
|
// 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
|
|
1560
|
-
const depOriginPath = path$
|
|
1561
|
-
|
|
1562
|
-
const
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
const
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
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
|
-
}
|
|
1724
|
+
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
1725
|
+
|
|
1726
|
+
const {
|
|
1727
|
+
ext: extAlias,
|
|
1728
|
+
file: depOriginFile,
|
|
1729
|
+
extPath
|
|
1730
|
+
} = ext$2(depOriginPath, extensions);
|
|
1731
|
+
|
|
1732
|
+
if (!fileInDir$2(includePath, depOriginFile)) {
|
|
1733
|
+
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
1734
|
+
return;
|
|
1735
|
+
} // eslint-disable-next-line
|
|
1736
|
+
|
|
1737
|
+
|
|
1738
|
+
const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
1739
|
+
const regRes = depItem.match(reg) || [];
|
|
1740
|
+
|
|
1741
|
+
if (regRes[2]) {
|
|
1742
|
+
const depDestPath = resolve$5(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
|
|
1743
|
+
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
1744
|
+
|
|
1745
|
+
if (!copyModules.has(depDestFile)) {
|
|
1746
|
+
copyModules.set(depDestFile, {
|
|
1747
|
+
depOriginFile,
|
|
1748
|
+
depDestFile,
|
|
1749
|
+
beforeDepPath: depItem,
|
|
1750
|
+
afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath)
|
|
1751
|
+
});
|
|
1598
1752
|
}
|
|
1599
1753
|
}
|
|
1600
1754
|
}
|
|
1601
1755
|
});
|
|
1602
|
-
});
|
|
1756
|
+
}); // console.log('mpCommonDep copyModules', copyModules);
|
|
1757
|
+
|
|
1603
1758
|
copyModules.forEach(({
|
|
1604
1759
|
depOriginFile,
|
|
1605
1760
|
depDestFile,
|
|
1606
1761
|
beforeDepPath,
|
|
1607
1762
|
afterDepPath
|
|
1608
1763
|
}) => {
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1764
|
+
diffContentCopyFile$2(depOriginFile, depDestFile);
|
|
1765
|
+
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
1766
|
+
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
1767
|
+
const defs = dfsFindCommonDep$2(depOriginFile, depDestFile, extensions, isWatch);
|
|
1612
1768
|
defs.forEach(item => {
|
|
1613
|
-
|
|
1614
|
-
});
|
|
1615
|
-
});
|
|
1616
|
-
|
|
1769
|
+
diffContentCopyFile$2(item.depOriginFile, item.depDestFile);
|
|
1770
|
+
}); // console.log('mpCommonDep defs', defs);
|
|
1771
|
+
});
|
|
1617
1772
|
file.contents = new Buffer(contents);
|
|
1618
1773
|
}
|
|
1619
1774
|
|
|
@@ -1623,50 +1778,36 @@ function jsDep$1(tmsConfig, module, extensions = ['.js', '.ts', '.wxs']) {
|
|
|
1623
1778
|
return stream;
|
|
1624
1779
|
}
|
|
1625
1780
|
|
|
1626
|
-
var
|
|
1627
|
-
|
|
1628
|
-
|
|
1781
|
+
var mpCommonDep_1 = {
|
|
1782
|
+
mpCommonDep: mpCommonDep$1,
|
|
1783
|
+
dfsFindCommonDep: dfsFindCommonDep$2
|
|
1629
1784
|
};
|
|
1630
1785
|
|
|
1631
|
-
|
|
1632
|
-
const
|
|
1786
|
+
/* eslint-disable no-param-reassign */
|
|
1787
|
+
const through$1 = require$$0__default$7;
|
|
1788
|
+
const path$3 = require$$1__default$1;
|
|
1633
1789
|
const {
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1790
|
+
ext: ext$1,
|
|
1791
|
+
fileInDir: fileInDir$1,
|
|
1792
|
+
diffContentCopyFile: diffContentCopyFile$1
|
|
1637
1793
|
} = io$2;
|
|
1638
1794
|
const {
|
|
1639
|
-
resolve: resolve$
|
|
1795
|
+
resolve: resolve$4
|
|
1640
1796
|
} = widgets;
|
|
1641
|
-
const fs$
|
|
1797
|
+
const fs$4 = require$$0__default$1;
|
|
1642
1798
|
const {
|
|
1643
|
-
|
|
1644
|
-
} =
|
|
1799
|
+
pluginError: pluginError$1
|
|
1800
|
+
} = pluginError_1;
|
|
1645
1801
|
const {
|
|
1646
|
-
|
|
1647
|
-
} =
|
|
1802
|
+
dfsFindCommonDep: dfsFindCommonDep$1
|
|
1803
|
+
} = mpCommonDep_1;
|
|
1648
1804
|
|
|
1649
|
-
function
|
|
1650
|
-
|
|
1651
|
-
const depDestContent = fs$2.readFileSync(depDestFile, 'utf8');
|
|
1652
|
-
const depOriginContent = fs$2.readFileSync(depOriginFile, 'utf8');
|
|
1653
|
-
|
|
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
|
-
}
|
|
1663
|
-
|
|
1664
|
-
function mpJsonDep$1(tmsConfig, module, extensions = ['.wxml'], filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less']) {
|
|
1665
|
-
const stream = through.obj(function (file, enc, cb) {
|
|
1805
|
+
function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch) {
|
|
1806
|
+
const stream = through$1.obj(function (file, enc, cb) {
|
|
1666
1807
|
// 当前分析的文件的路径
|
|
1667
1808
|
const anaFileOriginFile = file.history[0];
|
|
1668
|
-
const anaFileRelativeModule = path$
|
|
1669
|
-
const anaFileDestFile = resolve$
|
|
1809
|
+
const anaFileRelativeModule = path$3.relative(resolve$4(module.from), anaFileOriginFile);
|
|
1810
|
+
const anaFileDestFile = resolve$4(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
|
|
1670
1811
|
|
|
1671
1812
|
if (file.isBuffer()) {
|
|
1672
1813
|
const copyModules = new Map();
|
|
@@ -1682,38 +1823,36 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.wxml'], filesExt = ['.wx
|
|
|
1682
1823
|
const componentPath = contents.usingComponents[componentKey];
|
|
1683
1824
|
|
|
1684
1825
|
if (componentPath.indexOf(includeName) > -1) {
|
|
1685
|
-
const depOriginPath = path$
|
|
1686
|
-
|
|
1687
|
-
const depOriginPathExt = ext(depOriginPath, extensions);
|
|
1688
|
-
|
|
1689
|
-
if (!depOriginPathExt) {
|
|
1690
|
-
fail$2(`${anaFileOriginFile}的${componentPath}引用路径存找不到文件,请检查引用路径`);
|
|
1691
|
-
}
|
|
1826
|
+
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
|
|
1692
1827
|
|
|
1693
|
-
const
|
|
1828
|
+
const {
|
|
1829
|
+
ext: extAlias,
|
|
1830
|
+
file: depOriginFile,
|
|
1831
|
+
extPath
|
|
1832
|
+
} = ext$1(depOriginPath, extensions);
|
|
1833
|
+
const isFileInDir = fileInDir$1(includePath, depOriginFile);
|
|
1694
1834
|
|
|
1695
1835
|
if (!isFileInDir) {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
}
|
|
1836
|
+
pluginError$1(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
1837
|
+
return;
|
|
1838
|
+
} // eslint-disable-next-line
|
|
1839
|
+
|
|
1840
|
+
|
|
1841
|
+
const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
1842
|
+
const regRes = componentPath.match(reg) || [];
|
|
1843
|
+
|
|
1844
|
+
if (regRes[2]) {
|
|
1845
|
+
const depDestPath = resolve$4(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
|
|
1846
|
+
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
1847
|
+
|
|
1848
|
+
if (!copyModules.has(depDestFile)) {
|
|
1849
|
+
copyModules.set(depDestFile, {
|
|
1850
|
+
depOriginFile,
|
|
1851
|
+
depOriginExt: extAlias,
|
|
1852
|
+
depDestFile,
|
|
1853
|
+
beforeDepPath: componentPath,
|
|
1854
|
+
afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath)
|
|
1855
|
+
});
|
|
1717
1856
|
}
|
|
1718
1857
|
}
|
|
1719
1858
|
}
|
|
@@ -1721,8 +1860,9 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.wxml'], filesExt = ['.wx
|
|
|
1721
1860
|
});
|
|
1722
1861
|
}
|
|
1723
1862
|
} catch (e) {
|
|
1724
|
-
|
|
1725
|
-
}
|
|
1863
|
+
pluginError$1(e, isWatch);
|
|
1864
|
+
} // console.log('json copyModules', copyModules);
|
|
1865
|
+
|
|
1726
1866
|
|
|
1727
1867
|
copyModules.forEach(({
|
|
1728
1868
|
depOriginFile,
|
|
@@ -1731,27 +1871,29 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.wxml'], filesExt = ['.wx
|
|
|
1731
1871
|
beforeDepPath,
|
|
1732
1872
|
afterDepPath
|
|
1733
1873
|
}) => {
|
|
1874
|
+
// 拷贝当前依赖组件几个部分 wxml、wxss、wxs、json
|
|
1734
1875
|
filesExt.forEach(extKey => {
|
|
1735
1876
|
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
1736
1877
|
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
1737
1878
|
|
|
1738
|
-
if (fs$
|
|
1739
|
-
|
|
1740
|
-
const
|
|
1879
|
+
if (fs$4.existsSync(originFile)) {
|
|
1880
|
+
diffContentCopyFile$1(originFile, destFile);
|
|
1881
|
+
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
1882
|
+
|
|
1883
|
+
if (extensionsFilter.indexOf(extKey) > -1) {
|
|
1884
|
+
const defs = dfsFindCommonDep$1(originFile, destFile, extensionsFilter); // console.log('json defs', defs);
|
|
1741
1885
|
|
|
1742
|
-
if (jsExtensions.indexOf(extKey) > -1) {
|
|
1743
|
-
const defs = dfsFindJsDep(originFile, destFile, jsExtensions);
|
|
1744
1886
|
defs.forEach(item => {
|
|
1745
|
-
|
|
1887
|
+
diffContentCopyFile$1(item.depOriginFile, item.depDestFile);
|
|
1746
1888
|
});
|
|
1747
1889
|
}
|
|
1748
1890
|
}
|
|
1749
1891
|
});
|
|
1750
1892
|
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
1751
|
-
|
|
1893
|
+
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
1894
|
+
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
1752
1895
|
});
|
|
1753
|
-
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
1754
|
-
|
|
1896
|
+
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
1755
1897
|
file.contents = new Buffer(contents);
|
|
1756
1898
|
}
|
|
1757
1899
|
|
|
@@ -1765,22 +1907,319 @@ var mpJsonDep_1 = {
|
|
|
1765
1907
|
mpJsonDep: mpJsonDep$1
|
|
1766
1908
|
};
|
|
1767
1909
|
|
|
1910
|
+
/* eslint-disable no-param-reassign */
|
|
1911
|
+
const through = require$$0__default$7;
|
|
1912
|
+
const htmlparser2 = require$$1__default$5;
|
|
1913
|
+
const fs$3 = require$$0__default$1;
|
|
1914
|
+
const path$2 = require$$1__default$1;
|
|
1915
|
+
const {
|
|
1916
|
+
diffContentCopyFile,
|
|
1917
|
+
ext,
|
|
1918
|
+
fileInDir
|
|
1919
|
+
} = io$2;
|
|
1920
|
+
const {
|
|
1921
|
+
resolve: resolve$3
|
|
1922
|
+
} = widgets;
|
|
1923
|
+
const {
|
|
1924
|
+
dfsFindCommonDep
|
|
1925
|
+
} = mpCommonDep_1;
|
|
1926
|
+
const {
|
|
1927
|
+
pluginError
|
|
1928
|
+
} = pluginError_1; // 处理后缀(源码引入依赖时,不带后缀的情况)
|
|
1929
|
+
|
|
1930
|
+
const extFile = function (name, file) {
|
|
1931
|
+
const extMap = {
|
|
1932
|
+
import: '.wxml',
|
|
1933
|
+
include: '.wxml',
|
|
1934
|
+
wxs: '.wxs'
|
|
1935
|
+
};
|
|
1936
|
+
let extObj = {};
|
|
1937
|
+
|
|
1938
|
+
if (Object.keys(extMap).indexOf(name) > -1 && !file.endsWith(extMap[name])) {
|
|
1939
|
+
extObj = ext(file, [extMap[name]]);
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
return {
|
|
1943
|
+
extPath: extObj.extPath || '',
|
|
1944
|
+
ext: extObj.ext || '',
|
|
1945
|
+
file: extObj.file || file
|
|
1946
|
+
};
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = true) {
|
|
1950
|
+
const resDep = {
|
|
1951
|
+
image: new Map(),
|
|
1952
|
+
wxml: new Map(),
|
|
1953
|
+
wxs: new Map()
|
|
1954
|
+
};
|
|
1955
|
+
|
|
1956
|
+
function dfs(anaFileOriginFile, anaFileDestFile) {
|
|
1957
|
+
let contents = '';
|
|
1958
|
+
|
|
1959
|
+
try {
|
|
1960
|
+
contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
|
|
1961
|
+
} catch (e) {
|
|
1962
|
+
pluginError(e, isWatch);
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
const parser = new htmlparser2.Parser({
|
|
1966
|
+
onopentag(name, attributes) {
|
|
1967
|
+
var _attributes$src;
|
|
1968
|
+
|
|
1969
|
+
if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
|
|
1970
|
+
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
|
|
1971
|
+
|
|
1972
|
+
const {
|
|
1973
|
+
ext,
|
|
1974
|
+
file: depOriginFile,
|
|
1975
|
+
extPath
|
|
1976
|
+
} = extFile(name, depOriginPath);
|
|
1977
|
+
|
|
1978
|
+
if (!fs$3.existsSync(depOriginFile)) {
|
|
1979
|
+
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
1980
|
+
return;
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
const depDestPath = path$2.join(path$2.dirname(anaFileDestFile), attributes.src);
|
|
1984
|
+
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
|
|
1985
|
+
|
|
1986
|
+
if (['import', 'include'].indexOf(name) > -1) {
|
|
1987
|
+
resDep.wxml.set(depDestFile, {
|
|
1988
|
+
anaFileOriginFile,
|
|
1989
|
+
anaFileDestFile,
|
|
1990
|
+
depDestFile,
|
|
1991
|
+
depOriginFile
|
|
1992
|
+
});
|
|
1993
|
+
dfs(depOriginFile, depDestFile);
|
|
1994
|
+
} // 收集image依赖
|
|
1995
|
+
// if (name === 'image') {
|
|
1996
|
+
// resDep.image.set(attributes.src, {
|
|
1997
|
+
// anaFileOriginFile,
|
|
1998
|
+
// anaFileDestFile,
|
|
1999
|
+
// depDestFile,
|
|
2000
|
+
// depOriginFile,
|
|
2001
|
+
// });
|
|
2002
|
+
// dfs(depOriginFile, depDestFile);
|
|
2003
|
+
// }
|
|
2004
|
+
// 收集wxs依赖
|
|
2005
|
+
|
|
2006
|
+
|
|
2007
|
+
if (name === 'wxs') {
|
|
2008
|
+
resDep.wxs.set(depDestFile, {
|
|
2009
|
+
anaFileOriginFile,
|
|
2010
|
+
anaFileDestFile,
|
|
2011
|
+
depDestFile,
|
|
2012
|
+
depOriginFile
|
|
2013
|
+
});
|
|
2014
|
+
const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs']);
|
|
2015
|
+
defs.forEach((item, key) => {
|
|
2016
|
+
resDep.wxs.set(key, item);
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
});
|
|
2023
|
+
parser.write(contents);
|
|
2024
|
+
parser.end();
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
dfs(anaFileOriginFile, anaFileDestFile);
|
|
2028
|
+
return resDep;
|
|
2029
|
+
};
|
|
2030
|
+
|
|
2031
|
+
function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
2032
|
+
const stream = through.obj(function (file, enc, cb) {
|
|
2033
|
+
// 依赖分析的文件
|
|
2034
|
+
const anaFileOriginFile = file.history[0];
|
|
2035
|
+
const anaFileRelativeModule = path$2.relative(resolve$3(module.from), anaFileOriginFile);
|
|
2036
|
+
const anaFileDestFile = resolve$3(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
|
|
2037
|
+
|
|
2038
|
+
if (file.isBuffer()) {
|
|
2039
|
+
let contents = String(file.contents);
|
|
2040
|
+
const copyModules = new Map();
|
|
2041
|
+
const parser = new htmlparser2.Parser({
|
|
2042
|
+
onopentag(name, attributes) {
|
|
2043
|
+
const nameFilter = ['import', 'include', 'wxs'];
|
|
2044
|
+
|
|
2045
|
+
if (nameFilter.indexOf(name) > -1 && attributes.src) {
|
|
2046
|
+
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
|
|
2047
|
+
|
|
2048
|
+
const {
|
|
2049
|
+
ext,
|
|
2050
|
+
file: depOriginFile,
|
|
2051
|
+
extPath
|
|
2052
|
+
} = extFile(name, depOriginPath);
|
|
2053
|
+
Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
|
|
2054
|
+
if (attributes.src.indexOf(includeName) > -1) {
|
|
2055
|
+
const includePath = tmsConfig.gulp.dependencies[includeName];
|
|
2056
|
+
|
|
2057
|
+
if (!fileInDir(includePath, depOriginFile)) {
|
|
2058
|
+
pluginError(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
2059
|
+
return;
|
|
2060
|
+
} // eslint-disable-next-line
|
|
2061
|
+
|
|
2062
|
+
|
|
2063
|
+
const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2064
|
+
const regRes = attributes.src.match(reg) || [];
|
|
2065
|
+
|
|
2066
|
+
if (regRes[2]) {
|
|
2067
|
+
const depDestPath = resolve$3(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
|
|
2068
|
+
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2069
|
+
|
|
2070
|
+
if (!copyModules.has(depDestFile)) {
|
|
2071
|
+
copyModules.set(depDestFile, {
|
|
2072
|
+
depOriginFile,
|
|
2073
|
+
depDestFile,
|
|
2074
|
+
beforeDepPath: attributes.src,
|
|
2075
|
+
afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile)
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
});
|
|
2085
|
+
parser.write(contents);
|
|
2086
|
+
parser.end(); // console.log('wxml copyModules', copyModules);
|
|
2087
|
+
|
|
2088
|
+
copyModules.forEach(({
|
|
2089
|
+
depOriginFile,
|
|
2090
|
+
depDestFile,
|
|
2091
|
+
beforeDepPath,
|
|
2092
|
+
afterDepPath
|
|
2093
|
+
}) => {
|
|
2094
|
+
if (fs$3.existsSync(depOriginFile)) {
|
|
2095
|
+
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2096
|
+
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2097
|
+
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
if (depOriginFile.endsWith('.wxml')) {
|
|
2101
|
+
const defs = dfsFindWxmlDep(depOriginFile, depDestFile, isWatch); // console.log('wxml defs', defs);
|
|
2102
|
+
|
|
2103
|
+
[...defs.wxml, ...defs.wxs].forEach(([, item]) => {
|
|
2104
|
+
diffContentCopyFile(item.depOriginFile, item.depDestFile);
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
if (depOriginFile.endsWith('.wxs')) {
|
|
2109
|
+
const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs'], isWatch); // console.log('wxs defs', defs);
|
|
2110
|
+
|
|
2111
|
+
defs.forEach(item => {
|
|
2112
|
+
diffContentCopyFile(item.depOriginFile, item.depDestFile);
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
});
|
|
2116
|
+
file.contents = new Buffer(contents);
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
this.push(file);
|
|
2120
|
+
cb();
|
|
2121
|
+
});
|
|
2122
|
+
return stream;
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
var mpWxmlDep_1 = {
|
|
2126
|
+
mpWxmlDep: mpWxmlDep$1,
|
|
2127
|
+
dfsFindWxmlDep
|
|
2128
|
+
};
|
|
2129
|
+
|
|
2130
|
+
/* eslint-disable no-param-reassign */
|
|
2131
|
+
const postcss$1 = require$$0__default$9;
|
|
2132
|
+
const fs$2 = require$$0__default$1;
|
|
2133
|
+
const path$1 = require$$1__default$1;
|
|
2134
|
+
const {
|
|
2135
|
+
fail: fail$3
|
|
2136
|
+
} = log$2;
|
|
2137
|
+
var postcssFontBase64 = postcss$1.plugin('postcss-font-base64', options => {
|
|
2138
|
+
options = { ...options,
|
|
2139
|
+
...{
|
|
2140
|
+
match: {
|
|
2141
|
+
Scrabble: ['fakefont']
|
|
2142
|
+
},
|
|
2143
|
+
format: ['eot', 'woff', 'woff2', 'ttf']
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
return function (css, result) {
|
|
2147
|
+
css.walkAtRules('font-face', fontFace => {
|
|
2148
|
+
const fileTypeRegex = getRegexStringForFileTypes(options.format);
|
|
2149
|
+
fontFace.replaceValues(new RegExp(`url\\(["']?.+\\.${fileTypeRegex}["']?\\)`), attr => {
|
|
2150
|
+
const fontRePath = attr.replace(/(url|'|"|\(|\)|\?#iefix)/g, '');
|
|
2151
|
+
const fontAbPath = path$1.join(path$1.dirname(result.opts.from), fontRePath);
|
|
2152
|
+
const res64 = base64Encode(fontAbPath);
|
|
2153
|
+
const newUrlStr = 'url(data:'.concat(getMimeType(attr)).concat(';charset=utf-8;base64,').concat(res64).concat(')');
|
|
2154
|
+
return res64 ? newUrlStr : attr;
|
|
2155
|
+
});
|
|
2156
|
+
});
|
|
2157
|
+
|
|
2158
|
+
function getRegexStringForFileTypes(fileTypes) {
|
|
2159
|
+
const regex = fileTypes.map(fileType => fileType === 'eot' ? fileType.concat('(\\?#iefix)?') : fileType).join('|');
|
|
2160
|
+
return regex ? `(${regex})` : '';
|
|
2161
|
+
} // helper functions
|
|
2162
|
+
|
|
2163
|
+
|
|
2164
|
+
function getMimeType(attribute) {
|
|
2165
|
+
const formats = {
|
|
2166
|
+
'.woff': 'application/font-woff',
|
|
2167
|
+
'.woff2': 'font/woff2',
|
|
2168
|
+
'.ttf': 'application/font-sfnt',
|
|
2169
|
+
'.eot': 'application/vnd.ms-fontobject',
|
|
2170
|
+
'.otf': 'application/font-sfnt'
|
|
2171
|
+
};
|
|
2172
|
+
let match = '';
|
|
2173
|
+
const extension = attribute.match(/\.[a-z]{3,4}/)[0];
|
|
2174
|
+
|
|
2175
|
+
if (extension in formats) {
|
|
2176
|
+
match = formats[extension];
|
|
2177
|
+
}
|
|
2178
|
+
return match;
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
function base64Encode(file) {
|
|
2182
|
+
if (fs$2.existsSync(file)) {
|
|
2183
|
+
return readAndEncodeFile(file);
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
fail$3(`${file} does not exist.`);
|
|
2187
|
+
return '';
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
function readAndEncodeFile(file) {
|
|
2191
|
+
const bitmap = fs$2.readFileSync(file);
|
|
2192
|
+
return new Buffer(bitmap).toString('base64');
|
|
2193
|
+
}
|
|
2194
|
+
};
|
|
2195
|
+
});
|
|
2196
|
+
|
|
1768
2197
|
const {
|
|
1769
2198
|
src: src$1,
|
|
1770
|
-
dest
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
const
|
|
1774
|
-
const
|
|
1775
|
-
const watch = require$$
|
|
2199
|
+
dest,
|
|
2200
|
+
lastRun
|
|
2201
|
+
} = require$$0__default$a;
|
|
2202
|
+
const px2rpx = require$$1__default$6;
|
|
2203
|
+
const postcss = require$$2__default$1;
|
|
2204
|
+
const watch = require$$3__default$1;
|
|
2205
|
+
const cache = require$$4__default;
|
|
1776
2206
|
const image = require$$5__default$1;
|
|
1777
2207
|
const replaceEnv = replaceEnv_1;
|
|
1778
2208
|
const {
|
|
1779
|
-
|
|
1780
|
-
} =
|
|
2209
|
+
mpCommonDep
|
|
2210
|
+
} = mpCommonDep_1;
|
|
1781
2211
|
const {
|
|
1782
2212
|
mpJsonDep
|
|
1783
2213
|
} = mpJsonDep_1;
|
|
2214
|
+
const {
|
|
2215
|
+
mpWxmlDep
|
|
2216
|
+
} = mpWxmlDep_1;
|
|
2217
|
+
const base64 = postcssFontBase64;
|
|
2218
|
+
const {
|
|
2219
|
+
fail: fail$2
|
|
2220
|
+
} = log$2;
|
|
2221
|
+
|
|
2222
|
+
const since = task => file => lastRun(task) > file.stat.ctime ? lastRun(task) : 0;
|
|
1784
2223
|
|
|
1785
2224
|
var compile = function (tmsConfig, {
|
|
1786
2225
|
glob,
|
|
@@ -1794,7 +2233,12 @@ var compile = function (tmsConfig, {
|
|
|
1794
2233
|
}) {
|
|
1795
2234
|
Object.keys(glob).forEach(globKey => {
|
|
1796
2235
|
const globValue = glob[globKey];
|
|
1797
|
-
|
|
2236
|
+
|
|
2237
|
+
const task = () => src$1(globValue, { ...srcOption,
|
|
2238
|
+
since: since(task)
|
|
2239
|
+
});
|
|
2240
|
+
|
|
2241
|
+
let srcPipe = task();
|
|
1798
2242
|
|
|
1799
2243
|
if (isWatch) {
|
|
1800
2244
|
srcPipe = srcPipe.pipe(watch(globValue, watchOption));
|
|
@@ -1802,30 +2246,36 @@ var compile = function (tmsConfig, {
|
|
|
1802
2246
|
|
|
1803
2247
|
switch (globKey) {
|
|
1804
2248
|
case 'js':
|
|
1805
|
-
srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(
|
|
2249
|
+
srcPipe.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData)).pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch)).pipe(dest(destPath)).on('error', err => {
|
|
2250
|
+
fail$2(`js编译报错${err}`);
|
|
2251
|
+
});
|
|
1806
2252
|
break;
|
|
1807
2253
|
|
|
1808
|
-
case '
|
|
1809
|
-
srcPipe.pipe(less
|
|
2254
|
+
case 'wxss':
|
|
2255
|
+
srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch)).pipe(postcss([base64()])).on('error', err => {
|
|
2256
|
+
fail$2(`postcss编译报错${err}`);
|
|
2257
|
+
}).pipe(px2rpx({
|
|
1810
2258
|
designWidth: 375,
|
|
1811
2259
|
// 设计稿宽度,默认为750
|
|
1812
2260
|
precision: 2 // 小数最大精度,默认为6
|
|
1813
2261
|
|
|
1814
|
-
})).pipe(rename({
|
|
1815
|
-
extname: '.wxss'
|
|
1816
2262
|
})).pipe(dest(destPath));
|
|
1817
2263
|
break;
|
|
1818
2264
|
|
|
1819
2265
|
case 'json':
|
|
1820
|
-
srcPipe.pipe(mpJsonDep(tmsConfig, module)).
|
|
2266
|
+
srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch)).on('error', err => {
|
|
2267
|
+
fail$2(`json编译报错${err}`);
|
|
2268
|
+
}).pipe(dest(destPath));
|
|
1821
2269
|
break;
|
|
1822
2270
|
|
|
1823
|
-
case '
|
|
1824
|
-
srcPipe.pipe(dest(destPath));
|
|
2271
|
+
case 'wxml':
|
|
2272
|
+
srcPipe.pipe(mpWxmlDep(tmsConfig, module, isWatch)).pipe(dest(destPath));
|
|
1825
2273
|
break;
|
|
1826
2274
|
|
|
1827
2275
|
case 'image':
|
|
1828
|
-
srcPipe.pipe(image()).
|
|
2276
|
+
srcPipe.pipe(cache(image())).on('error', err => {
|
|
2277
|
+
fail$2(`image编译报错${err}`);
|
|
2278
|
+
}).pipe(dest(destPath));
|
|
1829
2279
|
break;
|
|
1830
2280
|
|
|
1831
2281
|
case 'other':
|
|
@@ -1836,7 +2286,7 @@ var compile = function (tmsConfig, {
|
|
|
1836
2286
|
};
|
|
1837
2287
|
|
|
1838
2288
|
(function (module) {
|
|
1839
|
-
const watch = require$$
|
|
2289
|
+
const watch = require$$3__default$1;
|
|
1840
2290
|
const {
|
|
1841
2291
|
resolve
|
|
1842
2292
|
} = widgets;
|
|
@@ -1848,8 +2298,9 @@ var compile = function (tmsConfig, {
|
|
|
1848
2298
|
} = require$$3;
|
|
1849
2299
|
const compile$1 = compile;
|
|
1850
2300
|
|
|
1851
|
-
function
|
|
2301
|
+
function excludeGlob(glob) {
|
|
1852
2302
|
const otherArr = new Set();
|
|
2303
|
+
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
1853
2304
|
Object.keys(glob).forEach(globKey => {
|
|
1854
2305
|
if (typeof glob[globKey] === 'string') {
|
|
1855
2306
|
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
@@ -1887,7 +2338,7 @@ var compile = function (tmsConfig, {
|
|
|
1887
2338
|
compile$1(tmsConfig, {
|
|
1888
2339
|
glob: {
|
|
1889
2340
|
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
1890
|
-
|
|
2341
|
+
wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
1891
2342
|
js: ['app.js', 'app.ts'].map(item => resolve(item))
|
|
1892
2343
|
},
|
|
1893
2344
|
module: {
|
|
@@ -1922,13 +2373,13 @@ var compile = function (tmsConfig, {
|
|
|
1922
2373
|
const glob = {
|
|
1923
2374
|
js: [`${resolve(module.path)}/**/*.{js,ts,wxs}`, ...excludes],
|
|
1924
2375
|
json: [`${resolve(module.path)}/**/*.json`, ...excludes],
|
|
1925
|
-
|
|
1926
|
-
|
|
2376
|
+
wxss: [`${resolve(module.path)}/**/*.{less,wxss}`, ...excludes],
|
|
2377
|
+
wxml: [`${resolve(module.path)}/**/*.wxml`, ...excludes],
|
|
1927
2378
|
image: [`${resolve(module.path)}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
|
|
1928
2379
|
};
|
|
1929
2380
|
compile$1(tmsConfig, {
|
|
1930
2381
|
glob: { ...glob,
|
|
1931
|
-
other: [`${resolve(module.path)}/**/*`, ...
|
|
2382
|
+
other: [`${resolve(module.path)}/**/*`, ...excludeGlob(glob)]
|
|
1932
2383
|
},
|
|
1933
2384
|
destPath: resolve(tmsConfig.gulp.outputDir, module.root),
|
|
1934
2385
|
module: {
|
|
@@ -1943,20 +2394,20 @@ var compile = function (tmsConfig, {
|
|
|
1943
2394
|
} // 监听copy模块
|
|
1944
2395
|
|
|
1945
2396
|
|
|
1946
|
-
if (tmsConfig !== null && tmsConfig !== void 0 && (_tmsConfig$gulp = tmsConfig.gulp) !== null && _tmsConfig$gulp !== void 0 && _tmsConfig$gulp.
|
|
1947
|
-
for (const item of (_tmsConfig$gulp3 = tmsConfig.gulp) === null || _tmsConfig$gulp3 === void 0 ? void 0 : _tmsConfig$gulp3.
|
|
2397
|
+
if (tmsConfig !== null && tmsConfig !== void 0 && (_tmsConfig$gulp = tmsConfig.gulp) !== null && _tmsConfig$gulp !== void 0 && _tmsConfig$gulp.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gulp2 = tmsConfig.gulp) === null || _tmsConfig$gulp2 === void 0 ? void 0 : _tmsConfig$gulp2.static.length) > 0) {
|
|
2398
|
+
for (const item of (_tmsConfig$gulp3 = tmsConfig.gulp) === null || _tmsConfig$gulp3 === void 0 ? void 0 : _tmsConfig$gulp3.static) {
|
|
1948
2399
|
var _tmsConfig$gulp3;
|
|
1949
2400
|
|
|
1950
2401
|
const glob = {
|
|
1951
2402
|
js: `${item.from}/**/*.{js,ts,wxs}`,
|
|
1952
2403
|
json: `${item.from}/**/*.json`,
|
|
1953
|
-
|
|
1954
|
-
|
|
2404
|
+
wxss: `${item.from}/**/*.{less,wxss}`,
|
|
2405
|
+
wxml: `${item.from}/**/*.wxml`,
|
|
1955
2406
|
image: `${item.from}/**/*.{png,jpg,jpeg,gif,svg}`
|
|
1956
2407
|
};
|
|
1957
2408
|
compile$1(tmsConfig, {
|
|
1958
2409
|
glob: { ...glob,
|
|
1959
|
-
other: [`${item.from}/**/*`, ...
|
|
2410
|
+
other: [`${item.from}/**/*`, ...excludeGlob(glob)]
|
|
1960
2411
|
},
|
|
1961
2412
|
destPath: item.to,
|
|
1962
2413
|
module: item,
|
|
@@ -1971,7 +2422,7 @@ var compile = function (tmsConfig, {
|
|
|
1971
2422
|
})(dev$3);
|
|
1972
2423
|
|
|
1973
2424
|
const fs$1 = require$$0__default$1;
|
|
1974
|
-
const semver$1 = require$$1__default$
|
|
2425
|
+
const semver$1 = require$$1__default$7;
|
|
1975
2426
|
const {
|
|
1976
2427
|
resolve: resolve$2
|
|
1977
2428
|
} = widgets;
|
|
@@ -2287,12 +2738,18 @@ var entry = [{
|
|
|
2287
2738
|
|
|
2288
2739
|
var require$$6 = {
|
|
2289
2740
|
name: "@tmsfe/tmskit",
|
|
2290
|
-
version: "0.0.5-beta.
|
|
2741
|
+
version: "0.0.5-beta.4",
|
|
2291
2742
|
description: "tmskit",
|
|
2292
2743
|
main: "main.js",
|
|
2293
2744
|
bin: {
|
|
2294
2745
|
tmskit: "main.js"
|
|
2295
2746
|
},
|
|
2747
|
+
files: [
|
|
2748
|
+
"src",
|
|
2749
|
+
"dist",
|
|
2750
|
+
"main.js",
|
|
2751
|
+
"package.json"
|
|
2752
|
+
],
|
|
2296
2753
|
scripts: {
|
|
2297
2754
|
dev: "rollup -wc --environment TARGET:tmskit",
|
|
2298
2755
|
build: "rollup -c --environment TARGET:tmskit"
|
|
@@ -2324,21 +2781,27 @@ var require$$6 = {
|
|
|
2324
2781
|
ejs: "^3.1.5",
|
|
2325
2782
|
"glob-ignore": "^1.0.2",
|
|
2326
2783
|
gulp: "^4.0.2",
|
|
2784
|
+
"gulp-cache": "^1.1.3",
|
|
2327
2785
|
"gulp-image": "^5.1.0",
|
|
2328
|
-
"gulp-
|
|
2786
|
+
"gulp-postcss": "^9.0.1",
|
|
2329
2787
|
"gulp-px-to-rpx": "^1.0.7",
|
|
2330
|
-
"gulp-rename": "^2.0.0",
|
|
2331
2788
|
"gulp-watch": "^5.0.1",
|
|
2789
|
+
htmlparser2: "^7.2.0",
|
|
2332
2790
|
inquirer: "^7.3.3",
|
|
2333
2791
|
leven: "3.1.0",
|
|
2334
2792
|
lodash: "^4.17.21",
|
|
2335
2793
|
metalsmith: "^2.3.0",
|
|
2336
2794
|
"miniprogram-ci": "1.4.13",
|
|
2795
|
+
"object-assign": "^4.0.1",
|
|
2337
2796
|
ora: "^5.1.0",
|
|
2797
|
+
"plugin-error": "^1.0.0",
|
|
2798
|
+
postcss: "^8.4.6",
|
|
2338
2799
|
precinct: "^8.3.1",
|
|
2339
2800
|
"replace-ext": "^2.0.0",
|
|
2340
2801
|
shelljs: "^0.8.4",
|
|
2341
|
-
|
|
2802
|
+
"strip-comments": "^2.0.1",
|
|
2803
|
+
through2: "^4.0.2",
|
|
2804
|
+
"vinyl-sourcemaps-apply": "^0.2.0"
|
|
2342
2805
|
},
|
|
2343
2806
|
engines: {
|
|
2344
2807
|
node: "^12.17.0 || >= 14.13.1"
|
|
@@ -2348,7 +2811,7 @@ var require$$6 = {
|
|
|
2348
2811
|
}
|
|
2349
2812
|
};
|
|
2350
2813
|
|
|
2351
|
-
const semver = require$$1__default$
|
|
2814
|
+
const semver = require$$1__default$7;
|
|
2352
2815
|
const packageJson = require$$6;
|
|
2353
2816
|
const chalk$1 = require$$0__default$2;
|
|
2354
2817
|
const {
|