@tmsfe/tmskit 0.0.19 → 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/CHANGELOG.md +12 -1
- package/dist/index.cjs.js +1772 -1860
- package/package.json +13 -14
- package/src/{init.js → check.js} +2 -3
- package/src/compile/build.js +2 -2
- package/src/compile/compile.js +53 -155
- package/src/compile/dev.js +33 -72
- package/src/compile/plugins/mpProjectJson.js +13 -0
- package/src/compile/watch.js +79 -28
- package/src/config/constant.js +48 -9
- package/src/core/buildAppJson.js +17 -21
- package/src/core/checkDependencies.js +41 -21
- package/src/core/cloneModules.js +8 -7
- package/src/core/handleError.js +7 -1
- package/src/core/npm.js +13 -27
- package/src/core/recommendVersion.js +118 -0
- package/src/core/report.js +30 -0
- package/src/core/symbolicLink.js +17 -19
- package/src/core/tmsMpconfig.js +189 -97
- package/src/entry.js +16 -17
- package/src/index.js +61 -20
- package/src/scripts/create/generator.js +1 -2
- package/src/scripts/create/index.js +75 -32
- package/src/scripts/extend-cmd/index.js +74 -0
- package/src/scripts/run/build/index.js +7 -4
- package/src/scripts/run/cloud/index.js +0 -2
- package/src/scripts/run/dev/index.js +22 -15
- package/src/scripts/run/index.js +50 -60
- package/src/scripts/run/init/index.js +13 -34
- package/src/{core → scripts/run/install}/cache.js +4 -4
- package/src/scripts/run/install/index.js +18 -21
- package/src/utils/log.js +3 -0
- package/src/utils/widgets.js +58 -34
package/dist/index.cjs.js
CHANGED
|
@@ -1,97 +1,84 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var require$$
|
|
3
|
+
var require$$3 = require('chalk');
|
|
4
4
|
var require$$1 = require('moment');
|
|
5
|
-
var require$$0
|
|
6
|
-
var require$$1$1 = require('
|
|
7
|
-
var require$$
|
|
8
|
-
var require$$
|
|
9
|
-
var require$$
|
|
10
|
-
var require$$
|
|
11
|
-
var require$$
|
|
12
|
-
var require$$0$
|
|
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');
|
|
13
13
|
var require$$1$3 = require('ejs');
|
|
14
14
|
var require$$1$4 = require('inquirer');
|
|
15
|
-
var require$$0$
|
|
16
|
-
var require$$0$
|
|
15
|
+
var require$$0$4 = require('metalsmith');
|
|
16
|
+
var require$$0$5 = require('request');
|
|
17
|
+
var require$$10 = require('unzipper');
|
|
17
18
|
var require$$1$5 = require('crypto');
|
|
18
|
-
var require$$0$
|
|
19
|
+
var require$$0$6 = require('miniprogram-ci');
|
|
19
20
|
var require$$1$6 = require('fs-extra');
|
|
20
21
|
var require$$1$7 = require('semver');
|
|
21
|
-
var require$$0$
|
|
22
|
-
var require$$
|
|
23
|
-
var require$$1
|
|
24
|
-
var require$$
|
|
25
|
-
var require$$0$
|
|
26
|
-
var require$$
|
|
27
|
-
var require$$3 = require('fancy-log');
|
|
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
28
|
var require$$4$1 = require('ansi-colors');
|
|
29
29
|
var require$$5 = require('chokidar');
|
|
30
30
|
var require$$6$1 = require('readable-stream');
|
|
31
|
-
var require$$7
|
|
31
|
+
var require$$7 = require('vinyl-file');
|
|
32
32
|
var require$$8 = require('vinyl');
|
|
33
33
|
var require$$9 = require('anymatch');
|
|
34
34
|
var require$$11 = require('glob-parent');
|
|
35
|
-
var require$$2$
|
|
36
|
-
var require$$10 = require('path-is-absolute');
|
|
37
|
-
var require$$12 = require('slash');
|
|
35
|
+
var require$$2$2 = require('plugin-error');
|
|
36
|
+
var require$$10$1 = require('path-is-absolute');
|
|
37
|
+
var require$$12$1 = require('slash');
|
|
38
|
+
var require$$1$8 = require('commander');
|
|
38
39
|
|
|
39
40
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
40
41
|
|
|
41
|
-
var require$$
|
|
42
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
42
43
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
43
|
-
var require$$0__default
|
|
44
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
44
45
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
46
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
45
47
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
48
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
46
49
|
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
47
50
|
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
48
51
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
49
|
-
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
50
|
-
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
51
52
|
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
52
53
|
var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
|
|
54
|
+
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
53
55
|
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
54
|
-
var require$$
|
|
56
|
+
var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
|
|
55
57
|
var require$$1__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$1$5);
|
|
56
|
-
var require$$0__default$
|
|
58
|
+
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
57
59
|
var require$$1__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$1$6);
|
|
58
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);
|
|
59
65
|
var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
60
|
-
var require$$
|
|
61
|
-
var require$$
|
|
62
|
-
var require$$1__default$9 = /*#__PURE__*/_interopDefaultLegacy(require$$1$9);
|
|
63
|
-
var require$$0__default$a = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
64
|
-
var require$$0__default$b = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
|
|
65
|
-
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
66
|
-
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
|
|
66
|
+
var require$$3__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
|
|
67
|
+
var require$$4__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
|
|
67
68
|
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
68
69
|
var require$$6__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$6$1);
|
|
69
|
-
var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7
|
|
70
|
+
var require$$7__default = /*#__PURE__*/_interopDefaultLegacy(require$$7);
|
|
70
71
|
var require$$8__default = /*#__PURE__*/_interopDefaultLegacy(require$$8);
|
|
71
72
|
var require$$9__default = /*#__PURE__*/_interopDefaultLegacy(require$$9);
|
|
72
73
|
var require$$11__default = /*#__PURE__*/_interopDefaultLegacy(require$$11);
|
|
73
|
-
var require$$2__default$
|
|
74
|
-
var require$$10__default = /*#__PURE__*/_interopDefaultLegacy(require$$10);
|
|
75
|
-
var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12);
|
|
76
|
-
|
|
77
|
-
function getAugmentedNamespace(n) {
|
|
78
|
-
if (n.__esModule) return n;
|
|
79
|
-
var a = Object.defineProperty({}, '__esModule', {value: true});
|
|
80
|
-
Object.keys(n).forEach(function (k) {
|
|
81
|
-
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
82
|
-
Object.defineProperty(a, k, d.get ? d : {
|
|
83
|
-
enumerable: true,
|
|
84
|
-
get: function () {
|
|
85
|
-
return n[k];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
return a;
|
|
90
|
-
}
|
|
74
|
+
var require$$2__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$2$2);
|
|
75
|
+
var require$$10__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$10$1);
|
|
76
|
+
var require$$12__default = /*#__PURE__*/_interopDefaultLegacy(require$$12$1);
|
|
77
|
+
var require$$1__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$1$8);
|
|
91
78
|
|
|
92
79
|
var src$2 = {};
|
|
93
80
|
|
|
94
|
-
const chalk$
|
|
81
|
+
const chalk$4 = require$$3__default;
|
|
95
82
|
const moment = require$$1__default;
|
|
96
83
|
/**
|
|
97
84
|
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
@@ -134,29 +121,29 @@ const succeed$2 = (message = '') => {
|
|
|
134
121
|
|
|
135
122
|
|
|
136
123
|
const warn$2 = message => {
|
|
137
|
-
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$
|
|
124
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk$4.yellow(message));
|
|
138
125
|
};
|
|
139
126
|
|
|
140
|
-
const info$
|
|
127
|
+
const info$d = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
128
|
+
|
|
129
|
+
const infoNoTime$2 = (...args) => console.log(...args);
|
|
141
130
|
|
|
142
131
|
var log$1 = {
|
|
143
132
|
fail: fail$9,
|
|
144
133
|
succeed: succeed$2,
|
|
145
134
|
warn: warn$2,
|
|
146
|
-
info: info$
|
|
135
|
+
info: info$d,
|
|
136
|
+
infoNoTime: infoNoTime$2
|
|
147
137
|
};
|
|
148
138
|
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
const shelljs$7 = require$$0__default$3;
|
|
155
|
-
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;
|
|
156
144
|
const {
|
|
157
|
-
info: info$
|
|
145
|
+
info: info$c
|
|
158
146
|
} = log$1;
|
|
159
|
-
const chalk$2 = require$$0__default;
|
|
160
147
|
const shelljsOptions = {
|
|
161
148
|
slient: true,
|
|
162
149
|
async: false
|
|
@@ -164,38 +151,16 @@ const shelljsOptions = {
|
|
|
164
151
|
|
|
165
152
|
const cwd = process.cwd();
|
|
166
153
|
|
|
167
|
-
function resolve$
|
|
168
|
-
return path$
|
|
154
|
+
function resolve$e(...args) {
|
|
155
|
+
return path$f.resolve(cwd, ...args);
|
|
169
156
|
}
|
|
170
|
-
/**
|
|
171
|
-
* 用户输入命令时,进行提示
|
|
172
|
-
* @param {String} unknownCommand 非预期的命令
|
|
173
|
-
* @returns {Undefined} 无需返回值
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
const suggestCommands$1 = unknownCommand => {
|
|
177
|
-
const availableCommands = program$1.commands.map(cmd => cmd._name);
|
|
178
|
-
let suggestion;
|
|
179
|
-
availableCommands.forEach(cmd => {
|
|
180
|
-
const isBestMatch = leven(cmd, unknownCommand) < leven(suggestion || '', unknownCommand);
|
|
181
|
-
|
|
182
|
-
if (leven(cmd, unknownCommand) < 3 && isBestMatch) {
|
|
183
|
-
suggestion = cmd;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
if (suggestion) {
|
|
188
|
-
info$9(` ${chalk$2.red(`Did you mean ${chalk$2.yellow(suggestion)}?`)}`);
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
157
|
/**
|
|
192
158
|
* 判断变量是否是一个数组
|
|
193
159
|
* @param { unknown } obj 变量
|
|
194
160
|
* @returns { boolean } 是否是一个数组
|
|
195
161
|
*/
|
|
196
162
|
|
|
197
|
-
|
|
198
|
-
function isObject$2(obj) {
|
|
163
|
+
function isObject(obj) {
|
|
199
164
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
200
165
|
}
|
|
201
166
|
/**
|
|
@@ -205,7 +170,7 @@ function isObject$2(obj) {
|
|
|
205
170
|
*/
|
|
206
171
|
|
|
207
172
|
|
|
208
|
-
function isArray
|
|
173
|
+
function isArray(obj) {
|
|
209
174
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
210
175
|
}
|
|
211
176
|
/**
|
|
@@ -217,24 +182,24 @@ function isArray$1(obj) {
|
|
|
217
182
|
*/
|
|
218
183
|
|
|
219
184
|
|
|
220
|
-
function downloadRepoForGit$
|
|
185
|
+
function downloadRepoForGit$1(url, dest, branch) {
|
|
221
186
|
const cwd = process.cwd();
|
|
222
187
|
return new Promise((resolve, reject) => {
|
|
223
188
|
// 如果目标目录不存在
|
|
224
189
|
if (fs$g.existsSync(dest)) {
|
|
225
|
-
shelljs$
|
|
190
|
+
shelljs$9.rm('-rf', path$f.join(dest));
|
|
226
191
|
}
|
|
227
192
|
|
|
228
|
-
shelljs$
|
|
229
|
-
shelljs$
|
|
230
|
-
shelljs$
|
|
193
|
+
shelljs$9.mkdir('-p', dest);
|
|
194
|
+
shelljs$9.cd(dest);
|
|
195
|
+
shelljs$9.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, {
|
|
231
196
|
silent: true
|
|
232
197
|
}, (code, stdout, stderr) => {
|
|
233
198
|
if (code !== 0) {
|
|
234
199
|
reject(stderr);
|
|
235
200
|
}
|
|
236
201
|
|
|
237
|
-
shelljs$
|
|
202
|
+
shelljs$9.cd(cwd);
|
|
238
203
|
resolve();
|
|
239
204
|
});
|
|
240
205
|
});
|
|
@@ -250,30 +215,32 @@ function downloadRepoForGit$2(url, dest, branch) {
|
|
|
250
215
|
function pullRepoForGit$1(dest, branch) {
|
|
251
216
|
const cwd = process.cwd();
|
|
252
217
|
return new Promise((resolve, reject) => {
|
|
253
|
-
shelljs$
|
|
254
|
-
shelljs$
|
|
255
|
-
shelljs$
|
|
218
|
+
shelljs$9.cd(dest);
|
|
219
|
+
shelljs$9.exec('git config pull.rebase false', shelljsOptions);
|
|
220
|
+
shelljs$9.exec(`git pull origin ${branch}`, {
|
|
256
221
|
silent: true
|
|
257
222
|
}, (code, stdout, stderr) => {
|
|
258
223
|
if (code !== 0) {
|
|
259
224
|
reject(stderr);
|
|
260
225
|
}
|
|
261
226
|
|
|
262
|
-
shelljs$
|
|
227
|
+
shelljs$9.cd(cwd);
|
|
263
228
|
resolve();
|
|
264
229
|
});
|
|
265
230
|
});
|
|
266
231
|
}
|
|
267
232
|
/**
|
|
268
233
|
* npm 下载依赖
|
|
269
|
-
* @param {
|
|
234
|
+
* @param {string} dir 下载npm的目录
|
|
235
|
+
* @param {object} npm npm的配置 (见下获取npm源入参)
|
|
270
236
|
* @returns
|
|
271
237
|
*/
|
|
272
238
|
|
|
273
239
|
|
|
274
|
-
function npmInstall$2(dir) {
|
|
240
|
+
function npmInstall$2(dir, npmConfig) {
|
|
275
241
|
return new Promise((resolve, reject) => {
|
|
276
|
-
|
|
242
|
+
const registry = getNpmRegistry(npmConfig);
|
|
243
|
+
shelljs$9.exec(`npm install --production ${registry}`, {
|
|
277
244
|
cwd: dir,
|
|
278
245
|
silent: true
|
|
279
246
|
}, (code, stdout, stderr) => {
|
|
@@ -284,6 +251,30 @@ function npmInstall$2(dir) {
|
|
|
284
251
|
resolve();
|
|
285
252
|
});
|
|
286
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;
|
|
287
278
|
}
|
|
288
279
|
/**
|
|
289
280
|
* 计算各项任务耗时
|
|
@@ -305,8 +296,8 @@ const cost = start => Date.now() - start;
|
|
|
305
296
|
function createTask$3(task, startText, endText) {
|
|
306
297
|
return async (...args) => {
|
|
307
298
|
const start = Date.now();
|
|
308
|
-
const spinner = ora();
|
|
309
|
-
info$
|
|
299
|
+
const spinner = ora$1();
|
|
300
|
+
info$c(startText);
|
|
310
301
|
spinner.start();
|
|
311
302
|
const result = await task(...args);
|
|
312
303
|
endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
|
|
@@ -322,20 +313,16 @@ function createTask$3(task, startText, endText) {
|
|
|
322
313
|
|
|
323
314
|
const camelize = str => str.replace(/-(\w)/g, (a, c) => c ? c.toUpperCase() : '');
|
|
324
315
|
|
|
325
|
-
const mergeMap = function (obj, src) {
|
|
316
|
+
const mergeMap$1 = function (obj, src) {
|
|
326
317
|
for (const [k, v] of src) {
|
|
327
|
-
|
|
328
|
-
obj.set(k, obj.get(k) + v);
|
|
329
|
-
} else {
|
|
330
|
-
obj.set(k, v);
|
|
331
|
-
}
|
|
318
|
+
obj.set(k, v);
|
|
332
319
|
}
|
|
333
320
|
|
|
334
321
|
return obj;
|
|
335
322
|
};
|
|
336
323
|
|
|
337
324
|
const relativeCwdPath$1 = function (file) {
|
|
338
|
-
return path$
|
|
325
|
+
return path$f.relative(process.cwd(), file);
|
|
339
326
|
};
|
|
340
327
|
/**
|
|
341
328
|
* 从一个对象中,检索出去几个字段
|
|
@@ -345,7 +332,7 @@ const relativeCwdPath$1 = function (file) {
|
|
|
345
332
|
*/
|
|
346
333
|
|
|
347
334
|
|
|
348
|
-
const filterField$
|
|
335
|
+
const filterField$5 = (obj, filterNames = []) => {
|
|
349
336
|
const newObj = { ...obj
|
|
350
337
|
};
|
|
351
338
|
filterNames.forEach(name => {
|
|
@@ -359,7 +346,7 @@ const filterField$3 = (obj, filterNames = []) => {
|
|
|
359
346
|
|
|
360
347
|
function findFiles(globPath, filter = []) {
|
|
361
348
|
return new Promise((resolve, reject) => {
|
|
362
|
-
glob
|
|
349
|
+
glob(globPath, filter, (err, files) => {
|
|
363
350
|
if (err) {
|
|
364
351
|
reject(err);
|
|
365
352
|
}
|
|
@@ -367,89 +354,494 @@ function findFiles(globPath, filter = []) {
|
|
|
367
354
|
resolve(files);
|
|
368
355
|
});
|
|
369
356
|
});
|
|
357
|
+
} // 获取绝对路径
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
function getAbsolutePath$3(pathDir, cwd = '') {
|
|
361
|
+
let newPath = pathDir;
|
|
362
|
+
newPath = newPath.startsWith('/') ? newPath : resolve$e(cwd, newPath);
|
|
363
|
+
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
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;
|
|
370
386
|
}
|
|
371
387
|
|
|
372
388
|
var widgets = {
|
|
373
|
-
resolve: resolve$
|
|
374
|
-
isObject
|
|
375
|
-
isArray
|
|
389
|
+
resolve: resolve$e,
|
|
390
|
+
isObject,
|
|
391
|
+
isArray,
|
|
376
392
|
createTask: createTask$3,
|
|
377
|
-
downloadRepoForGit: downloadRepoForGit$
|
|
393
|
+
downloadRepoForGit: downloadRepoForGit$1,
|
|
378
394
|
pullRepoForGit: pullRepoForGit$1,
|
|
379
|
-
suggestCommands: suggestCommands$1,
|
|
380
395
|
camelize,
|
|
381
396
|
npmInstall: npmInstall$2,
|
|
382
|
-
mergeMap,
|
|
397
|
+
mergeMap: mergeMap$1,
|
|
383
398
|
relativeCwdPath: relativeCwdPath$1,
|
|
384
|
-
filterField: filterField$
|
|
385
|
-
findFiles
|
|
399
|
+
filterField: filterField$5,
|
|
400
|
+
findFiles,
|
|
401
|
+
getAbsolutePath: getAbsolutePath$3,
|
|
402
|
+
getNpmRegistry,
|
|
403
|
+
versionCompare: versionCompare$1
|
|
386
404
|
};
|
|
387
405
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const os = require('os'); // 用户目录
|
|
406
|
+
var tmsMpconfig = {exports: {}};
|
|
391
407
|
|
|
408
|
+
const path$e = require$$1__default$1;
|
|
409
|
+
const os = require$$1__default$2; // 用户目录
|
|
392
410
|
|
|
393
411
|
const HOME_DIR = os.homedir(); // 所有文件的缓存目录
|
|
394
412
|
|
|
395
|
-
const CACHE_DIR
|
|
413
|
+
const CACHE_DIR = path$e.resolve(HOME_DIR, '.tmskit'); // 版本管理的CDN地址
|
|
414
|
+
|
|
415
|
+
const VERSION_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json'; // version缓存文件
|
|
416
|
+
|
|
417
|
+
const VERSION_CACHE_FILE$1 = path$e.resolve(CACHE_DIR, 'version_cache_file.json'); // npm缓存文件
|
|
396
418
|
|
|
397
|
-
const
|
|
419
|
+
const NPM_CACHE_FILE$1 = path$e.resolve(CACHE_DIR, 'npm_cache_file.json'); // 脚手架模板代码所在目录
|
|
398
420
|
|
|
399
|
-
const TEMPLATE_DIR$1 = path$
|
|
421
|
+
const TEMPLATE_DIR$1 = path$e.resolve(CACHE_DIR, 'template'); // 第三方模块源码存放的临时缓存目录
|
|
400
422
|
|
|
401
|
-
const MODULE_CODE_DIR$
|
|
423
|
+
const MODULE_CODE_DIR$2 = path$e.resolve(CACHE_DIR, 'modules_code'); // 缓存分包node_modules的目录
|
|
402
424
|
|
|
403
|
-
const
|
|
425
|
+
const NODE_MODULES_DIR$2 = path$e.resolve(CACHE_DIR, 'node_modules'); // 扩展命令源码的存放处
|
|
426
|
+
|
|
427
|
+
const EXTEND_CMD$1 = path$e.resolve(CACHE_DIR, 'cmd'); // 创建模板的名称
|
|
428
|
+
|
|
429
|
+
const TEMPLATE_NAME$1 = 'tmskit-template'; // 脚手架模板的远程地址
|
|
430
|
+
|
|
431
|
+
const TEMPLATE_URL$1 = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip'; // 脚手架的名称
|
|
404
432
|
|
|
405
433
|
const TMS_NAME$1 = 'tmskit'; // 脚手架的配置名称
|
|
406
434
|
|
|
407
|
-
const TMS_CONFIG_FILENAME
|
|
408
|
-
const TMS_PRIVATE_FILENAME
|
|
435
|
+
const TMS_CONFIG_FILENAME = 'tms.config.js';
|
|
436
|
+
const TMS_PRIVATE_FILENAME = 'tms.private.config.js'; // 模块代码的默认在modules子目录
|
|
409
437
|
|
|
410
438
|
const DEFAULT_MODULE_DIR = 'modules'; // 模块代码的默认在modules子目录
|
|
411
439
|
|
|
412
440
|
const DEFAULT_CLOUD_MODULE_DIR = './cloud'; // 模块的配置文件的名称
|
|
413
441
|
|
|
414
|
-
const MODULE_CONFIG_FILENAME
|
|
442
|
+
const MODULE_CONFIG_FILENAME = 'module.config.json'; // 默认的webpack entry
|
|
415
443
|
|
|
416
444
|
const DEFAULT_WEBPACK_ENTRY = {
|
|
417
|
-
app: path$
|
|
445
|
+
app: path$e.resolve(process.cwd(), 'app')
|
|
418
446
|
}; // 默认从源码拷贝到编译后的配置
|
|
419
447
|
|
|
420
|
-
const DEFAULT_COPY_CONFIG$
|
|
448
|
+
const DEFAULT_COPY_CONFIG$2 = ['package.json', 'sitemap.json', 'project.config.json'];
|
|
421
449
|
const ENV = {
|
|
422
450
|
dev: 'development',
|
|
423
451
|
prod: 'production'
|
|
424
452
|
};
|
|
425
453
|
const TEMPLATE_TKIT_DIR$2 = '_tmskit';
|
|
454
|
+
const CREATE_TEMPLATE_QUESTION$1 = [{
|
|
455
|
+
type: 'list',
|
|
456
|
+
name: 'projectType',
|
|
457
|
+
message: '选择你要创建的模板',
|
|
458
|
+
choices: [{
|
|
459
|
+
name: '小程序项目',
|
|
460
|
+
value: 'mp'
|
|
461
|
+
}, {
|
|
462
|
+
name: '小程序模块',
|
|
463
|
+
value: 'mp-module'
|
|
464
|
+
}, {
|
|
465
|
+
name: '构建工具扩展命令',
|
|
466
|
+
value: 'cmd'
|
|
467
|
+
}]
|
|
468
|
+
}];
|
|
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
|
+
};
|
|
493
|
+
|
|
494
|
+
var defaultTmsConfig = {
|
|
495
|
+
// 全局的环境配置项
|
|
496
|
+
envData: {},
|
|
497
|
+
// 模块配置信息
|
|
498
|
+
modules: {},
|
|
499
|
+
cloudDir: 'cloud',
|
|
500
|
+
// 第三方依赖代码需要拷贝到本项目的
|
|
501
|
+
dependencies: {},
|
|
426
502
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
503
|
+
/** 编译输出文件夹位置 */
|
|
504
|
+
outputDir: 'dist',
|
|
505
|
+
|
|
506
|
+
/** 源码监听路径 */
|
|
507
|
+
sourceDir: './',
|
|
508
|
+
|
|
509
|
+
/** 静态资源目录 */
|
|
510
|
+
static: []
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* 用来读取处理tms.config.js与module.config.json字段
|
|
515
|
+
*/
|
|
516
|
+
|
|
517
|
+
(function (module) {
|
|
518
|
+
/* eslint-disable no-param-reassign, no-nested-ternary */
|
|
519
|
+
const loadash = require$$0__default$2;
|
|
520
|
+
const fs = require$$0__default$1;
|
|
521
|
+
const path = require$$1__default$1;
|
|
522
|
+
const {
|
|
523
|
+
TMS_CONFIG_FILENAME,
|
|
524
|
+
MODULE_CONFIG_FILENAME,
|
|
525
|
+
TMS_PRIVATE_FILENAME
|
|
526
|
+
} = constant;
|
|
527
|
+
const {
|
|
528
|
+
resolve,
|
|
529
|
+
isObject,
|
|
530
|
+
isArray,
|
|
531
|
+
getAbsolutePath
|
|
532
|
+
} = widgets;
|
|
533
|
+
const defaultTmsConfig$1 = defaultTmsConfig;
|
|
534
|
+
const {
|
|
535
|
+
fail
|
|
536
|
+
} = log$1;
|
|
537
|
+
/**
|
|
538
|
+
* 读取tms.config.js
|
|
539
|
+
* @param {string} configPath tms.config.js的路径
|
|
540
|
+
*/
|
|
541
|
+
|
|
542
|
+
const readTmsConfig = function (configPath) {
|
|
543
|
+
const tmsConfigPath = configPath ? `${configPath}/${TMS_CONFIG_FILENAME}` : resolve(TMS_CONFIG_FILENAME);
|
|
544
|
+
|
|
545
|
+
if (!fs.existsSync(tmsConfigPath)) {
|
|
546
|
+
fail(`${path.dirname(tmsConfigPath)}没有找到tms.config.js,请进行配置`);
|
|
547
|
+
process.exit(1);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const tmsConfigFn = require(tmsConfigPath);
|
|
551
|
+
|
|
552
|
+
const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn() : tmsConfigFn; // 合并默认值
|
|
553
|
+
|
|
554
|
+
return loadash.mergeWith({}, defaultTmsConfig$1, tmsConfig);
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* 读取tms.private.config.js
|
|
558
|
+
* @param {string} configPath tms.private.config.js的路径
|
|
559
|
+
*/
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
const readTmsPrivateCf = function (configPath) {
|
|
563
|
+
let tmsPrivateCf = {};
|
|
564
|
+
const tmsPrivatePath = configPath ? `${configPath}/${TMS_PRIVATE_FILENAME}` : resolve(TMS_PRIVATE_FILENAME);
|
|
565
|
+
|
|
566
|
+
if (fs.existsSync(tmsPrivatePath)) {
|
|
567
|
+
const tmsPrivateFn = require(tmsPrivatePath);
|
|
568
|
+
|
|
569
|
+
tmsPrivateCf = typeof tmsPrivateFn === 'function' ? tmsPrivateFn() : tmsPrivateFn;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
return tmsPrivateCf;
|
|
573
|
+
};
|
|
574
|
+
/**
|
|
575
|
+
* 获取tms.config.js, tms.private.config.js的配置项
|
|
576
|
+
* @param {string} configPath config.js的路径
|
|
577
|
+
* @returns
|
|
578
|
+
*/
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
const getTmsConfig = configPath => {
|
|
582
|
+
const tmsPrivateCf = readTmsPrivateCf(configPath);
|
|
583
|
+
const tmsConfig = readTmsConfig(configPath);
|
|
584
|
+
const modules = {};
|
|
585
|
+
|
|
586
|
+
if (Array.isArray(tmsConfig.modules)) {
|
|
587
|
+
modules.all = tmsConfig.modules;
|
|
588
|
+
tmsConfig.modules = modules;
|
|
589
|
+
} // 合并默认值
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
|
|
593
|
+
if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
|
|
594
|
+
return objValue.concat(srcValue);
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
return res;
|
|
598
|
+
};
|
|
599
|
+
/**
|
|
600
|
+
* 根据moduleNames获取modules
|
|
601
|
+
* @param { object } tmsConfig
|
|
602
|
+
* @param { array } moduleNames
|
|
603
|
+
* @param {boolean} errorIsQuit 找不到配置文件是否退出
|
|
604
|
+
* @returns
|
|
605
|
+
*/
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
const getModulesByModuleNames = function (tmsConfig, moduleNames = []) {
|
|
609
|
+
const targetModules = [];
|
|
610
|
+
moduleNames.forEach(moduleName => {
|
|
611
|
+
const module = tmsConfig.modules.all.find(module => module.moduleName === moduleName);
|
|
612
|
+
|
|
613
|
+
if (!module) {
|
|
614
|
+
throw new Error(`你启动的模块${moduleName}在tms.config.js的modules.all中没有注册`);
|
|
615
|
+
}
|
|
446
616
|
|
|
447
|
-
|
|
617
|
+
targetModules.push(module);
|
|
618
|
+
});
|
|
619
|
+
return targetModules;
|
|
620
|
+
};
|
|
621
|
+
/**
|
|
622
|
+
* 适配处理module.config.json的字段
|
|
623
|
+
* @param { object } fileContent module.config.json的内容
|
|
624
|
+
* @param { string } appName 小程序的名称
|
|
625
|
+
*/
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
function adaptMpCgContent(fileContent, appName) {
|
|
629
|
+
const handleContent = function (appName, current) {
|
|
630
|
+
let res = current;
|
|
631
|
+
|
|
632
|
+
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
633
|
+
res = { ...current,
|
|
634
|
+
...current.mpConfig[appName]
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
delete res.mpConfig;
|
|
639
|
+
delete res.isSubpackages;
|
|
640
|
+
return res;
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
let content = fileContent;
|
|
644
|
+
|
|
645
|
+
if (isArray(content)) {
|
|
646
|
+
let i = content.length - 1;
|
|
647
|
+
|
|
648
|
+
while (i >= 0) {
|
|
649
|
+
content[i] = handleContent(appName, content[i]);
|
|
650
|
+
i--; // eslint-disable-line
|
|
651
|
+
}
|
|
652
|
+
} else {
|
|
653
|
+
content = handleContent(appName, content);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
return content;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const adaptDependencies = function (dependencies, subPackages) {
|
|
660
|
+
const newDependencies = dependencies || [];
|
|
661
|
+
subPackages.forEach(item => {
|
|
662
|
+
if (item.dependencies) {
|
|
663
|
+
dependencies = newDependencies.concat(item.dependencies);
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
return newDependencies;
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
const adaptSubPackages = function (moduleConfig, appName) {
|
|
670
|
+
const subPackages = isObject(moduleConfig) && moduleConfig.subPackages ? moduleConfig.subPackages : isObject(moduleConfig) ? [moduleConfig] : moduleConfig;
|
|
671
|
+
return adaptMpCgContent(subPackages, appName);
|
|
672
|
+
};
|
|
673
|
+
/**
|
|
674
|
+
* 获取模块module.config.json中的配置信息
|
|
675
|
+
* @param {array} modules 用户要编译的模块列表
|
|
676
|
+
* @param { string } appName 小程序的名称
|
|
677
|
+
*/
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
function getModulesConfig(modules = [], appName) {
|
|
681
|
+
const modulesConfig = [];
|
|
682
|
+
modules.forEach(moduleItem => {
|
|
683
|
+
const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
|
|
684
|
+
let moduleConfig;
|
|
685
|
+
|
|
686
|
+
try {
|
|
687
|
+
moduleConfig = JSON.parse(fs.readFileSync(moduleConfigPath, 'utf-8'));
|
|
688
|
+
} catch (e) {
|
|
689
|
+
throw new Error(`${moduleConfigPath}json解析报错: ${e}`);
|
|
690
|
+
} // 兼容历史逻辑,后续可删除--- start
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
const subPackages = adaptSubPackages(moduleConfig, appName);
|
|
694
|
+
const dependencies = adaptDependencies(moduleConfig.dependencies, subPackages);
|
|
695
|
+
moduleConfig = { ...(isObject(moduleConfig) ? moduleConfig : {}),
|
|
696
|
+
subPackages,
|
|
697
|
+
dependencies
|
|
698
|
+
}; // 兼容逻辑--- end
|
|
699
|
+
|
|
700
|
+
modulesConfig.push(moduleConfig);
|
|
701
|
+
});
|
|
702
|
+
return modulesConfig;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* 获取分包内容 (读取module.config.json的配置项)
|
|
706
|
+
* @param {array} modules
|
|
707
|
+
* @returns
|
|
708
|
+
*/
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
const getSubPackages = modules => {
|
|
712
|
+
const newSubPackages = [];
|
|
713
|
+
modules.forEach(module => {
|
|
714
|
+
(module.subPackages || []).forEach(subPackage => {
|
|
715
|
+
newSubPackages.push({ ...subPackage
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
});
|
|
719
|
+
return newSubPackages;
|
|
720
|
+
};
|
|
721
|
+
/**
|
|
722
|
+
* 获取分包的root字段
|
|
723
|
+
* @param {*} modulePath 模块的编译路径
|
|
724
|
+
* @param {*} root 分包的root字段
|
|
725
|
+
* @returns
|
|
726
|
+
*/
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
const getSubPackageRoot = function (modulePath, root) {
|
|
730
|
+
return root.startsWith(modulePath) ? root : `${modulePath}/${root}`;
|
|
731
|
+
}; // 获取分包的源码路径
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
const getSubPackageSrcPath = function (tmsConfig, module, subPackage) {
|
|
735
|
+
const srcModulePath = getAbsolutePath(module.path);
|
|
736
|
+
const buildModulePath = resolve(tmsConfig.outputDir, module.modulePath);
|
|
737
|
+
const subPackageRoot = getSubPackageRoot(module.modulePath, subPackage.root);
|
|
738
|
+
const buildSubPackagePath = resolve(tmsConfig.outputDir, subPackageRoot);
|
|
739
|
+
const subPackageRelativeModule = path.relative(buildModulePath, buildSubPackagePath);
|
|
740
|
+
const srcSubPackagePath = path.join(srcModulePath, subPackageRelativeModule);
|
|
741
|
+
return srcSubPackagePath;
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
const checkModuleItem = (tmsConfig, tmsModuleItem, moduleConfig) => {
|
|
745
|
+
const newModuleItem = { ...tmsModuleItem,
|
|
746
|
+
...moduleConfig
|
|
747
|
+
}; // 兼容逻辑
|
|
748
|
+
|
|
749
|
+
if (!newModuleItem.moduleName) newModuleItem.moduleName = newModuleItem.name;
|
|
750
|
+
delete newModuleItem.name; // 参数校验-模块源码路径
|
|
751
|
+
|
|
752
|
+
if (!newModuleItem.path) {
|
|
753
|
+
throw new Error(`${newModuleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
|
|
754
|
+
} // 参数校验-模块编译路径
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
if (!newModuleItem.modulePath) {
|
|
758
|
+
throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到modulePath字段`);
|
|
759
|
+
} // 参数校验-分包校验
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
for (const subPackage of newModuleItem.subPackages) {
|
|
763
|
+
if (!subPackage.root) {
|
|
764
|
+
throw new Error(`${newModuleItem.moduleName}模块的module.config.json中没有找到${subPackage.name}分包的root字段`);
|
|
765
|
+
} // 参数校验-判断分包源码目录是否存在
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
const subPackageSrcPath = getSubPackageSrcPath(tmsConfig, newModuleItem, subPackage);
|
|
769
|
+
|
|
770
|
+
if (!subPackageSrcPath || !fs.existsSync(subPackageSrcPath)) {
|
|
771
|
+
throw new Error(`没有找到${newModuleItem.moduleName}模块的${subPackage.name}分包源码:${subPackageSrcPath}`);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
subPackage.path = subPackageSrcPath;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
return newModuleItem;
|
|
778
|
+
};
|
|
779
|
+
/**
|
|
780
|
+
* 获取所有的模块,合并模块的依赖模块
|
|
781
|
+
* @param { object } tmsConfig
|
|
782
|
+
* @param {array} modules
|
|
783
|
+
* @param {boolean} errorIsQuit 找不到配置文件是否退出
|
|
784
|
+
* @returns
|
|
785
|
+
*/
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
const getModulesByMergeDepModules = (tmsConfig, modules, errorIsQuit = false) => {
|
|
789
|
+
const allModules = new Map();
|
|
790
|
+
|
|
791
|
+
function dfs(tmsConfig, modules) {
|
|
792
|
+
modules.forEach(moduleItem => {
|
|
793
|
+
const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
|
|
794
|
+
|
|
795
|
+
if (!fs.existsSync(moduleConfigPath)) {
|
|
796
|
+
if (!allModules.has(moduleItem.moduleName)) {
|
|
797
|
+
allModules.set(moduleItem.moduleName, moduleItem);
|
|
798
|
+
}
|
|
448
799
|
|
|
449
|
-
|
|
450
|
-
|
|
800
|
+
if (errorIsQuit) {
|
|
801
|
+
throw new Error(`${moduleItem.moduleName}模块的配置文件module.config.json在${moduleItem.path}目录下没有找到`);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
const [moduleConfig = {}] = getModulesConfig([moduleItem], tmsConfig.appName);
|
|
808
|
+
|
|
809
|
+
if (!allModules.has(moduleItem.moduleName)) {
|
|
810
|
+
allModules.set(moduleItem.moduleName, checkModuleItem(tmsConfig, moduleItem, moduleConfig));
|
|
811
|
+
const dependenciesModules = getModulesByModuleNames(tmsConfig, moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.dependencies);
|
|
812
|
+
|
|
813
|
+
if (dependenciesModules.length) {
|
|
814
|
+
dfs(tmsConfig, dependenciesModules);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
dfs(tmsConfig, modules);
|
|
821
|
+
const modulesArr = [];
|
|
822
|
+
|
|
823
|
+
for (const module of allModules.values()) {
|
|
824
|
+
modulesArr.push(module);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
return modulesArr;
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
module.exports = {
|
|
831
|
+
readTmsConfig,
|
|
832
|
+
readTmsPrivateCf,
|
|
833
|
+
getModulesConfig,
|
|
834
|
+
getModulesByModuleNames,
|
|
835
|
+
getSubPackages,
|
|
836
|
+
getModulesByMergeDepModules,
|
|
837
|
+
getTmsConfig
|
|
838
|
+
};
|
|
839
|
+
})(tmsMpconfig);
|
|
840
|
+
|
|
841
|
+
const fs$f = require$$0__default$1;
|
|
842
|
+
const path$d = require$$1__default$1;
|
|
451
843
|
const {
|
|
452
|
-
info: info$
|
|
844
|
+
info: info$b
|
|
453
845
|
} = log$1;
|
|
454
846
|
const {
|
|
455
847
|
relativeCwdPath
|
|
@@ -477,7 +869,7 @@ const isFile = pathName => {
|
|
|
477
869
|
*/
|
|
478
870
|
|
|
479
871
|
|
|
480
|
-
const ensureDirExist$
|
|
872
|
+
const ensureDirExist$4 = dirname => {
|
|
481
873
|
if (!fs$f.existsSync(dirname)) {
|
|
482
874
|
fs$f.mkdirSync(dirname, {
|
|
483
875
|
recursive: true
|
|
@@ -491,29 +883,29 @@ const copyFile = function (src, dest) {
|
|
|
491
883
|
fs$f.unlinkSync(dest);
|
|
492
884
|
}
|
|
493
885
|
|
|
494
|
-
const dir = path$
|
|
495
|
-
ensureDirExist$
|
|
886
|
+
const dir = path$d.dirname(dest);
|
|
887
|
+
ensureDirExist$4(dir);
|
|
496
888
|
fs$f.copyFileSync(src, dest);
|
|
497
889
|
}; // 判断文件内容是否一致,不一致再进行拷贝
|
|
498
890
|
|
|
499
891
|
|
|
500
|
-
function diffContentCopyFile
|
|
892
|
+
function diffContentCopyFile(originFile, destFile) {
|
|
501
893
|
if (fs$f.existsSync(destFile)) {
|
|
502
894
|
const depDestContent = fs$f.readFileSync(destFile, 'utf8');
|
|
503
895
|
const depOriginContent = fs$f.readFileSync(originFile, 'utf8');
|
|
504
896
|
|
|
505
897
|
if (depDestContent !== depOriginContent) {
|
|
506
|
-
info$
|
|
898
|
+
info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
507
899
|
copyFile(originFile, destFile);
|
|
508
900
|
}
|
|
509
901
|
} else {
|
|
510
|
-
info$
|
|
902
|
+
info$b(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
511
903
|
copyFile(originFile, destFile);
|
|
512
904
|
}
|
|
513
905
|
} // 添加后缀
|
|
514
906
|
|
|
515
907
|
|
|
516
|
-
function ext
|
|
908
|
+
function ext(filePath, extensions) {
|
|
517
909
|
let newFilePath = filePath;
|
|
518
910
|
let extPath = ''; // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
|
|
519
911
|
|
|
@@ -546,12 +938,12 @@ function ext$3(filePath, extensions) {
|
|
|
546
938
|
} // 判断文件是否在某个目录
|
|
547
939
|
|
|
548
940
|
|
|
549
|
-
const fileInDir
|
|
941
|
+
const fileInDir = (dir, file) => {
|
|
550
942
|
if (!fs$f.existsSync(dir) || !fs$f.existsSync(file)) {
|
|
551
943
|
return false;
|
|
552
944
|
}
|
|
553
945
|
|
|
554
|
-
const relativePath = path$
|
|
946
|
+
const relativePath = path$d.relative(dir, file);
|
|
555
947
|
|
|
556
948
|
if (relativePath.startsWith('..')) {
|
|
557
949
|
return false;
|
|
@@ -560,13 +952,13 @@ const fileInDir$3 = (dir, file) => {
|
|
|
560
952
|
return true;
|
|
561
953
|
};
|
|
562
954
|
|
|
563
|
-
function findAllFilesOfDir
|
|
955
|
+
function findAllFilesOfDir(dir) {
|
|
564
956
|
const list = [];
|
|
565
957
|
|
|
566
958
|
function listFile(dir) {
|
|
567
959
|
const arr = fs$f.readdirSync(dir);
|
|
568
960
|
arr.forEach(item => {
|
|
569
|
-
const fullPath = path$
|
|
961
|
+
const fullPath = path$d.join(dir, item);
|
|
570
962
|
const stats = fs$f.statSync(fullPath);
|
|
571
963
|
|
|
572
964
|
if (stats.isDirectory()) {
|
|
@@ -585,15 +977,15 @@ function findAllFilesOfDir$1(dir) {
|
|
|
585
977
|
var io$3 = {
|
|
586
978
|
isDirEmpty,
|
|
587
979
|
copyFile,
|
|
588
|
-
diffContentCopyFile
|
|
589
|
-
ensureDirExist: ensureDirExist$
|
|
590
|
-
ext
|
|
591
|
-
fileInDir
|
|
980
|
+
diffContentCopyFile,
|
|
981
|
+
ensureDirExist: ensureDirExist$4,
|
|
982
|
+
ext,
|
|
983
|
+
fileInDir,
|
|
592
984
|
isFile,
|
|
593
|
-
findAllFilesOfDir
|
|
985
|
+
findAllFilesOfDir
|
|
594
986
|
};
|
|
595
987
|
|
|
596
|
-
const async = require$$0__default$
|
|
988
|
+
const async = require$$0__default$3;
|
|
597
989
|
const ejs = require$$1__default$3;
|
|
598
990
|
|
|
599
991
|
const render$1 = (files, metalsmith, next) => {
|
|
@@ -613,14 +1005,14 @@ const render$1 = (files, metalsmith, next) => {
|
|
|
613
1005
|
|
|
614
1006
|
var render_1 = render$1;
|
|
615
1007
|
|
|
616
|
-
const fs$e = require$$0__default$
|
|
617
|
-
const inquirer = require$$1__default$4;
|
|
1008
|
+
const fs$e = require$$0__default$1;
|
|
1009
|
+
const inquirer$2 = require$$1__default$4;
|
|
618
1010
|
const {
|
|
619
|
-
resolve: resolve$
|
|
1011
|
+
resolve: resolve$d
|
|
620
1012
|
} = widgets;
|
|
621
1013
|
const {
|
|
622
1014
|
TEMPLATE_TKIT_DIR: TEMPLATE_TKIT_DIR$1
|
|
623
|
-
} =
|
|
1015
|
+
} = constant;
|
|
624
1016
|
/**
|
|
625
1017
|
* 获取模板内的问题
|
|
626
1018
|
* @param {string} dir questions.json所在的目录
|
|
@@ -668,7 +1060,7 @@ const isQuestionType = result => {
|
|
|
668
1060
|
};
|
|
669
1061
|
|
|
670
1062
|
const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
671
|
-
const prompts = parseTemplateQuestions(resolve$
|
|
1063
|
+
const prompts = parseTemplateQuestions(resolve$d(templateDir, TEMPLATE_TKIT_DIR$1));
|
|
672
1064
|
const metadata = metalsmith.metadata();
|
|
673
1065
|
const filteredPrompts = prompts.filter(prompt => {
|
|
674
1066
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -677,7 +1069,7 @@ const ask$1 = templateDir => (files, metalsmith, next) => {
|
|
|
677
1069
|
|
|
678
1070
|
return true;
|
|
679
1071
|
});
|
|
680
|
-
inquirer.prompt(filteredPrompts).then(res => {
|
|
1072
|
+
inquirer$2.prompt(filteredPrompts).then(res => {
|
|
681
1073
|
for (const prompt of filteredPrompts) {
|
|
682
1074
|
metadata[prompt.name] = res[prompt.name];
|
|
683
1075
|
}
|
|
@@ -693,12 +1085,12 @@ var ask_1 = ask$1;
|
|
|
693
1085
|
const FILES_TO_IGNORE$1 = ['node_modules'];
|
|
694
1086
|
var ignoreFiles = FILES_TO_IGNORE$1;
|
|
695
1087
|
|
|
696
|
-
const Metalsmith = require$$0__default$
|
|
1088
|
+
const Metalsmith = require$$0__default$4;
|
|
697
1089
|
const render = render_1;
|
|
698
1090
|
const ask = ask_1;
|
|
699
1091
|
const FILES_TO_IGNORE = ignoreFiles;
|
|
700
1092
|
|
|
701
|
-
const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, reject) => {
|
|
1093
|
+
const generator$1 = (buildDir, distDir, preMetadata = {}) => new Promise((resolve, reject) => {
|
|
702
1094
|
Metalsmith(buildDir).metadata(preMetadata).ignore(FILES_TO_IGNORE).clean(false).use(ask(buildDir)).source('./').destination(distDir).use(render).build(err => {
|
|
703
1095
|
if (err) {
|
|
704
1096
|
reject(err);
|
|
@@ -710,33 +1102,75 @@ const generator$1 = (buildDir, distDir, preMetadata) => new Promise((resolve, re
|
|
|
710
1102
|
|
|
711
1103
|
var generator_1 = generator$1;
|
|
712
1104
|
|
|
713
|
-
const
|
|
714
|
-
const
|
|
715
|
-
const
|
|
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;
|
|
716
1147
|
const {
|
|
717
1148
|
TEMPLATE_DIR,
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
1149
|
+
TEMPLATE_URL,
|
|
1150
|
+
TEMPLATE_NAME,
|
|
1151
|
+
TEMPLATE_TKIT_DIR,
|
|
1152
|
+
CREATE_TEMPLATE_QUESTION
|
|
1153
|
+
} = constant;
|
|
721
1154
|
const {
|
|
722
|
-
|
|
723
|
-
createTask: createTask$2,
|
|
724
|
-
resolve: resolve$d
|
|
1155
|
+
resolve: resolve$c
|
|
725
1156
|
} = widgets;
|
|
726
1157
|
const io$2 = io$3;
|
|
727
1158
|
const {
|
|
728
1159
|
fail: fail$8,
|
|
729
1160
|
succeed: succeed$1,
|
|
730
|
-
info: info$
|
|
1161
|
+
info: info$a
|
|
731
1162
|
} = log$1;
|
|
732
1163
|
const generator = generator_1;
|
|
1164
|
+
const request$1 = require$$0__default$5;
|
|
1165
|
+
const unzip = require$$10__default;
|
|
1166
|
+
const report$7 = report_1;
|
|
733
1167
|
/**
|
|
734
1168
|
* 如果该目录下面存在文件,换个名字
|
|
735
1169
|
* @param { string } targetDir 当前文件夹
|
|
736
1170
|
* @returns { undefined }
|
|
737
1171
|
*/
|
|
738
1172
|
|
|
739
|
-
async function
|
|
1173
|
+
async function createProjectDir(targetDir) {
|
|
740
1174
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
741
1175
|
if (fs$d.existsSync(targetDir)) {
|
|
742
1176
|
if (!(await io$2.isDirEmpty(targetDir))) {
|
|
@@ -744,310 +1178,193 @@ async function createAppDir(targetDir) {
|
|
|
744
1178
|
process.exit(1);
|
|
745
1179
|
}
|
|
746
1180
|
} else {
|
|
747
|
-
shelljs$
|
|
1181
|
+
shelljs$7.mkdir('-p', targetDir);
|
|
748
1182
|
}
|
|
749
1183
|
}
|
|
1184
|
+
/**
|
|
1185
|
+
* 下载和解压远程的小程序模板
|
|
1186
|
+
* @param {string} templateDir
|
|
1187
|
+
* @param {string} templateUrl
|
|
1188
|
+
* @param {string} templateName
|
|
1189
|
+
* @returns
|
|
1190
|
+
*/
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
|
|
1194
|
+
return new Promise((resolve, reject) => {
|
|
1195
|
+
const localZipPath = `${templateDir}/${templateName}.zip`;
|
|
1196
|
+
const stream = fs$d.createWriteStream(localZipPath);
|
|
1197
|
+
request$1(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
|
|
1198
|
+
if (err) {
|
|
1199
|
+
reject(err);
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
fs$d.createReadStream(localZipPath).pipe(unzip.Extract({
|
|
1204
|
+
path: templateDir
|
|
1205
|
+
})).on('close', err => {
|
|
1206
|
+
if (err) {
|
|
1207
|
+
reject(err);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
resolve();
|
|
1212
|
+
});
|
|
1213
|
+
});
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
750
1216
|
/**
|
|
751
1217
|
* 创建本地小程序运行环境
|
|
752
|
-
* @param { string }
|
|
753
|
-
* @param { string }
|
|
1218
|
+
* @param { string } projectType 项目类型
|
|
1219
|
+
* @param { string } projectName 项目名称
|
|
754
1220
|
*/
|
|
755
1221
|
|
|
756
1222
|
|
|
757
|
-
async function create(
|
|
1223
|
+
async function create(projectName) {
|
|
758
1224
|
const cwd = process.cwd();
|
|
759
|
-
const targetDir = path$
|
|
760
|
-
const
|
|
761
|
-
|
|
1225
|
+
const targetDir = path$c.resolve(cwd, projectName);
|
|
1226
|
+
const {
|
|
1227
|
+
projectType
|
|
1228
|
+
} = await inquirer$1.prompt(CREATE_TEMPLATE_QUESTION);
|
|
1229
|
+
report$7('create-start', {
|
|
1230
|
+
projectType
|
|
1231
|
+
}); // 创建项目目录
|
|
762
1232
|
|
|
763
|
-
|
|
1233
|
+
await createProjectDir(targetDir); // 新创建缓存目录
|
|
764
1234
|
|
|
765
|
-
|
|
1235
|
+
if (fs$d.existsSync(TEMPLATE_DIR)) {
|
|
1236
|
+
shelljs$7.rm('-rf', TEMPLATE_DIR);
|
|
1237
|
+
}
|
|
766
1238
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
}).then(() => {
|
|
771
|
-
shelljs$6.cd(appName);
|
|
1239
|
+
fs$d.mkdirSync(TEMPLATE_DIR, {
|
|
1240
|
+
recursive: true
|
|
1241
|
+
}); // 下载和解压模板
|
|
772
1242
|
|
|
773
|
-
|
|
1243
|
+
await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME); // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
774
1244
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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');
|
|
1248
|
+
|
|
1249
|
+
if (fs$d.existsSync(hookFilePath)) {
|
|
1250
|
+
const hooks = require(hookFilePath);
|
|
1251
|
+
|
|
1252
|
+
if (hooks.afterCreate) {
|
|
1253
|
+
hooks.afterCreate.forEach(item => {
|
|
1254
|
+
if (typeof item === 'function') {
|
|
1255
|
+
item.call(null, shelljs$7, {
|
|
1256
|
+
projectName
|
|
1257
|
+
});
|
|
1258
|
+
} else {
|
|
1259
|
+
shelljs$7.exec(item);
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
shelljs$7.rm('-rf', resolve$c(projectName, TEMPLATE_TKIT_DIR));
|
|
785
1265
|
}
|
|
786
1266
|
|
|
787
|
-
|
|
1267
|
+
report$7('create-success', {
|
|
1268
|
+
projectType
|
|
1269
|
+
});
|
|
788
1270
|
succeed$1('项目创建完成.');
|
|
789
1271
|
}).catch(err => {
|
|
790
1272
|
fail$8(err.message);
|
|
791
|
-
info$
|
|
1273
|
+
info$a('详细的错误信息:', err);
|
|
792
1274
|
});
|
|
793
1275
|
}
|
|
794
1276
|
|
|
795
1277
|
var create_1 = create;
|
|
796
1278
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
// 模块配置信息
|
|
801
|
-
modules: {},
|
|
802
|
-
cloudDir: 'cloud',
|
|
803
|
-
// 第三方依赖代码需要拷贝到本项目的
|
|
804
|
-
dependencies: {},
|
|
805
|
-
|
|
806
|
-
/** 编译输出文件夹位置 */
|
|
807
|
-
outputDir: 'dist',
|
|
808
|
-
|
|
809
|
-
/** 源码监听路径 */
|
|
810
|
-
sourceDir: './',
|
|
811
|
-
|
|
812
|
-
/** 静态资源目录 */
|
|
813
|
-
static: []
|
|
814
|
-
};
|
|
815
|
-
|
|
816
|
-
/**
|
|
817
|
-
* 用来读取处理tms.config.js与module.config.json字段
|
|
818
|
-
*/
|
|
819
|
-
const loadash$1 = require$$0__default$6;
|
|
820
|
-
const fs$c = require$$0__default$2;
|
|
1279
|
+
const fs$c = require$$0__default$1;
|
|
1280
|
+
const path$b = require$$1__default$1;
|
|
1281
|
+
const shellJs$1 = require$$2__default;
|
|
821
1282
|
const {
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
1283
|
+
ensureDirExist: ensureDirExist$3
|
|
1284
|
+
} = io$3;
|
|
1285
|
+
const {
|
|
1286
|
+
EXTEND_CMD
|
|
1287
|
+
} = constant;
|
|
826
1288
|
const {
|
|
827
|
-
|
|
828
|
-
isObject: isObject$1,
|
|
829
|
-
isArray
|
|
1289
|
+
createTask: createTask$2
|
|
830
1290
|
} = widgets;
|
|
831
|
-
const defaultTmsConfig = defaultTmsConfig$1;
|
|
832
1291
|
const {
|
|
1292
|
+
info: info$9,
|
|
833
1293
|
fail: fail$7
|
|
834
1294
|
} = log$1;
|
|
835
1295
|
/**
|
|
836
|
-
*
|
|
837
|
-
* @param
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
const readTmsConfig$1 = function (env) {
|
|
841
|
-
const tmsConfigPath = resolve$c(TMS_CONFIG_FILENAME);
|
|
842
|
-
|
|
843
|
-
if (!fs$c.existsSync(tmsConfigPath)) {
|
|
844
|
-
fail$7('当前执行目录没有tms.config.js的配置项,请进行配置');
|
|
845
|
-
process.exit(1);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
const tmsConfigFn = require(tmsConfigPath);
|
|
849
|
-
|
|
850
|
-
const tmsConfig = tmsConfigFn({
|
|
851
|
-
env
|
|
852
|
-
}); // 合并默认值
|
|
853
|
-
|
|
854
|
-
return loadash$1.mergeWith(defaultTmsConfig, tmsConfig);
|
|
855
|
-
};
|
|
856
|
-
/**
|
|
857
|
-
* 读取tms.private.config.js
|
|
858
|
-
*/
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
const readTmsPrivateCf$1 = function () {
|
|
862
|
-
let tmsPrivateCf = {};
|
|
863
|
-
const tmsPrivatePath = resolve$c(TMS_PRIVATE_FILENAME);
|
|
864
|
-
|
|
865
|
-
if (fs$c.existsSync(tmsPrivatePath)) {
|
|
866
|
-
tmsPrivateCf = require(tmsPrivatePath);
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
return tmsPrivateCf;
|
|
870
|
-
};
|
|
871
|
-
/**
|
|
872
|
-
* 从tms.config.json中检索用户传入的有效modules
|
|
873
|
-
* @param { object } tmsConfig
|
|
874
|
-
* @param { array } modules
|
|
875
|
-
* @returns
|
|
876
|
-
*/
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
const checkModules$1 = function (tmsConfig, modules, isQuit = false) {
|
|
880
|
-
const targetModules = [];
|
|
881
|
-
modules.forEach(moduleName => {
|
|
882
|
-
const module = tmsConfig.modules.all.find(module => module.name === moduleName);
|
|
883
|
-
module && targetModules.push(module);
|
|
884
|
-
});
|
|
885
|
-
|
|
886
|
-
if (targetModules.length === 0) {
|
|
887
|
-
fail$7(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
|
|
888
|
-
>name字段与module.config.json的name字段是否一致`);
|
|
889
|
-
isQuit && process.exit(1);
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
return targetModules;
|
|
893
|
-
};
|
|
894
|
-
/**
|
|
895
|
-
* 适配处理module.config.json的字段
|
|
896
|
-
* @param { object } fileContent module.config.json的内容
|
|
897
|
-
* @param { string } appName 小程序的名称
|
|
1296
|
+
* 下载扩展命令的npm包
|
|
1297
|
+
* @param {string} npmName npm包名
|
|
1298
|
+
* @param {object} cmd {registry: 'http://mirrors.tencent.com/npm/'} 用户输入执行install-cmd的参数
|
|
898
1299
|
*/
|
|
899
1300
|
|
|
1301
|
+
async function installCmd(npmName, cmd) {
|
|
1302
|
+
try {
|
|
1303
|
+
const cmdPackageJson = `${EXTEND_CMD}/package.json`;
|
|
900
1304
|
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
res = { ...current,
|
|
907
|
-
...current.mpConfig[appName]
|
|
908
|
-
};
|
|
1305
|
+
if (!fs$c.existsSync(cmdPackageJson)) {
|
|
1306
|
+
ensureDirExist$3(EXTEND_CMD);
|
|
1307
|
+
fs$c.writeFileSync(cmdPackageJson, JSON.stringify({
|
|
1308
|
+
dependencies: {}
|
|
1309
|
+
}, null, 2));
|
|
909
1310
|
}
|
|
910
1311
|
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
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
|
+
}
|
|
920
1322
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1323
|
+
resolve();
|
|
1324
|
+
});
|
|
1325
|
+
}), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
|
|
1326
|
+
} catch (e) {
|
|
1327
|
+
fail$7('构建出现错误:');
|
|
1328
|
+
info$9(e);
|
|
1329
|
+
process.exit(1);
|
|
927
1330
|
}
|
|
928
|
-
|
|
929
|
-
return content;
|
|
930
|
-
}
|
|
931
|
-
/**
|
|
932
|
-
* 递归获取本地所有模块的配置信息
|
|
933
|
-
* @param {array} modules 用户要编译的模块列表
|
|
934
|
-
* @param { string } appName 小程序的名称
|
|
935
|
-
* @param { string } moduleConfigFilename moduleConfig的文件名
|
|
936
|
-
*/
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
function getModuleConfig$1(modules = [], appName, moduleConfigFilename) {
|
|
940
|
-
const modulesConfig = {};
|
|
941
|
-
modules.forEach(({
|
|
942
|
-
path
|
|
943
|
-
}) => {
|
|
944
|
-
const moduleConfigPath = resolve$c(path, moduleConfigFilename);
|
|
945
|
-
|
|
946
|
-
if (fs$c.existsSync(moduleConfigPath)) {
|
|
947
|
-
const content = fs$c.readFileSync(moduleConfigPath, 'utf-8');
|
|
948
|
-
modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
|
|
949
|
-
}
|
|
950
|
-
});
|
|
951
|
-
return modulesConfig;
|
|
952
1331
|
}
|
|
953
1332
|
/**
|
|
954
|
-
*
|
|
955
|
-
* @param {array} modules
|
|
956
|
-
* @param {string} appName
|
|
957
|
-
* @param {string} moduleDir
|
|
1333
|
+
* 加载扩展命令的npm包
|
|
958
1334
|
* @returns
|
|
959
1335
|
*/
|
|
960
1336
|
|
|
961
1337
|
|
|
962
|
-
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
path: relativePath,
|
|
966
|
-
name: moduleName
|
|
967
|
-
}, moduleIndex) => {
|
|
968
|
-
const moduleConfigPath = resolve$c(relativePath, MODULE_CONFIG_FILENAME$1);
|
|
969
|
-
|
|
970
|
-
if (fs$c.existsSync(moduleConfigPath)) {
|
|
971
|
-
try {
|
|
972
|
-
let findModule = false;
|
|
973
|
-
let moduleConfigContent = fs$c.readFileSync(moduleConfigPath, 'utf-8');
|
|
974
|
-
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
975
|
-
const moduleContentArr = isObject$1(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
976
|
-
moduleContentArr.forEach(({
|
|
977
|
-
name
|
|
978
|
-
}, moduleContentArrIndex) => {
|
|
979
|
-
if (name === moduleName) {
|
|
980
|
-
findModule = true;
|
|
981
|
-
newModules.push({ ...modules[moduleIndex],
|
|
982
|
-
...moduleContentArr[moduleContentArrIndex]
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
});
|
|
986
|
-
|
|
987
|
-
if (!findModule) {
|
|
988
|
-
fail$7(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
|
|
989
|
-
process.exit(1);
|
|
990
|
-
}
|
|
991
|
-
} catch (e) {
|
|
992
|
-
fail$7(`${moduleConfigPath}配置错误: ${e}`);
|
|
993
|
-
newModules.push({ ...modules[moduleIndex]
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
|
-
} else {
|
|
997
|
-
newModules.push({ ...modules[moduleIndex]
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
});
|
|
1001
|
-
return newModules;
|
|
1002
|
-
};
|
|
1003
|
-
/**
|
|
1004
|
-
* 分包依赖了分包的模块 合并所依赖的modules
|
|
1005
|
-
* @param { object } tmsConfig
|
|
1006
|
-
* @param {array} modules
|
|
1007
|
-
* @param {string} moduleDir
|
|
1008
|
-
* @returns
|
|
1009
|
-
*/
|
|
1338
|
+
function loadExtendCmd$1() {
|
|
1339
|
+
const cmdPackageJson = `${EXTEND_CMD}/package.json`;
|
|
1340
|
+
const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
|
|
1010
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');
|
|
1011
1351
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
modules.forEach(({
|
|
1015
|
-
name: moduleName
|
|
1016
|
-
}) => {
|
|
1017
|
-
moduleNames.push(moduleName);
|
|
1018
|
-
});
|
|
1019
|
-
let mergeModules = modules;
|
|
1020
|
-
let isOver = true;
|
|
1021
|
-
modules.forEach(({
|
|
1022
|
-
dependencies: dependencyModules
|
|
1023
|
-
}) => {
|
|
1024
|
-
dependencyModules === null || dependencyModules === void 0 ? void 0 : dependencyModules.forEach(item => {
|
|
1025
|
-
// 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
|
|
1026
|
-
// 否则递归处理,根据name找到相关配置加到modules里
|
|
1027
|
-
if (moduleNames.indexOf(item) === -1) {
|
|
1028
|
-
const tmpModules = checkModules$1(tmsConfig, [...new Set([item])]);
|
|
1029
|
-
|
|
1030
|
-
if (tmpModules.length > 0) {
|
|
1031
|
-
isOver = false;
|
|
1032
|
-
mergeModules = [...mergeModules, ...tmpModules];
|
|
1033
|
-
mergeModules = tmsModulesMergeLocalModuleCfg$3(mergeModules, tmsConfig.appName);
|
|
1034
|
-
}
|
|
1352
|
+
if (fs$c.existsSync(cmdConfig)) {
|
|
1353
|
+
cmdConfigs.push(cmdConfig);
|
|
1035
1354
|
}
|
|
1036
1355
|
});
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1356
|
+
return cmdConfigs;
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
return [];
|
|
1360
|
+
}
|
|
1040
1361
|
|
|
1041
|
-
var
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
getModuleConfig: getModuleConfig$1,
|
|
1045
|
-
checkModules: checkModules$1,
|
|
1046
|
-
tmsModulesMergeLocalModuleCfg: tmsModulesMergeLocalModuleCfg$3,
|
|
1047
|
-
subModulesMergeDepModules: subModulesMergeDepModules$2
|
|
1362
|
+
var extendCmd = {
|
|
1363
|
+
installCmd,
|
|
1364
|
+
loadExtendCmd: loadExtendCmd$1
|
|
1048
1365
|
};
|
|
1049
1366
|
|
|
1050
|
-
const global$
|
|
1367
|
+
const global$7 = {
|
|
1051
1368
|
data: {},
|
|
1052
1369
|
|
|
1053
1370
|
setData(...args) {
|
|
@@ -1069,19 +1386,25 @@ const global$6 = {
|
|
|
1069
1386
|
|
|
1070
1387
|
};
|
|
1071
1388
|
var global_1 = {
|
|
1072
|
-
global: global$
|
|
1389
|
+
global: global$7
|
|
1073
1390
|
};
|
|
1074
1391
|
|
|
1075
1392
|
const {
|
|
1076
1393
|
fail: fail$6
|
|
1077
1394
|
} = log$1;
|
|
1078
1395
|
const {
|
|
1079
|
-
global: global$
|
|
1396
|
+
global: global$6
|
|
1080
1397
|
} = global_1;
|
|
1081
1398
|
|
|
1082
|
-
function handleError$
|
|
1399
|
+
function handleError$5(error, isQuit = false) {
|
|
1083
1400
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
1084
|
-
|
|
1401
|
+
|
|
1402
|
+
if (isQuit) {
|
|
1403
|
+
fail$6(errMsg);
|
|
1404
|
+
process.exit(1);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
const isDev = global$6.getData('isDev');
|
|
1085
1408
|
|
|
1086
1409
|
if (isDev) {
|
|
1087
1410
|
fail$6(errMsg);
|
|
@@ -1092,7 +1415,7 @@ function handleError$6(error) {
|
|
|
1092
1415
|
}
|
|
1093
1416
|
|
|
1094
1417
|
var handleError_1 = {
|
|
1095
|
-
handleError: handleError$
|
|
1418
|
+
handleError: handleError$5
|
|
1096
1419
|
};
|
|
1097
1420
|
|
|
1098
1421
|
/**
|
|
@@ -1100,27 +1423,26 @@ var handleError_1 = {
|
|
|
1100
1423
|
*/
|
|
1101
1424
|
/* eslint-disable no-param-reassign */
|
|
1102
1425
|
|
|
1103
|
-
const fs$b = require$$0__default$
|
|
1104
|
-
const {
|
|
1105
|
-
MODULE_CONFIG_FILENAME
|
|
1106
|
-
} = require$$4;
|
|
1426
|
+
const fs$b = require$$0__default$1;
|
|
1107
1427
|
const {
|
|
1108
|
-
|
|
1109
|
-
|
|
1428
|
+
getSubPackages: getSubPackages$3,
|
|
1429
|
+
getModulesConfig
|
|
1430
|
+
} = tmsMpconfig.exports;
|
|
1110
1431
|
const {
|
|
1111
|
-
fail: fail$5
|
|
1432
|
+
fail: fail$5,
|
|
1433
|
+
info: info$8
|
|
1112
1434
|
} = log$1;
|
|
1113
1435
|
const {
|
|
1114
1436
|
resolve: resolve$b,
|
|
1115
|
-
|
|
1116
|
-
filterField: filterField$2
|
|
1437
|
+
filterField: filterField$4
|
|
1117
1438
|
} = widgets;
|
|
1118
1439
|
const {
|
|
1119
|
-
handleError: handleError$
|
|
1440
|
+
handleError: handleError$4
|
|
1120
1441
|
} = handleError_1;
|
|
1121
1442
|
const {
|
|
1122
|
-
global: global$
|
|
1443
|
+
global: global$5
|
|
1123
1444
|
} = global_1;
|
|
1445
|
+
const report$6 = report_1;
|
|
1124
1446
|
/**
|
|
1125
1447
|
* 更新appJson里面的主包配置
|
|
1126
1448
|
* @param { object } appJson appJson信息
|
|
@@ -1128,7 +1450,7 @@ const {
|
|
|
1128
1450
|
* @returns { object } appJson小程序主页配置信息
|
|
1129
1451
|
*/
|
|
1130
1452
|
|
|
1131
|
-
function updateMainPackages(appJson, mainPackages
|
|
1453
|
+
function updateMainPackages(appJson, mainPackages) {
|
|
1132
1454
|
let foundMainPackages = appJson.subpackages.filter(subpackage => mainPackages.includes(subpackage.name));
|
|
1133
1455
|
|
|
1134
1456
|
if (foundMainPackages.length === 0) {
|
|
@@ -1175,22 +1497,6 @@ const getAppJsonContent = sourceAppJsonPath => {
|
|
|
1175
1497
|
appJson.pages = [];
|
|
1176
1498
|
return appJson;
|
|
1177
1499
|
};
|
|
1178
|
-
/**
|
|
1179
|
-
* 更新app.json中的subpackages
|
|
1180
|
-
* @param {Object} appJson
|
|
1181
|
-
* @param {Object} modulesConfigs
|
|
1182
|
-
*/
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
const updateSubpackages = (appJson, modulesConfigs) => {
|
|
1186
|
-
// eslint-disable-next-line
|
|
1187
|
-
for (const modulePath in modulesConfigs) {
|
|
1188
|
-
const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
|
|
1189
|
-
appJson.subpackages = appJson.subpackages.concat(moduleInfo);
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
1193
|
-
};
|
|
1194
1500
|
/**
|
|
1195
1501
|
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
1196
1502
|
* @param {Object} appJson appjson
|
|
@@ -1230,7 +1536,7 @@ const fixAppJson = appJson => {
|
|
|
1230
1536
|
appJson[key] = preloadRuleMap;
|
|
1231
1537
|
}
|
|
1232
1538
|
});
|
|
1233
|
-
return filterField$
|
|
1539
|
+
return filterField$4(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
|
|
1234
1540
|
}); // 如果plugins重复,则错误提示
|
|
1235
1541
|
|
|
1236
1542
|
const pluginsErrMsg = Object.keys(pluginsMap).map(pk => {
|
|
@@ -1255,16 +1561,19 @@ const fixAppJson = appJson => {
|
|
|
1255
1561
|
*/
|
|
1256
1562
|
|
|
1257
1563
|
|
|
1258
|
-
function buildOutputAppJson$
|
|
1564
|
+
function buildOutputAppJson$2(tmsConfig, modules) {
|
|
1259
1565
|
try {
|
|
1260
1566
|
var _tmsConfig$hooks;
|
|
1261
1567
|
|
|
1262
|
-
//
|
|
1263
|
-
const
|
|
1568
|
+
// 获取所有模块,合并模块依赖的模块
|
|
1569
|
+
const modulesConfig = getModulesConfig(modules, tmsConfig.appName, false); // 获取所有的分包
|
|
1570
|
+
|
|
1571
|
+
const subPackages = getSubPackages$3(modulesConfig); // 获取app.json的配置
|
|
1264
1572
|
|
|
1265
1573
|
const appJson = getAppJsonContent(resolve$b('./app.json')); // 更新app.json中的subpackages
|
|
1266
1574
|
|
|
1267
|
-
|
|
1575
|
+
appJson.subpackages = subPackages;
|
|
1576
|
+
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name)); // 处理appJson中重复||冲突的地方
|
|
1268
1577
|
|
|
1269
1578
|
fixAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
|
|
1270
1579
|
|
|
@@ -1275,27 +1584,29 @@ function buildOutputAppJson$1(tmsConfig, modules) {
|
|
|
1275
1584
|
var _tmsConfig$hooks2;
|
|
1276
1585
|
|
|
1277
1586
|
tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.updateAppJson({
|
|
1278
|
-
tmsConfig: filterField$
|
|
1587
|
+
tmsConfig: filterField$4(tmsConfig, ['gitAccount']),
|
|
1279
1588
|
modules,
|
|
1280
1589
|
appJson,
|
|
1281
|
-
isDev: global$
|
|
1590
|
+
isDev: global$5.getData('isDev')
|
|
1282
1591
|
});
|
|
1592
|
+
report$6('hooks:updateAppJson');
|
|
1283
1593
|
}
|
|
1284
1594
|
|
|
1285
1595
|
return appJson;
|
|
1286
1596
|
} catch (e) {
|
|
1287
|
-
handleError$
|
|
1597
|
+
handleError$4(`生成app.json出现错误: ${e}`);
|
|
1598
|
+
info$8(e);
|
|
1288
1599
|
}
|
|
1289
1600
|
}
|
|
1290
1601
|
|
|
1291
1602
|
var buildAppJson = {
|
|
1292
|
-
buildOutputAppJson: buildOutputAppJson$
|
|
1603
|
+
buildOutputAppJson: buildOutputAppJson$2
|
|
1293
1604
|
};
|
|
1294
1605
|
|
|
1295
1606
|
/**
|
|
1296
1607
|
* 下载第三方代码
|
|
1297
1608
|
*/
|
|
1298
|
-
const MetalSmith = require$$0__default$
|
|
1609
|
+
const MetalSmith = require$$0__default$4;
|
|
1299
1610
|
const crypto$2 = require$$1__default$5;
|
|
1300
1611
|
const {
|
|
1301
1612
|
downloadRepoForGit,
|
|
@@ -1304,15 +1615,15 @@ const {
|
|
|
1304
1615
|
} = widgets;
|
|
1305
1616
|
const {
|
|
1306
1617
|
fail: fail$4,
|
|
1307
|
-
info: info$
|
|
1618
|
+
info: info$7
|
|
1308
1619
|
} = log$1;
|
|
1309
|
-
const fs$a = require$$0__default$
|
|
1310
|
-
const shelljs$
|
|
1620
|
+
const fs$a = require$$0__default$1;
|
|
1621
|
+
const shelljs$6 = require$$2__default;
|
|
1311
1622
|
const {
|
|
1312
|
-
handleError: handleError$
|
|
1623
|
+
handleError: handleError$3
|
|
1313
1624
|
} = handleError_1;
|
|
1314
1625
|
const {
|
|
1315
|
-
global: global$
|
|
1626
|
+
global: global$4
|
|
1316
1627
|
} = global_1;
|
|
1317
1628
|
/**
|
|
1318
1629
|
* 处理用户没有clone git仓库权限问题,拼接tms.private.config.js的账号信息
|
|
@@ -1322,15 +1633,15 @@ const {
|
|
|
1322
1633
|
*/
|
|
1323
1634
|
|
|
1324
1635
|
function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
1325
|
-
var _tmsConfig$
|
|
1636
|
+
var _tmsConfig$gitAccount;
|
|
1326
1637
|
|
|
1327
1638
|
// 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
|
|
1328
|
-
const tmsConfig = global$
|
|
1639
|
+
const tmsConfig = global$4.getData('tmsConfig');
|
|
1329
1640
|
let gitUrl = httpRepoUrl;
|
|
1330
1641
|
const {
|
|
1331
1642
|
username = '',
|
|
1332
1643
|
pass = ''
|
|
1333
|
-
} = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$
|
|
1644
|
+
} = (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gitAccount = tmsConfig.gitAccount) === null || _tmsConfig$gitAccount === void 0 ? void 0 : _tmsConfig$gitAccount[moduleName]) || {};
|
|
1334
1645
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
1335
1646
|
|
|
1336
1647
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -1348,8 +1659,12 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
1348
1659
|
*/
|
|
1349
1660
|
|
|
1350
1661
|
|
|
1351
|
-
function moveFile(sourceDir, targetDir, ignore
|
|
1352
|
-
|
|
1662
|
+
function moveFile(sourceDir, targetDir, ignore) {
|
|
1663
|
+
if (fs$a.existsSync(targetDir)) {
|
|
1664
|
+
shelljs$6.rm('-rf', targetDir);
|
|
1665
|
+
} // 删除不是文件夹的文件
|
|
1666
|
+
|
|
1667
|
+
|
|
1353
1668
|
return new Promise((resolve, reject) => {
|
|
1354
1669
|
MetalSmith(__dirname).ignore(ignore).source(sourceDir).destination(targetDir).build(e => {
|
|
1355
1670
|
if (e) {
|
|
@@ -1402,11 +1717,11 @@ async function cloneModules$1(sourceDir, targetDir, modules) {
|
|
|
1402
1717
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1403
1718
|
return Promise.all(callArr);
|
|
1404
1719
|
}).catch(e => {
|
|
1405
|
-
handleError$
|
|
1720
|
+
handleError$3(`下载代码${params.httpRepoUrl}出现错误:${e}`);
|
|
1406
1721
|
}));
|
|
1407
1722
|
});
|
|
1408
1723
|
await Promise.all(arrPromises);
|
|
1409
|
-
shelljs$
|
|
1724
|
+
shelljs$6.cd(cwd);
|
|
1410
1725
|
}
|
|
1411
1726
|
/**
|
|
1412
1727
|
* 收集下载模块代码的任务
|
|
@@ -1440,10 +1755,10 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1440
1755
|
path: gitPath = ''
|
|
1441
1756
|
},
|
|
1442
1757
|
path,
|
|
1443
|
-
|
|
1758
|
+
moduleName
|
|
1444
1759
|
} = moduleInfo; // 处理仓库权限问题
|
|
1445
1760
|
|
|
1446
|
-
const gitUrl = replaceGitUrlAccount(httpRepoUrl,
|
|
1761
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName); // 根据gitUrl与branch计算md5
|
|
1447
1762
|
|
|
1448
1763
|
const md5Key = md5ByGitUrlBranch(gitUrl, branch); // git源码临时存在的源目录
|
|
1449
1764
|
|
|
@@ -1460,7 +1775,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1460
1775
|
},
|
|
1461
1776
|
fn: async (sourceModulePath, targetPath) => {
|
|
1462
1777
|
if (fs$a.existsSync(targetPath)) {
|
|
1463
|
-
shelljs$
|
|
1778
|
+
shelljs$6.rm('-rf', `${targetPath}/*`);
|
|
1464
1779
|
}
|
|
1465
1780
|
|
|
1466
1781
|
await moveFile(`${sourceModulePath}`, targetPath, ['node_modules', '.git']);
|
|
@@ -1476,12 +1791,12 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
1476
1791
|
|
|
1477
1792
|
if (fs$a.existsSync(sourcePath) && fs$a.existsSync(`${sourcePath}/.git`)) {
|
|
1478
1793
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1479
|
-
info$
|
|
1794
|
+
info$7(`git pull:${httpRepoUrl}`);
|
|
1480
1795
|
return pullRepoForGit(sourcePath, branch);
|
|
1481
1796
|
};
|
|
1482
1797
|
} else {
|
|
1483
1798
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
1484
|
-
info$
|
|
1799
|
+
info$7(`git clone: ${httpRepoUrl}`);
|
|
1485
1800
|
return downloadRepoForGit(gitUrl, sourcePath, branch);
|
|
1486
1801
|
};
|
|
1487
1802
|
}
|
|
@@ -1517,9 +1832,9 @@ function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
|
1517
1832
|
buildGitTag,
|
|
1518
1833
|
httpRepoUrl
|
|
1519
1834
|
},
|
|
1520
|
-
|
|
1835
|
+
moduleName
|
|
1521
1836
|
} = moduleInfo;
|
|
1522
|
-
const gitUrl = replaceGitUrlAccount(httpRepoUrl,
|
|
1837
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
|
|
1523
1838
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
1524
1839
|
|
|
1525
1840
|
if (!fs$a.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
@@ -1535,8 +1850,8 @@ var cloneModules_1 = {
|
|
|
1535
1850
|
checkRemoteModGitUrlBranch
|
|
1536
1851
|
};
|
|
1537
1852
|
|
|
1538
|
-
const ci = require$$0__default$
|
|
1539
|
-
const path$
|
|
1853
|
+
const ci = require$$0__default$6;
|
|
1854
|
+
const path$a = require$$1__default$1;
|
|
1540
1855
|
/**
|
|
1541
1856
|
* 获取小程序ci的Project对象
|
|
1542
1857
|
* @returns {Object} 小程序ci对象
|
|
@@ -1550,7 +1865,7 @@ const getMpCi = ({
|
|
|
1550
1865
|
}) => {
|
|
1551
1866
|
var _cfgJsonContent$packO;
|
|
1552
1867
|
|
|
1553
|
-
const cfgJsonContent = require(path$
|
|
1868
|
+
const cfgJsonContent = require(path$a.join(projectPath, 'project.config.json'));
|
|
1554
1869
|
|
|
1555
1870
|
const ignores = (cfgJsonContent === null || cfgJsonContent === void 0 ? void 0 : (_cfgJsonContent$packO = cfgJsonContent.packOptions) === null || _cfgJsonContent$packO === void 0 ? void 0 : _cfgJsonContent$packO.ignore.map(({
|
|
1556
1871
|
value
|
|
@@ -1616,20 +1931,19 @@ var mpCi = {
|
|
|
1616
1931
|
buildMpNpm: buildMpNpm$1
|
|
1617
1932
|
};
|
|
1618
1933
|
|
|
1619
|
-
const fs$9 = require$$0__default$
|
|
1620
|
-
const path$
|
|
1934
|
+
const fs$9 = require$$0__default$1;
|
|
1935
|
+
const path$9 = require$$1__default$1;
|
|
1621
1936
|
const {
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
} = require$$4;
|
|
1937
|
+
NPM_CACHE_FILE
|
|
1938
|
+
} = constant;
|
|
1625
1939
|
const {
|
|
1626
|
-
ensureDirExist: ensureDirExist$
|
|
1940
|
+
ensureDirExist: ensureDirExist$2
|
|
1627
1941
|
} = io$3;
|
|
1628
1942
|
|
|
1629
1943
|
function getCache$1(projectDir, type) {
|
|
1630
1944
|
var _content$projectDir;
|
|
1631
1945
|
|
|
1632
|
-
const filePath =
|
|
1946
|
+
const filePath = NPM_CACHE_FILE;
|
|
1633
1947
|
|
|
1634
1948
|
if (!fs$9.existsSync(filePath)) {
|
|
1635
1949
|
return null;
|
|
@@ -1641,11 +1955,11 @@ function getCache$1(projectDir, type) {
|
|
|
1641
1955
|
}
|
|
1642
1956
|
|
|
1643
1957
|
function setCache$1(projectDir, type = 'miniprogram_npm', data) {
|
|
1644
|
-
const filePath =
|
|
1958
|
+
const filePath = NPM_CACHE_FILE;
|
|
1645
1959
|
|
|
1646
1960
|
if (!fs$9.existsSync(filePath)) {
|
|
1647
|
-
const dir = path$
|
|
1648
|
-
ensureDirExist$
|
|
1961
|
+
const dir = path$9.dirname(filePath);
|
|
1962
|
+
ensureDirExist$2(dir);
|
|
1649
1963
|
fs$9.writeFileSync(filePath, '{}');
|
|
1650
1964
|
}
|
|
1651
1965
|
|
|
@@ -1669,19 +1983,21 @@ var cache = {
|
|
|
1669
1983
|
/**
|
|
1670
1984
|
* 本文件主要负责项目或者分包依赖的npm的安装
|
|
1671
1985
|
*/
|
|
1672
|
-
const fs$8 = require$$0__default$
|
|
1986
|
+
const fs$8 = require$$0__default$1;
|
|
1673
1987
|
const fsExtra = require$$1__default$6;
|
|
1674
1988
|
const crypto$1 = require$$1__default$5;
|
|
1675
|
-
const path$
|
|
1676
|
-
const shell = require$$
|
|
1677
|
-
const glob = require$$6__default;
|
|
1989
|
+
const path$8 = require$$1__default$1;
|
|
1990
|
+
const shell = require$$2__default;
|
|
1678
1991
|
const log = log$1;
|
|
1679
1992
|
const {
|
|
1680
1993
|
npmInstall: npmInstall$1
|
|
1681
1994
|
} = widgets;
|
|
1682
1995
|
const {
|
|
1683
|
-
handleError: handleError$
|
|
1996
|
+
handleError: handleError$2
|
|
1684
1997
|
} = handleError_1;
|
|
1998
|
+
const {
|
|
1999
|
+
global: global$3
|
|
2000
|
+
} = global_1;
|
|
1685
2001
|
const shellJsOption = {
|
|
1686
2002
|
async: false,
|
|
1687
2003
|
silent: true
|
|
@@ -1705,21 +2021,28 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1705
2021
|
|
|
1706
2022
|
for (const packageJsonPath of packageJsonFiles) {
|
|
1707
2023
|
const packageContent = fs$8.readFileSync(packageJsonPath);
|
|
1708
|
-
|
|
2024
|
+
let packageJson;
|
|
2025
|
+
|
|
2026
|
+
try {
|
|
2027
|
+
packageJson = JSON.parse(packageContent);
|
|
2028
|
+
} catch (e) {
|
|
2029
|
+
throw new Error(`${packageJsonPath}json解析出现错误:${e}`);
|
|
2030
|
+
}
|
|
2031
|
+
|
|
1709
2032
|
const md5Obj = {
|
|
1710
2033
|
dependencies: packageJson.dependencies || {}
|
|
1711
2034
|
};
|
|
1712
2035
|
|
|
1713
2036
|
if (Object.keys(md5Obj.dependencies).length !== 0) {
|
|
1714
2037
|
const md5Key = crypto$1.createHash('md5').update(JSON.stringify(md5Obj)).digest('hex');
|
|
1715
|
-
const cacheNMPath = path$
|
|
1716
|
-
const cacheNMTarFile = path$
|
|
2038
|
+
const cacheNMPath = path$8.join(cacheDir, md5Key);
|
|
2039
|
+
const cacheNMTarFile = path$8.join(cacheNMPath, 'node_modules.tar.gz'); // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
|
|
1717
2040
|
|
|
1718
2041
|
const callback = {
|
|
1719
2042
|
params: {
|
|
1720
2043
|
cacheNMPath,
|
|
1721
2044
|
cacheNMTarFile,
|
|
1722
|
-
packageJsonDir: path$
|
|
2045
|
+
packageJsonDir: path$8.dirname(packageJsonPath),
|
|
1723
2046
|
shell
|
|
1724
2047
|
},
|
|
1725
2048
|
fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
|
|
@@ -1748,7 +2071,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1748
2071
|
fsExtra.emptydirSync(cacheNMPath);
|
|
1749
2072
|
shell.cp('-f', packageJsonPath, cacheNMPath);
|
|
1750
2073
|
log.info(`npm install: ${packageJsonPath}`);
|
|
1751
|
-
|
|
2074
|
+
const tmsConfig = global$3.getData('tmsConfig');
|
|
2075
|
+
return npmInstall$1(cacheNMPath, tmsConfig.npm).then(() => {
|
|
1752
2076
|
const newShellJsOption = { ...shellJsOption,
|
|
1753
2077
|
cwd: cacheNMPath
|
|
1754
2078
|
};
|
|
@@ -1776,9 +2100,9 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
1776
2100
|
}; // 遍历安装指定目录下所有项目的npm依赖
|
|
1777
2101
|
|
|
1778
2102
|
|
|
1779
|
-
const npmInstallAll$1 = async (
|
|
2103
|
+
const npmInstallAll$1 = async (subPackages, contextDir, cacheDir) => {
|
|
1780
2104
|
const cwd = process.cwd();
|
|
1781
|
-
const packageJsonFiles = await findAllPackageJson(
|
|
2105
|
+
const packageJsonFiles = await findAllPackageJson(subPackages, contextDir); // 收集npm install的任务
|
|
1782
2106
|
|
|
1783
2107
|
const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir); // 开始执行npm install和回调(移动)的任务
|
|
1784
2108
|
|
|
@@ -1795,7 +2119,7 @@ const npmInstallAll$1 = async (modules, contextDir, cacheDir) => {
|
|
|
1795
2119
|
}) => fn(...Object.keys(cParams).map(key => cParams[key])));
|
|
1796
2120
|
return Promise.all(callArr);
|
|
1797
2121
|
}).catch(e => {
|
|
1798
|
-
handleError$
|
|
2122
|
+
handleError$2(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
|
|
1799
2123
|
}));
|
|
1800
2124
|
});
|
|
1801
2125
|
await Promise.all(arrPromises);
|
|
@@ -1836,7 +2160,7 @@ const findFilesByFilter = (startPath, filter) => {
|
|
|
1836
2160
|
|
|
1837
2161
|
const files = fs$8.readdirSync(startPath);
|
|
1838
2162
|
files.forEach(file => {
|
|
1839
|
-
const filename = path$
|
|
2163
|
+
const filename = path$8.join(startPath, file);
|
|
1840
2164
|
const stat = fs$8.lstatSync(filename); // 当前文件是文件夹类型,继续递归
|
|
1841
2165
|
|
|
1842
2166
|
if (stat.isDirectory()) {
|
|
@@ -1863,15 +2187,10 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1863
2187
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1864
2188
|
|
|
1865
2189
|
const cwd = contextDir || dirPath;
|
|
1866
|
-
const result = [path$
|
|
2190
|
+
const result = [path$8.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
|
|
1867
2191
|
|
|
1868
2192
|
subRoots.forEach(subRoot => {
|
|
1869
|
-
|
|
1870
|
-
log.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
|
|
1871
|
-
process.exit(1);
|
|
1872
|
-
}
|
|
1873
|
-
|
|
1874
|
-
const toppath = path$7.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
2193
|
+
const toppath = path$8.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
|
|
1875
2194
|
|
|
1876
2195
|
const list = findFilesByFilter(toppath, packageJsonName);
|
|
1877
2196
|
result.push(...list);
|
|
@@ -1879,33 +2198,14 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
1879
2198
|
return result;
|
|
1880
2199
|
};
|
|
1881
2200
|
|
|
1882
|
-
function cloudNpmInstall(contextDir) {
|
|
1883
|
-
return new Promise((resolve, reject) => {
|
|
1884
|
-
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
1885
|
-
if (err) {
|
|
1886
|
-
reject(err);
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
files.forEach(file => {
|
|
1890
|
-
const dir = path$7.dirname(file);
|
|
1891
|
-
shell.cd(dir);
|
|
1892
|
-
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', {
|
|
1893
|
-
silent: false
|
|
1894
|
-
});
|
|
1895
|
-
});
|
|
1896
|
-
resolve();
|
|
1897
|
-
});
|
|
1898
|
-
});
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
2201
|
var npm = {
|
|
1902
|
-
cloudNpmInstall,
|
|
1903
2202
|
npmInstallAll: npmInstallAll$1,
|
|
1904
|
-
findAllPackageJson
|
|
2203
|
+
findAllPackageJson,
|
|
2204
|
+
findFilesByFilter
|
|
1905
2205
|
};
|
|
1906
2206
|
|
|
1907
2207
|
const crypto = require$$1__default$5;
|
|
1908
|
-
const fs$7 = require$$0__default$
|
|
2208
|
+
const fs$7 = require$$0__default$1;
|
|
1909
2209
|
|
|
1910
2210
|
function fileMd5$1(filePath) {
|
|
1911
2211
|
return new Promise((resolve, reject) => {
|
|
@@ -1928,42 +2228,40 @@ var md5 = {
|
|
|
1928
2228
|
fileMd5: fileMd5$1
|
|
1929
2229
|
};
|
|
1930
2230
|
|
|
1931
|
-
const fs$6 = require$$0__default$
|
|
2231
|
+
const fs$6 = require$$0__default$1;
|
|
1932
2232
|
const semver$1 = require$$1__default$7;
|
|
1933
2233
|
const {
|
|
1934
|
-
resolve: resolve$9
|
|
2234
|
+
resolve: resolve$9,
|
|
2235
|
+
getAbsolutePath: getAbsolutePath$2
|
|
1935
2236
|
} = widgets;
|
|
1936
|
-
const path$
|
|
1937
|
-
const shelljs$
|
|
2237
|
+
const path$7 = require$$1__default$1;
|
|
2238
|
+
const shelljs$5 = require$$2__default;
|
|
1938
2239
|
const {
|
|
1939
|
-
handleError: handleError$
|
|
2240
|
+
handleError: handleError$1
|
|
1940
2241
|
} = handleError_1;
|
|
1941
2242
|
|
|
1942
2243
|
const getLatestVersion = npmName => {
|
|
1943
|
-
const data = shelljs$
|
|
1944
|
-
return data.stdout || '0.0.0';
|
|
1945
|
-
};
|
|
1946
|
-
/**
|
|
1947
|
-
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
1948
|
-
* @param {*} modules 模块
|
|
1949
|
-
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
1950
|
-
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
1951
|
-
* @returns
|
|
1952
|
-
*/
|
|
2244
|
+
const data = shelljs$5.exec(`npm view ${npmName} version`);
|
|
1953
2245
|
|
|
2246
|
+
if (data.code === 0) {
|
|
2247
|
+
return data.stdout;
|
|
2248
|
+
}
|
|
1954
2249
|
|
|
1955
|
-
|
|
1956
|
-
|
|
2250
|
+
return '0.0.0';
|
|
2251
|
+
}; // 收集package.json
|
|
2252
|
+
|
|
2253
|
+
|
|
2254
|
+
function collectPackageJson(subPackages, cwd, outputDir) {
|
|
1957
2255
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
1958
2256
|
// 1.1根目录的package.json
|
|
1959
2257
|
|
|
1960
2258
|
const packageArr = [{
|
|
1961
|
-
srcPackageDir: path$
|
|
2259
|
+
srcPackageDir: path$7.join(cwd, packageJsonName),
|
|
1962
2260
|
destNpmDir: resolve$9(outputDir, 'node_modules')
|
|
1963
2261
|
}]; // 1.2模块的package.json
|
|
1964
2262
|
|
|
1965
|
-
|
|
1966
|
-
const srcPackageDir =
|
|
2263
|
+
subPackages.forEach(item => {
|
|
2264
|
+
const srcPackageDir = `${getAbsolutePath$2(item.path)}/package.json`;
|
|
1967
2265
|
|
|
1968
2266
|
if (fs$6.existsSync(srcPackageDir)) {
|
|
1969
2267
|
packageArr.push({
|
|
@@ -1971,29 +2269,54 @@ const isDependenciesUpdate$1 = (modules, cwd, outputDir) => {
|
|
|
1971
2269
|
destNpmDir: resolve$9(outputDir, item.root, 'node_modules')
|
|
1972
2270
|
});
|
|
1973
2271
|
}
|
|
1974
|
-
});
|
|
2272
|
+
});
|
|
2273
|
+
return packageArr;
|
|
2274
|
+
} // 读取package.json的依赖
|
|
1975
2275
|
|
|
1976
|
-
for (const item of packageArr) {
|
|
1977
|
-
const packageJson = fs$6.readFileSync(item.srcPackageDir, 'utf-8');
|
|
1978
|
-
let dependencies = {};
|
|
1979
2276
|
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
}
|
|
2277
|
+
function readPackageDependencies(srcPackageDir) {
|
|
2278
|
+
const packageJson = fs$6.readFileSync(srcPackageDir, 'utf-8');
|
|
2279
|
+
let dependencies = {};
|
|
2280
|
+
|
|
2281
|
+
try {
|
|
2282
|
+
const json = packageJson ? JSON.parse(packageJson) : {};
|
|
2283
|
+
dependencies = (json === null || json === void 0 ? void 0 : json.dependencies) || {};
|
|
2284
|
+
} catch (e) {
|
|
2285
|
+
handleError$1(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
return dependencies;
|
|
2289
|
+
}
|
|
2290
|
+
/**
|
|
2291
|
+
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
2292
|
+
* @param {*} subPackages 模块
|
|
2293
|
+
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
2294
|
+
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
2295
|
+
* @returns
|
|
2296
|
+
*/
|
|
2297
|
+
|
|
2298
|
+
|
|
2299
|
+
const isDependenciesUpdate$1 = (subPackages, cwd, outputDir) => {
|
|
2300
|
+
// 步骤1. 收集package.json
|
|
2301
|
+
const packageArr = collectPackageJson(subPackages, cwd, outputDir); // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
1986
2302
|
|
|
2303
|
+
return checkPackageVersion$1(packageArr);
|
|
2304
|
+
}; // 比较package.json的依赖与node_modules依赖的版本号
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
const checkPackageVersion$1 = packageArr => {
|
|
2308
|
+
for (const item of packageArr) {
|
|
2309
|
+
const dependencies = readPackageDependencies(item.srcPackageDir);
|
|
1987
2310
|
const dependenciesKeys = Object.keys(dependencies);
|
|
1988
2311
|
|
|
1989
2312
|
for (const key of dependenciesKeys) {
|
|
1990
|
-
const depPath = path$
|
|
2313
|
+
const depPath = path$7.join(item.destNpmDir, key);
|
|
1991
2314
|
|
|
1992
2315
|
if (!fs$6.existsSync(depPath)) {
|
|
1993
2316
|
return true;
|
|
1994
2317
|
}
|
|
1995
2318
|
|
|
1996
|
-
const depPackagePath = path$
|
|
2319
|
+
const depPackagePath = path$7.join(depPath, 'package.json');
|
|
1997
2320
|
|
|
1998
2321
|
if (fs$6.existsSync(depPackagePath)) {
|
|
1999
2322
|
const packageData = require(depPackagePath);
|
|
@@ -2017,16 +2340,18 @@ const isDependenciesUpdate$1 = (modules, cwd, outputDir) => {
|
|
|
2017
2340
|
};
|
|
2018
2341
|
|
|
2019
2342
|
var checkDependencies = {
|
|
2020
|
-
isDependenciesUpdate: isDependenciesUpdate$1
|
|
2343
|
+
isDependenciesUpdate: isDependenciesUpdate$1,
|
|
2344
|
+
checkPackageVersion: checkPackageVersion$1
|
|
2021
2345
|
};
|
|
2022
2346
|
|
|
2023
|
-
const shelljs$
|
|
2024
|
-
const fs$5 = require$$0__default$
|
|
2025
|
-
const path$
|
|
2347
|
+
const shelljs$4 = require$$2__default;
|
|
2348
|
+
const fs$5 = require$$0__default$1;
|
|
2349
|
+
const path$6 = require$$1__default$1;
|
|
2026
2350
|
const io$1 = io$3;
|
|
2027
2351
|
const {
|
|
2028
2352
|
createTask: createTask$1,
|
|
2029
|
-
resolve: resolve$8
|
|
2353
|
+
resolve: resolve$8,
|
|
2354
|
+
getAbsolutePath: getAbsolutePath$1
|
|
2030
2355
|
} = widgets;
|
|
2031
2356
|
const {
|
|
2032
2357
|
buildMpNpm
|
|
@@ -2036,14 +2361,13 @@ const {
|
|
|
2036
2361
|
getCache
|
|
2037
2362
|
} = cache;
|
|
2038
2363
|
const {
|
|
2039
|
-
|
|
2040
|
-
} =
|
|
2364
|
+
NODE_MODULES_DIR: NODE_MODULES_DIR$1
|
|
2365
|
+
} = constant;
|
|
2041
2366
|
const {
|
|
2042
2367
|
npmInstallAll
|
|
2043
2368
|
} = npm;
|
|
2044
2369
|
const {
|
|
2045
|
-
|
|
2046
|
-
info: info$5
|
|
2370
|
+
info: info$6
|
|
2047
2371
|
} = log$1;
|
|
2048
2372
|
const {
|
|
2049
2373
|
fileMd5
|
|
@@ -2052,51 +2376,45 @@ const {
|
|
|
2052
2376
|
isDependenciesUpdate
|
|
2053
2377
|
} = checkDependencies;
|
|
2054
2378
|
|
|
2055
|
-
async function install$2(tmsConfig,
|
|
2379
|
+
async function install$2(tmsConfig, subPackages, useCache) {
|
|
2056
2380
|
const cwd = process.cwd();
|
|
2057
|
-
const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig,
|
|
2381
|
+
const npmInstallRes = await createTask$1(npmInstall, '小程序 开始npm install', '小程序npm install 完成')(tmsConfig, subPackages, useCache); // 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
|
|
2058
2382
|
|
|
2059
2383
|
if (!npmInstallRes.isCache) {
|
|
2060
2384
|
// 构建miniprogram_npm, 不使用缓存
|
|
2061
|
-
await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig,
|
|
2385
|
+
await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, false);
|
|
2062
2386
|
} else {
|
|
2063
2387
|
// 构建miniprogram_npm
|
|
2064
|
-
await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig,
|
|
2388
|
+
await createTask$1(mpCiInstall, '开始构建miniprogram_npm', '构建miniprogram_npm 完成')(tmsConfig, subPackages, useCache);
|
|
2065
2389
|
}
|
|
2066
2390
|
|
|
2067
|
-
shelljs$
|
|
2391
|
+
shelljs$4.cd(cwd);
|
|
2068
2392
|
}
|
|
2069
2393
|
|
|
2070
|
-
async function npmInstall(tmsConfig,
|
|
2394
|
+
async function npmInstall(tmsConfig, subPackages, useCache) {
|
|
2071
2395
|
// 如果依赖没有更新和使用缓存数据(则命中缓存)
|
|
2072
|
-
if (!isDependenciesUpdate(
|
|
2073
|
-
info$
|
|
2396
|
+
if (!isDependenciesUpdate(subPackages, resolve$8('./'), tmsConfig.outputDir) && useCache) {
|
|
2397
|
+
info$6('node_modules命中缓存');
|
|
2074
2398
|
return {
|
|
2075
2399
|
isCache: true
|
|
2076
2400
|
};
|
|
2077
2401
|
} // 拷贝模块的package.json到编译输出目录
|
|
2078
2402
|
|
|
2079
2403
|
|
|
2080
|
-
|
|
2404
|
+
subPackages.forEach(item => {
|
|
2081
2405
|
const outputModuleDir = resolve$8(`${tmsConfig.outputDir}/${item.root}`);
|
|
2082
|
-
|
|
2083
|
-
if (!fs$5.existsSync(resolve$8(item.path))) {
|
|
2084
|
-
fail$3(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2085
|
-
process.exit(1);
|
|
2086
|
-
}
|
|
2087
|
-
|
|
2088
2406
|
io$1.ensureDirExist(outputModuleDir);
|
|
2089
|
-
const modulePackagePath =
|
|
2090
|
-
if (fs$5.existsSync(modulePackagePath)) shelljs$
|
|
2407
|
+
const modulePackagePath = `${getAbsolutePath$1(item.path)}/package.json`;
|
|
2408
|
+
if (fs$5.existsSync(modulePackagePath)) shelljs$4.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
2091
2409
|
});
|
|
2092
|
-
await npmInstallAll(
|
|
2410
|
+
await npmInstallAll(subPackages, resolve$8(tmsConfig.outputDir), NODE_MODULES_DIR$1);
|
|
2093
2411
|
return {
|
|
2094
2412
|
isCache: false
|
|
2095
2413
|
};
|
|
2096
2414
|
} // 构建miniprogram_npm
|
|
2097
2415
|
|
|
2098
2416
|
|
|
2099
|
-
async function mpCiInstall(tmsConfig,
|
|
2417
|
+
async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
2100
2418
|
const packageJsonFiles = [];
|
|
2101
2419
|
const rootPackFile = resolve$8(`${tmsConfig.outputDir}/package.json`);
|
|
2102
2420
|
|
|
@@ -2104,7 +2422,7 @@ async function mpCiInstall(tmsConfig, modules, useCache) {
|
|
|
2104
2422
|
packageJsonFiles.push(rootPackFile);
|
|
2105
2423
|
}
|
|
2106
2424
|
|
|
2107
|
-
|
|
2425
|
+
subPackages.forEach(item => {
|
|
2108
2426
|
const packageJsonFile = resolve$8(`${tmsConfig.outputDir}/${item.root}/package.json`);
|
|
2109
2427
|
|
|
2110
2428
|
if (fs$5.existsSync(packageJsonFile)) {
|
|
@@ -2120,7 +2438,7 @@ async function mpCiInstall(tmsConfig, modules, useCache) {
|
|
|
2120
2438
|
if (useCache) {
|
|
2121
2439
|
let flag = true;
|
|
2122
2440
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2123
|
-
const packageDir = path$
|
|
2441
|
+
const packageDir = path$6.dirname(item);
|
|
2124
2442
|
const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
|
|
2125
2443
|
const md5Value = await getMNPMd5(packageDir);
|
|
2126
2444
|
const preCache = getCache(mpDir, 'miniprogram_npm'); // console.log('miniprogram_npm', preCache, md5Value);
|
|
@@ -2134,13 +2452,13 @@ async function mpCiInstall(tmsConfig, modules, useCache) {
|
|
|
2134
2452
|
}
|
|
2135
2453
|
|
|
2136
2454
|
if (isCache) {
|
|
2137
|
-
info$
|
|
2455
|
+
info$6('miniprogram_npm命中缓存');
|
|
2138
2456
|
return;
|
|
2139
2457
|
} // 即将构建,在cache中标记开始
|
|
2140
2458
|
|
|
2141
2459
|
|
|
2142
2460
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2143
|
-
const packageDir = path$
|
|
2461
|
+
const packageDir = path$6.dirname(item);
|
|
2144
2462
|
const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
|
|
2145
2463
|
setCache(mpDir, 'miniprogram_npm', {
|
|
2146
2464
|
md5: '',
|
|
@@ -2154,7 +2472,7 @@ async function mpCiInstall(tmsConfig, modules, useCache) {
|
|
|
2154
2472
|
}); // 构建成功后,计算md5写入cache
|
|
2155
2473
|
|
|
2156
2474
|
await Promise.all(packageJsonFiles.map(async item => {
|
|
2157
|
-
const packageDir = path$
|
|
2475
|
+
const packageDir = path$6.dirname(item);
|
|
2158
2476
|
const mpDir = resolve$8(`${packageDir}/miniprogram_npm`);
|
|
2159
2477
|
const md5Value = await getMNPMd5(packageDir);
|
|
2160
2478
|
setCache(mpDir, 'miniprogram_npm', {
|
|
@@ -2170,15 +2488,16 @@ async function getMNPMd5(cwd) {
|
|
|
2170
2488
|
async: false,
|
|
2171
2489
|
silent: true
|
|
2172
2490
|
};
|
|
2173
|
-
shelljs$
|
|
2491
|
+
shelljs$4.cd(cwd);
|
|
2174
2492
|
|
|
2175
2493
|
if (fs$5.existsSync('miniprogram_npm')) {
|
|
2176
|
-
shelljs$
|
|
2494
|
+
shelljs$4.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', {
|
|
2177
2495
|
cwd,
|
|
2178
2496
|
...shellJsOption
|
|
2179
2497
|
});
|
|
2180
|
-
const
|
|
2181
|
-
|
|
2498
|
+
const tarDir = path$6.join(cwd, './miniprogram_npm.tar.gz');
|
|
2499
|
+
const md5Value = await fileMd5(tarDir);
|
|
2500
|
+
shelljs$4.rm('-rf', tarDir);
|
|
2182
2501
|
return md5Value;
|
|
2183
2502
|
}
|
|
2184
2503
|
|
|
@@ -2187,30 +2506,30 @@ async function getMNPMd5(cwd) {
|
|
|
2187
2506
|
|
|
2188
2507
|
var install_1 = install$2;
|
|
2189
2508
|
|
|
2190
|
-
const shelljs$
|
|
2191
|
-
const fs$4 = require$$0__default$
|
|
2509
|
+
const shelljs$3 = require$$2__default;
|
|
2510
|
+
const fs$4 = require$$0__default$1;
|
|
2192
2511
|
const io = io$3;
|
|
2193
2512
|
const {
|
|
2194
2513
|
resolve: resolve$7,
|
|
2195
2514
|
createTask
|
|
2196
2515
|
} = widgets;
|
|
2197
2516
|
const {
|
|
2198
|
-
buildOutputAppJson
|
|
2517
|
+
buildOutputAppJson: buildOutputAppJson$1
|
|
2199
2518
|
} = buildAppJson;
|
|
2200
2519
|
const {
|
|
2201
|
-
MODULE_CODE_DIR,
|
|
2202
|
-
DEFAULT_COPY_CONFIG
|
|
2203
|
-
} =
|
|
2520
|
+
MODULE_CODE_DIR: MODULE_CODE_DIR$1,
|
|
2521
|
+
DEFAULT_COPY_CONFIG: DEFAULT_COPY_CONFIG$1
|
|
2522
|
+
} = constant;
|
|
2204
2523
|
const {
|
|
2205
2524
|
cloneModules
|
|
2206
2525
|
} = cloneModules_1;
|
|
2207
2526
|
const {
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
} = tmsMpconfig;
|
|
2527
|
+
getModulesByMergeDepModules: getModulesByMergeDepModules$2,
|
|
2528
|
+
getSubPackages: getSubPackages$2
|
|
2529
|
+
} = tmsMpconfig.exports;
|
|
2211
2530
|
const {
|
|
2212
|
-
fail: fail$
|
|
2213
|
-
info: info$
|
|
2531
|
+
fail: fail$3,
|
|
2532
|
+
info: info$5
|
|
2214
2533
|
} = log$1;
|
|
2215
2534
|
const install$1 = install_1;
|
|
2216
2535
|
/**
|
|
@@ -2226,641 +2545,108 @@ const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
|
2226
2545
|
io.ensureDirExist(outputDir);
|
|
2227
2546
|
defaultFiles.forEach(item => {
|
|
2228
2547
|
if (fs$4.existsSync(resolve$7(item))) {
|
|
2229
|
-
shelljs$
|
|
2548
|
+
shelljs$3.cp('-rf', resolve$7(item), resolve$7(tmsConfig.outputDir, item));
|
|
2230
2549
|
}
|
|
2231
2550
|
});
|
|
2232
2551
|
};
|
|
2233
|
-
/**
|
|
2234
|
-
* 校验相关配置项
|
|
2235
|
-
* @param {*} targetModules
|
|
2236
|
-
* @returns
|
|
2237
|
-
*/
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
function checkConfig(targetModules) {
|
|
2241
|
-
for (const item of targetModules) {
|
|
2242
|
-
if (!item.root) {
|
|
2243
|
-
throw new Error(`检查${item.name} module.config.json的root字段`);
|
|
2244
|
-
} // 判断源码目录是否有该模块
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
if (item.path && !fs$4.existsSync(resolve$7(item.path))) {
|
|
2248
|
-
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
2249
|
-
}
|
|
2250
|
-
}
|
|
2251
|
-
|
|
2252
|
-
return true;
|
|
2253
|
-
}
|
|
2254
2552
|
|
|
2255
2553
|
async function task(tmsConfig, targetModules) {
|
|
2256
2554
|
// 下载和移动代码
|
|
2257
|
-
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR, resolve$7('./'), targetModules); //
|
|
2555
|
+
await createTask(cloneModules, '开始下载模块代码', '下载模块代码码完成')(MODULE_CODE_DIR$1, resolve$7('./'), targetModules); // 获取所有模块,合并模块依赖的模块
|
|
2258
2556
|
|
|
2259
|
-
|
|
2557
|
+
const newModules = getModulesByMergeDepModules$2(tmsConfig, targetModules, true); // 获取所有的分包
|
|
2260
2558
|
|
|
2261
|
-
|
|
2262
|
-
checkConfig(newModules); // 拷贝相关配置文件到输出目录
|
|
2559
|
+
const newSubPackages = getSubPackages$2(newModules); // 拷贝相关配置文件到输出目录
|
|
2263
2560
|
|
|
2264
|
-
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG); // install
|
|
2561
|
+
await createTask(cpFilesToOutput, '开始拷贝文件到编译输出目录', '拷贝文件到编译输出目录完成')(tmsConfig, DEFAULT_COPY_CONFIG$1); // install
|
|
2265
2562
|
|
|
2266
|
-
await install$1(tmsConfig,
|
|
2563
|
+
await install$1(tmsConfig, newSubPackages, true); // 动态生成编译后的app.json;
|
|
2267
2564
|
|
|
2268
|
-
await createTask(buildOutputAppJson, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
2269
|
-
return
|
|
2565
|
+
await createTask(buildOutputAppJson$1, '开始生成编译后的app.json', '生成编译后的app.json完成')(tmsConfig, newModules);
|
|
2566
|
+
return {
|
|
2567
|
+
modules: newModules,
|
|
2568
|
+
subPackages: newSubPackages
|
|
2569
|
+
};
|
|
2270
2570
|
}
|
|
2271
2571
|
|
|
2272
|
-
async function init$
|
|
2572
|
+
async function init$3(tmsConfig, targetModules) {
|
|
2273
2573
|
try {
|
|
2274
|
-
const
|
|
2275
|
-
return
|
|
2276
|
-
targetModules: newModules
|
|
2277
|
-
};
|
|
2574
|
+
const taskRes = await task(tmsConfig, targetModules);
|
|
2575
|
+
return taskRes;
|
|
2278
2576
|
} catch (error) {
|
|
2279
2577
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
2280
|
-
fail$
|
|
2281
|
-
info$
|
|
2578
|
+
fail$3(`初始化流程出现错误: ${errMsg}`);
|
|
2579
|
+
info$5('详细的错误信息', error);
|
|
2282
2580
|
process.exit(1);
|
|
2283
2581
|
}
|
|
2284
2582
|
}
|
|
2285
2583
|
|
|
2286
|
-
var init_1 = init$
|
|
2287
|
-
|
|
2288
|
-
var dev$3 = {exports: {}};
|
|
2584
|
+
var init_1 = init$3;
|
|
2289
2585
|
|
|
2290
2586
|
/* eslint-disable no-param-reassign */
|
|
2291
|
-
const strip = require$$0__default$8; // 匹配规则
|
|
2292
|
-
|
|
2293
|
-
const MATCH_RULE = new RegExp(/@import *(?:url\(['"]?([^'")]+)['"]?\)|['"]([^'"]+)['"]);?/g);
|
|
2294
|
-
/**
|
|
2295
|
-
* 获取样式文件中的@import语句
|
|
2296
|
-
* @param code 代码片段
|
|
2297
|
-
* @returns 结果数组
|
|
2298
|
-
*/
|
|
2299
2587
|
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
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
|
+
}
|
|
2303
2598
|
|
|
2304
|
-
|
|
2599
|
+
cb();
|
|
2600
|
+
};
|
|
2601
|
+
}
|
|
2305
2602
|
|
|
2306
|
-
|
|
2307
|
-
let matchList; // 循环遍历代码段,直至匹配结果为空
|
|
2603
|
+
var mpProjectJson_1 = mpProjectJson$1;
|
|
2308
2604
|
|
|
2309
|
-
while (matchList = MATCH_RULE.exec(code)) {
|
|
2310
|
-
var _matchList, _matchList2;
|
|
2311
|
-
|
|
2312
|
-
// 存入结果数组
|
|
2313
|
-
result.push(((_matchList = matchList) === null || _matchList === void 0 ? void 0 : _matchList[1]) || ((_matchList2 = matchList) === null || _matchList2 === void 0 ? void 0 : _matchList2[2]));
|
|
2314
|
-
} // 返回结果
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
return result;
|
|
2318
|
-
};
|
|
2319
|
-
|
|
2320
|
-
var findCssImport = {
|
|
2321
|
-
findCssImports: findCssImports$1
|
|
2322
|
-
};
|
|
2323
|
-
|
|
2324
|
-
/* eslint-disable no-param-reassign */
|
|
2325
|
-
const {
|
|
2326
|
-
fail: fail$1
|
|
2327
|
-
} = log$1;
|
|
2328
|
-
|
|
2329
|
-
function pluginError$3(error, isWatch) {
|
|
2330
|
-
const errMsg = error.message;
|
|
2331
|
-
|
|
2332
|
-
if (isWatch) {
|
|
2333
|
-
fail$1(errMsg);
|
|
2334
|
-
} else {
|
|
2335
|
-
fail$1(errMsg);
|
|
2336
|
-
process.exit(1);
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
|
|
2340
|
-
var pluginError_1 = {
|
|
2341
|
-
pluginError: pluginError$3
|
|
2342
|
-
};
|
|
2343
|
-
|
|
2344
|
-
/* eslint-disable no-param-reassign */
|
|
2345
|
-
const through$2 = require$$0__default$9;
|
|
2346
|
-
const precinct = require$$1__default$8;
|
|
2347
|
-
const path$4 = require$$1__default$2;
|
|
2348
|
-
const {
|
|
2349
|
-
findCssImports
|
|
2350
|
-
} = findCssImport;
|
|
2351
2605
|
const {
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
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;
|
|
2356
2613
|
const {
|
|
2357
2614
|
resolve: resolve$6
|
|
2358
2615
|
} = widgets;
|
|
2359
|
-
const
|
|
2360
|
-
const {
|
|
2361
|
-
pluginError: pluginError$2
|
|
2362
|
-
} = pluginError_1;
|
|
2363
|
-
const cssFilter = ['.less', '.wxss'];
|
|
2364
|
-
|
|
2365
|
-
const dfsFindCommonDep$2 = function (anaFileOriginFile, anaFileDestFile, extensions, isWatch = true) {
|
|
2366
|
-
const resDep = new Map();
|
|
2367
|
-
|
|
2368
|
-
function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
|
|
2369
|
-
let contents = '';
|
|
2370
|
-
|
|
2371
|
-
try {
|
|
2372
|
-
contents = fs$3.readFileSync(anaFileOriginFile, 'utf8');
|
|
2373
|
-
} catch (e) {
|
|
2374
|
-
pluginError$2(e, isWatch);
|
|
2375
|
-
}
|
|
2376
|
-
|
|
2377
|
-
const deps = cssFilter.indexOf(path$4.extname(anaFileOriginFile)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2378
|
-
deps.forEach(depItem => {
|
|
2379
|
-
if (depItem.startsWith('.')) {
|
|
2380
|
-
// 被依赖文件的存在的绝对路径
|
|
2381
|
-
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2382
|
-
|
|
2383
|
-
const {
|
|
2384
|
-
ext: extAlias,
|
|
2385
|
-
file: depOriginFile,
|
|
2386
|
-
extPath
|
|
2387
|
-
} = ext$2(depOriginPath, extensions);
|
|
2388
|
-
|
|
2389
|
-
if (!fs$3.existsSync(depOriginFile)) {
|
|
2390
|
-
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`), isWatch);
|
|
2391
|
-
return;
|
|
2392
|
-
}
|
|
2393
|
-
|
|
2394
|
-
const depDestPath = resolve$6(path$4.dirname(anaFileDestFile), depItem);
|
|
2395
|
-
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2396
|
-
|
|
2397
|
-
if (!resDep.has(depDestFile)) {
|
|
2398
|
-
resDep.set(depDestFile, {
|
|
2399
|
-
anaFileOriginFile,
|
|
2400
|
-
anaFileDestFile,
|
|
2401
|
-
depDestFile,
|
|
2402
|
-
depOriginFile
|
|
2403
|
-
});
|
|
2404
|
-
dfs(depOriginFile, depDestFile, extensions);
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2407
|
-
});
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
dfs(anaFileOriginFile, anaFileDestFile, extensions);
|
|
2411
|
-
return resDep;
|
|
2412
|
-
};
|
|
2413
|
-
|
|
2414
|
-
function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
|
|
2415
|
-
const stream = through$2.obj(function (file, enc, cb) {
|
|
2416
|
-
// 依赖分析的文件
|
|
2417
|
-
const anaFileOriginFile = file.history[0];
|
|
2418
|
-
const anaFileRelativeModule = path$4.relative(resolve$6(module.from), anaFileOriginFile);
|
|
2419
|
-
const anaFileDestFile = resolve$6(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2420
|
-
|
|
2421
|
-
if (file.isBuffer()) {
|
|
2422
|
-
let contents = String(file.contents);
|
|
2423
|
-
const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
|
|
2424
|
-
const copyModules = new Map();
|
|
2425
|
-
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2426
|
-
const includePath = tmsConfig.dependencies[includeName];
|
|
2427
|
-
deps.forEach(depItem => {
|
|
2428
|
-
if (depItem.indexOf(includeName) > -1) {
|
|
2429
|
-
// 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
|
|
2430
|
-
const depOriginPath = path$4.join(path$4.dirname(anaFileOriginFile), depItem); // 被依赖文件加上后缀
|
|
2431
|
-
|
|
2432
|
-
const {
|
|
2433
|
-
ext: extAlias,
|
|
2434
|
-
file: depOriginFile,
|
|
2435
|
-
extPath
|
|
2436
|
-
} = ext$2(depOriginPath, extensions);
|
|
2437
|
-
|
|
2438
|
-
if (!fileInDir$2(includePath, depOriginFile)) {
|
|
2439
|
-
pluginError$2(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
2440
|
-
return;
|
|
2441
|
-
} // eslint-disable-next-line
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2445
|
-
const regRes = depItem.match(reg) || [];
|
|
2446
|
-
|
|
2447
|
-
if (regRes[2]) {
|
|
2448
|
-
const depDestPath = resolve$6(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2449
|
-
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2450
|
-
|
|
2451
|
-
if (!copyModules.has(depDestFile)) {
|
|
2452
|
-
copyModules.set(depDestFile, {
|
|
2453
|
-
depOriginFile,
|
|
2454
|
-
depDestFile,
|
|
2455
|
-
beforeDepPath: depItem,
|
|
2456
|
-
afterDepPath: path$4.relative(path$4.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2457
|
-
});
|
|
2458
|
-
}
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
});
|
|
2462
|
-
}); // console.log('mpCommonDep copyModules', copyModules);
|
|
2463
|
-
|
|
2464
|
-
copyModules.forEach(({
|
|
2465
|
-
depOriginFile,
|
|
2466
|
-
depDestFile,
|
|
2467
|
-
beforeDepPath,
|
|
2468
|
-
afterDepPath
|
|
2469
|
-
}) => {
|
|
2470
|
-
diffContentCopyFile$2(depOriginFile, depDestFile);
|
|
2471
|
-
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2472
|
-
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
2473
|
-
const defs = dfsFindCommonDep$2(depOriginFile, depDestFile, extensions, isWatch);
|
|
2474
|
-
defs.forEach(item => {
|
|
2475
|
-
diffContentCopyFile$2(item.depOriginFile, item.depDestFile);
|
|
2476
|
-
}); // console.log('mpCommonDep defs', defs);
|
|
2477
|
-
});
|
|
2478
|
-
file.contents = Buffer.from(contents);
|
|
2479
|
-
}
|
|
2480
|
-
|
|
2481
|
-
this.push(file);
|
|
2482
|
-
cb();
|
|
2483
|
-
});
|
|
2484
|
-
return stream;
|
|
2485
|
-
}
|
|
2486
|
-
|
|
2487
|
-
var mpCommonDep_1 = {
|
|
2488
|
-
mpCommonDep: mpCommonDep$1,
|
|
2489
|
-
dfsFindCommonDep: dfsFindCommonDep$2
|
|
2490
|
-
};
|
|
2491
|
-
|
|
2492
|
-
/* eslint-disable no-param-reassign */
|
|
2493
|
-
const through$1 = require$$0__default$9;
|
|
2494
|
-
const path$3 = require$$1__default$2;
|
|
2495
|
-
const {
|
|
2496
|
-
ext: ext$1,
|
|
2497
|
-
fileInDir: fileInDir$1,
|
|
2498
|
-
diffContentCopyFile: diffContentCopyFile$1
|
|
2499
|
-
} = io$3;
|
|
2500
|
-
const {
|
|
2501
|
-
resolve: resolve$5
|
|
2502
|
-
} = widgets;
|
|
2503
|
-
const fs$2 = require$$0__default$2;
|
|
2504
|
-
const {
|
|
2505
|
-
pluginError: pluginError$1
|
|
2506
|
-
} = pluginError_1;
|
|
2507
|
-
const {
|
|
2508
|
-
dfsFindCommonDep: dfsFindCommonDep$1
|
|
2509
|
-
} = mpCommonDep_1;
|
|
2510
|
-
|
|
2511
|
-
function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch) {
|
|
2512
|
-
const stream = through$1.obj(function (file, enc, cb) {
|
|
2513
|
-
// 当前分析的文件的路径
|
|
2514
|
-
const anaFileOriginFile = file.history[0];
|
|
2515
|
-
const anaFileRelativeModule = path$3.relative(resolve$5(module.from), anaFileOriginFile);
|
|
2516
|
-
const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2517
|
-
|
|
2518
|
-
if (file.isBuffer()) {
|
|
2519
|
-
let contents = String(file.contents);
|
|
2520
|
-
const copyModules = new Map();
|
|
2521
|
-
|
|
2522
|
-
try {
|
|
2523
|
-
try {
|
|
2524
|
-
contents = contents ? JSON.parse(contents) : {};
|
|
2525
|
-
} catch (e) {
|
|
2526
|
-
throw new Error(`解析${file.path}出现错误,请检查配置信息: ${e}`);
|
|
2527
|
-
}
|
|
2528
|
-
|
|
2529
|
-
if (contents.usingComponents) {
|
|
2530
|
-
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2531
|
-
const includePath = tmsConfig.dependencies[includeName];
|
|
2532
|
-
Object.keys(contents.usingComponents).forEach(componentKey => {
|
|
2533
|
-
const componentPath = contents.usingComponents[componentKey];
|
|
2534
|
-
|
|
2535
|
-
if (componentPath.indexOf(includeName) > -1) {
|
|
2536
|
-
const depOriginPath = path$3.join(path$3.dirname(anaFileOriginFile), componentPath); // 被依赖文件加上后缀
|
|
2537
|
-
|
|
2538
|
-
const {
|
|
2539
|
-
ext: extAlias,
|
|
2540
|
-
file: depOriginFile,
|
|
2541
|
-
extPath
|
|
2542
|
-
} = ext$1(depOriginPath, extensions);
|
|
2543
|
-
const isFileInDir = fileInDir$1(includePath, depOriginFile);
|
|
2544
|
-
|
|
2545
|
-
if (!isFileInDir) {
|
|
2546
|
-
pluginError$1(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
2547
|
-
return;
|
|
2548
|
-
} // eslint-disable-next-line
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2552
|
-
const regRes = componentPath.match(reg) || [];
|
|
2553
|
-
|
|
2554
|
-
if (regRes[2]) {
|
|
2555
|
-
const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2556
|
-
const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
|
|
2557
|
-
|
|
2558
|
-
if (!copyModules.has(depDestFile)) {
|
|
2559
|
-
copyModules.set(depDestFile, {
|
|
2560
|
-
depOriginFile,
|
|
2561
|
-
depOriginExt: extAlias,
|
|
2562
|
-
depDestFile,
|
|
2563
|
-
beforeDepPath: componentPath,
|
|
2564
|
-
afterDepPath: path$3.relative(path$3.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/')
|
|
2565
|
-
});
|
|
2566
|
-
}
|
|
2567
|
-
}
|
|
2568
|
-
}
|
|
2569
|
-
});
|
|
2570
|
-
});
|
|
2571
|
-
}
|
|
2572
|
-
} catch (e) {
|
|
2573
|
-
pluginError$1(e, isWatch);
|
|
2574
|
-
} // console.log('json copyModules', copyModules);
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
copyModules.forEach(({
|
|
2578
|
-
depOriginFile,
|
|
2579
|
-
depOriginExt,
|
|
2580
|
-
depDestFile,
|
|
2581
|
-
beforeDepPath,
|
|
2582
|
-
afterDepPath
|
|
2583
|
-
}) => {
|
|
2584
|
-
// 拷贝当前依赖组件几个部分 wxml、wxss、wxs、json
|
|
2585
|
-
filesExt.forEach(extKey => {
|
|
2586
|
-
const originFile = depOriginFile.replace(depOriginExt, extKey);
|
|
2587
|
-
const destFile = depDestFile.replace(depOriginExt, extKey);
|
|
2588
|
-
|
|
2589
|
-
if (fs$2.existsSync(originFile)) {
|
|
2590
|
-
diffContentCopyFile$1(originFile, destFile);
|
|
2591
|
-
const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
|
|
2592
|
-
|
|
2593
|
-
if (extensionsFilter.indexOf(extKey) > -1) {
|
|
2594
|
-
const defs = dfsFindCommonDep$1(originFile, destFile, extensionsFilter); // console.log('json defs', defs);
|
|
2595
|
-
|
|
2596
|
-
defs.forEach(item => {
|
|
2597
|
-
diffContentCopyFile$1(item.depOriginFile, item.depDestFile);
|
|
2598
|
-
});
|
|
2599
|
-
}
|
|
2600
|
-
}
|
|
2601
|
-
});
|
|
2602
|
-
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
2603
|
-
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2604
|
-
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
2605
|
-
});
|
|
2606
|
-
contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
|
|
2607
|
-
file.contents = Buffer.from(contents);
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2610
|
-
this.push(file);
|
|
2611
|
-
cb();
|
|
2612
|
-
});
|
|
2613
|
-
return stream;
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
var mpJsonDep_1 = {
|
|
2617
|
-
mpJsonDep: mpJsonDep$1
|
|
2618
|
-
};
|
|
2619
|
-
|
|
2620
|
-
/* eslint-disable no-param-reassign */
|
|
2621
|
-
const through = require$$0__default$9;
|
|
2622
|
-
const htmlparser2 = require$$1__default$9;
|
|
2623
|
-
const fs$1 = require$$0__default$2;
|
|
2624
|
-
const path$2 = require$$1__default$2;
|
|
2625
|
-
const {
|
|
2626
|
-
diffContentCopyFile,
|
|
2627
|
-
ext,
|
|
2628
|
-
fileInDir
|
|
2629
|
-
} = io$3;
|
|
2630
|
-
const {
|
|
2631
|
-
resolve: resolve$4
|
|
2632
|
-
} = widgets;
|
|
2633
|
-
const {
|
|
2634
|
-
dfsFindCommonDep
|
|
2635
|
-
} = mpCommonDep_1;
|
|
2616
|
+
const through = require$$6__default;
|
|
2636
2617
|
const {
|
|
2637
|
-
|
|
2638
|
-
} =
|
|
2639
|
-
|
|
2640
|
-
const extFile = function (name, file) {
|
|
2641
|
-
const extMap = {
|
|
2642
|
-
import: '.wxml',
|
|
2643
|
-
include: '.wxml',
|
|
2644
|
-
wxs: '.wxs'
|
|
2645
|
-
};
|
|
2646
|
-
let extObj = {};
|
|
2647
|
-
|
|
2648
|
-
if (Object.keys(extMap).indexOf(name) > -1 && !file.endsWith(extMap[name])) {
|
|
2649
|
-
extObj = ext(file, [extMap[name]]);
|
|
2650
|
-
}
|
|
2618
|
+
fail: fail$2
|
|
2619
|
+
} = log$1;
|
|
2651
2620
|
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
};
|
|
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;
|
|
2657
2625
|
};
|
|
2658
2626
|
|
|
2659
|
-
const
|
|
2660
|
-
const
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
onopentag(name, attributes) {
|
|
2677
|
-
var _attributes$src;
|
|
2678
|
-
|
|
2679
|
-
if (attributes !== null && attributes !== void 0 && (_attributes$src = attributes.src) !== null && _attributes$src !== void 0 && _attributes$src.startsWith('.')) {
|
|
2680
|
-
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 被依赖文件加上后缀
|
|
2681
|
-
|
|
2682
|
-
const {
|
|
2683
|
-
ext,
|
|
2684
|
-
file: depOriginFile,
|
|
2685
|
-
extPath
|
|
2686
|
-
} = extFile(name, depOriginPath);
|
|
2687
|
-
|
|
2688
|
-
if (!fs$1.existsSync(depOriginFile)) {
|
|
2689
|
-
pluginError(new Error(`${anaFileOriginFile}引用的路径${depOriginFile}找不到应用文件,请检查引用路径`), isWatch);
|
|
2690
|
-
return;
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
|
-
const depDestPath = path$2.join(path$2.dirname(anaFileDestFile), attributes.src);
|
|
2694
|
-
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath; // 收集wxml依赖
|
|
2695
|
-
|
|
2696
|
-
if (['import', 'include'].indexOf(name) > -1) {
|
|
2697
|
-
resDep.wxml.set(depDestFile, {
|
|
2698
|
-
anaFileOriginFile,
|
|
2699
|
-
anaFileDestFile,
|
|
2700
|
-
depDestFile,
|
|
2701
|
-
depOriginFile
|
|
2702
|
-
});
|
|
2703
|
-
dfs(depOriginFile, depDestFile);
|
|
2704
|
-
} // 收集image依赖
|
|
2705
|
-
// if (name === 'image') {
|
|
2706
|
-
// resDep.image.set(attributes.src, {
|
|
2707
|
-
// anaFileOriginFile,
|
|
2708
|
-
// anaFileDestFile,
|
|
2709
|
-
// depDestFile,
|
|
2710
|
-
// depOriginFile,
|
|
2711
|
-
// });
|
|
2712
|
-
// dfs(depOriginFile, depDestFile);
|
|
2713
|
-
// }
|
|
2714
|
-
// 收集wxs依赖
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
if (name === 'wxs') {
|
|
2718
|
-
resDep.wxs.set(depDestFile, {
|
|
2719
|
-
anaFileOriginFile,
|
|
2720
|
-
anaFileDestFile,
|
|
2721
|
-
depDestFile,
|
|
2722
|
-
depOriginFile
|
|
2723
|
-
});
|
|
2724
|
-
const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs']);
|
|
2725
|
-
defs.forEach((item, key) => {
|
|
2726
|
-
resDep.wxs.set(key, item);
|
|
2727
|
-
});
|
|
2728
|
-
}
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2731
|
-
|
|
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
|
|
2732
2644
|
});
|
|
2733
|
-
parser.write(contents);
|
|
2734
|
-
parser.end();
|
|
2735
|
-
}
|
|
2736
|
-
|
|
2737
|
-
dfs(anaFileOriginFile, anaFileDestFile);
|
|
2738
|
-
return resDep;
|
|
2739
|
-
};
|
|
2740
|
-
|
|
2741
|
-
function mpWxmlDep$1(tmsConfig, module, isWatch) {
|
|
2742
|
-
const stream = through.obj(function (file, enc, cb) {
|
|
2743
|
-
// 依赖分析的文件
|
|
2744
|
-
const anaFileOriginFile = file.history[0];
|
|
2745
|
-
const anaFileRelativeModule = path$2.relative(resolve$4(module.from), anaFileOriginFile);
|
|
2746
|
-
const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
2747
|
-
|
|
2748
|
-
if (file.isBuffer()) {
|
|
2749
|
-
let contents = String(file.contents);
|
|
2750
|
-
const copyModules = new Map();
|
|
2751
|
-
const parser = new htmlparser2.Parser({
|
|
2752
|
-
onopentag(name, attributes) {
|
|
2753
|
-
const nameFilter = ['import', 'include', 'wxs'];
|
|
2754
|
-
|
|
2755
|
-
if (nameFilter.indexOf(name) > -1 && attributes.src) {
|
|
2756
|
-
const depOriginPath = path$2.join(path$2.dirname(anaFileOriginFile), attributes.src); // 处理后缀(源码引入依赖时,后缀不全的情况)
|
|
2757
|
-
|
|
2758
|
-
const {
|
|
2759
|
-
ext,
|
|
2760
|
-
file: depOriginFile,
|
|
2761
|
-
extPath
|
|
2762
|
-
} = extFile(name, depOriginPath);
|
|
2763
|
-
Object.keys(tmsConfig.dependencies).forEach(includeName => {
|
|
2764
|
-
if (attributes.src.indexOf(includeName) > -1) {
|
|
2765
|
-
const includePath = tmsConfig.dependencies[includeName];
|
|
2766
|
-
|
|
2767
|
-
if (!fileInDir(includePath, depOriginFile)) {
|
|
2768
|
-
pluginError(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
|
|
2769
|
-
return;
|
|
2770
|
-
} // eslint-disable-next-line
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
const reg = new RegExp(`^(\./\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
2774
|
-
const regRes = attributes.src.match(reg) || [];
|
|
2775
|
-
|
|
2776
|
-
if (regRes[2]) {
|
|
2777
|
-
const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
|
2778
|
-
const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
|
|
2779
|
-
|
|
2780
|
-
if (!copyModules.has(depDestFile)) {
|
|
2781
|
-
copyModules.set(depDestFile, {
|
|
2782
|
-
depOriginFile,
|
|
2783
|
-
depDestFile,
|
|
2784
|
-
beforeDepPath: attributes.src,
|
|
2785
|
-
afterDepPath: path$2.relative(path$2.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/')
|
|
2786
|
-
});
|
|
2787
|
-
}
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
});
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
|
|
2794
|
-
});
|
|
2795
|
-
parser.write(contents);
|
|
2796
|
-
parser.end(); // console.log('wxml copyModules', copyModules);
|
|
2797
|
-
|
|
2798
|
-
copyModules.forEach(({
|
|
2799
|
-
depOriginFile,
|
|
2800
|
-
depDestFile,
|
|
2801
|
-
beforeDepPath,
|
|
2802
|
-
afterDepPath
|
|
2803
|
-
}) => {
|
|
2804
|
-
if (fs$1.existsSync(depOriginFile)) {
|
|
2805
|
-
diffContentCopyFile(depOriginFile, depDestFile);
|
|
2806
|
-
const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
|
|
2807
|
-
contents = contents.replace(reg, `"${afterDepPath}"`);
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2810
|
-
if (depOriginFile.endsWith('.wxml')) {
|
|
2811
|
-
const defs = dfsFindWxmlDep(depOriginFile, depDestFile, isWatch); // console.log('wxml defs', defs);
|
|
2812
|
-
|
|
2813
|
-
[...defs.wxml, ...defs.wxs].forEach(([, item]) => {
|
|
2814
|
-
diffContentCopyFile(item.depOriginFile, item.depDestFile);
|
|
2815
|
-
});
|
|
2816
|
-
}
|
|
2817
|
-
|
|
2818
|
-
if (depOriginFile.endsWith('.wxs')) {
|
|
2819
|
-
const defs = dfsFindCommonDep(depOriginFile, depDestFile, ['.wxs'], isWatch); // console.log('wxs defs', defs);
|
|
2820
|
-
|
|
2821
|
-
defs.forEach(item => {
|
|
2822
|
-
diffContentCopyFile(item.depOriginFile, item.depDestFile);
|
|
2823
|
-
});
|
|
2824
|
-
}
|
|
2825
|
-
});
|
|
2826
|
-
file.contents = Buffer.from(contents);
|
|
2827
|
-
}
|
|
2828
|
-
|
|
2829
2645
|
this.push(file);
|
|
2830
|
-
|
|
2831
|
-
});
|
|
2832
|
-
return stream;
|
|
2833
|
-
}
|
|
2834
|
-
|
|
2835
|
-
var mpWxmlDep_1 = {
|
|
2836
|
-
mpWxmlDep: mpWxmlDep$1,
|
|
2837
|
-
dfsFindWxmlDep
|
|
2646
|
+
}))), srcPipe);
|
|
2838
2647
|
};
|
|
2839
2648
|
|
|
2840
|
-
|
|
2841
|
-
src: src$1,
|
|
2842
|
-
dest
|
|
2843
|
-
} = require$$0__default$a; // const px2rpx = require('gulp-px-to-rpx');
|
|
2844
|
-
// const cache = require('gulp-cache');
|
|
2845
|
-
// const image = require('gulp-image');
|
|
2846
|
-
// const replaceEnv = require('./plugins/replaceEnv');
|
|
2847
|
-
|
|
2848
|
-
const {
|
|
2849
|
-
mpCommonDep
|
|
2850
|
-
} = mpCommonDep_1;
|
|
2851
|
-
const {
|
|
2852
|
-
mpJsonDep
|
|
2853
|
-
} = mpJsonDep_1;
|
|
2854
|
-
const {
|
|
2855
|
-
mpWxmlDep
|
|
2856
|
-
} = mpWxmlDep_1; // const postcss = require('gulp-postcss');
|
|
2857
|
-
// const base64 = require('./plugins/postcss-font-base64');
|
|
2858
|
-
|
|
2859
|
-
const {
|
|
2860
|
-
fail
|
|
2861
|
-
} = log$1; // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
|
|
2862
|
-
|
|
2863
|
-
var compile = function (tmsConfig, {
|
|
2649
|
+
var compile$1 = function (tmsConfig, {
|
|
2864
2650
|
glob,
|
|
2865
2651
|
destPath,
|
|
2866
2652
|
srcOption,
|
|
@@ -2868,122 +2654,21 @@ var compile = function (tmsConfig, {
|
|
|
2868
2654
|
isDev
|
|
2869
2655
|
}) {
|
|
2870
2656
|
const compileTasksMap = new Map();
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
}).pipe(dest(newDestPath, {
|
|
2887
|
-
overwrite: true
|
|
2888
|
-
})).on('error', err => {
|
|
2889
|
-
fail(`js编译报错${err}`);
|
|
2890
|
-
});
|
|
2891
|
-
}
|
|
2892
|
-
});
|
|
2893
|
-
break;
|
|
2894
|
-
|
|
2895
|
-
case 'wxss':
|
|
2896
|
-
compileTasksMap.set(globValue, {
|
|
2897
|
-
module,
|
|
2898
|
-
taskFn: (sourceFile, targetPath) => {
|
|
2899
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2900
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
2901
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2902
|
-
});
|
|
2903
|
-
return srcPipe.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev)).on('error', err => {
|
|
2904
|
-
fail(`mpCommonDep编译报错${err}`);
|
|
2905
|
-
}) // .pipe(postcss([base64()]))
|
|
2906
|
-
// .on('error', (err) => {
|
|
2907
|
-
// fail(`postcss编译报错${err}`);
|
|
2908
|
-
// })
|
|
2909
|
-
// .pipe(px2rpx({
|
|
2910
|
-
// designWidth: 375, // 设计稿宽度,默认为750
|
|
2911
|
-
// precision: 2, // 小数最大精度,默认为6
|
|
2912
|
-
// }))
|
|
2913
|
-
.pipe(dest(newDestPath)).on('error', err => {
|
|
2914
|
-
fail(`wxss编译报错${err}`);
|
|
2915
|
-
});
|
|
2916
|
-
}
|
|
2917
|
-
});
|
|
2918
|
-
break;
|
|
2919
|
-
|
|
2920
|
-
case 'json':
|
|
2921
|
-
compileTasksMap.set(globValue, {
|
|
2922
|
-
module,
|
|
2923
|
-
taskFn: (sourceFile, targetPath) => {
|
|
2924
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2925
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
2926
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2927
|
-
});
|
|
2928
|
-
return srcPipe.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev)).on('error', err => {
|
|
2929
|
-
fail(`mpJsonDep编译报错${err}`);
|
|
2930
|
-
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2931
|
-
fail(`json编译报错${err}`);
|
|
2932
|
-
});
|
|
2933
|
-
}
|
|
2934
|
-
});
|
|
2935
|
-
break;
|
|
2936
|
-
|
|
2937
|
-
case 'wxml':
|
|
2938
|
-
compileTasksMap.set(globValue, {
|
|
2939
|
-
module,
|
|
2940
|
-
taskFn: (sourceFile, targetPath) => {
|
|
2941
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2942
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
2943
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2944
|
-
});
|
|
2945
|
-
return srcPipe.pipe(mpWxmlDep(tmsConfig, module, isDev)).on('error', err => {
|
|
2946
|
-
fail(`mpWxmlDep编译报错${err}`);
|
|
2947
|
-
}).pipe(dest(newDestPath)).on('error', err => {
|
|
2948
|
-
fail(`wxml编译报错${err}`);
|
|
2949
|
-
});
|
|
2950
|
-
}
|
|
2951
|
-
});
|
|
2952
|
-
break;
|
|
2953
|
-
|
|
2954
|
-
case 'image':
|
|
2955
|
-
compileTasksMap.set(globValue, {
|
|
2956
|
-
module,
|
|
2957
|
-
taskFn: (sourceFile, targetPath) => {
|
|
2958
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2959
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
2960
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2961
|
-
});
|
|
2962
|
-
return srcPipe // .pipe(cache(image()))
|
|
2963
|
-
// .on('error', (err) => {
|
|
2964
|
-
// fail(`image编译报错${err}`);
|
|
2965
|
-
// })
|
|
2966
|
-
.pipe(dest(newDestPath)).on('error', err => {
|
|
2967
|
-
fail(`image编译报错${err}`);
|
|
2968
|
-
});
|
|
2969
|
-
}
|
|
2970
|
-
});
|
|
2971
|
-
break;
|
|
2972
|
-
|
|
2973
|
-
case 'other':
|
|
2974
|
-
compileTasksMap.set(globValue, {
|
|
2975
|
-
module,
|
|
2976
|
-
taskFn: (sourceFile, targetPath) => {
|
|
2977
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
2978
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
2979
|
-
const srcPipe = src$1(newGlobValue, { ...srcOption
|
|
2980
|
-
});
|
|
2981
|
-
return srcPipe.pipe(dest(newDestPath)).on('error', err => {
|
|
2982
|
-
fail(`编译报错${err}`);
|
|
2983
|
-
});
|
|
2984
|
-
}
|
|
2985
|
-
});
|
|
2986
|
-
break;
|
|
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}`);
|
|
2671
|
+
});
|
|
2987
2672
|
}
|
|
2988
2673
|
});
|
|
2989
2674
|
return compileTasksMap;
|
|
@@ -2992,11 +2677,11 @@ var compile = function (tmsConfig, {
|
|
|
2992
2677
|
/* eslint-disable */
|
|
2993
2678
|
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
2994
2679
|
|
|
2995
|
-
const assign = require$$0__default$
|
|
2996
|
-
const path$
|
|
2997
|
-
const PluginError = require$$2__default$
|
|
2998
|
-
const fancyLog = require$$3__default;
|
|
2999
|
-
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;
|
|
3000
2685
|
const chokidar = require$$5__default;
|
|
3001
2686
|
const {
|
|
3002
2687
|
Duplex
|
|
@@ -3004,7 +2689,7 @@ const {
|
|
|
3004
2689
|
const vinyl = require$$7__default;
|
|
3005
2690
|
const File = require$$8__default;
|
|
3006
2691
|
const anymatch = require$$9__default;
|
|
3007
|
-
const pathIsAbsolute = require$$10__default;
|
|
2692
|
+
const pathIsAbsolute = require$$10__default$1;
|
|
3008
2693
|
const globParent = require$$11__default;
|
|
3009
2694
|
const slash = require$$12__default;
|
|
3010
2695
|
|
|
@@ -3024,7 +2709,7 @@ function normalizeGlobs(globs) {
|
|
|
3024
2709
|
return globs;
|
|
3025
2710
|
}
|
|
3026
2711
|
|
|
3027
|
-
function watch$
|
|
2712
|
+
function watch$2(globs, opts, cb) {
|
|
3028
2713
|
globs = normalizeGlobs(globs);
|
|
3029
2714
|
|
|
3030
2715
|
if (typeof opts === 'function') {
|
|
@@ -3032,16 +2717,16 @@ function watch$1(globs, opts, cb) {
|
|
|
3032
2717
|
opts = {};
|
|
3033
2718
|
}
|
|
3034
2719
|
|
|
3035
|
-
opts = assign({}, watch$
|
|
2720
|
+
opts = assign({}, watch$2._defaultOptions, opts);
|
|
3036
2721
|
|
|
3037
2722
|
cb = cb || function () {};
|
|
3038
2723
|
|
|
3039
2724
|
function resolveFilepath(filepath) {
|
|
3040
2725
|
if (pathIsAbsolute(filepath)) {
|
|
3041
|
-
return path$
|
|
2726
|
+
return path$4.normalize(filepath);
|
|
3042
2727
|
}
|
|
3043
2728
|
|
|
3044
|
-
return path$
|
|
2729
|
+
return path$4.resolve(opts.cwd || process.cwd(), filepath);
|
|
3045
2730
|
}
|
|
3046
2731
|
|
|
3047
2732
|
function resolveGlob(glob) {
|
|
@@ -3097,7 +2782,7 @@ function watch$1(globs, opts, cb) {
|
|
|
3097
2782
|
let glob;
|
|
3098
2783
|
let currentFilepath = filepath;
|
|
3099
2784
|
|
|
3100
|
-
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$
|
|
2785
|
+
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path$4.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
|
|
3101
2786
|
|
|
3102
2787
|
|
|
3103
2788
|
if (!glob) {
|
|
@@ -3106,7 +2791,7 @@ function watch$1(globs, opts, cb) {
|
|
|
3106
2791
|
}
|
|
3107
2792
|
|
|
3108
2793
|
if (!baseForced) {
|
|
3109
|
-
fileOpts.base = path$
|
|
2794
|
+
fileOpts.base = path$4.normalize(globParent(glob));
|
|
3110
2795
|
} // Do not stat deleted files
|
|
3111
2796
|
|
|
3112
2797
|
|
|
@@ -3157,319 +2842,560 @@ function watch$1(globs, opts, cb) {
|
|
|
3157
2842
|
// Avoid modifying gulp-watch's default options inside a library/reusable package, please.
|
|
3158
2843
|
|
|
3159
2844
|
|
|
3160
|
-
watch$
|
|
2845
|
+
watch$2._defaultOptions = {
|
|
3161
2846
|
events: ['add', 'change', 'unlink'],
|
|
3162
2847
|
ignoreInitial: true,
|
|
3163
2848
|
readDelay: 10
|
|
3164
2849
|
};
|
|
3165
|
-
var gulpWatch = watch$
|
|
2850
|
+
var gulpWatch = watch$2;
|
|
3166
2851
|
|
|
3167
|
-
|
|
3168
|
-
const
|
|
3169
|
-
const
|
|
2852
|
+
/* eslint-disable no-restricted-syntax */
|
|
2853
|
+
const watch$1 = gulpWatch;
|
|
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;
|
|
3170
2859
|
const {
|
|
3171
|
-
info: info$
|
|
3172
|
-
warn: warn$1
|
|
2860
|
+
info: info$4,
|
|
2861
|
+
warn: warn$1,
|
|
2862
|
+
fail: fail$1
|
|
3173
2863
|
} = log$1;
|
|
3174
2864
|
const {
|
|
3175
|
-
resolve: resolve$
|
|
2865
|
+
resolve: resolve$5,
|
|
2866
|
+
filterField: filterField$3
|
|
3176
2867
|
} = widgets;
|
|
3177
2868
|
const {
|
|
3178
2869
|
global: global$2
|
|
3179
2870
|
} = global_1;
|
|
3180
2871
|
const {
|
|
3181
|
-
|
|
3182
|
-
} =
|
|
2872
|
+
checkPackageVersion
|
|
2873
|
+
} = checkDependencies;
|
|
2874
|
+
const report$5 = report_1;
|
|
3183
2875
|
const TIP_MAP = {
|
|
3184
|
-
'package.json':
|
|
3185
|
-
|
|
2876
|
+
'package.json': {
|
|
2877
|
+
tip: '依赖版本有变动,请重新执行tmskit run dev',
|
|
2878
|
+
check: (sourceFile, targetFile) => {
|
|
2879
|
+
const targetArr = targetFile.split('/');
|
|
2880
|
+
targetArr[targetArr.length - 1] = 'node_modules';
|
|
2881
|
+
const packageArr = [{
|
|
2882
|
+
srcPackageDir: sourceFile,
|
|
2883
|
+
destNpmDir: targetArr.join('/')
|
|
2884
|
+
}];
|
|
2885
|
+
return checkPackageVersion(packageArr);
|
|
2886
|
+
}
|
|
2887
|
+
},
|
|
2888
|
+
'module.config.json': {
|
|
2889
|
+
tip: '若dependencies字段有变动,请重新执行tmskit run dev才会生效',
|
|
2890
|
+
check: () => true
|
|
2891
|
+
}
|
|
3186
2892
|
};
|
|
3187
2893
|
|
|
3188
|
-
const logTip = (fileName, tipMap) => {
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
2894
|
+
const logTip = (fileName, sourceFile, targetFile, tipMap) => {
|
|
2895
|
+
try {
|
|
2896
|
+
for (const item in tipMap) {
|
|
2897
|
+
if (fileName.indexOf(item) > -1 && tipMap[item].check(sourceFile, targetFile)) {
|
|
2898
|
+
warn$1(`${fileName}有更新, ${tipMap[item].tip}`);
|
|
2899
|
+
return;
|
|
2900
|
+
}
|
|
3194
2901
|
}
|
|
3195
|
-
}
|
|
3196
2902
|
|
|
3197
|
-
|
|
2903
|
+
info$4(`${fileName}有更新`);
|
|
2904
|
+
} catch (e) {
|
|
2905
|
+
fail$1(`${sourceFile}文件更新提示出现错误: ${e.message}`);
|
|
2906
|
+
}
|
|
3198
2907
|
};
|
|
3199
2908
|
|
|
3200
2909
|
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
3201
|
-
const sourceFileRelativeModule = path.relative(resolve$
|
|
3202
|
-
const targetFile = resolve$
|
|
2910
|
+
const sourceFileRelativeModule = path$3.relative(resolve$5(module.from), sourceFile);
|
|
2911
|
+
const targetFile = resolve$5(outputDir, module.to, sourceFileRelativeModule);
|
|
3203
2912
|
return targetFile;
|
|
3204
2913
|
};
|
|
3205
2914
|
|
|
3206
2915
|
var watch_1 = function (globValue, watchOptions, callback, module) {
|
|
3207
|
-
watch(globValue, { // readDelay: 100,
|
|
2916
|
+
watch$1(globValue, { // readDelay: 100,
|
|
3208
2917
|
...watchOptions
|
|
3209
2918
|
}, vinyl => {
|
|
3210
2919
|
const sourceFile = vinyl.history[0];
|
|
3211
2920
|
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
3212
2921
|
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
3213
2922
|
const tmsConfig = global$2.getData('tmsConfig');
|
|
2923
|
+
const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
|
|
2924
|
+
|
|
2925
|
+
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
2926
|
+
info$4(`删除${sourceFileName}`);
|
|
2927
|
+
shellJs.rm('-rf', targetFile);
|
|
2928
|
+
updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
|
|
2929
|
+
return;
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2932
|
+
runCallback({
|
|
2933
|
+
tmsConfig,
|
|
2934
|
+
sourceFile,
|
|
2935
|
+
targetFile,
|
|
2936
|
+
callback,
|
|
2937
|
+
type: vinyl.event
|
|
2938
|
+
});
|
|
2939
|
+
logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
|
|
2940
|
+
});
|
|
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
|
+
|
|
2965
|
+
|
|
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;
|
|
2984
|
+
const {
|
|
2985
|
+
parallel,
|
|
2986
|
+
series
|
|
2987
|
+
} = require$$0__default$7;
|
|
2988
|
+
const {
|
|
2989
|
+
resolve: resolve$4,
|
|
2990
|
+
mergeMap,
|
|
2991
|
+
filterField: filterField$2,
|
|
2992
|
+
getAbsolutePath
|
|
2993
|
+
} = widgets;
|
|
2994
|
+
const {
|
|
2995
|
+
buildOutputAppJson
|
|
2996
|
+
} = buildAppJson;
|
|
2997
|
+
const {
|
|
2998
|
+
DEFAULT_COPY_CONFIG
|
|
2999
|
+
} = constant;
|
|
3000
|
+
const compile = compile$1;
|
|
3001
|
+
const watch = watch_1;
|
|
3002
|
+
const {
|
|
3003
|
+
info: info$3
|
|
3004
|
+
} = log$1;
|
|
3005
|
+
const report$4 = report_1;
|
|
3006
|
+
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
3007
|
+
|
|
3008
|
+
var dev$3 = async (tmsConfig, modules, isDev = true) => {
|
|
3009
|
+
const compileTasksMap = new Map(); // 监听根目录的文件
|
|
3010
|
+
|
|
3011
|
+
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3012
|
+
glob: DEFAULT_COPY_CONFIG.map(item => resolve$4(item)),
|
|
3013
|
+
module: {
|
|
3014
|
+
from: resolve$4(),
|
|
3015
|
+
to: resolve$4(tmsConfig.outputDir)
|
|
3016
|
+
},
|
|
3017
|
+
destPath: resolve$4(tmsConfig.outputDir),
|
|
3018
|
+
srcOption: {
|
|
3019
|
+
allowEmpty: true
|
|
3020
|
+
},
|
|
3021
|
+
isDev
|
|
3022
|
+
})); // 监听模块的文件
|
|
3023
|
+
|
|
3024
|
+
for (let moduleItem of modules) {
|
|
3025
|
+
// 处理默认参数
|
|
3026
|
+
moduleItem = { ...{
|
|
3027
|
+
exclude: []
|
|
3028
|
+
},
|
|
3029
|
+
...moduleItem
|
|
3030
|
+
};
|
|
3031
|
+
const srcModulePath = getAbsolutePath(moduleItem.path);
|
|
3032
|
+
const buildModulePath = resolve$4(tmsConfig.outputDir, moduleItem.modulePath);
|
|
3033
|
+
|
|
3034
|
+
if (isDev) {
|
|
3035
|
+
// 监听模块配置文件
|
|
3036
|
+
watch([`${srcModulePath}/**/module.config.json`], {
|
|
3037
|
+
events: watchEvents
|
|
3038
|
+
}, () => buildOutputAppJson(tmsConfig, modules, isDev), {
|
|
3039
|
+
from: srcModulePath,
|
|
3040
|
+
to: buildModulePath
|
|
3041
|
+
});
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
const excludes = moduleItem.exclude.map(ePath => {
|
|
3045
|
+
const newPath = getAbsolutePath(ePath, srcModulePath);
|
|
3046
|
+
const ext = path$2.extname(ePath).slice(1);
|
|
3047
|
+
|
|
3048
|
+
if (ext) {
|
|
3049
|
+
return `!${resolve$4(srcModulePath, newPath)}`;
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
return `!${resolve$4(srcModulePath, newPath)}/**/*`;
|
|
3053
|
+
});
|
|
3054
|
+
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3055
|
+
glob: [`${srcModulePath}/**/*`, `!${srcModulePath}/**/module.config.json`, ...excludes],
|
|
3056
|
+
destPath: buildModulePath,
|
|
3057
|
+
module: {
|
|
3058
|
+
from: srcModulePath,
|
|
3059
|
+
to: buildModulePath
|
|
3060
|
+
},
|
|
3061
|
+
srcOption: {
|
|
3062
|
+
allowEmpty: true
|
|
3063
|
+
},
|
|
3064
|
+
isDev
|
|
3065
|
+
}));
|
|
3066
|
+
} // static静态资源目录
|
|
3067
|
+
|
|
3068
|
+
|
|
3069
|
+
if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
|
|
3070
|
+
for (const item of tmsConfig.static) {
|
|
3071
|
+
item.from = getAbsolutePath(item.from);
|
|
3072
|
+
item.to = getAbsolutePath(item.to);
|
|
3073
|
+
let glob = {};
|
|
3074
|
+
const ext = path$2.extname(item.from).slice(1);
|
|
3075
|
+
|
|
3076
|
+
if (ext) {
|
|
3077
|
+
glob = [item.from];
|
|
3078
|
+
} else {
|
|
3079
|
+
glob = [`${item.from}/**/*`];
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3082
|
+
const from = fs$3.lstatSync(item.from).isFile() ? path$2.dirname(item.from) : item.from;
|
|
3083
|
+
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
3084
|
+
glob,
|
|
3085
|
+
destPath: item.to,
|
|
3086
|
+
module: {
|
|
3087
|
+
from,
|
|
3088
|
+
to: item.to
|
|
3089
|
+
},
|
|
3090
|
+
srcOption: {
|
|
3091
|
+
allowEmpty: true
|
|
3092
|
+
},
|
|
3093
|
+
isDev
|
|
3094
|
+
}));
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
let sTime;
|
|
3099
|
+
let eTime;
|
|
3100
|
+
const spinner = ora();
|
|
3101
|
+
|
|
3102
|
+
function start(cb) {
|
|
3103
|
+
info$3('启动编译...');
|
|
3104
|
+
spinner.start();
|
|
3105
|
+
sTime = new Date().getTime();
|
|
3106
|
+
cb();
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
async function end(cb) {
|
|
3110
|
+
var _tmsConfig$hooks;
|
|
3111
|
+
|
|
3112
|
+
if (isDev) {
|
|
3113
|
+
// 监听app.json
|
|
3114
|
+
watch([resolve$4('app.json')], {
|
|
3115
|
+
ignoreInitial: false,
|
|
3116
|
+
events: watchEvents
|
|
3117
|
+
}, () => buildOutputAppJson(tmsConfig, modules, isDev), {
|
|
3118
|
+
from: resolve$4(),
|
|
3119
|
+
to: resolve$4(tmsConfig.outputDir)
|
|
3120
|
+
}); // 监听其他文件
|
|
3121
|
+
|
|
3122
|
+
compileTasksMap.forEach(({
|
|
3123
|
+
taskFn,
|
|
3124
|
+
module
|
|
3125
|
+
}, globValue) => {
|
|
3126
|
+
watch(globValue, {
|
|
3127
|
+
ignoreInitial: true,
|
|
3128
|
+
events: watchEvents
|
|
3129
|
+
}, taskFn, module);
|
|
3130
|
+
});
|
|
3131
|
+
} else {
|
|
3132
|
+
buildOutputAppJson(tmsConfig, modules, isDev);
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
eTime = new Date().getTime() - sTime;
|
|
3136
|
+
|
|
3137
|
+
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.afterCompile) === 'function') {
|
|
3138
|
+
var _tmsConfig$hooks2;
|
|
3139
|
+
|
|
3140
|
+
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.afterCompile({
|
|
3141
|
+
isDev,
|
|
3142
|
+
tmsConfig: filterField$2(tmsConfig, ['gitAccount']),
|
|
3143
|
+
modules
|
|
3144
|
+
}));
|
|
3145
|
+
report$4('hooks:afterCompile');
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
spinner.succeed(chalk$3.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
3149
|
+
spinner.stop();
|
|
3150
|
+
cb();
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
const compileTasks = [];
|
|
3154
|
+
compileTasksMap.forEach(({
|
|
3155
|
+
taskFn
|
|
3156
|
+
}) => {
|
|
3157
|
+
compileTasks.push(taskFn);
|
|
3158
|
+
}); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
3159
|
+
|
|
3160
|
+
series(start, parallel(...compileTasks), end)();
|
|
3161
|
+
};
|
|
3162
|
+
|
|
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
|
+
};
|
|
3214
3247
|
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
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版本
|
|
3218
3268
|
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
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);
|
|
3225
3276
|
}
|
|
3277
|
+
});
|
|
3278
|
+
});
|
|
3279
|
+
} // 获取当前用户tmskit的版本
|
|
3226
3280
|
|
|
3227
|
-
return;
|
|
3228
|
-
}
|
|
3229
3281
|
|
|
3230
|
-
|
|
3282
|
+
function getUserTmskitVersion() {
|
|
3283
|
+
const data = shelljs$2.exec('tmskit -v', {
|
|
3284
|
+
async: false,
|
|
3285
|
+
silent: true
|
|
3286
|
+
});
|
|
3231
3287
|
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
}
|
|
3288
|
+
if (data.code === 0) {
|
|
3289
|
+
// tmskit 0.0.21 => 0.0.21
|
|
3290
|
+
return data.slice(7);
|
|
3291
|
+
}
|
|
3237
3292
|
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
});
|
|
3241
|
-
};
|
|
3293
|
+
return '0.0.0';
|
|
3294
|
+
} // 询问用户是否安装最新版本
|
|
3242
3295
|
|
|
3243
|
-
(function (module) {
|
|
3244
|
-
const path = require$$1__default$2;
|
|
3245
|
-
const fs = require$$0__default$2;
|
|
3246
|
-
const ora = require$$2__default;
|
|
3247
|
-
const chalk = require$$0__default;
|
|
3248
|
-
const {
|
|
3249
|
-
parallel,
|
|
3250
|
-
series
|
|
3251
|
-
} = require$$0__default$a;
|
|
3252
|
-
const {
|
|
3253
|
-
resolve,
|
|
3254
|
-
mergeMap,
|
|
3255
|
-
filterField
|
|
3256
|
-
} = widgets;
|
|
3257
|
-
const {
|
|
3258
|
-
buildOutputAppJson
|
|
3259
|
-
} = buildAppJson;
|
|
3260
|
-
const {
|
|
3261
|
-
DEFAULT_COPY_CONFIG
|
|
3262
|
-
} = require$$4;
|
|
3263
|
-
const compile$1 = compile;
|
|
3264
|
-
const watch = watch_1;
|
|
3265
|
-
const {
|
|
3266
|
-
info
|
|
3267
|
-
} = log$1;
|
|
3268
|
-
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
3269
|
-
|
|
3270
|
-
function excludeGlob(glob) {
|
|
3271
|
-
const otherArr = new Set();
|
|
3272
|
-
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
3273
|
-
Object.keys(glob).forEach(globKey => {
|
|
3274
|
-
if (typeof glob[globKey] === 'string') {
|
|
3275
|
-
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
3276
|
-
otherArr.add(data);
|
|
3277
|
-
}
|
|
3278
3296
|
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
}
|
|
3288
|
-
|
|
3289
|
-
|
|
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的版本是否推荐过
|
|
3290
3311
|
|
|
3291
|
-
function adaptPath(pathDir) {
|
|
3292
|
-
let newPath = pathDir;
|
|
3293
|
-
newPath = newPath.startsWith('/') ? newPath : resolve(newPath);
|
|
3294
|
-
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
3295
|
-
return newPath;
|
|
3296
|
-
}
|
|
3297
3312
|
|
|
3298
|
-
|
|
3299
|
-
|
|
3313
|
+
function getVersionIsRecommend(version) {
|
|
3314
|
+
const filePath = VERSION_CACHE_FILE;
|
|
3300
3315
|
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
// js: ['app.js', 'app.ts'].map(item => resolve(item)),
|
|
3316
|
+
if (!fs$2.existsSync(filePath)) {
|
|
3317
|
+
return false;
|
|
3318
|
+
}
|
|
3305
3319
|
|
|
3306
|
-
|
|
3307
|
-
module: {
|
|
3308
|
-
from: resolve(),
|
|
3309
|
-
to: resolve(tmsConfig.outputDir)
|
|
3310
|
-
},
|
|
3311
|
-
destPath: resolve(tmsConfig.outputDir),
|
|
3312
|
-
srcOption: {
|
|
3313
|
-
allowEmpty: true
|
|
3314
|
-
},
|
|
3315
|
-
isDev
|
|
3316
|
-
})); // 监听模块的文件
|
|
3320
|
+
const content = require(filePath);
|
|
3317
3321
|
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
module = { ...{
|
|
3321
|
-
exclude: []
|
|
3322
|
-
},
|
|
3323
|
-
...module
|
|
3324
|
-
};
|
|
3325
|
-
const modulePath = adaptPath(module.path);
|
|
3322
|
+
return content === null || content === void 0 ? void 0 : content[version];
|
|
3323
|
+
} // 设置tmskit版本推荐过
|
|
3326
3324
|
|
|
3327
|
-
if (isDev) {
|
|
3328
|
-
// 监听模块配置文件
|
|
3329
|
-
watch([`${modulePath}/**/module.config.json`], {
|
|
3330
|
-
events: watchEvents
|
|
3331
|
-
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
3332
|
-
from: modulePath,
|
|
3333
|
-
to: modulePath
|
|
3334
|
-
});
|
|
3335
|
-
}
|
|
3336
3325
|
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
3340
|
-
json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
|
|
3341
|
-
wxss: [`${modulePath}/**/*.{less,wxss}`, ...excludes],
|
|
3342
|
-
wxml: [`${modulePath}/**/*.wxml`, ...excludes],
|
|
3343
|
-
image: [`${modulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes]
|
|
3344
|
-
};
|
|
3345
|
-
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
3346
|
-
glob: { ...glob,
|
|
3347
|
-
other: [`${modulePath}/**/*`, ...excludeGlob(glob)]
|
|
3348
|
-
},
|
|
3349
|
-
destPath: resolve(tmsConfig.outputDir, module.root),
|
|
3350
|
-
module: {
|
|
3351
|
-
from: module.path,
|
|
3352
|
-
to: module.root
|
|
3353
|
-
},
|
|
3354
|
-
srcOption: {
|
|
3355
|
-
allowEmpty: true
|
|
3356
|
-
},
|
|
3357
|
-
isDev
|
|
3358
|
-
}));
|
|
3359
|
-
} // 静态资源目录-拷贝
|
|
3326
|
+
function setVersionRecommend(version, isRecommend) {
|
|
3327
|
+
const filePath = VERSION_CACHE_FILE;
|
|
3360
3328
|
|
|
3329
|
+
if (!fs$2.existsSync(filePath)) {
|
|
3330
|
+
const dir = path$1.dirname(filePath);
|
|
3331
|
+
ensureDirExist$1(dir);
|
|
3332
|
+
fs$2.writeFileSync(filePath, '{}');
|
|
3333
|
+
}
|
|
3361
3334
|
|
|
3362
|
-
|
|
3363
|
-
for (const item of tmsConfig.static) {
|
|
3364
|
-
item.from = adaptPath(item.from);
|
|
3365
|
-
item.to = adaptPath(item.to);
|
|
3366
|
-
let glob = {};
|
|
3367
|
-
const ext = path.extname(item.from).slice(1);
|
|
3335
|
+
const content = require(filePath);
|
|
3368
3336
|
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
glob = {
|
|
3373
|
-
js: [`${item.from}/**/*.{js,ts,wxs}`],
|
|
3374
|
-
json: [`${item.from}/**/*.json`],
|
|
3375
|
-
wxss: [`${item.from}/**/*.{less,wxss}`],
|
|
3376
|
-
wxml: [`${item.from}/**/*.wxml`],
|
|
3377
|
-
image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`]
|
|
3378
|
-
};
|
|
3379
|
-
glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
|
|
3380
|
-
}
|
|
3337
|
+
content[version] = isRecommend;
|
|
3338
|
+
fs$2.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
3339
|
+
} // 推荐理由
|
|
3381
3340
|
|
|
3382
|
-
const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
|
|
3383
|
-
mergeMap(compileTasksMap, compile$1(tmsConfig, {
|
|
3384
|
-
glob,
|
|
3385
|
-
destPath: item.to,
|
|
3386
|
-
module: {
|
|
3387
|
-
from,
|
|
3388
|
-
to: item.to
|
|
3389
|
-
},
|
|
3390
|
-
srcOption: {
|
|
3391
|
-
allowEmpty: true
|
|
3392
|
-
},
|
|
3393
|
-
isDev
|
|
3394
|
-
}));
|
|
3395
|
-
}
|
|
3396
|
-
}
|
|
3397
3341
|
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3342
|
+
function displayRecommends(arr) {
|
|
3343
|
+
infoNoTime$1(chalk$2.green('构建工具有新的版本~~:'));
|
|
3344
|
+
arr.forEach(item => {
|
|
3345
|
+
infoNoTime$1(chalk$2.green(item));
|
|
3346
|
+
});
|
|
3347
|
+
} // 推荐tmskit的安装版本
|
|
3401
3348
|
|
|
3402
|
-
function start(cb) {
|
|
3403
|
-
info('启动编译...');
|
|
3404
|
-
spinner.start();
|
|
3405
|
-
sTime = new Date().getTime();
|
|
3406
|
-
cb();
|
|
3407
|
-
}
|
|
3408
3349
|
|
|
3409
|
-
|
|
3410
|
-
|
|
3350
|
+
async function recommendVersion$1() {
|
|
3351
|
+
try {
|
|
3352
|
+
// 获取当前用户安装的版本
|
|
3353
|
+
const tmskitVersion = getUserTmskitVersion(); // 获取官方推荐版本
|
|
3411
3354
|
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
watch([resolve('app.json')], {
|
|
3415
|
-
ignoreInitial: false,
|
|
3416
|
-
events: watchEvents
|
|
3417
|
-
}, () => buildOutputAppJson(tmsConfig, newModules, isDev), {
|
|
3418
|
-
from: resolve(),
|
|
3419
|
-
to: resolve(tmsConfig.outputDir)
|
|
3420
|
-
}); // 监听其他文件
|
|
3421
|
-
|
|
3422
|
-
compileTasksMap.forEach(({
|
|
3423
|
-
taskFn,
|
|
3424
|
-
module
|
|
3425
|
-
}, globValue) => {
|
|
3426
|
-
watch(globValue, {
|
|
3427
|
-
ignoreInitial: true,
|
|
3428
|
-
events: watchEvents
|
|
3429
|
-
}, taskFn, module);
|
|
3430
|
-
});
|
|
3431
|
-
} else {
|
|
3432
|
-
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
3433
|
-
}
|
|
3355
|
+
const recommendRes = await getRecommendVersion();
|
|
3356
|
+
const recommendVersion = recommendRes.version; // 当前用户安装版本小于官方推荐版本 && 该版本没有推荐过
|
|
3434
3357
|
|
|
3435
|
-
|
|
3358
|
+
if (versionCompare(tmskitVersion, recommendVersion) === -1 && !getVersionIsRecommend(recommendVersion)) {
|
|
3359
|
+
displayRecommends(recommendRes.version_detail); // 设置该版本推荐过
|
|
3436
3360
|
|
|
3437
|
-
|
|
3438
|
-
var _tmsConfig$hooks2;
|
|
3361
|
+
setVersionRecommend(recommendVersion, true); // 询问用户是否安装最新版本
|
|
3439
3362
|
|
|
3440
|
-
|
|
3441
|
-
isDev,
|
|
3442
|
-
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3443
|
-
modules: newModules
|
|
3444
|
-
}));
|
|
3445
|
-
}
|
|
3363
|
+
const installRes = await isInstallLatestVersion(recommendRes);
|
|
3446
3364
|
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
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
|
+
}
|
|
3450
3380
|
}
|
|
3381
|
+
} catch {}
|
|
3382
|
+
}
|
|
3451
3383
|
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
}) => {
|
|
3456
|
-
compileTasks.push(taskFn);
|
|
3457
|
-
}); // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
3458
|
-
|
|
3459
|
-
series(start, parallel(...compileTasks), end)();
|
|
3460
|
-
};
|
|
3461
|
-
})(dev$3);
|
|
3384
|
+
var recommendVersion_1 = {
|
|
3385
|
+
recommendVersion: recommendVersion$1
|
|
3386
|
+
};
|
|
3462
3387
|
|
|
3463
|
-
const shelljs$1 = require$$
|
|
3464
|
-
const compileDev = dev$3
|
|
3388
|
+
const shelljs$1 = require$$2__default;
|
|
3389
|
+
const compileDev = dev$3;
|
|
3465
3390
|
const {
|
|
3466
|
-
resolve: resolve$
|
|
3391
|
+
resolve: resolve$3,
|
|
3467
3392
|
filterField: filterField$1
|
|
3468
3393
|
} = widgets;
|
|
3469
|
-
const init$
|
|
3394
|
+
const init$2 = init_1;
|
|
3470
3395
|
const {
|
|
3471
|
-
|
|
3472
|
-
|
|
3396
|
+
getModulesByMergeDepModules: getModulesByMergeDepModules$1,
|
|
3397
|
+
getSubPackages: getSubPackages$1
|
|
3398
|
+
} = tmsMpconfig.exports;
|
|
3473
3399
|
const {
|
|
3474
3400
|
info: info$2
|
|
3475
3401
|
} = log$1;
|
|
@@ -3477,15 +3403,23 @@ const {
|
|
|
3477
3403
|
global: global$1
|
|
3478
3404
|
} = global_1;
|
|
3479
3405
|
const {
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
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)
|
|
3413
|
+
|
|
3414
|
+
function delOtherPackages(tmsConfig, targetSubPackages) {
|
|
3415
|
+
// 获取所有模块,合并模块依赖的模块
|
|
3416
|
+
const allModules = getModulesByMergeDepModules$1(tmsConfig, tmsConfig.modules.all); // 获取所有的分包
|
|
3417
|
+
|
|
3418
|
+
const allSubPackages = getSubPackages$1(allModules);
|
|
3419
|
+
const targetSubPackagesName = targetSubPackages.map(item => item.name);
|
|
3420
|
+
allSubPackages.forEach(item => {
|
|
3421
|
+
if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
|
|
3422
|
+
const moduleRootDir = resolve$3(`${tmsConfig.outputDir}/${item.root}`);
|
|
3489
3423
|
shelljs$1.rm('-rf', `${moduleRootDir}/*`, {
|
|
3490
3424
|
silent: true
|
|
3491
3425
|
}); // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
@@ -3494,23 +3428,27 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
3494
3428
|
});
|
|
3495
3429
|
}
|
|
3496
3430
|
|
|
3497
|
-
async function dev$2(tmsConfig, targetModules
|
|
3431
|
+
async function dev$2(tmsConfig, targetModules) {
|
|
3498
3432
|
var _tmsConfig$hooks;
|
|
3499
3433
|
|
|
3500
|
-
let newModules = targetModules;
|
|
3501
3434
|
const {
|
|
3502
3435
|
noCache
|
|
3503
3436
|
} = global$1.getData('cmd');
|
|
3504
3437
|
|
|
3505
3438
|
if (noCache) {
|
|
3506
|
-
shelljs$1.rm('-rf', resolve$
|
|
3507
|
-
shelljs$1.rm('-rf',
|
|
3508
|
-
|
|
3439
|
+
shelljs$1.rm('-rf', resolve$3(tmsConfig.outputDir));
|
|
3440
|
+
shelljs$1.rm('-rf', MODULE_CODE_DIR);
|
|
3441
|
+
shelljs$1.rm('-rf', NODE_MODULES_DIR);
|
|
3442
|
+
} // 推荐tmskit的版本
|
|
3443
|
+
|
|
3509
3444
|
|
|
3445
|
+
await recommendVersion(); // 初始化操作
|
|
3510
3446
|
|
|
3511
|
-
const
|
|
3512
|
-
|
|
3513
|
-
|
|
3447
|
+
const {
|
|
3448
|
+
subPackages,
|
|
3449
|
+
modules: newModules
|
|
3450
|
+
} = await init$2(tmsConfig, targetModules);
|
|
3451
|
+
info$2('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
|
|
3514
3452
|
|
|
3515
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') {
|
|
3516
3454
|
var _tmsConfig$hooks2;
|
|
@@ -3520,62 +3458,64 @@ async function dev$2(tmsConfig, targetModules, env) {
|
|
|
3520
3458
|
tmsConfig: filterField$1(tmsConfig, ['gitAccount']),
|
|
3521
3459
|
modules: newModules
|
|
3522
3460
|
}));
|
|
3461
|
+
report$3('hooks:beforeCompile');
|
|
3523
3462
|
}
|
|
3524
|
-
|
|
3525
|
-
compileDev(tmsConfig, newModules,
|
|
3463
|
+
delOtherPackages(tmsConfig, subPackages);
|
|
3464
|
+
compileDev(tmsConfig, newModules, true);
|
|
3526
3465
|
}
|
|
3527
3466
|
|
|
3528
3467
|
var dev_1 = dev$2;
|
|
3529
3468
|
|
|
3530
|
-
const dev$1 = dev$3
|
|
3469
|
+
const dev$1 = dev$3;
|
|
3531
3470
|
|
|
3532
|
-
var build$2 = async (tmsConfig, newModules) => {
|
|
3533
|
-
dev$1(tmsConfig, newModules,
|
|
3471
|
+
var build$2 = async (tmsConfig, newModules, isDev) => {
|
|
3472
|
+
dev$1(tmsConfig, newModules, isDev);
|
|
3534
3473
|
};
|
|
3535
3474
|
|
|
3536
|
-
const shelljs = require$$
|
|
3475
|
+
const shelljs = require$$2__default;
|
|
3537
3476
|
const {
|
|
3538
|
-
resolve: resolve$
|
|
3477
|
+
resolve: resolve$2,
|
|
3539
3478
|
filterField
|
|
3540
3479
|
} = widgets;
|
|
3541
|
-
const init$
|
|
3480
|
+
const init$1 = init_1;
|
|
3542
3481
|
const compileBuild = build$2;
|
|
3482
|
+
const report$2 = report_1;
|
|
3543
3483
|
|
|
3544
|
-
async function build$1(tmsConfig, targetModules
|
|
3484
|
+
async function build$1(tmsConfig, targetModules) {
|
|
3545
3485
|
var _tmsConfig$hooks;
|
|
3546
3486
|
|
|
3547
3487
|
// 开始构建前,清理输出目录
|
|
3548
|
-
await shelljs.rm('-rf', resolve$
|
|
3488
|
+
await shelljs.rm('-rf', resolve$2(tmsConfig.outputDir));
|
|
3549
3489
|
const {
|
|
3550
|
-
|
|
3551
|
-
} = await init$
|
|
3490
|
+
modules: newModules
|
|
3491
|
+
} = await init$1(tmsConfig, targetModules);
|
|
3492
|
+
const isDev = false;
|
|
3552
3493
|
|
|
3553
3494
|
if (typeof (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks = tmsConfig.hooks) === null || _tmsConfig$hooks === void 0 ? void 0 : _tmsConfig$hooks.beforeCompile) === 'function') {
|
|
3554
3495
|
var _tmsConfig$hooks2;
|
|
3555
3496
|
|
|
3556
3497
|
await (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$hooks2 = tmsConfig.hooks) === null || _tmsConfig$hooks2 === void 0 ? void 0 : _tmsConfig$hooks2.beforeCompile({
|
|
3557
|
-
isDev
|
|
3498
|
+
isDev,
|
|
3558
3499
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
3559
3500
|
modules: newModules
|
|
3560
3501
|
}));
|
|
3502
|
+
report$2('hooks:beforeCompile');
|
|
3561
3503
|
}
|
|
3562
|
-
compileBuild(tmsConfig, newModules,
|
|
3504
|
+
compileBuild(tmsConfig, newModules, isDev);
|
|
3563
3505
|
}
|
|
3564
3506
|
|
|
3565
3507
|
var build_1 = build$1;
|
|
3566
3508
|
|
|
3567
|
-
const fs = require$$0__default$
|
|
3509
|
+
const fs$1 = require$$0__default$1;
|
|
3568
3510
|
const {
|
|
3569
|
-
resolve
|
|
3511
|
+
resolve: resolve$1
|
|
3570
3512
|
} = widgets;
|
|
3571
|
-
const {
|
|
3572
|
-
handleError: handleError$1
|
|
3573
|
-
} = handleError_1;
|
|
3574
3513
|
const {
|
|
3575
3514
|
ensureDirExist
|
|
3576
3515
|
} = io$3;
|
|
3577
3516
|
const {
|
|
3578
|
-
warn
|
|
3517
|
+
warn,
|
|
3518
|
+
succeed
|
|
3579
3519
|
} = log$1;
|
|
3580
3520
|
/**
|
|
3581
3521
|
* 根据相关配置创建软链接
|
|
@@ -3583,26 +3523,25 @@ const {
|
|
|
3583
3523
|
*/
|
|
3584
3524
|
|
|
3585
3525
|
const symLink$1 = tmsConfig => {
|
|
3586
|
-
|
|
3587
|
-
ensureDirExist(resolve(tmsConfig.cloudDir));
|
|
3526
|
+
ensureDirExist(resolve$1(tmsConfig.cloudDir));
|
|
3588
3527
|
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3528
|
+
if (tmsConfig.cloudModules) {
|
|
3529
|
+
tmsConfig.cloudModules.forEach(item => {
|
|
3530
|
+
const sourcePath = resolve$1(item.path);
|
|
3531
|
+
const targetPath = resolve$1(tmsConfig.cloudDir, item.name);
|
|
3593
3532
|
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3533
|
+
if (!fs$1.existsSync(sourcePath)) {
|
|
3534
|
+
warn(`云函数${sourcePath}不存在`);
|
|
3535
|
+
return;
|
|
3536
|
+
}
|
|
3598
3537
|
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
}
|
|
3605
|
-
|
|
3538
|
+
if (!fs$1.existsSync(targetPath)) {
|
|
3539
|
+
fs$1.symlinkSync(sourcePath, targetPath);
|
|
3540
|
+
}
|
|
3541
|
+
});
|
|
3542
|
+
succeed('云函数创建软链成功');
|
|
3543
|
+
} else {
|
|
3544
|
+
warn('你没有在tms.config.js的cloudModules注册云函数');
|
|
3606
3545
|
}
|
|
3607
3546
|
};
|
|
3608
3547
|
|
|
@@ -3616,36 +3555,35 @@ const {
|
|
|
3616
3555
|
const {
|
|
3617
3556
|
handleError
|
|
3618
3557
|
} = handleError_1;
|
|
3619
|
-
const {
|
|
3620
|
-
succeed
|
|
3621
|
-
} = log$1;
|
|
3622
3558
|
|
|
3623
3559
|
var cloud$1 = async tmsConfig => {
|
|
3624
3560
|
try {
|
|
3625
3561
|
await symLink(tmsConfig);
|
|
3626
|
-
succeed('云函数创建软链成功');
|
|
3627
3562
|
} catch (e) {
|
|
3628
3563
|
handleError(`创建软链错误: ${e}`);
|
|
3629
3564
|
}
|
|
3630
3565
|
};
|
|
3631
3566
|
|
|
3632
3567
|
/* eslint-disable no-param-reassign */
|
|
3633
|
-
const
|
|
3634
|
-
const init$2 = init_1;
|
|
3568
|
+
const init = init_1;
|
|
3635
3569
|
const dev = dev_1;
|
|
3636
3570
|
const build = build_1;
|
|
3637
3571
|
const install = install_1;
|
|
3638
3572
|
const cloud = cloud$1;
|
|
3573
|
+
const {
|
|
3574
|
+
fail,
|
|
3575
|
+
info: info$1
|
|
3576
|
+
} = log$1;
|
|
3639
3577
|
const {
|
|
3640
3578
|
global
|
|
3641
3579
|
} = global_1;
|
|
3580
|
+
const report$1 = report_1;
|
|
3642
3581
|
const {
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
} = tmsMpconfig;
|
|
3582
|
+
getTmsConfig: getTmsConfig$1,
|
|
3583
|
+
getModulesByMergeDepModules,
|
|
3584
|
+
getSubPackages,
|
|
3585
|
+
getModulesByModuleNames
|
|
3586
|
+
} = tmsMpconfig.exports;
|
|
3649
3587
|
|
|
3650
3588
|
const handleModuleArg = cmd => {
|
|
3651
3589
|
// 单模块或多模块开发-用户通过脚手架参数指定的模块
|
|
@@ -3663,7 +3601,7 @@ const handleModuleArg = cmd => {
|
|
|
3663
3601
|
*/
|
|
3664
3602
|
|
|
3665
3603
|
|
|
3666
|
-
const
|
|
3604
|
+
const getSpecificModuleNames = (moduleArg, modules) => {
|
|
3667
3605
|
if (moduleArg.length > 0) {
|
|
3668
3606
|
return moduleArg;
|
|
3669
3607
|
}
|
|
@@ -3680,76 +3618,88 @@ const getSpecificModules = (moduleArg, modules) => {
|
|
|
3680
3618
|
}
|
|
3681
3619
|
|
|
3682
3620
|
if ((exclude === null || exclude === void 0 ? void 0 : exclude.length) > 0) {
|
|
3683
|
-
return all.filter(module => !exclude.includes(module.
|
|
3621
|
+
return all.filter(module => !exclude.includes(module.moduleName)).map(item => item.moduleName);
|
|
3684
3622
|
}
|
|
3685
3623
|
|
|
3686
3624
|
if (blockRemote === true) {
|
|
3687
|
-
return all.filter(module => module.repoInfo === undefined).map(item => item.
|
|
3625
|
+
return all.filter(module => module.repoInfo === undefined).map(item => item.moduleName);
|
|
3688
3626
|
}
|
|
3689
3627
|
|
|
3690
|
-
return all.map(item => item.
|
|
3628
|
+
return all.map(item => item.moduleName);
|
|
3691
3629
|
};
|
|
3692
3630
|
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
if (Array.isArray(tmsConfig.modules)) {
|
|
3697
|
-
modules.all = tmsConfig.modules;
|
|
3698
|
-
tmsConfig.modules = modules;
|
|
3699
|
-
} // 合并默认值
|
|
3631
|
+
async function run(commandName, cmd) {
|
|
3632
|
+
// 用户本地的配置
|
|
3633
|
+
const tmsConfig = getTmsConfig$1();
|
|
3700
3634
|
|
|
3635
|
+
try {
|
|
3636
|
+
// 缓存数据
|
|
3637
|
+
global.setData({
|
|
3638
|
+
cmd,
|
|
3639
|
+
tmsConfig
|
|
3640
|
+
});
|
|
3701
3641
|
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3642
|
+
if (commandName === 'cloud') {
|
|
3643
|
+
cloud(tmsConfig);
|
|
3644
|
+
report$1('run:cloud', {
|
|
3645
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3646
|
+
});
|
|
3647
|
+
return;
|
|
3705
3648
|
}
|
|
3706
|
-
});
|
|
3707
|
-
return res;
|
|
3708
|
-
};
|
|
3709
3649
|
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3650
|
+
otherCommands(tmsConfig, commandName, cmd);
|
|
3651
|
+
} catch (error) {
|
|
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
|
+
});
|
|
3657
|
+
fail(`构建出现错误: ${errMsg}`);
|
|
3658
|
+
info$1('详细错误信息', error);
|
|
3659
|
+
process.exit(1);
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3718
3662
|
|
|
3719
|
-
|
|
3720
|
-
|
|
3663
|
+
function otherCommands(tmsConfig, commandName, cmd) {
|
|
3664
|
+
// 处理module参数
|
|
3665
|
+
const specificModuleNames = getSpecificModuleNames(handleModuleArg(cmd), tmsConfig.modules); // moduleNames => ['home', 'car']
|
|
3721
3666
|
|
|
3722
|
-
|
|
3667
|
+
const moduleNames = [...new Set([...specificModuleNames])];
|
|
3668
|
+
const modules = getModulesByModuleNames(tmsConfig, moduleNames, false); // 获取所有模块,合并模块依赖的模块
|
|
3723
3669
|
|
|
3724
|
-
newModules =
|
|
3670
|
+
const newModules = getModulesByMergeDepModules(tmsConfig, modules, false); // 获取所有的分包
|
|
3725
3671
|
|
|
3726
|
-
|
|
3727
|
-
env,
|
|
3728
|
-
cmd,
|
|
3729
|
-
tmsConfig
|
|
3730
|
-
});
|
|
3672
|
+
const subPackages = getSubPackages(newModules);
|
|
3731
3673
|
|
|
3732
3674
|
switch (commandName) {
|
|
3733
3675
|
case 'init':
|
|
3734
|
-
init
|
|
3676
|
+
init(tmsConfig, newModules);
|
|
3677
|
+
report$1('run:init', {
|
|
3678
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3679
|
+
});
|
|
3735
3680
|
return;
|
|
3736
3681
|
|
|
3737
3682
|
case 'dev':
|
|
3738
3683
|
global.setData('isDev', true);
|
|
3739
|
-
dev(tmsConfig, newModules
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
cloud(tmsConfig, env);
|
|
3684
|
+
dev(tmsConfig, newModules);
|
|
3685
|
+
report$1('run:dev', {
|
|
3686
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3687
|
+
});
|
|
3744
3688
|
return;
|
|
3745
3689
|
|
|
3746
3690
|
case 'install':
|
|
3747
|
-
install(tmsConfig,
|
|
3691
|
+
install(tmsConfig, subPackages, false);
|
|
3692
|
+
report$1('run:install', {
|
|
3693
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3694
|
+
});
|
|
3748
3695
|
return;
|
|
3749
3696
|
|
|
3750
3697
|
case 'build':
|
|
3751
3698
|
global.setData('isDev', false);
|
|
3752
|
-
build(tmsConfig, newModules
|
|
3699
|
+
build(tmsConfig, newModules);
|
|
3700
|
+
report$1('run:build', {
|
|
3701
|
+
appName: tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.appName
|
|
3702
|
+
});
|
|
3753
3703
|
return;
|
|
3754
3704
|
|
|
3755
3705
|
default:
|
|
@@ -3760,14 +3710,22 @@ async function run(commandName, cmd) {
|
|
|
3760
3710
|
var run_1 = run;
|
|
3761
3711
|
|
|
3762
3712
|
var entry = [{
|
|
3763
|
-
command: 'create <
|
|
3764
|
-
description: '
|
|
3765
|
-
action:
|
|
3766
|
-
create_1(
|
|
3713
|
+
command: 'create <project-name>',
|
|
3714
|
+
description: '创建项目',
|
|
3715
|
+
action: projectName => {
|
|
3716
|
+
create_1(projectName);
|
|
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);
|
|
3767
3725
|
}
|
|
3768
3726
|
}, {
|
|
3769
3727
|
name: 'run',
|
|
3770
|
-
type: '
|
|
3728
|
+
type: 'parent',
|
|
3771
3729
|
description: '项目开发使用的命令',
|
|
3772
3730
|
commands: [{
|
|
3773
3731
|
command: 'install',
|
|
@@ -3797,112 +3755,14 @@ var entry = [{
|
|
|
3797
3755
|
action: cmd => {
|
|
3798
3756
|
run_1('build', cmd);
|
|
3799
3757
|
}
|
|
3800
|
-
}
|
|
3801
|
-
// {
|
|
3802
|
-
// command: 'init',
|
|
3803
|
-
// description: '模块配置初始化项目(eg: 下载第三方模块代码、安装依赖、生成app.json等)',
|
|
3804
|
-
// options: [
|
|
3805
|
-
// ['-m, --module [moduleName]', '模块名称'],
|
|
3806
|
-
// ['-e, --env [env]', '环境变量'],
|
|
3807
|
-
// ],
|
|
3808
|
-
// action: (cmd) => {
|
|
3809
|
-
// require('./scripts/run/index')('init', cmd);
|
|
3810
|
-
// },
|
|
3811
|
-
// },
|
|
3812
|
-
]
|
|
3758
|
+
}]
|
|
3813
3759
|
}];
|
|
3814
3760
|
|
|
3815
|
-
var require$$7 = {
|
|
3816
|
-
name: "@tmsfe/tmskit",
|
|
3817
|
-
version: "0.0.19",
|
|
3818
|
-
description: "tmskit",
|
|
3819
|
-
main: "dist/index.cjs",
|
|
3820
|
-
bin: {
|
|
3821
|
-
tmskit: "main.js"
|
|
3822
|
-
},
|
|
3823
|
-
files: [
|
|
3824
|
-
"build",
|
|
3825
|
-
"src",
|
|
3826
|
-
"dist",
|
|
3827
|
-
"main.js",
|
|
3828
|
-
"package.json"
|
|
3829
|
-
],
|
|
3830
|
-
scripts: {
|
|
3831
|
-
dev: "rollup -wc --environment TARGET:tmskit",
|
|
3832
|
-
build: "rollup -c --environment TARGET:tmskit",
|
|
3833
|
-
"pub:patch": "sh build/publish.sh patch",
|
|
3834
|
-
"pub:minor": "sh build/publish.sh minor",
|
|
3835
|
-
"pub:major": "sh build/publish.sh major"
|
|
3836
|
-
},
|
|
3837
|
-
author: "tms·web",
|
|
3838
|
-
license: "ISC",
|
|
3839
|
-
buildOptions: {
|
|
3840
|
-
formats: [
|
|
3841
|
-
"cjs"
|
|
3842
|
-
]
|
|
3843
|
-
},
|
|
3844
|
-
devDependencies: {
|
|
3845
|
-
"@rollup/plugin-babel": "^5.0.2",
|
|
3846
|
-
"@rollup/plugin-commonjs": "^19.0.0",
|
|
3847
|
-
"@rollup/plugin-dynamic-import-vars": "^1.1.1",
|
|
3848
|
-
"@rollup/plugin-json": "^4.0.3",
|
|
3849
|
-
rollup: "^2.6.1",
|
|
3850
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
3851
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
3852
|
-
"rollup-plugin-terser": "^6.1.0",
|
|
3853
|
-
"rollup-plugin-typescript2": "0.27.0"
|
|
3854
|
-
},
|
|
3855
|
-
dependencies: {
|
|
3856
|
-
"ansi-colors": "1.1.0",
|
|
3857
|
-
anymatch: "^1.3.0",
|
|
3858
|
-
"fancy-log": "1.3.2",
|
|
3859
|
-
"glob-parent": "^3.0.1",
|
|
3860
|
-
"path-is-absolute": "^1.0.1",
|
|
3861
|
-
"readable-stream": "^2.2.2",
|
|
3862
|
-
slash: "^1.0.0",
|
|
3863
|
-
vinyl: "^2.1.0",
|
|
3864
|
-
"vinyl-file": "^2.0.0",
|
|
3865
|
-
async: "^3.2.2",
|
|
3866
|
-
chalk: "^4.1.0",
|
|
3867
|
-
chokidar: "^3.5.3",
|
|
3868
|
-
commander: "^8.3.0",
|
|
3869
|
-
"copy-webpack-plugin": "^9.1.0",
|
|
3870
|
-
ejs: "^3.1.5",
|
|
3871
|
-
"fs-extra": "^10.0.1",
|
|
3872
|
-
"glob-ignore": "^1.0.2",
|
|
3873
|
-
gulp: "^4.0.2",
|
|
3874
|
-
"gulp-watch": "^5.0.1",
|
|
3875
|
-
htmlparser2: "^7.2.0",
|
|
3876
|
-
inquirer: "^7.3.3",
|
|
3877
|
-
leven: "3.1.0",
|
|
3878
|
-
lodash: "^4.17.21",
|
|
3879
|
-
metalsmith: "^2.3.0",
|
|
3880
|
-
"miniprogram-ci": "1.4.13",
|
|
3881
|
-
moment: "^2.29.2",
|
|
3882
|
-
"object-assign": "^4.0.1",
|
|
3883
|
-
ora: "^5.1.0",
|
|
3884
|
-
"plugin-error": "^1.0.0",
|
|
3885
|
-
postcss: "^8.4.6",
|
|
3886
|
-
precinct: "^8.3.1",
|
|
3887
|
-
"replace-ext": "^2.0.0",
|
|
3888
|
-
shelljs: "^0.8.4",
|
|
3889
|
-
"strip-comments": "^2.0.1",
|
|
3890
|
-
through2: "^4.0.2",
|
|
3891
|
-
"vinyl-sourcemaps-apply": "^0.2.0"
|
|
3892
|
-
},
|
|
3893
|
-
engines: {
|
|
3894
|
-
node: "^12.17.0 || >= 14.13.1"
|
|
3895
|
-
},
|
|
3896
|
-
jest: {
|
|
3897
|
-
testEnvironment: "jest-environment-node"
|
|
3898
|
-
}
|
|
3899
|
-
};
|
|
3900
|
-
|
|
3901
3761
|
const semver = require$$1__default$7;
|
|
3902
|
-
const packageJson = require$$
|
|
3903
|
-
const chalk$1 = require$$
|
|
3762
|
+
const packageJson = require$$12;
|
|
3763
|
+
const chalk$1 = require$$3__default;
|
|
3904
3764
|
const {
|
|
3905
|
-
info
|
|
3765
|
+
info
|
|
3906
3766
|
} = log$1;
|
|
3907
3767
|
const requiredVersion = packageJson.engines.node;
|
|
3908
3768
|
const packName = packageJson.name;
|
|
@@ -3917,44 +3777,53 @@ const checkNodeVersion = (wanted, id) => {
|
|
|
3917
3777
|
if (!semver.satisfies(process.version, wanted, {
|
|
3918
3778
|
includePrerelease: true
|
|
3919
3779
|
})) {
|
|
3920
|
-
info
|
|
3780
|
+
info(chalk$1.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id} 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
|
|
3921
3781
|
process.exit(1);
|
|
3922
3782
|
}
|
|
3923
3783
|
};
|
|
3924
3784
|
/**
|
|
3925
3785
|
* 检查运行环境
|
|
3926
|
-
* @returns {Undefined} 无需返回值
|
|
3927
3786
|
*/
|
|
3928
3787
|
|
|
3929
3788
|
|
|
3930
|
-
function
|
|
3789
|
+
function check$1() {
|
|
3931
3790
|
// 执行操作前检查node版本
|
|
3932
3791
|
// 旧版本node直接提示升级,退出脚本
|
|
3933
3792
|
checkNodeVersion(requiredVersion, packName);
|
|
3934
3793
|
}
|
|
3935
3794
|
|
|
3936
|
-
var
|
|
3795
|
+
var check_1 = check$1;
|
|
3937
3796
|
|
|
3938
|
-
|
|
3939
|
-
const
|
|
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;
|
|
3940
3802
|
const {
|
|
3941
|
-
|
|
3803
|
+
resolve
|
|
3942
3804
|
} = widgets;
|
|
3943
3805
|
const {
|
|
3944
|
-
|
|
3806
|
+
infoNoTime
|
|
3945
3807
|
} = log$1;
|
|
3808
|
+
const {
|
|
3809
|
+
getTmsConfig
|
|
3810
|
+
} = tmsMpconfig.exports;
|
|
3946
3811
|
const {
|
|
3947
3812
|
TMS_NAME
|
|
3948
|
-
} =
|
|
3813
|
+
} = constant;
|
|
3949
3814
|
const commands = entry;
|
|
3950
|
-
const
|
|
3951
|
-
|
|
3815
|
+
const check = check_1;
|
|
3816
|
+
const {
|
|
3817
|
+
loadExtendCmd
|
|
3818
|
+
} = extendCmd;
|
|
3819
|
+
const report = report_1;
|
|
3820
|
+
check();
|
|
3952
3821
|
const program = new commander.Command(TMS_NAME);
|
|
3953
|
-
program.version(`${TMS_NAME} ${require$$
|
|
3822
|
+
program.version(`${TMS_NAME} ${require$$12.version}`, '-v, -V, --version'); // 注册命令底层实现
|
|
3954
3823
|
|
|
3955
3824
|
function registerCommand(program, commands) {
|
|
3956
3825
|
commands.forEach(cmd => {
|
|
3957
|
-
if (cmd.type === '
|
|
3826
|
+
if (cmd.type === 'parent') {
|
|
3958
3827
|
const childProgram = new commander.Command(cmd.name);
|
|
3959
3828
|
cmd.usage && childProgram.usage(cmd.usage);
|
|
3960
3829
|
cmd.description && childProgram.description(cmd.description);
|
|
@@ -3966,22 +3835,65 @@ function registerCommand(program, commands) {
|
|
|
3966
3835
|
const command = program.command(cmd.command);
|
|
3967
3836
|
cmd.usage && command.usage(cmd.usage);
|
|
3968
3837
|
cmd.description && command.description(cmd.description);
|
|
3969
|
-
(_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
|
+
});
|
|
3970
3847
|
command.action(cmd.action);
|
|
3971
3848
|
}
|
|
3972
3849
|
});
|
|
3850
|
+
} // 注册扩展命令
|
|
3851
|
+
|
|
3852
|
+
|
|
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;
|
|
3858
|
+
|
|
3859
|
+
if (Array.isArray(commands)) {
|
|
3860
|
+
registerCommand(program, commands);
|
|
3861
|
+
}
|
|
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
|
+
}
|
|
3973
3880
|
}
|
|
3974
3881
|
|
|
3975
|
-
|
|
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
|
+
});
|
|
3976
3895
|
program.on('--help', () => {
|
|
3977
|
-
|
|
3978
|
-
}); // 捕获未注册的命令
|
|
3979
|
-
|
|
3980
|
-
program.arguments('<command>').action(cmd => {
|
|
3981
|
-
program.outputHelp();
|
|
3982
|
-
info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
|
|
3983
|
-
suggestCommands(cmd);
|
|
3984
|
-
process.exitCode = 1;
|
|
3896
|
+
infoNoTime(`Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
3985
3897
|
});
|
|
3986
3898
|
|
|
3987
3899
|
if (!process.argv.slice(2).length) {
|