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