@tmsfe/tmskit 0.0.21 → 0.0.22

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/dist/index.cjs.js CHANGED
@@ -1,101 +1,84 @@
1
1
  'use strict';
2
2
 
3
- var require$$0 = require('chalk');
3
+ var require$$3 = require('chalk');
4
4
  var require$$1 = require('moment');
5
- var require$$0$1 = require('commander');
6
- var require$$1$1 = require('leven');
7
- var require$$2 = require('ora');
8
- var require$$1$2 = require('path');
9
- var require$$0$2 = require('fs');
10
- var require$$0$3 = require('shelljs');
11
- var require$$6 = require('glob-ignore');
12
- var require$$0$4 = require('lodash');
13
- var require$$0$5 = require('async');
5
+ var require$$0 = require('ora');
6
+ var require$$1$1 = require('path');
7
+ var require$$0$1 = require('fs');
8
+ var require$$2 = require('shelljs');
9
+ var require$$4 = require('glob-ignore');
10
+ var require$$1$2 = require('os');
11
+ var require$$0$2 = require('lodash');
12
+ var require$$0$3 = require('async');
14
13
  var require$$1$3 = require('ejs');
15
14
  var require$$1$4 = require('inquirer');
16
- var require$$0$6 = require('metalsmith');
17
- var require$$9$1 = require('request');
15
+ var require$$0$4 = require('metalsmith');
16
+ var require$$0$5 = require('request');
18
17
  var require$$10 = require('unzipper');
19
18
  var require$$1$5 = require('crypto');
20
- var require$$0$7 = require('miniprogram-ci');
19
+ var require$$0$6 = require('miniprogram-ci');
21
20
  var require$$1$6 = require('fs-extra');
22
21
  var require$$1$7 = require('semver');
23
- var require$$0$8 = require('strip-comments');
24
- var require$$0$9 = require('through2');
25
- var require$$1$8 = require('precinct');
26
- var require$$1$9 = require('htmlparser2');
27
- var require$$0$a = require('gulp');
28
- var require$$0$b = require('object-assign');
29
- var require$$3 = require('fancy-log');
30
- var require$$4 = require('ansi-colors');
31
- var require$$5$1 = require('chokidar');
22
+ var require$$0$7 = require('gulp');
23
+ var require$$2$1 = require('minimatch');
24
+ var require$$3$1 = require('gulp-if');
25
+ var require$$6 = require('through2');
26
+ var require$$0$8 = require('object-assign');
27
+ var require$$3$2 = require('fancy-log');
28
+ var require$$4$1 = require('ansi-colors');
29
+ var require$$5 = require('chokidar');
32
30
  var require$$6$1 = require('readable-stream');
33
31
  var require$$7 = require('vinyl-file');
34
32
  var require$$8 = require('vinyl');
35
- var require$$9$2 = require('anymatch');
33
+ var require$$9 = require('anymatch');
36
34
  var require$$11 = require('glob-parent');
37
- var require$$2$1 = require('plugin-error');
35
+ var require$$2$2 = require('plugin-error');
38
36
  var require$$10$1 = require('path-is-absolute');
39
- var require$$12 = require('slash');
37
+ var require$$12$1 = require('slash');
38
+ var require$$1$8 = require('commander');
40
39
 
41
40
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
42
41
 
43
- var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
42
+ var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
44
43
  var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
45
- var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
44
+ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
46
45
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
46
+ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
47
47
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
48
+ var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
48
49
  var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
49
50
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
50
51
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
51
- var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
52
- var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
53
- var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
54
52
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
55
53
  var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
56
- var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
57
- var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9$1);
54
+ var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
55
+ var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
58
56
  var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
59
57
  var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
60
- var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
58
+ var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
61
59
  var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
62
60
  var require$$1__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$1$7);
61
+ var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
62
+ var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
63
+ var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
64
+ var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
63
65
  var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
64
- var require$$0__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
65
- var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
66
- var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
67
- var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
68
- var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
69
- var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
70
- var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
71
- var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5$1);
66
+ var require$$3__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
67
+ var require$$4__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
68
+ var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
72
69
  var require$$6__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
73
70
  var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
74
71
  var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
75
- var require$$9__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$9$2);
72
+ var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
76
73
  var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
77
- var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
74
+ var require$$2__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$2$2);
78
75
  var require$$10__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$10$1);
79
- var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12);
80
-
81
- function getAugmentedNamespace(n) {
82
- if (n.__esModule) return n;
83
- var a = Object.defineProperty({}, '__esModule', {value: true});
84
- Object.keys(n).forEach(function (k) {
85
- var d = Object.getOwnPropertyDescriptor(n, k);
86
- Object.defineProperty(a, k, d.get ? d : {
87
- enumerable: true,
88
- get: function () {
89
- return n[k];
90
- }
91
- });
92
- });
93
- return a;
94
- }
76
+ var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12$1);
77
+ var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
95
78
 
96
79
  var src$2 = {};
97
80
 
98
- const chalk$4 = require$$0__default;
81
+ const chalk$4 = require$$3__default;
99
82
  const moment = require$$1__default;
100
83
  /**
101
84
  * 本文件提供无依赖的在终端打印彩色文字的方法。
@@ -143,24 +126,24 @@ const warn$2 = message => {
143
126
 
144
127
  const info$d = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
145
128
 
129
+ const infoNoTime$2 = (...args) => console.log(...args);
130
+
146
131
  var log$1 = {
147
132
  fail: fail$9,
148
133
  succeed: succeed$2,
149
134
  warn: warn$2,
150
- info: info$d
135
+ info: info$d,
136
+ infoNoTime: infoNoTime$2
151
137
  };
152
138
 
153
- const program$1 = require$$0__default$1;
154
- const leven = require$$1__default$1;
155
- const ora$1 = require$$2__default;
156
- const path$e = require$$1__default$2;
157
- const fs$h = require$$0__default$2;
158
- const shelljs$7 = require$$0__default$3;
159
- const glob$1 = require$$6__default;
139
+ const ora$1 = require$$0__default;
140
+ const path$f = require$$1__default$1;
141
+ const fs$g = require$$0__default$1;
142
+ const shelljs$9 = require$$2__default;
143
+ const glob = require$$4__default;
160
144
  const {
161
145
  info: info$c
162
146
  } = log$1;
163
- const chalk$3 = require$$0__default;
164
147
  const shelljsOptions = {
165
148
  slient: true,
166
149
  async: false
@@ -168,37 +151,15 @@ const shelljsOptions = {
168
151
 
169
152
  const cwd = process.cwd();
170
153
 
171
- function resolve$g(...args) {
172
- return path$e.resolve(cwd, ...args);
154
+ function resolve$e(...args) {
155
+ return path$f.resolve(cwd, ...args);
173
156
  }
174
- /**
175
- * 用户输入命令时,进行提示
176
- * @param {String} unknownCommand 非预期的命令
177
- * @returns {Undefined} 无需返回值
178
- */
179
-
180
- const suggestCommands$1 = unknownCommand => {
181
- const availableCommands = program$1.commands.map(cmd => cmd._name);
182
- let suggestion;
183
- availableCommands.forEach(cmd => {
184
- const isBestMatch = leven(cmd, unknownCommand) < leven(suggestion || '', unknownCommand);
185
-
186
- if (leven(cmd, unknownCommand) < 3 && isBestMatch) {
187
- suggestion = cmd;
188
- }
189
- });
190
-
191
- if (suggestion) {
192
- info$c(` ${chalk$3.red(`Did you mean ${chalk$3.yellow(suggestion)}?`)}`);
193
- }
194
- };
195
157
  /**
196
158
  * 判断变量是否是一个数组
197
159
  * @param { unknown } obj 变量
198
160
  * @returns { boolean } 是否是一个数组
199
161
  */
200
162
 
201
-
202
163
  function isObject(obj) {
203
164
  return Object.prototype.toString.call(obj) === '[object Object]';
204
165
  }
@@ -225,20 +186,20 @@ function downloadRepoForGit$1(url, dest, branch) {
225
186
  const cwd = process.cwd();
226
187
  return new Promise((resolve, reject) => {
227
188
  // 如果目标目录不存在
228
- if (fs$h.existsSync(dest)) {
229
- shelljs$7.rm('-rf', path$e.join(dest));
189
+ if (fs$g.existsSync(dest)) {
190
+ shelljs$9.rm('-rf', path$f.join(dest));
230
191
  }
231
192
 
232
- shelljs$7.mkdir('-p', dest);
233
- shelljs$7.cd(dest);
234
- shelljs$7.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
193
+ shelljs$9.mkdir('-p', dest);
194
+ shelljs$9.cd(dest);
195
+ shelljs$9.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
235
196
  silent: true
236
197
  }, (code, stdout, stderr) => {
237
198
  if (code !== 0) {
238
199
  reject(stderr);
239
200
  }
240
201
 
241
- shelljs$7.cd(cwd);
202
+ shelljs$9.cd(cwd);
242
203
  resolve();
243
204
  });
244
205
  });
@@ -254,30 +215,32 @@ function downloadRepoForGit$1(url, dest, branch) {
254
215
  function pullRepoForGit$1(dest, branch) {
255
216
  const cwd = process.cwd();
256
217
  return new Promise((resolve, reject) => {
257
- shelljs$7.cd(dest);
258
- shelljs$7.exec('git config pull.rebase false', shelljsOptions);
259
- shelljs$7.exec(`git pull origin ${branch}`, {
218
+ shelljs$9.cd(dest);
219
+ shelljs$9.exec('git config pull.rebase false', shelljsOptions);
220
+ shelljs$9.exec(`git pull origin ${branch}`, {
260
221
  silent: true
261
222
  }, (code, stdout, stderr) => {
262
223
  if (code !== 0) {
263
224
  reject(stderr);
264
225
  }
265
226
 
266
- shelljs$7.cd(cwd);
227
+ shelljs$9.cd(cwd);
267
228
  resolve();
268
229
  });
269
230
  });
270
231
  }
271
232
  /**
272
233
  * npm 下载依赖
273
- * @param {*} dir
234
+ * @param {string} dir 下载npm的目录
235
+ * @param {object} npm npm的配置 (见下获取npm源入参)
274
236
  * @returns
275
237
  */
276
238
 
277
239
 
278
- function npmInstall$2(dir) {
240
+ function npmInstall$2(dir, npmConfig) {
279
241
  return new Promise((resolve, reject) => {
280
- shelljs$7.exec('npm install --production --registry http://mirrors.tencent.com/npm/', {
242
+ const registry = getNpmRegistry(npmConfig);
243
+ shelljs$9.exec(`npm install --production ${registry}`, {
281
244
  cwd: dir,
282
245
  silent: true
283
246
  }, (code, stdout, stderr) => {
@@ -288,6 +251,30 @@ function npmInstall$2(dir) {
288
251
  resolve();
289
252
  });
290
253
  });
254
+ } // 获取npm源
255
+ // 入参:{
256
+ // registry: "https://registry.npmjs.org/",
257
+ // scope: {
258
+ // "@tencent": "http://mirrors.tencent.com/npm/"
259
+ // }
260
+ // }
261
+ // 出参: --@tencent:registry=http://mirrors.tencent.com/npm/ --registry=https://registry.npmjs.org/
262
+
263
+
264
+ function getNpmRegistry(npmConfig = {}) {
265
+ let resRegistry = '';
266
+
267
+ if (npmConfig.registry) {
268
+ resRegistry = ` --registry=${npmConfig.registry}`;
269
+ }
270
+
271
+ if (isObject(npmConfig.scope)) {
272
+ Object.keys(npmConfig.scope).forEach(key => {
273
+ resRegistry += ` --${key}:registry=${npmConfig.scope[key]}`;
274
+ });
275
+ }
276
+
277
+ return resRegistry;
291
278
  }
292
279
  /**
293
280
  * 计算各项任务耗时
@@ -306,7 +293,7 @@ const cost = start => Date.now() - start;
306
293
  */
307
294
 
308
295
 
309
- function createTask$2(task, startText, endText) {
296
+ function createTask$3(task, startText, endText) {
310
297
  return async (...args) => {
311
298
  const start = Date.now();
312
299
  const spinner = ora$1();
@@ -328,18 +315,14 @@ const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : ''
328
315
 
329
316
  const mergeMap$1 = function (obj, src) {
330
317
  for (const [k, v] of src) {
331
- if (obj.has(k)) {
332
- obj.set(k, obj.get(k) + v);
333
- } else {
334
- obj.set(k, v);
335
- }
318
+ obj.set(k, v);
336
319
  }
337
320
 
338
321
  return obj;
339
322
  };
340
323
 
341
324
  const relativeCwdPath$1 = function (file) {
342
- return path$e.relative(process.cwd(), file);
325
+ return path$f.relative(process.cwd(), file);
343
326
  };
344
327
  /**
345
328
  * 从一个对象中,检索出去几个字段
@@ -349,7 +332,7 @@ const relativeCwdPath$1 = function (file) {
349
332
  */
350
333
 
351
334
 
352
- const filterField$4 = (obj, filterNames = []) => {
335
+ const filterField$5 = (obj, filterNames = []) => {
353
336
  const newObj = { ...obj
354
337
  };
355
338
  filterNames.forEach(name => {
@@ -363,7 +346,7 @@ const filterField$4 = (obj, filterNames = []) => {
363
346
 
364
347
  function findFiles(globPath, filter = []) {
365
348
  return new Promise((resolve, reject) => {
366
- glob$1(globPath, filter, (err, files) => {
349
+ glob(globPath, filter, (err, files) => {
367
350
  if (err) {
368
351
  reject(err);
369
352
  }
@@ -376,46 +359,74 @@ function findFiles(globPath, filter = []) {
376
359
 
377
360
  function getAbsolutePath$3(pathDir, cwd = '') {
378
361
  let newPath = pathDir;
379
- newPath = newPath.startsWith('/') ? newPath : resolve$g(cwd, newPath);
362
+ newPath = newPath.startsWith('/') ? newPath : resolve$e(cwd, newPath);
380
363
  newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
381
364
  return newPath;
365
+ } // 版本比较 => 1(大于), 0(等于), -1(小于)
366
+
367
+
368
+ function versionCompare$1(v1, v2) {
369
+ // 将两个版本号拆成数组
370
+ const arr1 = v1.split('.');
371
+ const arr2 = v2.split('.');
372
+ const minLength = Math.min(arr1.length, arr2.length); // 依次比较版本号每一位大小
373
+
374
+ for (let i = 0; i < minLength; i++) {
375
+ if (parseInt(arr1[i], 10) !== parseInt(arr2[i], 10)) {
376
+ return parseInt(arr1[i], 10) > parseInt(arr2[i], 10) ? 1 : -1;
377
+ }
378
+ } // 若前几位分隔相同,则按分隔数比较。
379
+
380
+
381
+ if (arr1.length === arr2.length) {
382
+ return 0;
383
+ }
384
+
385
+ return arr1.length > arr2.length ? 1 : -1;
382
386
  }
383
387
 
384
388
  var widgets = {
385
- resolve: resolve$g,
389
+ resolve: resolve$e,
386
390
  isObject,
387
391
  isArray,
388
- createTask: createTask$2,
392
+ createTask: createTask$3,
389
393
  downloadRepoForGit: downloadRepoForGit$1,
390
394
  pullRepoForGit: pullRepoForGit$1,
391
- suggestCommands: suggestCommands$1,
392
395
  camelize,
393
396
  npmInstall: npmInstall$2,
394
397
  mergeMap: mergeMap$1,
395
398
  relativeCwdPath: relativeCwdPath$1,
396
- filterField: filterField$4,
399
+ filterField: filterField$5,
397
400
  findFiles,
398
- getAbsolutePath: getAbsolutePath$3
401
+ getAbsolutePath: getAbsolutePath$3,
402
+ getNpmRegistry,
403
+ versionCompare: versionCompare$1
399
404
  };
400
405
 
401
406
  var tmsMpconfig = {exports: {}};
402
407
 
403
- const path$d = require('path');
408
+ const path$e = require$$1__default$1;
409
+ const os = require$$1__default$2; // 用户目录
410
+
411
+ const HOME_DIR = os.homedir(); // 所有文件的缓存目录
404
412
 
405
- const os = require('os'); // 用户目录
413
+ const CACHE_DIR = path$e.resolve(HOME_DIR, '.tmskit'); // 版本管理的CDN地址
406
414
 
415
+ const VERSION_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json'; // version缓存文件
407
416
 
408
- const HOME_DIR = os.homedir(); // 所有文件的缓存目录
417
+ const VERSION_CACHE_FILE$1 = path$e.resolve(CACHE_DIR, 'version_cache_file.json'); // npm缓存文件
409
418
 
410
- const CACHE_DIR$3 = path$d.resolve(HOME_DIR, '.tmskit'); // 缓存文件
419
+ const NPM_CACHE_FILE$1 = path$e.resolve(CACHE_DIR, 'npm_cache_file.json'); // 脚手架模板代码所在目录
411
420
 
412
- const CACHE_FILE$1 = 'cache_file.json'; // 脚手架模板代码所在目录
421
+ const TEMPLATE_DIR$1 = path$e.resolve(CACHE_DIR, 'template'); // 第三方模块源码存放的临时缓存目录
413
422
 
414
- const TEMPLATE_DIR$1 = path$d.resolve(CACHE_DIR$3, 'template'); // 模板的名称
423
+ const MODULE_CODE_DIR$2 = path$e.resolve(CACHE_DIR, 'modules_code'); // 缓存分包node_modules的目录
415
424
 
416
- const TEMPLATE_NAME$1 = 'tmskit-template'; // 第三方模块源码存放的临时缓存目录
425
+ const NODE_MODULES_DIR$2 = path$e.resolve(CACHE_DIR, 'node_modules'); // 扩展命令源码的存放处
417
426
 
418
- const MODULE_CODE_DIR$1 = path$d.resolve(CACHE_DIR$3, 'modules_code'); // 脚手架模板的远程地址
427
+ const EXTEND_CMD$1 = path$e.resolve(CACHE_DIR, 'cmd'); // 创建模板的名称
428
+
429
+ const TEMPLATE_NAME$1 = 'tmskit-template'; // 脚手架模板的远程地址
419
430
 
420
431
  const TEMPLATE_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip'; // 脚手架的名称
421
432
 
@@ -431,10 +442,10 @@ const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
431
442
  const MODULE_CONFIG_FILENAME = 'module.config.json'; // 默认的webpack entry
432
443
 
433
444
  const DEFAULT_WEBPACK_ENTRY = {
434
- app: path$d.resolve(process.cwd(), 'app')
445
+ app: path$e.resolve(process.cwd(), 'app')
435
446
  }; // 默认从源码拷贝到编译后的配置
436
447
 
437
- const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json'];
448
+ const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json', 'project.config.json'];
438
449
  const ENV = {
439
450
  dev: 'development',
440
451
  prod: 'production'
@@ -450,32 +461,35 @@ const CREATE_TEMPLATE_QUESTION$1 = [{
450
461
  }, {
451
462
  name: '小程序模块',
452
463
  value: 'mp-module'
464
+ }, {
465
+ name: '构建工具扩展命令',
466
+ value: 'cmd'
453
467
  }]
454
468
  }];
455
-
456
- var constant = /*#__PURE__*/Object.freeze({
457
- __proto__: null,
458
- HOME_DIR: HOME_DIR,
459
- CACHE_DIR: CACHE_DIR$3,
460
- CACHE_FILE: CACHE_FILE$1,
461
- TEMPLATE_DIR: TEMPLATE_DIR$1,
462
- TEMPLATE_NAME: TEMPLATE_NAME$1,
463
- TMS_NAME: TMS_NAME$1,
464
- TMS_CONFIG_FILENAME: TMS_CONFIG_FILENAME,
465
- TMS_PRIVATE_FILENAME: TMS_PRIVATE_FILENAME,
466
- DEFAULT_MODULE_DIR: DEFAULT_MODULE_DIR,
467
- MODULE_CONFIG_FILENAME: MODULE_CONFIG_FILENAME,
468
- DEFAULT_WEBPACK_ENTRY: DEFAULT_WEBPACK_ENTRY,
469
- DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
470
- MODULE_CODE_DIR: MODULE_CODE_DIR$1,
471
- ENV: ENV,
472
- TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
473
- DEFAULT_CLOUD_MODULE_DIR: DEFAULT_CLOUD_MODULE_DIR,
474
- CREATE_TEMPLATE_QUESTION: CREATE_TEMPLATE_QUESTION$1,
475
- TEMPLATE_URL: TEMPLATE_URL$1
476
- });
477
-
478
- var require$$5 = /*@__PURE__*/getAugmentedNamespace(constant);
469
+ var constant = {
470
+ HOME_DIR,
471
+ CACHE_DIR,
472
+ NPM_CACHE_FILE: NPM_CACHE_FILE$1,
473
+ VERSION_CACHE_FILE: VERSION_CACHE_FILE$1,
474
+ TEMPLATE_DIR: TEMPLATE_DIR$1,
475
+ TEMPLATE_NAME: TEMPLATE_NAME$1,
476
+ TMS_NAME: TMS_NAME$1,
477
+ TMS_CONFIG_FILENAME,
478
+ TMS_PRIVATE_FILENAME,
479
+ DEFAULT_MODULE_DIR,
480
+ MODULE_CONFIG_FILENAME,
481
+ EXTEND_CMD: EXTEND_CMD$1,
482
+ DEFAULT_WEBPACK_ENTRY,
483
+ DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$2,
484
+ MODULE_CODE_DIR: MODULE_CODE_DIR$2,
485
+ NODE_MODULES_DIR: NODE_MODULES_DIR$2,
486
+ ENV,
487
+ TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$2,
488
+ DEFAULT_CLOUD_MODULE_DIR,
489
+ CREATE_TEMPLATE_QUESTION: CREATE_TEMPLATE_QUESTION$1,
490
+ TEMPLATE_URL: TEMPLATE_URL$1,
491
+ VERSION_URL: VERSION_URL$1
492
+ };
479
493
 
480
494
  var defaultTmsConfig = {
481
495
  // 全局的环境配置项
@@ -502,14 +516,14 @@ var defaultTmsConfig = {
502
516
 
503
517
  (function (module) {
504
518
  /* eslint-disable no-param-reassign, no-nested-ternary */
505
- const loadash = require$$0__default$4;
506
- const fs = require$$0__default$2;
507
- const path = require$$1__default$2;
519
+ const loadash = require$$0__default$2;
520
+ const fs = require$$0__default$1;
521
+ const path = require$$1__default$1;
508
522
  const {
509
523
  TMS_CONFIG_FILENAME,
510
524
  MODULE_CONFIG_FILENAME,
511
525
  TMS_PRIVATE_FILENAME
512
- } = require$$5;
526
+ } = constant;
513
527
  const {
514
528
  resolve,
515
529
  isObject,
@@ -522,14 +536,14 @@ var defaultTmsConfig = {
522
536
  } = log$1;
523
537
  /**
524
538
  * 读取tms.config.js
525
- * @param env {string} 环境变量
539
+ * @param {string} configPath tms.config.js的路径
526
540
  */
527
541
 
528
- const readTmsConfig = function () {
529
- const tmsConfigPath = resolve(TMS_CONFIG_FILENAME);
542
+ const readTmsConfig = function (configPath) {
543
+ const tmsConfigPath = configPath ? `${configPath}/${TMS_CONFIG_FILENAME}` : resolve(TMS_CONFIG_FILENAME);
530
544
 
531
545
  if (!fs.existsSync(tmsConfigPath)) {
532
- fail('当前执行目录没有tms.config.js的配置项,请进行配置');
546
+ fail(`${path.dirname(tmsConfigPath)}没有找到tms.config.js,请进行配置`);
533
547
  process.exit(1);
534
548
  }
535
549
 
@@ -537,16 +551,17 @@ var defaultTmsConfig = {
537
551
 
538
552
  const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn() : tmsConfigFn; // 合并默认值
539
553
 
540
- return loadash.mergeWith(defaultTmsConfig$1, tmsConfig);
554
+ return loadash.mergeWith({}, defaultTmsConfig$1, tmsConfig);
541
555
  };
542
556
  /**
543
557
  * 读取tms.private.config.js
558
+ * @param {string} configPath tms.private.config.js的路径
544
559
  */
545
560
 
546
561
 
547
- const readTmsPrivateCf = function () {
562
+ const readTmsPrivateCf = function (configPath) {
548
563
  let tmsPrivateCf = {};
549
- const tmsPrivatePath = resolve(TMS_PRIVATE_FILENAME);
564
+ const tmsPrivatePath = configPath ? `${configPath}/${TMS_PRIVATE_FILENAME}` : resolve(TMS_PRIVATE_FILENAME);
550
565
 
551
566
  if (fs.existsSync(tmsPrivatePath)) {
552
567
  const tmsPrivateFn = require(tmsPrivatePath);
@@ -558,13 +573,14 @@ var defaultTmsConfig = {
558
573
  };
559
574
  /**
560
575
  * 获取tms.config.js, tms.private.config.js的配置项
576
+ * @param {string} configPath config.js的路径
561
577
  * @returns
562
578
  */
563
579
 
564
580
 
565
- const getTmsConfig = () => {
566
- const tmsPrivateCf = readTmsPrivateCf();
567
- const tmsConfig = readTmsConfig();
581
+ const getTmsConfig = configPath => {
582
+ const tmsPrivateCf = readTmsPrivateCf(configPath);
583
+ const tmsConfig = readTmsConfig(configPath);
568
584
  const modules = {};
569
585
 
570
586
  if (Array.isArray(tmsConfig.modules)) {
@@ -822,8 +838,8 @@ var defaultTmsConfig = {
822
838
  };
823
839
  })(tmsMpconfig);
824
840
 
825
- const fs$g = require$$0__default$2;
826
- const path$c = require$$1__default$2;
841
+ const fs$f = require$$0__default$1;
842
+ const path$d = require$$1__default$1;
827
843
  const {
828
844
  info: info$b
829
845
  } = log$1;
@@ -836,12 +852,12 @@ const {
836
852
  * @returns
837
853
  */
838
854
 
839
- const isDirEmpty = dirname => fs$g.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
855
+ const isDirEmpty = dirname => fs$f.promises.readdir(dirname).then(files => files.length === 0); // 判断是否是文件
840
856
 
841
857
 
842
858
  const isFile = pathName => {
843
859
  try {
844
- const stat = fs$g.lstatSync(pathName);
860
+ const stat = fs$f.lstatSync(pathName);
845
861
  return stat.isFile();
846
862
  } catch {
847
863
  return false;
@@ -853,9 +869,9 @@ const isFile = pathName => {
853
869
  */
854
870
 
855
871
 
856
- const ensureDirExist$2 = dirname => {
857
- if (!fs$g.existsSync(dirname)) {
858
- fs$g.mkdirSync(dirname, {
872
+ const ensureDirExist$4 = dirname => {
873
+ if (!fs$f.existsSync(dirname)) {
874
+ fs$f.mkdirSync(dirname, {
859
875
  recursive: true
860
876
  });
861
877
  }
@@ -863,20 +879,20 @@ const ensureDirExist$2 = dirname => {
863
879
 
864
880
 
865
881
  const copyFile = function (src, dest) {
866
- if (fs$g.existsSync(dest)) {
867
- fs$g.unlinkSync(dest);
882
+ if (fs$f.existsSync(dest)) {
883
+ fs$f.unlinkSync(dest);
868
884
  }
869
885
 
870
- const dir = path$c.dirname(dest);
871
- ensureDirExist$2(dir);
872
- fs$g.copyFileSync(src, dest);
886
+ const dir = path$d.dirname(dest);
887
+ ensureDirExist$4(dir);
888
+ fs$f.copyFileSync(src, dest);
873
889
  }; // 判断文件内容是否一致,不一致再进行拷贝
874
890
 
875
891
 
876
- function diffContentCopyFile$3(originFile, destFile) {
877
- if (fs$g.existsSync(destFile)) {
878
- const depDestContent = fs$g.readFileSync(destFile, 'utf8');
879
- const depOriginContent = fs$g.readFileSync(originFile, 'utf8');
892
+ function diffContentCopyFile(originFile, destFile) {
893
+ if (fs$f.existsSync(destFile)) {
894
+ const depDestContent = fs$f.readFileSync(destFile, 'utf8');
895
+ const depOriginContent = fs$f.readFileSync(originFile, 'utf8');
880
896
 
881
897
  if (depDestContent !== depOriginContent) {
882
898
  info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
@@ -889,12 +905,12 @@ function diffContentCopyFile$3(originFile, destFile) {
889
905
  } // 添加后缀
890
906
 
891
907
 
892
- function ext$3(filePath, extensions) {
908
+ function ext(filePath, extensions) {
893
909
  let newFilePath = filePath;
894
910
  let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
895
911
 
896
912
  try {
897
- const stat = fs$g.lstatSync(newFilePath);
913
+ const stat = fs$f.lstatSync(newFilePath);
898
914
 
899
915
  if (stat.isDirectory()) {
900
916
  extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
@@ -905,7 +921,7 @@ function ext$3(filePath, extensions) {
905
921
  for (const ext of extensions) {
906
922
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
907
923
 
908
- if (fs$g.existsSync(file)) {
924
+ if (fs$f.existsSync(file)) {
909
925
  return {
910
926
  ext,
911
927
  extPath: extPath + ext,
@@ -922,12 +938,12 @@ function ext$3(filePath, extensions) {
922
938
  } // 判断文件是否在某个目录
923
939
 
924
940
 
925
- const fileInDir$3 = (dir, file) => {
926
- if (!fs$g.existsSync(dir) || !fs$g.existsSync(file)) {
941
+ const fileInDir = (dir, file) => {
942
+ if (!fs$f.existsSync(dir) || !fs$f.existsSync(file)) {
927
943
  return false;
928
944
  }
929
945
 
930
- const relativePath = path$c.relative(dir, file);
946
+ const relativePath = path$d.relative(dir, file);
931
947
 
932
948
  if (relativePath.startsWith('..')) {
933
949
  return false;
@@ -936,14 +952,14 @@ const fileInDir$3 = (dir, file) => {
936
952
  return true;
937
953
  };
938
954
 
939
- function findAllFilesOfDir$1(dir) {
955
+ function findAllFilesOfDir(dir) {
940
956
  const list = [];
941
957
 
942
958
  function listFile(dir) {
943
- const arr = fs$g.readdirSync(dir);
959
+ const arr = fs$f.readdirSync(dir);
944
960
  arr.forEach(item => {
945
- const fullPath = path$c.join(dir, item);
946
- const stats = fs$g.statSync(fullPath);
961
+ const fullPath = path$d.join(dir, item);
962
+ const stats = fs$f.statSync(fullPath);
947
963
 
948
964
  if (stats.isDirectory()) {
949
965
  listFile(fullPath);
@@ -961,15 +977,15 @@ function findAllFilesOfDir$1(dir) {
961
977
  var io$3 = {
962
978
  isDirEmpty,
963
979
  copyFile,
964
- diffContentCopyFile: diffContentCopyFile$3,
965
- ensureDirExist: ensureDirExist$2,
966
- ext: ext$3,
967
- fileInDir: fileInDir$3,
980
+ diffContentCopyFile,
981
+ ensureDirExist: ensureDirExist$4,
982
+ ext,
983
+ fileInDir,
968
984
  isFile,
969
- findAllFilesOfDir: findAllFilesOfDir$1
985
+ findAllFilesOfDir
970
986
  };
971
987
 
972
- const async = require$$0__default$5;
988
+ const async = require$$0__default$3;
973
989
  const ejs = require$$1__default$3;
974
990
 
975
991
  const render$1 = (files, metalsmith, next) => {
@@ -989,14 +1005,14 @@ const render$1 = (files, metalsmith, next) => {
989
1005
 
990
1006
  var render_1 = render$1;
991
1007
 
992
- const fs$f = require$$0__default$2;
993
- const inquirer$1 = require$$1__default$4;
1008
+ const fs$e = require$$0__default$1;
1009
+ const inquirer$2 = require$$1__default$4;
994
1010
  const {
995
- resolve: resolve$f
1011
+ resolve: resolve$d
996
1012
  } = widgets;
997
1013
  const {
998
1014
  TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
999
- } = require$$5;
1015
+ } = constant;
1000
1016
  /**
1001
1017
  * 获取模板内的问题
1002
1018
  * @param {string} dir questions.json所在的目录
@@ -1006,12 +1022,12 @@ const {
1006
1022
  const parseTemplateQuestions = dir => {
1007
1023
  let prompts = [];
1008
1024
 
1009
- if (!fs$f.existsSync(`${dir}/questions.json`)) {
1025
+ if (!fs$e.existsSync(`${dir}/questions.json`)) {
1010
1026
  return prompts;
1011
1027
  }
1012
1028
 
1013
1029
  try {
1014
- const json = JSON.parse(fs$f.readFileSync(`${dir}/questions.json`));
1030
+ const json = JSON.parse(fs$e.readFileSync(`${dir}/questions.json`));
1015
1031
 
1016
1032
  if (Array.isArray(json) && json.length > 0) {
1017
1033
  json.forEach((item, index) => {
@@ -1044,7 +1060,7 @@ const isQuestionType = result => {
1044
1060
  };
1045
1061
 
1046
1062
  const ask$1 = templateDir => (files, metalsmith, next) => {
1047
- const prompts = parseTemplateQuestions(resolve$f(templateDir, TEMPLATE_TKIT_DIR$1));
1063
+ const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
1048
1064
  const metadata = metalsmith.metadata();
1049
1065
  const filteredPrompts = prompts.filter(prompt => {
1050
1066
  if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
@@ -1053,7 +1069,7 @@ const ask$1 = templateDir => (files, metalsmith, next) => {
1053
1069
 
1054
1070
  return true;
1055
1071
  });
1056
- inquirer$1.prompt(filteredPrompts).then(res => {
1072
+ inquirer$2.prompt(filteredPrompts).then(res => {
1057
1073
  for (const prompt of filteredPrompts) {
1058
1074
  metadata[prompt.name] = res[prompt.name];
1059
1075
  }
@@ -1069,7 +1085,7 @@ var ask_1 = ask$1;
1069
1085
  const FILES_TO_IGNORE$1 = ['node_modules'];
1070
1086
  var ignoreFiles = FILES_TO_IGNORE$1;
1071
1087
 
1072
- const Metalsmith = require$$0__default$6;
1088
+ const Metalsmith = require$$0__default$4;
1073
1089
  const render = render_1;
1074
1090
  const ask = ask_1;
1075
1091
  const FILES_TO_IGNORE = ignoreFiles;
@@ -1086,19 +1102,57 @@ const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolv
1086
1102
 
1087
1103
  var generator_1 = generator$1;
1088
1104
 
1089
- const path$b = require$$1__default$2;
1090
- const fs$e = require$$0__default$2;
1091
- const shelljs$6 = require$$0__default$3;
1092
- const inquirer = require$$1__default$4;
1105
+ const request$2 = require$$0__default$5;
1106
+ const shelljs$8 = require$$2__default;
1107
+ const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
1108
+
1109
+ function getGitUser() {
1110
+ const res = shelljs$8.exec('git config user.name', {
1111
+ async: false,
1112
+ silent: true
1113
+ });
1114
+ return res.stdout;
1115
+ }
1116
+
1117
+ const report$8 = (name, attrs = {}) => {
1118
+ try {
1119
+ const param = [];
1120
+ param[27] = name;
1121
+ param[28] = 'tmskit';
1122
+ param[29] = getGitUser();
1123
+ param[30] = JSON.stringify(attrs);
1124
+
1125
+ for (let i = 0; i < 40; i++) {
1126
+ if (!param[i]) param[i] = null;
1127
+ }
1128
+
1129
+ ;
1130
+ request$2.post({
1131
+ url: apiUrl,
1132
+ json: {
1133
+ param
1134
+ }
1135
+ }); // (error, response, body) => {
1136
+ // console.log('body:', body);
1137
+ // }
1138
+ } catch (e) {}
1139
+ };
1140
+
1141
+ var report_1 = report$8;
1142
+
1143
+ const path$c = require$$1__default$1;
1144
+ const fs$d = require$$0__default$1;
1145
+ const shelljs$7 = require$$2__default;
1146
+ const inquirer$1 = require$$1__default$4;
1093
1147
  const {
1094
1148
  TEMPLATE_DIR,
1095
1149
  TEMPLATE_URL,
1096
1150
  TEMPLATE_NAME,
1097
1151
  TEMPLATE_TKIT_DIR,
1098
1152
  CREATE_TEMPLATE_QUESTION
1099
- } = require$$5;
1153
+ } = constant;
1100
1154
  const {
1101
- resolve: resolve$e
1155
+ resolve: resolve$c
1102
1156
  } = widgets;
1103
1157
  const io$2 = io$3;
1104
1158
  const {
@@ -1107,8 +1161,9 @@ const {
1107
1161
  info: info$a
1108
1162
  } = log$1;
1109
1163
  const generator = generator_1;
1110
- const request = require$$9__default;
1164
+ const request$1 = require$$0__default$5;
1111
1165
  const unzip = require$$10__default;
1166
+ const report$7 = report_1;
1112
1167
  /**
1113
1168
  * 如果该目录下面存在文件,换个名字
1114
1169
  * @param { string } targetDir 当前文件夹
@@ -1117,13 +1172,13 @@ const unzip = require$$10__default;
1117
1172
 
1118
1173
  async function createProjectDir(targetDir) {
1119
1174
  // 如果目录非空或者已经存在,提示用户,做选择
1120
- if (fs$e.existsSync(targetDir)) {
1175
+ if (fs$d.existsSync(targetDir)) {
1121
1176
  if (!(await io$2.isDirEmpty(targetDir))) {
1122
1177
  fail$8('该目录名已经存在,换个项目名字吧~');
1123
1178
  process.exit(1);
1124
1179
  }
1125
1180
  } else {
1126
- shelljs$6.mkdir('-p', targetDir);
1181
+ shelljs$7.mkdir('-p', targetDir);
1127
1182
  }
1128
1183
  }
1129
1184
  /**
@@ -1138,14 +1193,14 @@ async function createProjectDir(targetDir) {
1138
1193
  function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1139
1194
  return new Promise((resolve, reject) => {
1140
1195
  const localZipPath = `${templateDir}/${templateName}.zip`;
1141
- const stream = fs$e.createWriteStream(localZipPath);
1142
- request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
1196
+ const stream = fs$d.createWriteStream(localZipPath);
1197
+ request$1(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
1143
1198
  if (err) {
1144
1199
  reject(err);
1145
1200
  return;
1146
1201
  }
1147
1202
 
1148
- fs$e.createReadStream(localZipPath).pipe(unzip.Extract({
1203
+ fs$d.createReadStream(localZipPath).pipe(unzip.Extract({
1149
1204
  path: templateDir
1150
1205
  })).on('close', err => {
1151
1206
  if (err) {
@@ -1167,45 +1222,51 @@ function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1167
1222
 
1168
1223
  async function create(projectName) {
1169
1224
  const cwd = process.cwd();
1170
- const targetDir = path$b.resolve(cwd, projectName);
1225
+ const targetDir = path$c.resolve(cwd, projectName);
1171
1226
  const {
1172
1227
  projectType
1173
- } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION); // 创建项目目录
1228
+ } = await inquirer$1.prompt(CREATE_TEMPLATE_QUESTION);
1229
+ report$7('create-start', {
1230
+ projectType
1231
+ }); // 创建项目目录
1174
1232
 
1175
1233
  await createProjectDir(targetDir); // 新创建缓存目录
1176
1234
 
1177
- if (fs$e.existsSync(TEMPLATE_DIR)) {
1178
- shelljs$6.rm('-rf', TEMPLATE_DIR);
1235
+ if (fs$d.existsSync(TEMPLATE_DIR)) {
1236
+ shelljs$7.rm('-rf', TEMPLATE_DIR);
1179
1237
  }
1180
1238
 
1181
- fs$e.mkdirSync(TEMPLATE_DIR, {
1239
+ fs$d.mkdirSync(TEMPLATE_DIR, {
1182
1240
  recursive: true
1183
1241
  }); // 下载和解压模板
1184
1242
 
1185
1243
  await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
1186
1244
 
1187
- generator(path$b.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1188
- shelljs$6.cd(projectName);
1189
- const hookFilePath = resolve$e(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1245
+ generator(path$c.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1246
+ shelljs$7.cd(projectName);
1247
+ const hookFilePath = resolve$c(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1190
1248
 
1191
- if (fs$e.existsSync(hookFilePath)) {
1249
+ if (fs$d.existsSync(hookFilePath)) {
1192
1250
  const hooks = require(hookFilePath);
1193
1251
 
1194
1252
  if (hooks.afterCreate) {
1195
1253
  hooks.afterCreate.forEach(item => {
1196
1254
  if (typeof item === 'function') {
1197
- item.call(null, shelljs$6, {
1255
+ item.call(null, shelljs$7, {
1198
1256
  projectName
1199
1257
  });
1200
1258
  } else {
1201
- shelljs$6.exec(item);
1259
+ shelljs$7.exec(item);
1202
1260
  }
1203
1261
  });
1204
1262
  }
1205
1263
 
1206
- shelljs$6.rm('-rf', resolve$e(projectName, TEMPLATE_TKIT_DIR));
1264
+ shelljs$7.rm('-rf', resolve$c(projectName, TEMPLATE_TKIT_DIR));
1207
1265
  }
1208
1266
 
1267
+ report$7('create-success', {
1268
+ projectType
1269
+ });
1209
1270
  succeed$1('项目创建完成.');
1210
1271
  }).catch(err => {
1211
1272
  fail$8(err.message);
@@ -1215,7 +1276,95 @@ async function create(projectName) {
1215
1276
 
1216
1277
  var create_1 = create;
1217
1278
 
1218
- const global$6 = {
1279
+ const fs$c = require$$0__default$1;
1280
+ const path$b = require$$1__default$1;
1281
+ const shellJs$1 = require$$2__default;
1282
+ const {
1283
+ ensureDirExist: ensureDirExist$3
1284
+ } = io$3;
1285
+ const {
1286
+ EXTEND_CMD
1287
+ } = constant;
1288
+ const {
1289
+ createTask: createTask$2
1290
+ } = widgets;
1291
+ const {
1292
+ info: info$9,
1293
+ fail: fail$7
1294
+ } = log$1;
1295
+ /**
1296
+ * 下载扩展命令的npm包
1297
+ * @param {string} npmName npm包名
1298
+ * @param {object} cmd {registry: 'http://mirrors.tencent.com/npm/'} 用户输入执行install-cmd的参数
1299
+ */
1300
+
1301
+ async function installCmd(npmName, cmd) {
1302
+ try {
1303
+ const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1304
+
1305
+ if (!fs$c.existsSync(cmdPackageJson)) {
1306
+ ensureDirExist$3(EXTEND_CMD);
1307
+ fs$c.writeFileSync(cmdPackageJson, JSON.stringify({
1308
+ dependencies: {}
1309
+ }, null, 2));
1310
+ }
1311
+
1312
+ shellJs$1.cd(EXTEND_CMD);
1313
+ await createTask$2(npmName => new Promise((resolve, reject) => {
1314
+ const registry = cmd.registry ? `--registry=${cmd.registry}` : '';
1315
+ shellJs$1.exec(`npm install --save ${npmName} ${registry}`, {
1316
+ cwd: EXTEND_CMD,
1317
+ silent: true
1318
+ }, (code, stdout, stderr) => {
1319
+ if (code !== 0) {
1320
+ reject(stderr);
1321
+ }
1322
+
1323
+ resolve();
1324
+ });
1325
+ }), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
1326
+ } catch (e) {
1327
+ fail$7('构建出现错误:');
1328
+ info$9(e);
1329
+ process.exit(1);
1330
+ }
1331
+ }
1332
+ /**
1333
+ * 加载扩展命令的npm包
1334
+ * @returns
1335
+ */
1336
+
1337
+
1338
+ function loadExtendCmd$1() {
1339
+ const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1340
+ const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
1341
+
1342
+ if (fs$c.existsSync(cmdPackageJson)) {
1343
+ const content = fs$c.readFileSync(cmdPackageJson, 'utf8');
1344
+ const json = JSON.parse(content);
1345
+ const deps = json.dependencies || {};
1346
+ const cmdConfigs = [];
1347
+ Object.keys(deps).forEach(name => {
1348
+ // 检索cmd的npm包
1349
+ if (!/^tmskit-cmd-|^@[^/]+\/tmskit-cmd-/.test(name)) return false;
1350
+ const cmdConfig = path$b.join(cmdNpmDir, name, 'tms.config.js');
1351
+
1352
+ if (fs$c.existsSync(cmdConfig)) {
1353
+ cmdConfigs.push(cmdConfig);
1354
+ }
1355
+ });
1356
+ return cmdConfigs;
1357
+ }
1358
+
1359
+ return [];
1360
+ }
1361
+
1362
+ var extendCmd = {
1363
+ installCmd,
1364
+ loadExtendCmd: loadExtendCmd$1
1365
+ };
1366
+
1367
+ const global$7 = {
1219
1368
  data: {},
1220
1369
 
1221
1370
  setData(...args) {
@@ -1237,30 +1386,30 @@ const global$6 = {
1237
1386
 
1238
1387
  };
1239
1388
  var global_1 = {
1240
- global: global$6
1389
+ global: global$7
1241
1390
  };
1242
1391
 
1243
1392
  const {
1244
- fail: fail$7
1393
+ fail: fail$6
1245
1394
  } = log$1;
1246
1395
  const {
1247
- global: global$5
1396
+ global: global$6
1248
1397
  } = global_1;
1249
1398
 
1250
1399
  function handleError$5(error, isQuit = false) {
1251
1400
  const errMsg = typeof error === 'object' ? error.message : error;
1252
1401
 
1253
1402
  if (isQuit) {
1254
- fail$7(errMsg);
1403
+ fail$6(errMsg);
1255
1404
  process.exit(1);
1256
1405
  }
1257
1406
 
1258
- const isDev = global$5.getData('isDev');
1407
+ const isDev = global$6.getData('isDev');
1259
1408
 
1260
1409
  if (isDev) {
1261
- fail$7(errMsg);
1410
+ fail$6(errMsg);
1262
1411
  } else {
1263
- fail$7(errMsg);
1412
+ fail$6(errMsg);
1264
1413
  process.exit(1);
1265
1414
  }
1266
1415
  }
@@ -1274,25 +1423,26 @@ var handleError_1 = {
1274
1423
  */
1275
1424
  /* eslint-disable no-param-reassign */
1276
1425
 
1277
- const fs$d = require$$0__default$2;
1426
+ const fs$b = require$$0__default$1;
1278
1427
  const {
1279
1428
  getSubPackages: getSubPackages$3,
1280
1429
  getModulesConfig
1281
1430
  } = tmsMpconfig.exports;
1282
1431
  const {
1283
- fail: fail$6,
1284
- info: info$9
1432
+ fail: fail$5,
1433
+ info: info$8
1285
1434
  } = log$1;
1286
1435
  const {
1287
- resolve: resolve$d,
1288
- filterField: filterField$3
1436
+ resolve: resolve$b,
1437
+ filterField: filterField$4
1289
1438
  } = widgets;
1290
1439
  const {
1291
1440
  handleError: handleError$4
1292
1441
  } = handleError_1;
1293
1442
  const {
1294
- global: global$4
1443
+ global: global$5
1295
1444
  } = global_1;
1445
+ const report$6 = report_1;
1296
1446
  /**
1297
1447
  * 更新appJson里面的主包配置
1298
1448
  * @param { object } appJson appJson信息
@@ -1300,7 +1450,7 @@ const {
1300
1450
  * @returns { object } appJson小程序主页配置信息
1301
1451
  */
1302
1452
 
1303
- function updateMainPackages(appJson, mainPackages = []) {
1453
+ function updateMainPackages(appJson, mainPackages) {
1304
1454
  let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
1305
1455
 
1306
1456
  if (foundMainPackages.length === 0) {
@@ -1311,7 +1461,7 @@ function updateMainPackages(appJson, mainPackages = []) {
1311
1461
 
1312
1462
  foundMainPackages.forEach(subpackage => {
1313
1463
  if (!subpackage.pages || !subpackage.pages.length) {
1314
- fail$6(`主包 ${subpackage} 不能没有 pages`);
1464
+ fail$5(`主包 ${subpackage} 不能没有 pages`);
1315
1465
  process.exit(-1);
1316
1466
  }
1317
1467
 
@@ -1336,12 +1486,12 @@ function updateMainPackages(appJson, mainPackages = []) {
1336
1486
 
1337
1487
 
1338
1488
  const getAppJsonContent = sourceAppJsonPath => {
1339
- if (!fs$d.existsSync(sourceAppJsonPath)) {
1340
- fail$6(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1489
+ if (!fs$b.existsSync(sourceAppJsonPath)) {
1490
+ fail$5(`当前路径 ${sourceAppJsonPath} 没找到app.json`);
1341
1491
  process.exit(1);
1342
1492
  }
1343
1493
 
1344
- const appJson = JSON.parse(fs$d.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1494
+ const appJson = JSON.parse(fs$b.readFileSync(sourceAppJsonPath), 'utf-8'); // 加入默认值
1345
1495
 
1346
1496
  appJson.subpackages = [];
1347
1497
  appJson.pages = [];
@@ -1386,7 +1536,7 @@ const fixAppJson = appJson => {
1386
1536
  appJson[key] = preloadRuleMap;
1387
1537
  }
1388
1538
  });
1389
- return filterField$3(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
1539
+ return filterField$4(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
1390
1540
  }); // 如果plugins重复,则错误提示
1391
1541
 
1392
1542
  const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
@@ -1420,7 +1570,7 @@ function buildOutputAppJson$2(tmsConfig, modules) {
1420
1570
 
1421
1571
  const subPackages = getSubPackages$3(modulesConfig); // 获取app.json的配置
1422
1572
 
1423
- const appJson = getAppJsonContent(resolve$d('./app.json')); // 更新app.json中的subpackages
1573
+ const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
1424
1574
 
1425
1575
  appJson.subpackages = subPackages;
1426
1576
  appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name)); // 处理appJson中重复||冲突的地方
@@ -1428,23 +1578,24 @@ function buildOutputAppJson$2(tmsConfig, modules) {
1428
1578
  fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
1429
1579
 
1430
1580
  updateMainPackages(appJson, tmsConfig.mainPackages);
1431
- fs$d.writeFileSync(resolve$d(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1581
+ fs$b.writeFileSync(resolve$b(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
1432
1582
 
1433
1583
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateAppJson) === 'function') {
1434
1584
  var _tmsConfig$hooks2;
1435
1585
 
1436
1586
  tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
1437
- tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
1587
+ tmsConfig: filterField$4(tmsConfig, ['gitAccount']),
1438
1588
  modules,
1439
1589
  appJson,
1440
- isDev: global$4.getData('isDev')
1590
+ isDev: global$5.getData('isDev')
1441
1591
  });
1592
+ report$6('hooks:updateAppJson');
1442
1593
  }
1443
1594
 
1444
1595
  return appJson;
1445
1596
  } catch (e) {
1446
1597
  handleError$4(`生成app.json出现错误: ${e}`);
1447
- info$9(e);
1598
+ info$8(e);
1448
1599
  }
1449
1600
  }
1450
1601
 
@@ -1455,24 +1606,24 @@ var buildAppJson = {
1455
1606
  /**
1456
1607
  * 下载第三方代码
1457
1608
  */
1458
- const MetalSmith = require$$0__default$6;
1609
+ const MetalSmith = require$$0__default$4;
1459
1610
  const crypto$2 = require$$1__default$5;
1460
1611
  const {
1461
1612
  downloadRepoForGit,
1462
1613
  pullRepoForGit,
1463
- resolve: resolve$c
1614
+ resolve: resolve$a
1464
1615
  } = widgets;
1465
1616
  const {
1466
- fail: fail$5,
1467
- info: info$8
1617
+ fail: fail$4,
1618
+ info: info$7
1468
1619
  } = log$1;
1469
- const fs$c = require$$0__default$2;
1470
- const shelljs$5 = require$$0__default$3;
1620
+ const fs$a = require$$0__default$1;
1621
+ const shelljs$6 = require$$2__default;
1471
1622
  const {
1472
1623
  handleError: handleError$3
1473
1624
  } = handleError_1;
1474
1625
  const {
1475
- global: global$3
1626
+ global: global$4
1476
1627
  } = global_1;
1477
1628
  /**
1478
1629
  * 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
@@ -1485,7 +1636,7 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1485
1636
  var _tmsConfig$gitAccount;
1486
1637
 
1487
1638
  // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
1488
- const tmsConfig = global$3.getData('tmsConfig');
1639
+ const tmsConfig = global$4.getData('tmsConfig');
1489
1640
  let gitUrl = httpRepoUrl;
1490
1641
  const {
1491
1642
  username = '',
@@ -1508,12 +1659,16 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
1508
1659
  */
1509
1660
 
1510
1661
 
1511
- function moveFile(sourceDir, targetDir, ignore = []) {
1512
- // 删除不是文件夹的文件
1662
+ function moveFile(sourceDir, targetDir, ignore) {
1663
+ if (fs$a.existsSync(targetDir)) {
1664
+ shelljs$6.rm('-rf', targetDir);
1665
+ } // 删除不是文件夹的文件
1666
+
1667
+
1513
1668
  return new Promise((resolve, reject) => {
1514
1669
  MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
1515
1670
  if (e) {
1516
- fail$5(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1671
+ fail$4(`${sourceDir} moveFile ${targetDir}出现错误: ${e}`);
1517
1672
  reject(e);
1518
1673
  }
1519
1674
 
@@ -1566,7 +1721,7 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
1566
1721
  }));
1567
1722
  });
1568
1723
  await Promise.all(arrPromises);
1569
- shelljs$5.cd(cwd);
1724
+ shelljs$6.cd(cwd);
1570
1725
  }
1571
1726
  /**
1572
1727
  * 收集下载模块代码的任务
@@ -1607,9 +1762,9 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1607
1762
 
1608
1763
  const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
1609
1764
 
1610
- const sourcePath = resolve$c(sourceDir, md5Key); // 模块源码要放到目标目录
1765
+ const sourcePath = resolve$a(sourceDir, md5Key); // 模块源码要放到目标目录
1611
1766
 
1612
- const targetPath = resolve$c(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1767
+ const targetPath = resolve$a(targetDir, path); // 从git源码仓库中找到模块源码路径 (一个仓库存在存放多个模块的情况)
1613
1768
 
1614
1769
  const sourceModulePath = gitPath ? `${sourcePath}/${gitPath}` : sourcePath; // 下载完代码后,添加回调函数(主要将模块代码从临时目录移动代码到目标目录)
1615
1770
 
@@ -1619,8 +1774,8 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1619
1774
  targetPath
1620
1775
  },
1621
1776
  fn: async (sourceModulePath, targetPath) => {
1622
- if (fs$c.existsSync(targetPath)) {
1623
- shelljs$5.rm('-rf', `${targetPath}/*`);
1777
+ if (fs$a.existsSync(targetPath)) {
1778
+ shelljs$6.rm('-rf', `${targetPath}/*`);
1624
1779
  }
1625
1780
 
1626
1781
  await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
@@ -1634,14 +1789,14 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
1634
1789
  } else {
1635
1790
  let promiseTask;
1636
1791
 
1637
- if (fs$c.existsSync(sourcePath) && fs$c.existsSync(`${sourcePath}/.git`)) {
1792
+ if (fs$a.existsSync(sourcePath) && fs$a.existsSync(`${sourcePath}/.git`)) {
1638
1793
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1639
- info$8(`git pull:${httpRepoUrl}`);
1794
+ info$7(`git pull:${httpRepoUrl}`);
1640
1795
  return pullRepoForGit(sourcePath, branch);
1641
1796
  };
1642
1797
  } else {
1643
1798
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
1644
- info$8(`git clone: ${httpRepoUrl}`);
1799
+ info$7(`git clone: ${httpRepoUrl}`);
1645
1800
  return downloadRepoForGit(gitUrl, sourcePath, branch);
1646
1801
  };
1647
1802
  }
@@ -1682,7 +1837,7 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
1682
1837
  const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
1683
1838
  const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
1684
1839
 
1685
- if (!fs$c.existsSync(`${sourceDir}/${md5Key}`)) {
1840
+ if (!fs$a.existsSync(`${sourceDir}/${md5Key}`)) {
1686
1841
  return true;
1687
1842
  }
1688
1843
  }
@@ -1695,8 +1850,8 @@ var cloneModules_1 = {
1695
1850
  checkRemoteModGitUrlBranch
1696
1851
  };
1697
1852
 
1698
- const ci = require$$0__default$7;
1699
- const path$a = require$$1__default$2;
1853
+ const ci = require$$0__default$6;
1854
+ const path$a = require$$1__default$1;
1700
1855
  /**
1701
1856
  * 获取小程序ci的Project对象
1702
1857
  * @returns {Object} 小程序ci对象
@@ -1776,22 +1931,21 @@ var mpCi = {
1776
1931
  buildMpNpm: buildMpNpm$1
1777
1932
  };
1778
1933
 
1779
- const fs$b = require$$0__default$2;
1780
- const path$9 = require$$1__default$2;
1934
+ const fs$9 = require$$0__default$1;
1935
+ const path$9 = require$$1__default$1;
1781
1936
  const {
1782
- CACHE_FILE,
1783
- CACHE_DIR: CACHE_DIR$2
1784
- } = require$$5;
1937
+ NPM_CACHE_FILE
1938
+ } = constant;
1785
1939
  const {
1786
- ensureDirExist: ensureDirExist$1
1940
+ ensureDirExist: ensureDirExist$2
1787
1941
  } = io$3;
1788
1942
 
1789
1943
  function getCache$1(projectDir, type) {
1790
1944
  var _content$projectDir;
1791
1945
 
1792
- const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
1946
+ const filePath = NPM_CACHE_FILE;
1793
1947
 
1794
- if (!fs$b.existsSync(filePath)) {
1948
+ if (!fs$9.existsSync(filePath)) {
1795
1949
  return null;
1796
1950
  }
1797
1951
 
@@ -1801,12 +1955,12 @@ function getCache$1(projectDir, type) {
1801
1955
  }
1802
1956
 
1803
1957
  function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1804
- const filePath = `${CACHE_DIR$2}/${CACHE_FILE}`;
1958
+ const filePath = NPM_CACHE_FILE;
1805
1959
 
1806
- if (!fs$b.existsSync(filePath)) {
1960
+ if (!fs$9.existsSync(filePath)) {
1807
1961
  const dir = path$9.dirname(filePath);
1808
- ensureDirExist$1(dir);
1809
- fs$b.writeFileSync(filePath, '{}');
1962
+ ensureDirExist$2(dir);
1963
+ fs$9.writeFileSync(filePath, '{}');
1810
1964
  }
1811
1965
 
1812
1966
  const content = require(filePath);
@@ -1818,7 +1972,7 @@ function setCache$1(projectDir, type = 'miniprogram_npm', data) {
1818
1972
  content[projectDir] = {
1819
1973
  [type]: data
1820
1974
  };
1821
- fs$b.writeFileSync(filePath, JSON.stringify(content, null, 2));
1975
+ fs$9.writeFileSync(filePath, JSON.stringify(content, null, 2));
1822
1976
  }
1823
1977
 
1824
1978
  var cache = {
@@ -1829,12 +1983,11 @@ var cache = {
1829
1983
  /**
1830
1984
  * 本文件主要负责项目或者分包依赖的npm的安装
1831
1985
  */
1832
- const fs$a = require$$0__default$2;
1986
+ const fs$8 = require$$0__default$1;
1833
1987
  const fsExtra = require$$1__default$6;
1834
1988
  const crypto$1 = require$$1__default$5;
1835
- const path$8 = require$$1__default$2;
1836
- const shell = require$$0__default$3;
1837
- const glob = require$$6__default;
1989
+ const path$8 = require$$1__default$1;
1990
+ const shell = require$$2__default;
1838
1991
  const log = log$1;
1839
1992
  const {
1840
1993
  npmInstall: npmInstall$1
@@ -1842,6 +1995,9 @@ const {
1842
1995
  const {
1843
1996
  handleError: handleError$2
1844
1997
  } = handleError_1;
1998
+ const {
1999
+ global: global$3
2000
+ } = global_1;
1845
2001
  const shellJsOption = {
1846
2002
  async: false,
1847
2003
  silent: true
@@ -1864,7 +2020,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1864
2020
  const npmTasksMap = new Map();
1865
2021
 
1866
2022
  for (const packageJsonPath of packageJsonFiles) {
1867
- const packageContent = fs$a.readFileSync(packageJsonPath);
2023
+ const packageContent = fs$8.readFileSync(packageJsonPath);
1868
2024
  let packageJson;
1869
2025
 
1870
2026
  try {
@@ -1915,7 +2071,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
1915
2071
  fsExtra.emptydirSync(cacheNMPath);
1916
2072
  shell.cp('-f', packageJsonPath, cacheNMPath);
1917
2073
  log.info(`npm install: ${packageJsonPath}`);
1918
- return npmInstall$1(cacheNMPath).then(() => {
2074
+ const tmsConfig = global$3.getData('tmsConfig');
2075
+ return npmInstall$1(cacheNMPath, tmsConfig.npm).then(() => {
1919
2076
  const newShellJsOption = { ...shellJsOption,
1920
2077
  cwd: cacheNMPath
1921
2078
  };
@@ -1988,7 +2145,7 @@ const findFilesByFilter = (startPath, filter) => {
1988
2145
 
1989
2146
  const find = (startPath, filter) => {
1990
2147
  // 目录不存在
1991
- if (!fs$a.existsSync(startPath)) {
2148
+ if (!fs$8.existsSync(startPath)) {
1992
2149
  log.fail(`${startPath}目录不存在`);
1993
2150
  process.exit(-1);
1994
2151
  return;
@@ -2001,10 +2158,10 @@ const findFilesByFilter = (startPath, filter) => {
2001
2158
  return;
2002
2159
  }
2003
2160
 
2004
- const files = fs$a.readdirSync(startPath);
2161
+ const files = fs$8.readdirSync(startPath);
2005
2162
  files.forEach(file => {
2006
2163
  const filename = path$8.join(startPath, file);
2007
- const stat = fs$a.lstatSync(filename); // 当前文件是文件夹类型,继续递归
2164
+ const stat = fs$8.lstatSync(filename); // 当前文件是文件夹类型,继续递归
2008
2165
 
2009
2166
  if (stat.isDirectory()) {
2010
2167
  find(filename, filter);
@@ -2041,39 +2198,19 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
2041
2198
  return result;
2042
2199
  };
2043
2200
 
2044
- function cloudNpmInstall(contextDir) {
2045
- return new Promise((resolve, reject) => {
2046
- glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
2047
- if (err) {
2048
- reject(err);
2049
- }
2050
-
2051
- files.forEach(file => {
2052
- const dir = path$8.dirname(file);
2053
- shell.cd(dir);
2054
- shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
2055
- silent: false
2056
- });
2057
- });
2058
- resolve();
2059
- });
2060
- });
2061
- }
2062
-
2063
2201
  var npm = {
2064
- cloudNpmInstall,
2065
2202
  npmInstallAll: npmInstallAll$1,
2066
2203
  findAllPackageJson,
2067
2204
  findFilesByFilter
2068
2205
  };
2069
2206
 
2070
2207
  const crypto = require$$1__default$5;
2071
- const fs$9 = require$$0__default$2;
2208
+ const fs$7 = require$$0__default$1;
2072
2209
 
2073
2210
  function fileMd5$1(filePath) {
2074
2211
  return new Promise((resolve, reject) => {
2075
2212
  const md5sum = crypto.createHash('md5');
2076
- const stream = fs$9.ReadStream(filePath);
2213
+ const stream = fs$7.ReadStream(filePath);
2077
2214
  stream.on('data', d => {
2078
2215
  md5sum.update(d);
2079
2216
  });
@@ -2091,21 +2228,26 @@ var md5 = {
2091
2228
  fileMd5: fileMd5$1
2092
2229
  };
2093
2230
 
2094
- const fs$8 = require$$0__default$2;
2231
+ const fs$6 = require$$0__default$1;
2095
2232
  const semver$1 = require$$1__default$7;
2096
2233
  const {
2097
- resolve: resolve$b,
2234
+ resolve: resolve$9,
2098
2235
  getAbsolutePath: getAbsolutePath$2
2099
2236
  } = widgets;
2100
- const path$7 = require$$1__default$2;
2101
- const shelljs$4 = require$$0__default$3;
2237
+ const path$7 = require$$1__default$1;
2238
+ const shelljs$5 = require$$2__default;
2102
2239
  const {
2103
2240
  handleError: handleError$1
2104
2241
  } = handleError_1;
2105
2242
 
2106
2243
  const getLatestVersion = npmName => {
2107
- const data = shelljs$4.exec(`npm view ${npmName} version`);
2108
- return data.stdout || '0.0.0';
2244
+ const data = shelljs$5.exec(`npm view ${npmName} version`);
2245
+
2246
+ if (data.code === 0) {
2247
+ return data.stdout;
2248
+ }
2249
+
2250
+ return '0.0.0';
2109
2251
  }; // 收集package.json
2110
2252
 
2111
2253
 
@@ -2115,16 +2257,16 @@ function collectPackageJson(subPackages, cwd, outputDir) {
2115
2257
 
2116
2258
  const packageArr = [{
2117
2259
  srcPackageDir: path$7.join(cwd, packageJsonName),
2118
- destNpmDir: resolve$b(outputDir, 'node_modules')
2260
+ destNpmDir: resolve$9(outputDir, 'node_modules')
2119
2261
  }]; // 1.2模块的package.json
2120
2262
 
2121
2263
  subPackages.forEach(item => {
2122
2264
  const srcPackageDir = `${getAbsolutePath$2(item.path)}/package.json`;
2123
2265
 
2124
- if (fs$8.existsSync(srcPackageDir)) {
2266
+ if (fs$6.existsSync(srcPackageDir)) {
2125
2267
  packageArr.push({
2126
2268
  srcPackageDir,
2127
- destNpmDir: resolve$b(outputDir, item.root, 'node_modules')
2269
+ destNpmDir: resolve$9(outputDir, item.root, 'node_modules')
2128
2270
  });
2129
2271
  }
2130
2272
  });
@@ -2133,7 +2275,7 @@ function collectPackageJson(subPackages, cwd, outputDir) {
2133
2275
 
2134
2276
 
2135
2277
  function readPackageDependencies(srcPackageDir) {
2136
- const packageJson = fs$8.readFileSync(srcPackageDir, 'utf-8');
2278
+ const packageJson = fs$6.readFileSync(srcPackageDir, 'utf-8');
2137
2279
  let dependencies = {};
2138
2280
 
2139
2281
  try {
@@ -2170,13 +2312,13 @@ const checkPackageVersion$1 = packageArr => {
2170
2312
  for (const key of dependenciesKeys) {
2171
2313
  const depPath = path$7.join(item.destNpmDir, key);
2172
2314
 
2173
- if (!fs$8.existsSync(depPath)) {
2315
+ if (!fs$6.existsSync(depPath)) {
2174
2316
  return true;
2175
2317
  }
2176
2318
 
2177
2319
  const depPackagePath = path$7.join(depPath, 'package.json');
2178
2320
 
2179
- if (fs$8.existsSync(depPackagePath)) {
2321
+ if (fs$6.existsSync(depPackagePath)) {
2180
2322
  const packageData = require(depPackagePath);
2181
2323
 
2182
2324
  if (dependencies[key] === 'latest') {
@@ -2202,13 +2344,13 @@ var checkDependencies = {
2202
2344
  checkPackageVersion: checkPackageVersion$1
2203
2345
  };
2204
2346
 
2205
- const shelljs$3 = require$$0__default$3;
2206
- const fs$7 = require$$0__default$2;
2207
- const path$6 = require$$1__default$2;
2347
+ const shelljs$4 = require$$2__default;
2348
+ const fs$5 = require$$0__default$1;
2349
+ const path$6 = require$$1__default$1;
2208
2350
  const io$1 = io$3;
2209
2351
  const {
2210
2352
  createTask: createTask$1,
2211
- resolve: resolve$a,
2353
+ resolve: resolve$8,
2212
2354
  getAbsolutePath: getAbsolutePath$1
2213
2355
  } = widgets;
2214
2356
  const {
@@ -2219,13 +2361,13 @@ const {
2219
2361
  getCache
2220
2362
  } = cache;
2221
2363
  const {
2222
- CACHE_DIR: CACHE_DIR$1
2223
- } = require$$5;
2364
+ NODE_MODULES_DIR: NODE_MODULES_DIR$1
2365
+ } = constant;
2224
2366
  const {
2225
2367
  npmInstallAll
2226
2368
  } = npm;
2227
2369
  const {
2228
- info: info$7
2370
+ info: info$6
2229
2371
  } = log$1;
2230
2372
  const {
2231
2373
  fileMd5
@@ -2234,7 +2376,7 @@ const {
2234
2376
  isDependenciesUpdate
2235
2377
  } = checkDependencies;
2236
2378
 
2237
- async function install$2(tmsConfig, subPackages, useCache = true) {
2379
+ async function install$2(tmsConfig, subPackages, useCache) {
2238
2380
  const cwd = process.cwd();
2239
2381
  const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
2240
2382
 
@@ -2246,13 +2388,13 @@ async function install$2(tmsConfig, subPackages, useCache = true) {
2246
2388
  await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
2247
2389
  }
2248
2390
 
2249
- shelljs$3.cd(cwd);
2391
+ shelljs$4.cd(cwd);
2250
2392
  }
2251
2393
 
2252
2394
  async function npmInstall(tmsConfig, subPackages, useCache) {
2253
2395
  // 如果依赖没有更新和使用缓存数据(则命中缓存)
2254
- if (!isDependenciesUpdate(subPackages, resolve$a('./'), tmsConfig.outputDir) && useCache) {
2255
- info$7('node_modules命中缓存');
2396
+ if (!isDependenciesUpdate(subPackages, resolve$8('./'), tmsConfig.outputDir) && useCache) {
2397
+ info$6('node_modules命中缓存');
2256
2398
  return {
2257
2399
  isCache: true
2258
2400
  };
@@ -2260,12 +2402,12 @@ async function npmInstall(tmsConfig, subPackages, useCache) {
2260
2402
 
2261
2403
 
2262
2404
  subPackages.forEach(item => {
2263
- const outputModuleDir = resolve$a(`${tmsConfig.outputDir}/${item.root}`);
2405
+ const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
2264
2406
  io$1.ensureDirExist(outputModuleDir);
2265
2407
  const modulePackagePath = `${getAbsolutePath$1(item.path)}/package.json`;
2266
- if (fs$7.existsSync(modulePackagePath)) shelljs$3.cp('-Rf', modulePackagePath, outputModuleDir);
2408
+ if (fs$5.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
2267
2409
  });
2268
- await npmInstallAll(subPackages, resolve$a(tmsConfig.outputDir), `${CACHE_DIR$1}/node_modules`);
2410
+ await npmInstallAll(subPackages, resolve$8(tmsConfig.outputDir), NODE_MODULES_DIR$1);
2269
2411
  return {
2270
2412
  isCache: false
2271
2413
  };
@@ -2274,16 +2416,16 @@ async function npmInstall(tmsConfig, subPackages, useCache) {
2274
2416
 
2275
2417
  async function mpCiInstall(tmsConfig, subPackages, useCache) {
2276
2418
  const packageJsonFiles = [];
2277
- const rootPackFile = resolve$a(`${tmsConfig.outputDir}/package.json`);
2419
+ const rootPackFile = resolve$8(`${tmsConfig.outputDir}/package.json`);
2278
2420
 
2279
- if (fs$7.existsSync(rootPackFile)) {
2421
+ if (fs$5.existsSync(rootPackFile)) {
2280
2422
  packageJsonFiles.push(rootPackFile);
2281
2423
  }
2282
2424
 
2283
2425
  subPackages.forEach(item => {
2284
- const packageJsonFile = resolve$a(`${tmsConfig.outputDir}/${item.root}/package.json`);
2426
+ const packageJsonFile = resolve$8(`${tmsConfig.outputDir}/${item.root}/package.json`);
2285
2427
 
2286
- if (fs$7.existsSync(packageJsonFile)) {
2428
+ if (fs$5.existsSync(packageJsonFile)) {
2287
2429
  packageJsonFiles.push(packageJsonFile);
2288
2430
  }
2289
2431
  });
@@ -2297,7 +2439,7 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2297
2439
  let flag = true;
2298
2440
  await Promise.all(packageJsonFiles.map(async item => {
2299
2441
  const packageDir = path$6.dirname(item);
2300
- const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2442
+ const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2301
2443
  const md5Value = await getMNPMd5(packageDir);
2302
2444
  const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
2303
2445
  // 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
@@ -2310,14 +2452,14 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2310
2452
  }
2311
2453
 
2312
2454
  if (isCache) {
2313
- info$7('miniprogram_npm命中缓存');
2455
+ info$6('miniprogram_npm命中缓存');
2314
2456
  return;
2315
2457
  } // 即将构建,在cache中标记开始
2316
2458
 
2317
2459
 
2318
2460
  await Promise.all(packageJsonFiles.map(async item => {
2319
2461
  const packageDir = path$6.dirname(item);
2320
- const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2462
+ const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2321
2463
  setCache(mpDir, 'miniprogram_npm', {
2322
2464
  md5: '',
2323
2465
  status: statusMap.doing
@@ -2325,13 +2467,13 @@ async function mpCiInstall(tmsConfig, subPackages, useCache) {
2325
2467
  }));
2326
2468
  await buildMpNpm({
2327
2469
  appId: tmsConfig.appId,
2328
- projectPath: resolve$a('./'),
2470
+ projectPath: resolve$8('./'),
2329
2471
  privateKey: tmsConfig.privateKey
2330
2472
  }); // 构建成功后,计算md5写入cache
2331
2473
 
2332
2474
  await Promise.all(packageJsonFiles.map(async item => {
2333
2475
  const packageDir = path$6.dirname(item);
2334
- const mpDir = resolve$a(`${packageDir}/miniprogram_npm`);
2476
+ const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
2335
2477
  const md5Value = await getMNPMd5(packageDir);
2336
2478
  setCache(mpDir, 'miniprogram_npm', {
2337
2479
  md5: md5Value,
@@ -2346,16 +2488,16 @@ async function getMNPMd5(cwd) {
2346
2488
  async: false,
2347
2489
  silent: true
2348
2490
  };
2349
- shelljs$3.cd(cwd);
2491
+ shelljs$4.cd(cwd);
2350
2492
 
2351
- if (fs$7.existsSync('miniprogram_npm')) {
2352
- shelljs$3.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
2493
+ if (fs$5.existsSync('miniprogram_npm')) {
2494
+ shelljs$4.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
2353
2495
  cwd,
2354
2496
  ...shellJsOption
2355
2497
  });
2356
2498
  const tarDir = path$6.join(cwd, './miniprogram_npm.tar.gz');
2357
2499
  const md5Value = await fileMd5(tarDir);
2358
- shelljs$3.rm('-rf', tarDir);
2500
+ shelljs$4.rm('-rf', tarDir);
2359
2501
  return md5Value;
2360
2502
  }
2361
2503
 
@@ -2364,20 +2506,20 @@ async function getMNPMd5(cwd) {
2364
2506
 
2365
2507
  var install_1 = install$2;
2366
2508
 
2367
- const shelljs$2 = require$$0__default$3;
2368
- const fs$6 = require$$0__default$2;
2509
+ const shelljs$3 = require$$2__default;
2510
+ const fs$4 = require$$0__default$1;
2369
2511
  const io = io$3;
2370
2512
  const {
2371
- resolve: resolve$9,
2513
+ resolve: resolve$7,
2372
2514
  createTask
2373
2515
  } = widgets;
2374
2516
  const {
2375
2517
  buildOutputAppJson: buildOutputAppJson$1
2376
2518
  } = buildAppJson;
2377
2519
  const {
2378
- MODULE_CODE_DIR,
2520
+ MODULE_CODE_DIR: MODULE_CODE_DIR$1,
2379
2521
  DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
2380
- } = require$$5;
2522
+ } = constant;
2381
2523
  const {
2382
2524
  cloneModules
2383
2525
  } = cloneModules_1;
@@ -2386,8 +2528,8 @@ const {
2386
2528
  getSubPackages: getSubPackages$2
2387
2529
  } = tmsMpconfig.exports;
2388
2530
  const {
2389
- fail: fail$4,
2390
- info: info$6
2531
+ fail: fail$3,
2532
+ info: info$5
2391
2533
  } = log$1;
2392
2534
  const install$1 = install_1;
2393
2535
  /**
@@ -2399,18 +2541,18 @@ const install$1 = install_1;
2399
2541
  */
2400
2542
 
2401
2543
  const cpFilesToOutput = function (tmsConfig, defaultFiles) {
2402
- const outputDir = resolve$9(tmsConfig.outputDir);
2544
+ const outputDir = resolve$7(tmsConfig.outputDir);
2403
2545
  io.ensureDirExist(outputDir);
2404
2546
  defaultFiles.forEach(item => {
2405
- if (fs$6.existsSync(resolve$9(item))) {
2406
- shelljs$2.cp('-rf', resolve$9(item), resolve$9(tmsConfig.outputDir, item));
2547
+ if (fs$4.existsSync(resolve$7(item))) {
2548
+ shelljs$3.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
2407
2549
  }
2408
2550
  });
2409
2551
  };
2410
2552
 
2411
2553
  async function task(tmsConfig, targetModules) {
2412
2554
  // 下载和移动代码
2413
- await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$9('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2555
+ await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$7('./'), targetModules); // 获取所有模块,合并模块依赖的模块
2414
2556
 
2415
2557
  const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
2416
2558
 
@@ -2433,8 +2575,8 @@ async function init$3(tmsConfig, targetModules) {
2433
2575
  return taskRes;
2434
2576
  } catch (error) {
2435
2577
  const errMsg = typeof error === 'object' ? error.message : error;
2436
- fail$4(`初始化流程出现错误: ${errMsg}`);
2437
- info$6('详细的错误信息', error);
2578
+ fail$3(`初始化流程出现错误: ${errMsg}`);
2579
+ info$5('详细的错误信息', error);
2438
2580
  process.exit(1);
2439
2581
  }
2440
2582
  }
@@ -2442,722 +2584,111 @@ async function init$3(tmsConfig, targetModules) {
2442
2584
  var init_1 = init$3;
2443
2585
 
2444
2586
  /* eslint-disable no-param-reassign */
2445
- const strip = require$$0__default$8; // 匹配规则
2446
-
2447
- const MATCH_RULE = new RegExp(/@import *(?:url\(['"]?([^'")]+)['"]?\)|['"]([^'"]+)['"]);?/g);
2448
- /**
2449
- * 获取样式文件中的@import语句
2450
- * @param code 代码片段
2451
- * @returns 结果数组
2452
- */
2453
-
2454
- const findCssImports$1 = code => {
2455
- // 将buffer转成字符串
2456
- code = code.toString(); // 去除注释
2457
-
2458
- code = strip.block(code); // 定义最后返回的结果
2459
-
2460
- const result = [];
2461
- let matchList; // 循环遍历代码段,直至匹配结果为空
2462
-
2463
- while (matchList = MATCH_RULE.exec(code)) {
2464
- var _matchList, _matchList2;
2465
-
2466
- // 存入结果数组
2467
- result.push(((_matchList = matchList) === null || _matchList === void 0 ? void 0 : _matchList[1]) || ((_matchList2 = matchList) === null || _matchList2 === void 0 ? void 0 : _matchList2[2]));
2468
- } // 返回结果
2469
-
2470
-
2471
- return result;
2472
- };
2473
-
2474
- var findCssImport = {
2475
- findCssImports: findCssImports$1
2476
- };
2477
-
2478
- /* eslint-disable no-param-reassign */
2479
- const {
2480
- fail: fail$3
2481
- } = log$1;
2482
2587
 
2483
- function pluginError$3(error, isWatch) {
2484
- const errMsg = error.message;
2588
+ function mpProjectJson$1() {
2589
+ return function ({
2590
+ file,
2591
+ cb
2592
+ }) {
2593
+ if (file.isBuffer()) {
2594
+ let contents = String(file.contents);
2595
+ contents = contents.replace(/"miniprogramRoot"[^,]+,/g, '');
2596
+ file.contents = Buffer.from(contents);
2597
+ }
2485
2598
 
2486
- if (isWatch) {
2487
- fail$3(errMsg);
2488
- } else {
2489
- fail$3(errMsg);
2490
- process.exit(1);
2491
- }
2599
+ cb();
2600
+ };
2492
2601
  }
2493
2602
 
2494
- var pluginError_1 = {
2495
- pluginError: pluginError$3
2496
- };
2603
+ var mpProjectJson_1 = mpProjectJson$1;
2497
2604
 
2498
- /* eslint-disable no-param-reassign */
2499
- const through$2 = require$$0__default$9;
2500
- const precinct = require$$1__default$8;
2501
- const path$5 = require$$1__default$2;
2502
2605
  const {
2503
- findCssImports
2504
- } = findCssImport;
2505
- const {
2506
- ext: ext$2,
2507
- fileInDir: fileInDir$2,
2508
- diffContentCopyFile: diffContentCopyFile$2
2509
- } = io$3;
2606
+ src: src$1,
2607
+ dest
2608
+ } = require$$0__default$7;
2609
+ const path$5 = require$$1__default$1;
2610
+ const minimatch = require$$2__default$1;
2611
+ const gulpif = require$$3__default$1;
2612
+ const mpProjectJson = mpProjectJson_1;
2510
2613
  const {
2511
- resolve: resolve$8
2614
+ resolve: resolve$6
2512
2615
  } = widgets;
2513
- const fs$5 = require$$0__default$2;
2616
+ const through = require$$6__default;
2514
2617
  const {
2515
- pluginError: pluginError$2
2516
- } = pluginError_1;
2517
- const cssFilter = ['.less', '.wxss'];
2518
-
2519
- const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensions, isWatch = true) {
2520
- const resDep = new Map();
2521
-
2522
- function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
2523
- let contents = '';
2524
-
2525
- try {
2526
- contents = fs$5.readFileSync(anaFileOriginFile, 'utf8');
2527
- } catch (e) {
2528
- pluginError$2(e, isWatch);
2529
- }
2530
-
2531
- const deps = cssFilter.indexOf(path$5.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
2532
- deps.forEach(depItem => {
2533
- if (depItem.startsWith('.')) {
2534
- // 被依赖文件的存在的绝对路径
2535
- const depOriginPath = path$5.join(path$5.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2536
-
2537
- const {
2538
- ext: extAlias,
2539
- file: depOriginFile,
2540
- extPath
2541
- } = ext$2(depOriginPath, extensions);
2542
-
2543
- if (!fs$5.existsSync(depOriginFile)) {
2544
- pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
2545
- return;
2546
- }
2618
+ fail: fail$2
2619
+ } = log$1;
2547
2620
 
2548
- const depDestPath = resolve$8(path$5.dirname(anaFileDestFile), depItem);
2549
- const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2621
+ const getTargetFile$1 = (sourceFile, module, outputDir) => {
2622
+ const sourceFileRelativeModule = path$5.relative(resolve$6(module.from), sourceFile);
2623
+ const targetFile = resolve$6(outputDir, module.to, sourceFileRelativeModule);
2624
+ return targetFile;
2625
+ };
2550
2626
 
2551
- if (!resDep.has(depDestFile)) {
2552
- resDep.set(depDestFile, {
2553
- anaFileOriginFile,
2554
- anaFileDestFile,
2555
- depDestFile,
2556
- depOriginFile
2557
- });
2558
- dfs(depOriginFile, depDestFile, extensions);
2559
- }
2560
- }
2627
+ const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
2628
+ const {
2629
+ plugins = []
2630
+ } = tmsConfig;
2631
+ const newPlugins = [{
2632
+ glob: '**/project.config.json',
2633
+ action: mpProjectJson()
2634
+ }, ...plugins];
2635
+ return newPlugins.reduce((srcPipe, pluginItem) => srcPipe.pipe(gulpif(file => minimatch(file.path, pluginItem.glob), through.obj(function (file, enc, cb) {
2636
+ const sourceFile = file.history[0];
2637
+ pluginItem.action({
2638
+ tmsConfig,
2639
+ sourceFile,
2640
+ file,
2641
+ targetFile: getTargetFile$1(sourceFile, pluginParams.module, tmsConfig.outputDir),
2642
+ isDev: pluginParams.isDev,
2643
+ cb
2561
2644
  });
2562
- }
2563
-
2564
- dfs(anaFileOriginFile, anaFileDestFile, extensions);
2565
- return resDep;
2645
+ this.push(file);
2646
+ }))), srcPipe);
2566
2647
  };
2567
2648
 
2568
- function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
2569
- const stream = through$2.obj(function (file, enc, cb) {
2570
- // 依赖分析的文件
2571
- const anaFileOriginFile = file.history[0];
2572
- const anaFileRelativeModule = path$5.relative(resolve$8(module.from), anaFileOriginFile);
2573
- const anaFileDestFile = resolve$8(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2574
-
2575
- if (file.isBuffer()) {
2576
- let contents = String(file.contents);
2577
- const deps = cssFilter.indexOf(path$5.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
2578
- const copyModules = new Map();
2579
- Object.keys(tmsConfig.dependencies).forEach(includeName => {
2580
- const includePath = tmsConfig.dependencies[includeName];
2581
- deps.forEach(depItem => {
2582
- if (depItem.indexOf(includeName) > -1) {
2583
- // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
2584
- const depOriginPath = path$5.join(path$5.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
2585
-
2586
- const {
2587
- ext: extAlias,
2588
- file: depOriginFile,
2589
- extPath
2590
- } = ext$2(depOriginPath, extensions);
2591
-
2592
- if (!fileInDir$2(includePath, depOriginFile)) {
2593
- pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
2594
- return;
2595
- } // eslint-disable-next-line
2596
-
2597
-
2598
- const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
2599
- const regRes = depItem.match(reg) || [];
2600
-
2601
- if (regRes[2]) {
2602
- const depDestPath = resolve$8(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2603
- const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2604
-
2605
- if (!copyModules.has(depDestFile)) {
2606
- copyModules.set(depDestFile, {
2607
- depOriginFile,
2608
- depDestFile,
2609
- beforeDepPath: depItem,
2610
- afterDepPath: path$5.relative(path$5.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2611
- });
2612
- }
2613
- }
2614
- }
2615
- });
2616
- }); // console.log('mpCommonDep copyModules', copyModules);
2617
-
2618
- copyModules.forEach(({
2619
- depOriginFile,
2620
- depDestFile,
2621
- beforeDepPath,
2622
- afterDepPath
2623
- }) => {
2624
- diffContentCopyFile$2(depOriginFile, depDestFile);
2625
- const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
2626
- contents = contents.replace(reg, `"${afterDepPath}"`);
2627
- const defs = dfsFindCommonDep$2(depOriginFile, depDestFile, extensions, isWatch);
2628
- defs.forEach(item => {
2629
- diffContentCopyFile$2(item.depOriginFile, item.depDestFile);
2630
- }); // console.log('mpCommonDep defs', defs);
2649
+ var compile$1 = function (tmsConfig, {
2650
+ glob,
2651
+ destPath,
2652
+ srcOption,
2653
+ module,
2654
+ isDev
2655
+ }) {
2656
+ const compileTasksMap = new Map();
2657
+ compileTasksMap.set(glob, {
2658
+ module,
2659
+ taskFn: (sourceFile, targetPath) => {
2660
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : glob;
2661
+ const newDestPath = targetPath ? targetPath : destPath;
2662
+ let srcPipe = src$1(newGlobValue, { ...srcOption
2663
+ });
2664
+ const pluginParams = {
2665
+ module,
2666
+ isDev
2667
+ };
2668
+ srcPipe = addPlugins(tmsConfig, srcPipe, pluginParams);
2669
+ return srcPipe.pipe(dest(newDestPath)).on('error', err => {
2670
+ fail$2(`编译报错${err}`);
2631
2671
  });
2632
- file.contents = Buffer.from(contents);
2633
2672
  }
2634
-
2635
- this.push(file);
2636
- cb();
2637
2673
  });
2638
- return stream;
2639
- }
2640
-
2641
- var mpCommonDep_1 = {
2642
- mpCommonDep: mpCommonDep$1,
2643
- dfsFindCommonDep: dfsFindCommonDep$2
2644
- };
2645
-
2646
- /* eslint-disable no-param-reassign */
2647
- const through$1 = require$$0__default$9;
2648
- const path$4 = require$$1__default$2;
2649
- const {
2650
- ext: ext$1,
2651
- fileInDir: fileInDir$1,
2652
- diffContentCopyFile: diffContentCopyFile$1
2653
- } = io$3;
2654
- const {
2655
- resolve: resolve$7
2656
- } = widgets;
2657
- const fs$4 = require$$0__default$2;
2658
- const {
2659
- pluginError: pluginError$1
2660
- } = pluginError_1;
2661
- const {
2662
- dfsFindCommonDep: dfsFindCommonDep$1
2663
- } = mpCommonDep_1;
2664
-
2665
- function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch) {
2666
- const stream = through$1.obj(function (file, enc, cb) {
2667
- // 当前分析的文件的路径
2668
- const anaFileOriginFile = file.history[0];
2669
- const anaFileRelativeModule = path$4.relative(resolve$7(module.from), anaFileOriginFile);
2670
- const anaFileDestFile = resolve$7(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2671
-
2672
- if (file.isBuffer()) {
2673
- let contents = String(file.contents);
2674
- const copyModules = new Map();
2675
-
2676
- try {
2677
- try {
2678
- contents = contents ? JSON.parse(contents) : {};
2679
- } catch (e) {
2680
- throw new Error(`解析${file.path}出现错误,请检查配置信息: ${e}`);
2681
- }
2682
-
2683
- if (contents.usingComponents) {
2684
- Object.keys(tmsConfig.dependencies).forEach(includeName => {
2685
- const includePath = tmsConfig.dependencies[includeName];
2686
- Object.keys(contents.usingComponents).forEach(componentKey => {
2687
- const componentPath = contents.usingComponents[componentKey];
2688
-
2689
- if (componentPath.indexOf(includeName) > -1) {
2690
- const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
2691
-
2692
- const {
2693
- ext: extAlias,
2694
- file: depOriginFile,
2695
- extPath
2696
- } = ext$1(depOriginPath, extensions);
2697
- const isFileInDir = fileInDir$1(includePath, depOriginFile);
2698
-
2699
- if (!isFileInDir) {
2700
- pluginError$1(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
2701
- return;
2702
- } // eslint-disable-next-line
2703
-
2704
-
2705
- const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
2706
- const regRes = componentPath.match(reg) || [];
2707
-
2708
- if (regRes[2]) {
2709
- const depDestPath = resolve$7(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2710
- const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
2711
-
2712
- if (!copyModules.has(depDestFile)) {
2713
- copyModules.set(depDestFile, {
2714
- depOriginFile,
2715
- depOriginExt: extAlias,
2716
- depDestFile,
2717
- beforeDepPath: componentPath,
2718
- afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
2719
- });
2720
- }
2721
- }
2722
- }
2723
- });
2724
- });
2725
- }
2726
- } catch (e) {
2727
- pluginError$1(e, isWatch);
2728
- } // console.log('json copyModules', copyModules);
2729
-
2730
-
2731
- copyModules.forEach(({
2732
- depOriginFile,
2733
- depOriginExt,
2734
- depDestFile,
2735
- beforeDepPath,
2736
- afterDepPath
2737
- }) => {
2738
- // 拷贝当前依赖组件几个部分 wxml、wxss、wxs、json
2739
- filesExt.forEach(extKey => {
2740
- const originFile = depOriginFile.replace(depOriginExt, extKey);
2741
- const destFile = depDestFile.replace(depOriginExt, extKey);
2742
-
2743
- if (fs$4.existsSync(originFile)) {
2744
- diffContentCopyFile$1(originFile, destFile);
2745
- const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
2746
-
2747
- if (extensionsFilter.indexOf(extKey) > -1) {
2748
- const defs = dfsFindCommonDep$1(originFile, destFile, extensionsFilter); // console.log('json defs', defs);
2749
-
2750
- defs.forEach(item => {
2751
- diffContentCopyFile$1(item.depOriginFile, item.depDestFile);
2752
- });
2753
- }
2754
- }
2755
- });
2756
- contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
2757
- const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
2758
- contents = contents.replace(reg, `"${afterDepPath}"`);
2759
- });
2760
- contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
2761
- file.contents = Buffer.from(contents);
2762
- }
2763
-
2764
- this.push(file);
2765
- cb();
2766
- });
2767
- return stream;
2768
- }
2769
-
2770
- var mpJsonDep_1 = {
2771
- mpJsonDep: mpJsonDep$1
2772
- };
2773
-
2774
- /* eslint-disable no-param-reassign */
2775
- const through = require$$0__default$9;
2776
- const htmlparser2 = require$$1__default$9;
2777
- const fs$3 = require$$0__default$2;
2778
- const path$3 = require$$1__default$2;
2779
- const {
2780
- diffContentCopyFile,
2781
- ext,
2782
- fileInDir
2783
- } = io$3;
2784
- const {
2785
- resolve: resolve$6
2786
- } = widgets;
2787
- const {
2788
- dfsFindCommonDep
2789
- } = mpCommonDep_1;
2790
- const {
2791
- pluginError
2792
- } = pluginError_1; // 处理后缀(源码引入依赖时,不带后缀的情况)
2793
-
2794
- const extFile = function (name, file) {
2795
- const extMap = {
2796
- import: '.wxml',
2797
- include: '.wxml',
2798
- wxs: '.wxs'
2799
- };
2800
- let extObj = {};
2801
-
2802
- if (Object.keys(extMap).indexOf(name) > -1 && !file.endsWith(extMap[name])) {
2803
- extObj = ext(file, [extMap[name]]);
2804
- }
2805
-
2806
- return {
2807
- extPath: extObj.extPath || '',
2808
- ext: extObj.ext || '',
2809
- file: extObj.file || file
2810
- };
2811
- };
2812
-
2813
- const dfsFindWxmlDep = function (anaFileOriginFile, anaFileDestFile, isWatch = true) {
2814
- const resDep = {
2815
- image: new Map(),
2816
- wxml: new Map(),
2817
- wxs: new Map()
2818
- };
2819
-
2820
- function dfs(anaFileOriginFile, anaFileDestFile) {
2821
- let contents = '';
2822
-
2823
- try {
2824
- contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
2825
- } catch (e) {
2826
- pluginError(e, isWatch);
2827
- }
2828
-
2829
- const parser = new htmlparser2.Parser({
2830
- onopentag(name, attributes) {
2831
- var _attributes$src;
2832
-
2833
- if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
2834
- const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
2835
-
2836
- const {
2837
- ext,
2838
- file: depOriginFile,
2839
- extPath
2840
- } = extFile(name, depOriginPath);
2841
-
2842
- if (!fs$3.existsSync(depOriginFile)) {
2843
- pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
2844
- return;
2845
- }
2846
-
2847
- const depDestPath = path$3.join(path$3.dirname(anaFileDestFile), attributes.src);
2848
- const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
2849
-
2850
- if (['import', 'include'].indexOf(name) > -1) {
2851
- resDep.wxml.set(depDestFile, {
2852
- anaFileOriginFile,
2853
- anaFileDestFile,
2854
- depDestFile,
2855
- depOriginFile
2856
- });
2857
- dfs(depOriginFile, depDestFile);
2858
- } // 收集image依赖
2859
- // if (name === 'image') {
2860
- // resDep.image.set(attributes.src, {
2861
- // anaFileOriginFile,
2862
- // anaFileDestFile,
2863
- // depDestFile,
2864
- // depOriginFile,
2865
- // });
2866
- // dfs(depOriginFile, depDestFile);
2867
- // }
2868
- // 收集wxs依赖
2869
-
2870
-
2871
- if (name === 'wxs') {
2872
- resDep.wxs.set(depDestFile, {
2873
- anaFileOriginFile,
2874
- anaFileDestFile,
2875
- depDestFile,
2876
- depOriginFile
2877
- });
2878
- const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs']);
2879
- defs.forEach((item, key) => {
2880
- resDep.wxs.set(key, item);
2881
- });
2882
- }
2883
- }
2884
- }
2885
-
2886
- });
2887
- parser.write(contents);
2888
- parser.end();
2889
- }
2890
-
2891
- dfs(anaFileOriginFile, anaFileDestFile);
2892
- return resDep;
2893
- };
2894
-
2895
- function mpWxmlDep$1(tmsConfig, module, isWatch) {
2896
- const stream = through.obj(function (file, enc, cb) {
2897
- // 依赖分析的文件
2898
- const anaFileOriginFile = file.history[0];
2899
- const anaFileRelativeModule = path$3.relative(resolve$6(module.from), anaFileOriginFile);
2900
- const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2901
-
2902
- if (file.isBuffer()) {
2903
- let contents = String(file.contents);
2904
- const copyModules = new Map();
2905
- const parser = new htmlparser2.Parser({
2906
- onopentag(name, attributes) {
2907
- const nameFilter = ['import', 'include', 'wxs'];
2908
-
2909
- if (nameFilter.indexOf(name) > -1 && attributes.src) {
2910
- const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
2911
-
2912
- const {
2913
- ext,
2914
- file: depOriginFile,
2915
- extPath
2916
- } = extFile(name, depOriginPath);
2917
- Object.keys(tmsConfig.dependencies).forEach(includeName => {
2918
- if (attributes.src.indexOf(includeName) > -1) {
2919
- const includePath = tmsConfig.dependencies[includeName];
2920
-
2921
- if (!fileInDir(includePath, depOriginFile)) {
2922
- pluginError(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
2923
- return;
2924
- } // eslint-disable-next-line
2925
-
2926
-
2927
- const reg = new RegExp(`^(\./\.\.\/)+.*\/${includeName}\/(.*)`);
2928
- const regRes = attributes.src.match(reg) || [];
2929
-
2930
- if (regRes[2]) {
2931
- const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2932
- const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
2933
-
2934
- if (!copyModules.has(depDestFile)) {
2935
- copyModules.set(depDestFile, {
2936
- depOriginFile,
2937
- depDestFile,
2938
- beforeDepPath: attributes.src,
2939
- afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
2940
- });
2941
- }
2942
- }
2943
- }
2944
- });
2945
- }
2946
- }
2947
-
2948
- });
2949
- parser.write(contents);
2950
- parser.end(); // console.log('wxml copyModules', copyModules);
2951
-
2952
- copyModules.forEach(({
2953
- depOriginFile,
2954
- depDestFile,
2955
- beforeDepPath,
2956
- afterDepPath
2957
- }) => {
2958
- if (fs$3.existsSync(depOriginFile)) {
2959
- diffContentCopyFile(depOriginFile, depDestFile);
2960
- const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
2961
- contents = contents.replace(reg, `"${afterDepPath}"`);
2962
- }
2963
-
2964
- if (depOriginFile.endsWith('.wxml')) {
2965
- const defs = dfsFindWxmlDep(depOriginFile, depDestFile, isWatch); // console.log('wxml defs', defs);
2966
-
2967
- [...defs.wxml, ...defs.wxs].forEach(([, item]) => {
2968
- diffContentCopyFile(item.depOriginFile, item.depDestFile);
2969
- });
2970
- }
2971
-
2972
- if (depOriginFile.endsWith('.wxs')) {
2973
- const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs'], isWatch); // console.log('wxs defs', defs);
2974
-
2975
- defs.forEach(item => {
2976
- diffContentCopyFile(item.depOriginFile, item.depDestFile);
2977
- });
2978
- }
2979
- });
2980
- file.contents = Buffer.from(contents);
2981
- }
2982
-
2983
- this.push(file);
2984
- cb();
2985
- });
2986
- return stream;
2987
- }
2988
-
2989
- var mpWxmlDep_1 = {
2990
- mpWxmlDep: mpWxmlDep$1,
2991
- dfsFindWxmlDep
2992
- };
2993
-
2994
- const {
2995
- src: src$1,
2996
- dest
2997
- } = require$$0__default$a; // const px2rpx = require('gulp-px-to-rpx');
2998
- // const cache = require('gulp-cache');
2999
- // const image = require('gulp-image');
3000
- // const replaceEnv = require('./plugins/replaceEnv');
3001
-
3002
- const {
3003
- mpCommonDep
3004
- } = mpCommonDep_1;
3005
- const {
3006
- mpJsonDep
3007
- } = mpJsonDep_1;
3008
- const {
3009
- mpWxmlDep
3010
- } = mpWxmlDep_1; // const postcss = require('gulp-postcss');
3011
- // const base64 = require('./plugins/postcss-font-base64');
3012
-
3013
- const {
3014
- fail: fail$2
3015
- } = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
3016
-
3017
- var compile$1 = function (tmsConfig, {
3018
- glob,
3019
- destPath,
3020
- srcOption,
3021
- module,
3022
- isDev
3023
- }) {
3024
- const compileTasksMap = new Map();
3025
- Object.keys(glob).forEach(globKey => {
3026
- const globValue = glob[globKey];
3027
-
3028
- switch (globKey) {
3029
- case 'js':
3030
- compileTasksMap.set(globValue, {
3031
- module,
3032
- taskFn: (sourceFile, targetPath) => {
3033
- const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
3034
- const newDestPath = targetPath ? targetPath : destPath;
3035
- const srcPipe = src$1(newGlobValue, { ...srcOption
3036
- });
3037
- return srcPipe // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
3038
- .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev)).on('error', err => {
3039
- fail$2(`mpCommonDep编译报错${err}`);
3040
- }).pipe(dest(newDestPath, {
3041
- overwrite: true
3042
- })).on('error', err => {
3043
- fail$2(`js编译报错${err}`);
3044
- });
3045
- }
3046
- });
3047
- break;
3048
-
3049
- case 'wxss':
3050
- compileTasksMap.set(globValue, {
3051
- module,
3052
- taskFn: (sourceFile, targetPath) => {
3053
- const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
3054
- const newDestPath = targetPath ? targetPath : destPath;
3055
- const srcPipe = src$1(newGlobValue, { ...srcOption
3056
- });
3057
- return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
3058
- fail$2(`mpCommonDep编译报错${err}`);
3059
- }) // .pipe(postcss([base64()]))
3060
- // .on('error', (err) => {
3061
- // fail(`postcss编译报错${err}`);
3062
- // })
3063
- // .pipe(px2rpx({
3064
- // designWidth: 375, // 设计稿宽度,默认为750
3065
- // precision: 2, // 小数最大精度,默认为6
3066
- // }))
3067
- .pipe(dest(newDestPath)).on('error', err => {
3068
- fail$2(`wxss编译报错${err}`);
3069
- });
3070
- }
3071
- });
3072
- break;
3073
-
3074
- case 'json':
3075
- compileTasksMap.set(globValue, {
3076
- module,
3077
- taskFn: (sourceFile, targetPath) => {
3078
- const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
3079
- const newDestPath = targetPath ? targetPath : destPath;
3080
- const srcPipe = src$1(newGlobValue, { ...srcOption
3081
- });
3082
- return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
3083
- fail$2(`mpJsonDep编译报错${err}`);
3084
- }).pipe(dest(newDestPath)).on('error', err => {
3085
- fail$2(`json编译报错${err}`);
3086
- });
3087
- }
3088
- });
3089
- break;
3090
-
3091
- case 'wxml':
3092
- compileTasksMap.set(globValue, {
3093
- module,
3094
- taskFn: (sourceFile, targetPath) => {
3095
- const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
3096
- const newDestPath = targetPath ? targetPath : destPath;
3097
- const srcPipe = src$1(newGlobValue, { ...srcOption
3098
- });
3099
- return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
3100
- fail$2(`mpWxmlDep编译报错${err}`);
3101
- }).pipe(dest(newDestPath)).on('error', err => {
3102
- fail$2(`wxml编译报错${err}`);
3103
- });
3104
- }
3105
- });
3106
- break;
3107
-
3108
- case 'image':
3109
- compileTasksMap.set(globValue, {
3110
- module,
3111
- taskFn: (sourceFile, targetPath) => {
3112
- const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
3113
- const newDestPath = targetPath ? targetPath : destPath;
3114
- const srcPipe = src$1(newGlobValue, { ...srcOption
3115
- });
3116
- return srcPipe // .pipe(cache(image()))
3117
- // .on('error', (err) => {
3118
- // fail(`image编译报错${err}`);
3119
- // })
3120
- .pipe(dest(newDestPath)).on('error', err => {
3121
- fail$2(`image编译报错${err}`);
3122
- });
3123
- }
3124
- });
3125
- break;
3126
-
3127
- case 'other':
3128
- compileTasksMap.set(globValue, {
3129
- module,
3130
- taskFn: (sourceFile, targetPath) => {
3131
- const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
3132
- const newDestPath = targetPath ? targetPath : destPath;
3133
- const srcPipe = src$1(newGlobValue, { ...srcOption
3134
- });
3135
- return srcPipe.pipe(dest(newDestPath)).on('error', err => {
3136
- fail$2(`编译报错${err}`);
3137
- });
3138
- }
3139
- });
3140
- break;
3141
- }
3142
- });
3143
- return compileTasksMap;
2674
+ return compileTasksMap;
3144
2675
  };
3145
2676
 
3146
2677
  /* eslint-disable */
3147
2678
  // 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
3148
2679
 
3149
- const assign = require$$0__default$b;
3150
- const path$2 = require$$1__default$2;
3151
- const PluginError = require$$2__default$1;
3152
- const fancyLog = require$$3__default;
3153
- const colors = require$$4__default;
2680
+ const assign = require$$0__default$8;
2681
+ const path$4 = require$$1__default$1;
2682
+ const PluginError = require$$2__default$2;
2683
+ const fancyLog = require$$3__default$2;
2684
+ const colors = require$$4__default$1;
3154
2685
  const chokidar = require$$5__default;
3155
2686
  const {
3156
2687
  Duplex
3157
2688
  } = require$$6__default$1;
3158
2689
  const vinyl = require$$7__default;
3159
2690
  const File = require$$8__default;
3160
- const anymatch = require$$9__default$1;
2691
+ const anymatch = require$$9__default;
3161
2692
  const pathIsAbsolute = require$$10__default$1;
3162
2693
  const globParent = require$$11__default;
3163
2694
  const slash = require$$12__default;
@@ -3192,10 +2723,10 @@ function watch$2(globs, opts, cb) {
3192
2723
 
3193
2724
  function resolveFilepath(filepath) {
3194
2725
  if (pathIsAbsolute(filepath)) {
3195
- return path$2.normalize(filepath);
2726
+ return path$4.normalize(filepath);
3196
2727
  }
3197
2728
 
3198
- return path$2.resolve(opts.cwd || process.cwd(), filepath);
2729
+ return path$4.resolve(opts.cwd || process.cwd(), filepath);
3199
2730
  }
3200
2731
 
3201
2732
  function resolveGlob(glob) {
@@ -3251,7 +2782,7 @@ function watch$2(globs, opts, cb) {
3251
2782
  let glob;
3252
2783
  let currentFilepath = filepath;
3253
2784
 
3254
- while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$2.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
2785
+ while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$4.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
3255
2786
 
3256
2787
 
3257
2788
  if (!glob) {
@@ -3260,7 +2791,7 @@ function watch$2(globs, opts, cb) {
3260
2791
  }
3261
2792
 
3262
2793
  if (!baseForced) {
3263
- fileOpts.base = path$2.normalize(globParent(glob));
2794
+ fileOpts.base = path$4.normalize(globParent(glob));
3264
2795
  } // Do not stat deleted files
3265
2796
 
3266
2797
 
@@ -3320,15 +2851,19 @@ var gulpWatch = watch$2;
3320
2851
 
3321
2852
  /* eslint-disable no-restricted-syntax */
3322
2853
  const watch$1 = gulpWatch;
3323
- const path$1 = require$$1__default$2;
3324
- const shellJs = require$$0__default$3;
2854
+ const path$3 = require$$1__default$1;
2855
+ const shellJs = require$$2__default;
2856
+ const {
2857
+ series: series$1
2858
+ } = require$$0__default$7;
3325
2859
  const {
3326
- info: info$5,
2860
+ info: info$4,
3327
2861
  warn: warn$1,
3328
2862
  fail: fail$1
3329
2863
  } = log$1;
3330
2864
  const {
3331
- resolve: resolve$5
2865
+ resolve: resolve$5,
2866
+ filterField: filterField$3
3332
2867
  } = widgets;
3333
2868
  const {
3334
2869
  global: global$2
@@ -3336,9 +2871,7 @@ const {
3336
2871
  const {
3337
2872
  checkPackageVersion
3338
2873
  } = checkDependencies;
3339
- const {
3340
- findAllFilesOfDir
3341
- } = io$3;
2874
+ const report$5 = report_1;
3342
2875
  const TIP_MAP = {
3343
2876
  'package.json': {
3344
2877
  tip: '依赖版本有变动,请重新执行tmskit run dev',
@@ -3367,14 +2900,14 @@ const logTip = (fileName, sourceFile, targetFile, tipMap) => {
3367
2900
  }
3368
2901
  }
3369
2902
 
3370
- info$5(`${fileName}有更新`);
2903
+ info$4(`${fileName}有更新`);
3371
2904
  } catch (e) {
3372
2905
  fail$1(`${sourceFile}文件更新提示出现错误: ${e.message}`);
3373
2906
  }
3374
2907
  };
3375
2908
 
3376
2909
  const getTargetFile = (sourceFile, module, outputDir) => {
3377
- const sourceFileRelativeModule = path$1.relative(resolve$5(module.from), sourceFile);
2910
+ const sourceFileRelativeModule = path$3.relative(resolve$5(module.from), sourceFile);
3378
2911
  const targetFile = resolve$5(outputDir, module.to, sourceFileRelativeModule);
3379
2912
  return targetFile;
3380
2913
  };
@@ -3387,43 +2920,71 @@ var watch_1 = function (globValue, watchOptions, callback, module) {
3387
2920
  const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
3388
2921
  const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
3389
2922
  const tmsConfig = global$2.getData('tmsConfig');
3390
-
3391
- if (vinyl.event === 'addDir') {
3392
- info$5(`更新${sourceFileName}目录`);
3393
- const files = findAllFilesOfDir(sourceFile);
3394
-
3395
- for (const file of files) {
3396
- const fileDirArr = file.replace(/\\/g, '/').split('/');
3397
- const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
3398
- const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
3399
- logTip(fileName, sourceFile, targetFile, TIP_MAP);
3400
- callback([file], path$1.dirname(targetFile));
3401
- }
3402
-
3403
- return;
3404
- }
3405
-
3406
2923
  const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
3407
2924
 
3408
2925
  if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
3409
- info$5(`删除${sourceFileName}`);
2926
+ info$4(`删除${sourceFileName}`);
3410
2927
  shellJs.rm('-rf', targetFile);
2928
+ updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
3411
2929
  return;
3412
2930
  }
3413
2931
 
2932
+ runCallback({
2933
+ tmsConfig,
2934
+ sourceFile,
2935
+ targetFile,
2936
+ callback,
2937
+ type: vinyl.event
2938
+ });
3414
2939
  logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
3415
- return callback([sourceFile], path$1.dirname(targetFile));
3416
2940
  });
3417
- };
2941
+ }; // 开始执行watch 文件的 callback函数
2942
+
2943
+
2944
+ async function runCallback({
2945
+ tmsConfig,
2946
+ sourceFile,
2947
+ targetFile,
2948
+ callback,
2949
+ type
2950
+ }) {
2951
+ // callbacl.name === taskFn 代表进入gulp编译流程
2952
+ // series为gulp编译串行执行,callback执行完毕后,执行updateFileHooks钩子
2953
+ if (callback.name === 'taskFn') {
2954
+ series$1(callback.bind(null, [sourceFile], path$3.dirname(targetFile)), cb => {
2955
+ cb();
2956
+ updateFileHook(tmsConfig, sourceFile, targetFile, type);
2957
+ })();
2958
+ } else {
2959
+ // 普通的callback函数
2960
+ await callback([sourceFile], path$3.dirname(targetFile));
2961
+ await updateFileHook(tmsConfig, sourceFile, targetFile, type);
2962
+ }
2963
+ } // 执行源码文件更新的钩子
2964
+
3418
2965
 
3419
- const path = require$$1__default$2;
3420
- const fs$2 = require$$0__default$2;
3421
- const ora = require$$2__default;
3422
- const chalk$2 = require$$0__default;
2966
+ async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
2967
+ var _tmsConfig$hooks;
2968
+
2969
+ if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.updateFile) === 'function') {
2970
+ await tmsConfig.hooks.updateFile({
2971
+ tmsConfig: filterField$3(tmsConfig, ['gitAccount']),
2972
+ sourceFile,
2973
+ targetFile,
2974
+ type
2975
+ });
2976
+ report$5('hooks:updateFile');
2977
+ }
2978
+ }
2979
+
2980
+ const path$2 = require$$1__default$1;
2981
+ const fs$3 = require$$0__default$1;
2982
+ const ora = require$$0__default;
2983
+ const chalk$3 = require$$3__default;
3423
2984
  const {
3424
2985
  parallel,
3425
2986
  series
3426
- } = require$$0__default$a;
2987
+ } = require$$0__default$7;
3427
2988
  const {
3428
2989
  resolve: resolve$4,
3429
2990
  mergeMap,
@@ -3435,42 +2996,20 @@ const {
3435
2996
  } = buildAppJson;
3436
2997
  const {
3437
2998
  DEFAULT_COPY_CONFIG
3438
- } = require$$5;
2999
+ } = constant;
3439
3000
  const compile = compile$1;
3440
3001
  const watch = watch_1;
3441
3002
  const {
3442
- info: info$4
3003
+ info: info$3
3443
3004
  } = log$1;
3005
+ const report$4 = report_1;
3444
3006
  const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
3445
3007
 
3446
- function excludeGlob(glob) {
3447
- const otherArr = new Set();
3448
- otherArr.add('!**/*.{ttf,otf,woff,eot}');
3449
- Object.keys(glob).forEach(globKey => {
3450
- if (typeof glob[globKey] === 'string') {
3451
- const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
3452
- otherArr.add(data);
3453
- }
3454
-
3455
- if (Array.isArray(glob[globKey])) {
3456
- glob[globKey].forEach(value => {
3457
- if (typeof value === 'string') {
3458
- const data = value.startsWith('!') ? value : `!${value}`;
3459
- otherArr.add(data);
3460
- }
3461
- });
3462
- }
3463
- });
3464
- return Array.from(otherArr);
3465
- }
3466
-
3467
3008
  var dev$3 = async (tmsConfig, modules, isDev = true) => {
3468
3009
  const compileTasksMap = new Map(); // 监听根目录的文件
3469
3010
 
3470
3011
  mergeMap(compileTasksMap, compile(tmsConfig, {
3471
- glob: {
3472
- json: DEFAULT_COPY_CONFIG.map(item => resolve$4(item))
3473
- },
3012
+ glob: DEFAULT_COPY_CONFIG.map(item => resolve$4(item)),
3474
3013
  module: {
3475
3014
  from: resolve$4(),
3476
3015
  to: resolve$4(tmsConfig.outputDir)
@@ -3504,7 +3043,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3504
3043
 
3505
3044
  const excludes = moduleItem.exclude.map(ePath => {
3506
3045
  const newPath = getAbsolutePath(ePath, srcModulePath);
3507
- const ext = path.extname(ePath).slice(1);
3046
+ const ext = path$2.extname(ePath).slice(1);
3508
3047
 
3509
3048
  if (ext) {
3510
3049
  return `!${resolve$4(srcModulePath, newPath)}`;
@@ -3512,17 +3051,8 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3512
3051
 
3513
3052
  return `!${resolve$4(srcModulePath, newPath)}/**/*`;
3514
3053
  });
3515
- const glob = {
3516
- js: [`${srcModulePath}/**/*.{js,ts,wxs}`, ...excludes],
3517
- json: [`${srcModulePath}/**/*.json`, `!${srcModulePath}/**/module.config.json`, ...excludes],
3518
- wxss: [`${srcModulePath}/**/*.{less,wxss,scss,sass,styl}`, ...excludes],
3519
- wxml: [`${srcModulePath}/**/*.wxml`, ...excludes],
3520
- image: [`${srcModulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
3521
- };
3522
3054
  mergeMap(compileTasksMap, compile(tmsConfig, {
3523
- glob: { ...glob,
3524
- other: [`${srcModulePath}/**/*`, ...excludeGlob(glob)]
3525
- },
3055
+ glob: [`${srcModulePath}/**/*`, `!${srcModulePath}/**/module.config.json`, ...excludes],
3526
3056
  destPath: buildModulePath,
3527
3057
  module: {
3528
3058
  from: srcModulePath,
@@ -3533,7 +3063,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3533
3063
  },
3534
3064
  isDev
3535
3065
  }));
3536
- } // 静态资源目录-拷贝
3066
+ } // static静态资源目录
3537
3067
 
3538
3068
 
3539
3069
  if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
@@ -3541,22 +3071,15 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3541
3071
  item.from = getAbsolutePath(item.from);
3542
3072
  item.to = getAbsolutePath(item.to);
3543
3073
  let glob = {};
3544
- const ext = path.extname(item.from).slice(1);
3074
+ const ext = path$2.extname(item.from).slice(1);
3545
3075
 
3546
3076
  if (ext) {
3547
- glob[ext] = [item.from];
3077
+ glob = [item.from];
3548
3078
  } else {
3549
- glob = {
3550
- js: [`${item.from}/**/*.{js,ts,wxs}`],
3551
- json: [`${item.from}/**/*.json`],
3552
- wxss: [`${item.from}/**/*.{less,wxss,scss,sass,styl}`],
3553
- wxml: [`${item.from}/**/*.wxml`],
3554
- image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`]
3555
- };
3556
- glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
3079
+ glob = [`${item.from}/**/*`];
3557
3080
  }
3558
3081
 
3559
- const from = fs$2.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
3082
+ const from = fs$3.lstatSync(item.from).isFile() ? path$2.dirname(item.from) : item.from;
3560
3083
  mergeMap(compileTasksMap, compile(tmsConfig, {
3561
3084
  glob,
3562
3085
  destPath: item.to,
@@ -3577,7 +3100,7 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3577
3100
  const spinner = ora();
3578
3101
 
3579
3102
  function start(cb) {
3580
- info$4('启动编译...');
3103
+ info$3('启动编译...');
3581
3104
  spinner.start();
3582
3105
  sTime = new Date().getTime();
3583
3106
  cb();
@@ -3619,9 +3142,10 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3619
3142
  tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
3620
3143
  modules
3621
3144
  }));
3145
+ report$4('hooks:afterCompile');
3622
3146
  }
3623
3147
 
3624
- spinner.succeed(chalk$2.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
3148
+ spinner.succeed(chalk$3.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
3625
3149
  spinner.stop();
3626
3150
  cb();
3627
3151
  }
@@ -3636,7 +3160,232 @@ var dev$3 = async (tmsConfig, modules, isDev = true) => {
3636
3160
  series(start, parallel(...compileTasks), end)();
3637
3161
  };
3638
3162
 
3639
- const shelljs$1 = require$$0__default$3;
3163
+ var require$$12 = {
3164
+ name: "@tmsfe/tmskit",
3165
+ version: "0.0.22",
3166
+ description: "tmskit",
3167
+ main: "dist/index.cjs",
3168
+ bin: {
3169
+ tmskit: "main.js"
3170
+ },
3171
+ files: [
3172
+ "build",
3173
+ "src",
3174
+ "dist",
3175
+ "main.js",
3176
+ "package.json"
3177
+ ],
3178
+ scripts: {
3179
+ dev: "rollup -wc --environment TARGET:tmskit",
3180
+ build: "rollup -c --environment TARGET:tmskit",
3181
+ "pub:patch": "sh build/publish.sh patch",
3182
+ "pub:minor": "sh build/publish.sh minor",
3183
+ "pub:major": "sh build/publish.sh major"
3184
+ },
3185
+ author: "tms·web",
3186
+ license: "ISC",
3187
+ buildOptions: {
3188
+ formats: [
3189
+ "cjs"
3190
+ ]
3191
+ },
3192
+ devDependencies: {
3193
+ "@rollup/plugin-babel": "^5.0.2",
3194
+ "@rollup/plugin-commonjs": "^19.0.0",
3195
+ "@rollup/plugin-json": "^4.0.3",
3196
+ rollup: "^2.6.1"
3197
+ },
3198
+ dependencies: {
3199
+ "ansi-colors": "1.1.0",
3200
+ anymatch: "^1.3.0",
3201
+ async: "^3.2.2",
3202
+ chalk: "^4.1.0",
3203
+ chokidar: "^3.5.3",
3204
+ commander: "^8.3.0",
3205
+ "copy-webpack-plugin": "^9.1.0",
3206
+ ejs: "^3.1.5",
3207
+ "fancy-log": "1.3.2",
3208
+ "fs-extra": "^10.0.1",
3209
+ "glob-ignore": "^1.0.2",
3210
+ "glob-parent": "^3.0.1",
3211
+ gulp: "^4.0.2",
3212
+ "gulp-if": "^3.0.0",
3213
+ "gulp-watch": "^5.0.1",
3214
+ htmlparser2: "^7.2.0",
3215
+ inquirer: "^7.3.3",
3216
+ leven: "3.1.0",
3217
+ lodash: "^4.17.21",
3218
+ metalsmith: "^2.3.0",
3219
+ minimatch: "^5.1.0",
3220
+ "miniprogram-ci": "1.4.13",
3221
+ moment: "^2.29.2",
3222
+ "object-assign": "^4.0.1",
3223
+ ora: "^5.1.0",
3224
+ "path-is-absolute": "^1.0.1",
3225
+ "plugin-error": "^1.0.0",
3226
+ postcss: "^8.4.6",
3227
+ precinct: "^8.3.1",
3228
+ "readable-stream": "^2.2.2",
3229
+ "replace-ext": "^2.0.0",
3230
+ request: "^2.88.2",
3231
+ shelljs: "^0.8.4",
3232
+ slash: "^1.0.0",
3233
+ "strip-comments": "^2.0.1",
3234
+ through2: "^4.0.2",
3235
+ unzipper: "^0.10.11",
3236
+ vinyl: "^2.1.0",
3237
+ "vinyl-file": "^2.0.0",
3238
+ "vinyl-sourcemaps-apply": "^0.2.0"
3239
+ },
3240
+ engines: {
3241
+ node: "^12.17.0 || >= 14.13.1"
3242
+ },
3243
+ jest: {
3244
+ testEnvironment: "jest-environment-node"
3245
+ }
3246
+ };
3247
+
3248
+ const fs$2 = require$$0__default$1;
3249
+ const path$1 = require$$1__default$1;
3250
+ const shelljs$2 = require$$2__default;
3251
+ const chalk$2 = require$$3__default;
3252
+ const request = require$$0__default$5;
3253
+ const inquirer = require$$1__default$4;
3254
+ const {
3255
+ infoNoTime: infoNoTime$1
3256
+ } = log$1;
3257
+ const packageJson$1 = require$$12;
3258
+ const {
3259
+ VERSION_CACHE_FILE,
3260
+ VERSION_URL
3261
+ } = constant;
3262
+ const {
3263
+ ensureDirExist: ensureDirExist$1
3264
+ } = io$3;
3265
+ const {
3266
+ versionCompare
3267
+ } = widgets; // 获取推荐的tmskit版本
3268
+
3269
+ function getRecommendVersion() {
3270
+ return new Promise((resolve, reject) => {
3271
+ request(`${VERSION_URL}?v=${new Date().getTime()}`, (error, response, body) => {
3272
+ if (!error && response && response.statusCode === 200) {
3273
+ resolve(JSON.parse(body));
3274
+ } else {
3275
+ reject(response.statusCode);
3276
+ }
3277
+ });
3278
+ });
3279
+ } // 获取当前用户tmskit的版本
3280
+
3281
+
3282
+ function getUserTmskitVersion() {
3283
+ const data = shelljs$2.exec('tmskit -v', {
3284
+ async: false,
3285
+ silent: true
3286
+ });
3287
+
3288
+ if (data.code === 0) {
3289
+ // tmskit 0.0.21 => 0.0.21
3290
+ return data.slice(7);
3291
+ }
3292
+
3293
+ return '0.0.0';
3294
+ } // 询问用户是否安装最新版本
3295
+
3296
+
3297
+ function isInstallLatestVersion() {
3298
+ return inquirer.prompt([{
3299
+ type: 'confirm',
3300
+ name: 'isInstall',
3301
+ message: '是否安装最新版本',
3302
+ choices: [{
3303
+ name: '否',
3304
+ value: false
3305
+ }, {
3306
+ name: '是',
3307
+ value: true
3308
+ }]
3309
+ }]);
3310
+ } // 获取tmskit的版本是否推荐过
3311
+
3312
+
3313
+ function getVersionIsRecommend(version) {
3314
+ const filePath = VERSION_CACHE_FILE;
3315
+
3316
+ if (!fs$2.existsSync(filePath)) {
3317
+ return false;
3318
+ }
3319
+
3320
+ const content = require(filePath);
3321
+
3322
+ return content === null || content === void 0 ? void 0 : content[version];
3323
+ } // 设置tmskit版本推荐过
3324
+
3325
+
3326
+ function setVersionRecommend(version, isRecommend) {
3327
+ const filePath = VERSION_CACHE_FILE;
3328
+
3329
+ if (!fs$2.existsSync(filePath)) {
3330
+ const dir = path$1.dirname(filePath);
3331
+ ensureDirExist$1(dir);
3332
+ fs$2.writeFileSync(filePath, '{}');
3333
+ }
3334
+
3335
+ const content = require(filePath);
3336
+
3337
+ content[version] = isRecommend;
3338
+ fs$2.writeFileSync(filePath, JSON.stringify(content, null, 2));
3339
+ } // 推荐理由
3340
+
3341
+
3342
+ function displayRecommends(arr) {
3343
+ infoNoTime$1(chalk$2.green('构建工具有新的版本~~:'));
3344
+ arr.forEach(item => {
3345
+ infoNoTime$1(chalk$2.green(item));
3346
+ });
3347
+ } // 推荐tmskit的安装版本
3348
+
3349
+
3350
+ async function recommendVersion$1() {
3351
+ try {
3352
+ // 获取当前用户安装的版本
3353
+ const tmskitVersion = getUserTmskitVersion(); // 获取官方推荐版本
3354
+
3355
+ const recommendRes = await getRecommendVersion();
3356
+ const recommendVersion = recommendRes.version; // 当前用户安装版本小于官方推荐版本 && 该版本没有推荐过
3357
+
3358
+ if (versionCompare(tmskitVersion, recommendVersion) === -1 && !getVersionIsRecommend(recommendVersion)) {
3359
+ displayRecommends(recommendRes.version_detail); // 设置该版本推荐过
3360
+
3361
+ setVersionRecommend(recommendVersion, true); // 询问用户是否安装最新版本
3362
+
3363
+ const installRes = await isInstallLatestVersion(recommendRes);
3364
+
3365
+ if (installRes.isInstall) {
3366
+ // mac
3367
+ if (process.platform === 'darwin') {
3368
+ infoNoTime$1(`将执行以下命令: ${chalk$2.green(`sudo npm install -g ${packageJson$1.name}@${recommendVersion}`)}`);
3369
+ shelljs$2.exec(`sudo npm install -g ${packageJson$1.name}@${recommendVersion}`, {
3370
+ async: false,
3371
+ silent: false
3372
+ });
3373
+ process.exit(-1);
3374
+ } else {
3375
+ // window
3376
+ infoNoTime$1(`请使用超级管理员执行以下命令: ${chalk$2.green(`npm install -g ${packageJson$1.name}@${recommendVersion}`)}`);
3377
+ process.exit(-1);
3378
+ }
3379
+ }
3380
+ }
3381
+ } catch {}
3382
+ }
3383
+
3384
+ var recommendVersion_1 = {
3385
+ recommendVersion: recommendVersion$1
3386
+ };
3387
+
3388
+ const shelljs$1 = require$$2__default;
3640
3389
  const compileDev = dev$3;
3641
3390
  const {
3642
3391
  resolve: resolve$3,
@@ -3648,14 +3397,19 @@ const {
3648
3397
  getSubPackages: getSubPackages$1
3649
3398
  } = tmsMpconfig.exports;
3650
3399
  const {
3651
- info: info$3
3400
+ info: info$2
3652
3401
  } = log$1;
3653
3402
  const {
3654
3403
  global: global$1
3655
3404
  } = global_1;
3656
3405
  const {
3657
- CACHE_DIR
3658
- } = require$$5; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3406
+ MODULE_CODE_DIR,
3407
+ NODE_MODULES_DIR
3408
+ } = constant;
3409
+ const report$3 = report_1;
3410
+ const {
3411
+ recommendVersion
3412
+ } = recommendVersion_1; // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
3659
3413
 
3660
3414
  function delOtherPackages(tmsConfig, targetSubPackages) {
3661
3415
  // 获取所有模块,合并模块依赖的模块
@@ -3683,15 +3437,18 @@ async function dev$2(tmsConfig, targetModules) {
3683
3437
 
3684
3438
  if (noCache) {
3685
3439
  shelljs$1.rm('-rf', resolve$3(tmsConfig.outputDir));
3686
- shelljs$1.rm('-rf', CACHE_DIR);
3687
- } // 初始化操作
3440
+ shelljs$1.rm('-rf', MODULE_CODE_DIR);
3441
+ shelljs$1.rm('-rf', NODE_MODULES_DIR);
3442
+ } // 推荐tmskit的版本
3688
3443
 
3689
3444
 
3445
+ await recommendVersion(); // 初始化操作
3446
+
3690
3447
  const {
3691
3448
  subPackages,
3692
3449
  modules: newModules
3693
3450
  } = await init$2(tmsConfig, targetModules);
3694
- info$3('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3451
+ info$2('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
3695
3452
 
3696
3453
  if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
3697
3454
  var _tmsConfig$hooks2;
@@ -3701,6 +3458,7 @@ async function dev$2(tmsConfig, targetModules) {
3701
3458
  tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
3702
3459
  modules: newModules
3703
3460
  }));
3461
+ report$3('hooks:beforeCompile');
3704
3462
  }
3705
3463
  delOtherPackages(tmsConfig, subPackages);
3706
3464
  compileDev(tmsConfig, newModules, true);
@@ -3714,13 +3472,14 @@ var build$2 = async (tmsConfig, newModules, isDev) => {
3714
3472
  dev$1(tmsConfig, newModules, isDev);
3715
3473
  };
3716
3474
 
3717
- const shelljs = require$$0__default$3;
3475
+ const shelljs = require$$2__default;
3718
3476
  const {
3719
3477
  resolve: resolve$2,
3720
3478
  filterField
3721
3479
  } = widgets;
3722
3480
  const init$1 = init_1;
3723
3481
  const compileBuild = build$2;
3482
+ const report$2 = report_1;
3724
3483
 
3725
3484
  async function build$1(tmsConfig, targetModules) {
3726
3485
  var _tmsConfig$hooks;
@@ -3740,13 +3499,14 @@ async function build$1(tmsConfig, targetModules) {
3740
3499
  tmsConfig: filterField(tmsConfig, ['gitAccount']),
3741
3500
  modules: newModules
3742
3501
  }));
3502
+ report$2('hooks:beforeCompile');
3743
3503
  }
3744
3504
  compileBuild(tmsConfig, newModules, isDev);
3745
3505
  }
3746
3506
 
3747
3507
  var build_1 = build$1;
3748
3508
 
3749
- const fs$1 = require$$0__default$2;
3509
+ const fs$1 = require$$0__default$1;
3750
3510
  const {
3751
3511
  resolve: resolve$1
3752
3512
  } = widgets;
@@ -3812,11 +3572,12 @@ const install = install_1;
3812
3572
  const cloud = cloud$1;
3813
3573
  const {
3814
3574
  fail,
3815
- info: info$2
3575
+ info: info$1
3816
3576
  } = log$1;
3817
3577
  const {
3818
3578
  global
3819
3579
  } = global_1;
3580
+ const report$1 = report_1;
3820
3581
  const {
3821
3582
  getTmsConfig: getTmsConfig$1,
3822
3583
  getModulesByMergeDepModules,
@@ -3868,10 +3629,11 @@ const getSpecificModuleNames = (moduleArg, modules) => {
3868
3629
  };
3869
3630
 
3870
3631
  async function run(commandName, cmd) {
3871
- try {
3872
- // 用户本地的配置
3873
- const tmsConfig = getTmsConfig$1(); // 缓存数据
3632
+ // 用户本地的配置
3633
+ const tmsConfig = getTmsConfig$1();
3874
3634
 
3635
+ try {
3636
+ // 缓存数据
3875
3637
  global.setData({
3876
3638
  cmd,
3877
3639
  tmsConfig
@@ -3879,14 +3641,21 @@ async function run(commandName, cmd) {
3879
3641
 
3880
3642
  if (commandName === 'cloud') {
3881
3643
  cloud(tmsConfig);
3644
+ report$1('run:cloud', {
3645
+ appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
3646
+ });
3882
3647
  return;
3883
3648
  }
3884
3649
 
3885
3650
  otherCommands(tmsConfig, commandName, cmd);
3886
3651
  } catch (error) {
3887
3652
  const errMsg = typeof error === 'object' ? error.message : error;
3653
+ report$1('run', {
3654
+ errMsg,
3655
+ appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
3656
+ });
3888
3657
  fail(`构建出现错误: ${errMsg}`);
3889
- info$2('详细错误信息', error);
3658
+ info$1('详细错误信息', error);
3890
3659
  process.exit(1);
3891
3660
  }
3892
3661
  }
@@ -3905,20 +3674,32 @@ function otherCommands(tmsConfig, commandName, cmd) {
3905
3674
  switch (commandName) {
3906
3675
  case 'init':
3907
3676
  init(tmsConfig, newModules);
3677
+ report$1('run:init', {
3678
+ appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
3679
+ });
3908
3680
  return;
3909
3681
 
3910
3682
  case 'dev':
3911
3683
  global.setData('isDev', true);
3912
3684
  dev(tmsConfig, newModules);
3685
+ report$1('run:dev', {
3686
+ appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
3687
+ });
3913
3688
  return;
3914
3689
 
3915
3690
  case 'install':
3916
3691
  install(tmsConfig, subPackages, false);
3692
+ report$1('run:install', {
3693
+ appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
3694
+ });
3917
3695
  return;
3918
3696
 
3919
3697
  case 'build':
3920
3698
  global.setData('isDev', false);
3921
3699
  build(tmsConfig, newModules);
3700
+ report$1('run:build', {
3701
+ appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
3702
+ });
3922
3703
  return;
3923
3704
 
3924
3705
  default:
@@ -3934,9 +3715,17 @@ var entry = [{
3934
3715
  action: projectName => {
3935
3716
  create_1(projectName);
3936
3717
  }
3718
+ }, {
3719
+ command: 'install-cmd <npm-name>',
3720
+ description: '安装扩展命令',
3721
+ options: [['--registry [registry]', 'npm源']],
3722
+ action: (npmName, cmd) => {
3723
+ const res = extendCmd;
3724
+ res.installCmd(npmName, cmd);
3725
+ }
3937
3726
  }, {
3938
3727
  name: 'run',
3939
- type: 'child',
3728
+ type: 'parent',
3940
3729
  description: '项目开发使用的命令',
3941
3730
  commands: [{
3942
3731
  command: 'install',
@@ -3966,114 +3755,14 @@ var entry = [{
3966
3755
  action: cmd => {
3967
3756
  run_1('build', cmd);
3968
3757
  }
3969
- } // 对外暂不暴露该命令
3970
- // {
3971
- // command: 'init',
3972
- // description: '模块配置初始化项目(eg: 下载第三方模块代码、安装依赖、生成app.json等)',
3973
- // options: [
3974
- // ['-m, --module [moduleName]', '模块名称'],
3975
- // ['-e, --env [env]', '环境变量'],
3976
- // ],
3977
- // action: (cmd) => {
3978
- // require('./scripts/run/index')('init', cmd);
3979
- // },
3980
- // },
3981
- ]
3758
+ }]
3982
3759
  }];
3983
3760
 
3984
- var require$$9 = {
3985
- name: "@tmsfe/tmskit",
3986
- version: "0.0.21",
3987
- description: "tmskit",
3988
- main: "dist/index.cjs",
3989
- bin: {
3990
- tmskit: "main.js"
3991
- },
3992
- files: [
3993
- "build",
3994
- "src",
3995
- "dist",
3996
- "main.js",
3997
- "package.json"
3998
- ],
3999
- scripts: {
4000
- dev: "rollup -wc --environment TARGET:tmskit",
4001
- build: "rollup -c --environment TARGET:tmskit",
4002
- "pub:patch": "sh build/publish.sh patch",
4003
- "pub:minor": "sh build/publish.sh minor",
4004
- "pub:major": "sh build/publish.sh major"
4005
- },
4006
- author: "tms·web",
4007
- license: "ISC",
4008
- buildOptions: {
4009
- formats: [
4010
- "cjs"
4011
- ]
4012
- },
4013
- devDependencies: {
4014
- "@rollup/plugin-babel": "^5.0.2",
4015
- "@rollup/plugin-commonjs": "^19.0.0",
4016
- "@rollup/plugin-dynamic-import-vars": "^1.1.1",
4017
- "@rollup/plugin-json": "^4.0.3",
4018
- rollup: "^2.6.1",
4019
- "rollup-plugin-node-resolve": "^5.2.0",
4020
- "rollup-plugin-replace": "^2.2.0",
4021
- "rollup-plugin-terser": "^6.1.0",
4022
- "rollup-plugin-typescript2": "0.27.0"
4023
- },
4024
- dependencies: {
4025
- "ansi-colors": "1.1.0",
4026
- anymatch: "^1.3.0",
4027
- async: "^3.2.2",
4028
- chalk: "^4.1.0",
4029
- chokidar: "^3.5.3",
4030
- commander: "^8.3.0",
4031
- "copy-webpack-plugin": "^9.1.0",
4032
- ejs: "^3.1.5",
4033
- "fancy-log": "1.3.2",
4034
- "fs-extra": "^10.0.1",
4035
- "glob-ignore": "^1.0.2",
4036
- "glob-parent": "^3.0.1",
4037
- gulp: "^4.0.2",
4038
- "gulp-watch": "^5.0.1",
4039
- htmlparser2: "^7.2.0",
4040
- inquirer: "^7.3.3",
4041
- leven: "3.1.0",
4042
- lodash: "^4.17.21",
4043
- metalsmith: "^2.3.0",
4044
- "miniprogram-ci": "1.4.13",
4045
- moment: "^2.29.2",
4046
- "object-assign": "^4.0.1",
4047
- ora: "^5.1.0",
4048
- "path-is-absolute": "^1.0.1",
4049
- "plugin-error": "^1.0.0",
4050
- postcss: "^8.4.6",
4051
- precinct: "^8.3.1",
4052
- "readable-stream": "^2.2.2",
4053
- "replace-ext": "^2.0.0",
4054
- request: "^2.88.2",
4055
- shelljs: "^0.8.4",
4056
- slash: "^1.0.0",
4057
- "strip-comments": "^2.0.1",
4058
- through2: "^4.0.2",
4059
- unzipper: "^0.10.11",
4060
- vinyl: "^2.1.0",
4061
- "vinyl-file": "^2.0.0",
4062
- "vinyl-sourcemaps-apply": "^0.2.0"
4063
- },
4064
- engines: {
4065
- node: "^12.17.0 || >= 14.13.1"
4066
- },
4067
- jest: {
4068
- testEnvironment: "jest-environment-node"
4069
- }
4070
- };
4071
-
4072
3761
  const semver = require$$1__default$7;
4073
- const packageJson = require$$9;
4074
- const chalk$1 = require$$0__default;
3762
+ const packageJson = require$$12;
3763
+ const chalk$1 = require$$3__default;
4075
3764
  const {
4076
- info: info$1
3765
+ info
4077
3766
  } = log$1;
4078
3767
  const requiredVersion = packageJson.engines.node;
4079
3768
  const packName = packageJson.name;
@@ -4088,7 +3777,7 @@ const checkNodeVersion = (wanted, id) => {
4088
3777
  if (!semver.satisfies(process.version, wanted, {
4089
3778
  includePrerelease: true
4090
3779
  })) {
4091
- info$1(chalk$1.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id} 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
3780
+ info(chalk$1.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id} 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
4092
3781
  process.exit(1);
4093
3782
  }
4094
3783
  };
@@ -4105,31 +3794,36 @@ function check$1() {
4105
3794
 
4106
3795
  var check_1 = check$1;
4107
3796
 
4108
- const chalk = require$$0__default;
4109
- const commander = require$$0__default$1;
3797
+ /* eslint-disable no-param-reassign */
3798
+ const chalk = require$$3__default;
3799
+ const commander = require$$1__default$8;
3800
+ const path = require$$1__default$1;
3801
+ const fs = require$$0__default$1;
4110
3802
  const {
4111
- suggestCommands,
4112
3803
  resolve
4113
3804
  } = widgets;
4114
3805
  const {
4115
- info
3806
+ infoNoTime
4116
3807
  } = log$1;
4117
3808
  const {
4118
3809
  getTmsConfig
4119
3810
  } = tmsMpconfig.exports;
4120
3811
  const {
4121
3812
  TMS_NAME
4122
- } = require$$5;
3813
+ } = constant;
4123
3814
  const commands = entry;
4124
3815
  const check = check_1;
4125
- const fs = require$$0__default$2;
3816
+ const {
3817
+ loadExtendCmd
3818
+ } = extendCmd;
3819
+ const report = report_1;
4126
3820
  check();
4127
3821
  const program = new commander.Command(TMS_NAME);
4128
- program.version(`${TMS_NAME} ${require$$9.version}`, '-v, -V, --version');
3822
+ program.version(`${TMS_NAME} ${require$$12.version}`, '-v, -V, --version'); // 注册命令底层实现
4129
3823
 
4130
3824
  function registerCommand(program, commands) {
4131
3825
  commands.forEach(cmd => {
4132
- if (cmd.type === 'child') {
3826
+ if (cmd.type === 'parent') {
4133
3827
  const childProgram = new commander.Command(cmd.name);
4134
3828
  cmd.usage && childProgram.usage(cmd.usage);
4135
3829
  cmd.description && childProgram.description(cmd.description);
@@ -4141,35 +3835,65 @@ function registerCommand(program, commands) {
4141
3835
  const command = program.command(cmd.command);
4142
3836
  cmd.usage && command.usage(cmd.usage);
4143
3837
  cmd.description && command.description(cmd.description);
4144
- (_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt));
3838
+ (_cmd$options = cmd.options) === null || _cmd$options === void 0 ? void 0 : _cmd$options.forEach(opt => command.option(...opt)); // 上报
3839
+
3840
+ command.hook('preAction', thisCommand => {
3841
+ report(`${thisCommand._name}-pre`);
3842
+ }); // 上报
3843
+
3844
+ command.hook('postAction', thisCommand => {
3845
+ report(`${thisCommand._name}-post`);
3846
+ });
4145
3847
  command.action(cmd.action);
4146
3848
  }
4147
3849
  });
4148
- }
3850
+ } // 注册扩展命令
4149
3851
 
4150
- function register() {
4151
- // 注册脚手架内部命令
4152
- registerCommand(program, commands); // 注册扩展命令
4153
3852
 
4154
- if (fs.existsSync(resolve('tms.config.js'))) {
4155
- const tmsConfig = getTmsConfig();
3853
+ function registerExtendCommand(program, configPath) {
3854
+ const tmsConfig = getTmsConfig(configPath);
3855
+
3856
+ if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.commands) {
3857
+ const commands = typeof tmsConfig.commands === 'function' ? tmsConfig.commands() : tmsConfig.commands;
4156
3858
 
4157
- if (Array.isArray(tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.commands)) {
4158
- registerCommand(program, tmsConfig.commands);
3859
+ if (Array.isArray(commands)) {
3860
+ registerCommand(program, commands);
4159
3861
  }
4160
3862
  }
3863
+ } // 注册所有的命令
3864
+
3865
+
3866
+ function registerAllCmds(program, commands) {
3867
+ // 注册脚手架内部命令
3868
+ registerCommand(program, commands); // 注册npm包扩展命令
3869
+
3870
+ const cmdConfigs = loadExtendCmd();
3871
+ cmdConfigs.forEach(cmdConfig => {
3872
+ registerExtendCommand(program, path.dirname(cmdConfig));
3873
+ }); // 注册当前目录扩展命令
3874
+
3875
+ const tmsConfigPath = resolve('./tms.config.js');
3876
+
3877
+ if (fs.existsSync(tmsConfigPath)) {
3878
+ registerExtendCommand(program, path.dirname(tmsConfigPath));
3879
+ }
4161
3880
  }
4162
3881
 
4163
- register();
3882
+ registerAllCmds(program, commands); // 捕获未注册的命令
3883
+
3884
+ program.arguments('<command>').option('-c, --config <value>', '配置', value => {
3885
+ // 注册指定配置的扩展命令
3886
+ registerExtendCommand(program, path.dirname(resolve(value)));
3887
+ }).action(cmd => {
3888
+ infoNoTime(chalk.yellow(`
3889
+ 没有找到${cmd}命令
3890
+ 你可以通过${chalk.green('tmskit install-cmd <npm-name>')}安装扩展命令, ${chalk.green('扩展命令列表:https://www.npmjs.com/search?q=tmskit-cmd')}
3891
+ 你也可以通过 ${chalk.green('tmskit <command> --config=../tms.config.js')} 指定本地的扩展命令
3892
+ `));
3893
+ report(`${cmd}-not-find`);
3894
+ });
4164
3895
  program.on('--help', () => {
4165
- info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
4166
- }); // 捕获未注册的命令
4167
-
4168
- program.arguments('<command>').action(cmd => {
4169
- program.outputHelp();
4170
- info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
4171
- suggestCommands(cmd);
4172
- process.exitCode = 1;
3896
+ infoNoTime(`Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
4173
3897
  });
4174
3898
 
4175
3899
  if (!process.argv.slice(2).length) {