@tmsfe/tmskit 0.0.21 → 0.0.24
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 +7 -1
- package/dist/index.cjs.js +1036 -1309
- package/package.json +4 -7
- package/src/compile/compile.js +53 -155
- package/src/compile/dev.js +10 -48
- package/src/compile/plugins/mpProjectJson.js +13 -0
- package/src/compile/plugins/replaceEnv.js +7 -14
- package/src/compile/watch.js +49 -17
- package/src/config/constant.js +29 -8
- package/src/core/buildAppJson.js +3 -0
- package/src/core/checkDependencies.js +4 -1
- package/src/core/cloneModules.js +3 -0
- package/src/core/npm.js +3 -19
- package/src/core/recommendVersion.js +118 -0
- package/src/core/report.js +30 -0
- package/src/core/tmsMpconfig.js +12 -10
- package/src/entry.js +12 -13
- package/src/index.js +54 -27
- package/src/scripts/create/index.js +3 -1
- package/src/scripts/extend-cmd/index.js +74 -0
- package/src/scripts/run/build/index.js +4 -2
- package/src/scripts/run/dev/index.js +10 -4
- package/src/scripts/run/index.js +9 -3
- package/src/scripts/run/install/cache.js +36 -0
- package/src/scripts/run/install/index.js +3 -3
- package/src/utils/log.js +3 -0
- package/src/utils/widgets.js +49 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "tmskit",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"bin": {
|
|
@@ -30,13 +30,8 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rollup/plugin-babel": "^5.0.2",
|
|
32
32
|
"@rollup/plugin-commonjs": "^19.0.0",
|
|
33
|
-
"@rollup/plugin-dynamic-import-vars": "^1.1.1",
|
|
34
33
|
"@rollup/plugin-json": "^4.0.3",
|
|
35
|
-
"rollup": "^2.6.1"
|
|
36
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
37
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
38
|
-
"rollup-plugin-terser": "^6.1.0",
|
|
39
|
-
"rollup-plugin-typescript2": "0.27.0"
|
|
34
|
+
"rollup": "^2.6.1"
|
|
40
35
|
},
|
|
41
36
|
"dependencies": {
|
|
42
37
|
"ansi-colors": "1.1.0",
|
|
@@ -52,12 +47,14 @@
|
|
|
52
47
|
"glob-ignore": "^1.0.2",
|
|
53
48
|
"glob-parent": "^3.0.1",
|
|
54
49
|
"gulp": "^4.0.2",
|
|
50
|
+
"gulp-if": "^3.0.0",
|
|
55
51
|
"gulp-watch": "^5.0.1",
|
|
56
52
|
"htmlparser2": "^7.2.0",
|
|
57
53
|
"inquirer": "^7.3.3",
|
|
58
54
|
"leven": "3.1.0",
|
|
59
55
|
"lodash": "^4.17.21",
|
|
60
56
|
"metalsmith": "^2.3.0",
|
|
57
|
+
"minimatch": "^5.1.0",
|
|
61
58
|
"miniprogram-ci": "1.4.13",
|
|
62
59
|
"moment": "^2.29.2",
|
|
63
60
|
"object-assign": "^4.0.1",
|
package/src/compile/compile.js
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
const { src, dest } = require('gulp');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
const
|
|
8
|
-
const { mpWxmlDep } = require('./plugins/mpWxmlDep');
|
|
9
|
-
// const postcss = require('gulp-postcss');
|
|
10
|
-
// const base64 = require('./plugins/postcss-font-base64');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const minimatch = require('minimatch');
|
|
4
|
+
const gulpif = require('gulp-if');
|
|
5
|
+
const mpProjectJson = require('./plugins/mpProjectJson');
|
|
6
|
+
const { resolve } = require('../utils/widgets');
|
|
7
|
+
const through = require('through2');
|
|
11
8
|
const { fail } = require('../utils/log');
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
11
|
+
const sourceFileRelativeModule = path.relative(resolve(module.from), sourceFile);
|
|
12
|
+
const targetFile = resolve(outputDir, module.to, sourceFileRelativeModule);
|
|
13
|
+
return targetFile;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const addPlugins = function (tmsConfig, srcPipe, pluginParams) {
|
|
17
|
+
const { plugins = [] } = tmsConfig;
|
|
18
|
+
const newPlugins = [{
|
|
19
|
+
glob: '**/project.config.json',
|
|
20
|
+
action: mpProjectJson(),
|
|
21
|
+
}, ...plugins];
|
|
22
|
+
return newPlugins.reduce((srcPipe, pluginItem) => srcPipe.pipe(gulpif(
|
|
23
|
+
vinyl => minimatch(vinyl.path, pluginItem.glob),
|
|
24
|
+
through.obj(function (vinyl, enc, next) {
|
|
25
|
+
const sourceFile = vinyl.history[0];
|
|
26
|
+
pluginItem.action({
|
|
27
|
+
tmsConfig,
|
|
28
|
+
sourceFile,
|
|
29
|
+
vinyl,
|
|
30
|
+
targetFile: getTargetFile(sourceFile, pluginParams.module, tmsConfig.outputDir),
|
|
31
|
+
isDev: pluginParams.isDev,
|
|
32
|
+
next,
|
|
33
|
+
});
|
|
34
|
+
this.push(vinyl);
|
|
35
|
+
}),
|
|
36
|
+
)), srcPipe);
|
|
37
|
+
};
|
|
38
|
+
|
|
14
39
|
module.exports = function (
|
|
15
40
|
tmsConfig,
|
|
16
41
|
{
|
|
@@ -22,150 +47,23 @@ module.exports = function (
|
|
|
22
47
|
},
|
|
23
48
|
) {
|
|
24
49
|
const compileTasksMap = new Map();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
44
|
-
.pipe(dest(newDestPath, { overwrite: true }))
|
|
45
|
-
.on('error', (err) => {
|
|
46
|
-
fail(`js编译报错${err}`);
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
);
|
|
51
|
-
break;
|
|
52
|
-
case 'wxss':
|
|
53
|
-
compileTasksMap.set(
|
|
54
|
-
globValue,
|
|
55
|
-
{
|
|
56
|
-
module,
|
|
57
|
-
taskFn: (sourceFile, targetPath) => {
|
|
58
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
59
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
60
|
-
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
61
|
-
return srcPipe
|
|
62
|
-
.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev))
|
|
63
|
-
.on('error', (err) => {
|
|
64
|
-
fail(`mpCommonDep编译报错${err}`);
|
|
65
|
-
})
|
|
66
|
-
// .pipe(postcss([base64()]))
|
|
67
|
-
// .on('error', (err) => {
|
|
68
|
-
// fail(`postcss编译报错${err}`);
|
|
69
|
-
// })
|
|
70
|
-
// .pipe(px2rpx({
|
|
71
|
-
// designWidth: 375, // 设计稿宽度,默认为750
|
|
72
|
-
// precision: 2, // 小数最大精度,默认为6
|
|
73
|
-
// }))
|
|
74
|
-
.pipe(dest(newDestPath))
|
|
75
|
-
.on('error', (err) => {
|
|
76
|
-
fail(`wxss编译报错${err}`);
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
);
|
|
81
|
-
break;
|
|
82
|
-
case 'json':
|
|
83
|
-
compileTasksMap.set(
|
|
84
|
-
globValue,
|
|
85
|
-
{
|
|
86
|
-
module,
|
|
87
|
-
taskFn: (sourceFile, targetPath) => {
|
|
88
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
89
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
90
|
-
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
91
|
-
return srcPipe
|
|
92
|
-
.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev))
|
|
93
|
-
.on('error', (err) => {
|
|
94
|
-
fail(`mpJsonDep编译报错${err}`);
|
|
95
|
-
})
|
|
96
|
-
.pipe(dest(newDestPath))
|
|
97
|
-
.on('error', (err) => {
|
|
98
|
-
fail(`json编译报错${err}`);
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
);
|
|
103
|
-
break;
|
|
104
|
-
case 'wxml':
|
|
105
|
-
compileTasksMap.set(
|
|
106
|
-
globValue,
|
|
107
|
-
{
|
|
108
|
-
module,
|
|
109
|
-
taskFn: (sourceFile, targetPath) => {
|
|
110
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
111
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
112
|
-
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
113
|
-
return srcPipe
|
|
114
|
-
.pipe(mpWxmlDep(tmsConfig, module, isDev))
|
|
115
|
-
.on('error', (err) => {
|
|
116
|
-
fail(`mpWxmlDep编译报错${err}`);
|
|
117
|
-
})
|
|
118
|
-
.pipe(dest(newDestPath))
|
|
119
|
-
.on('error', (err) => {
|
|
120
|
-
fail(`wxml编译报错${err}`);
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
);
|
|
125
|
-
break;
|
|
126
|
-
case 'image':
|
|
127
|
-
compileTasksMap.set(
|
|
128
|
-
globValue,
|
|
129
|
-
{
|
|
130
|
-
module,
|
|
131
|
-
taskFn: (sourceFile, targetPath) => {
|
|
132
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
133
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
134
|
-
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
135
|
-
return srcPipe
|
|
136
|
-
// .pipe(cache(image()))
|
|
137
|
-
// .on('error', (err) => {
|
|
138
|
-
// fail(`image编译报错${err}`);
|
|
139
|
-
// })
|
|
140
|
-
.pipe(dest(newDestPath))
|
|
141
|
-
.on('error', (err) => {
|
|
142
|
-
fail(`image编译报错${err}`);
|
|
143
|
-
});
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
);
|
|
147
|
-
break;
|
|
148
|
-
case 'other':
|
|
149
|
-
compileTasksMap.set(
|
|
150
|
-
globValue,
|
|
151
|
-
{
|
|
152
|
-
module,
|
|
153
|
-
taskFn: (sourceFile, targetPath) => {
|
|
154
|
-
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
155
|
-
const newDestPath = targetPath ? targetPath : destPath;
|
|
156
|
-
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
157
|
-
return srcPipe
|
|
158
|
-
.pipe(dest(newDestPath))
|
|
159
|
-
.on('error', (err) => {
|
|
160
|
-
fail(`编译报错${err}`);
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
);
|
|
165
|
-
break;
|
|
166
|
-
default:
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
50
|
+
compileTasksMap.set(
|
|
51
|
+
glob,
|
|
52
|
+
{
|
|
53
|
+
module,
|
|
54
|
+
taskFn: (sourceFile, targetPath) => {
|
|
55
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : glob;
|
|
56
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
57
|
+
let srcPipe = src(newGlobValue, { ...srcOption });
|
|
58
|
+
const pluginParams = { module, isDev };
|
|
59
|
+
srcPipe = addPlugins(tmsConfig, srcPipe, pluginParams);
|
|
60
|
+
return srcPipe
|
|
61
|
+
.pipe(dest(newDestPath))
|
|
62
|
+
.on('error', (err) => {
|
|
63
|
+
fail(`编译报错${err}`);
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
);
|
|
170
68
|
return compileTasksMap;
|
|
171
69
|
};
|
package/src/compile/dev.js
CHANGED
|
@@ -9,35 +9,16 @@ const { DEFAULT_COPY_CONFIG } = require('../config/constant');
|
|
|
9
9
|
const compile = require('./compile');
|
|
10
10
|
const watch = require('./watch');
|
|
11
11
|
const { info } = require('../utils/log');
|
|
12
|
+
const report = require('../core/report');
|
|
12
13
|
|
|
13
14
|
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
14
|
-
function excludeGlob(glob) {
|
|
15
|
-
const otherArr = new Set();
|
|
16
|
-
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
17
|
-
Object.keys(glob).forEach((globKey) => {
|
|
18
|
-
if (typeof glob[globKey] === 'string') {
|
|
19
|
-
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
20
|
-
otherArr.add(data);
|
|
21
|
-
} if (Array.isArray(glob[globKey])) {
|
|
22
|
-
glob[globKey].forEach((value) => {
|
|
23
|
-
if (typeof value === 'string') {
|
|
24
|
-
const data = value.startsWith('!') ? value : `!${value}`;
|
|
25
|
-
otherArr.add(data);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return Array.from(otherArr);
|
|
31
|
-
}
|
|
32
15
|
|
|
33
16
|
module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
34
17
|
const compileTasksMap = new Map();
|
|
35
18
|
|
|
36
19
|
// 监听根目录的文件
|
|
37
20
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
38
|
-
glob:
|
|
39
|
-
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
40
|
-
},
|
|
21
|
+
glob: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
41
22
|
module: { from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
42
23
|
destPath: resolve(tmsConfig.outputDir),
|
|
43
24
|
srcOption: { allowEmpty: true },
|
|
@@ -71,19 +52,9 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
|
71
52
|
}
|
|
72
53
|
return `!${resolve(srcModulePath, newPath)}/**/*`;
|
|
73
54
|
});
|
|
74
|
-
const glob = {
|
|
75
|
-
js: [`${srcModulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
76
|
-
json: [`${srcModulePath}/**/*.json`, `!${srcModulePath}/**/module.config.json`, ...excludes],
|
|
77
|
-
wxss: [`${srcModulePath}/**/*.{less,wxss,scss,sass,styl}`, ...excludes],
|
|
78
|
-
wxml: [`${srcModulePath}/**/*.wxml`, ...excludes],
|
|
79
|
-
image: [`${srcModulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes],
|
|
80
|
-
};
|
|
81
55
|
|
|
82
56
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
83
|
-
glob: {
|
|
84
|
-
...glob,
|
|
85
|
-
other: [`${srcModulePath}/**/*`, ...excludeGlob(glob)],
|
|
86
|
-
},
|
|
57
|
+
glob: [`${srcModulePath}/**/*`, `!${srcModulePath}/**/module.config.json`, ...excludes],
|
|
87
58
|
destPath: buildModulePath,
|
|
88
59
|
module: { from: srcModulePath, to: buildModulePath },
|
|
89
60
|
srcOption: { allowEmpty: true },
|
|
@@ -91,7 +62,7 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
|
91
62
|
}));
|
|
92
63
|
}
|
|
93
64
|
|
|
94
|
-
//
|
|
65
|
+
// static静态资源目录
|
|
95
66
|
if (tmsConfig?.static && tmsConfig?.static.length > 0) {
|
|
96
67
|
for (const item of tmsConfig.static) {
|
|
97
68
|
item.from = getAbsolutePath(item.from);
|
|
@@ -100,26 +71,16 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
|
100
71
|
let glob = {};
|
|
101
72
|
const ext = path.extname(item.from).slice(1);
|
|
102
73
|
if (ext) {
|
|
103
|
-
glob
|
|
74
|
+
glob = [item.from];
|
|
104
75
|
} else {
|
|
105
|
-
glob = {
|
|
106
|
-
js: [`${item.from}/**/*.{js,ts,wxs}`],
|
|
107
|
-
json: [`${item.from}/**/*.json`],
|
|
108
|
-
wxss: [`${item.from}/**/*.{less,wxss,scss,sass,styl}`],
|
|
109
|
-
wxml: [`${item.from}/**/*.wxml`],
|
|
110
|
-
image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`],
|
|
111
|
-
};
|
|
112
|
-
glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
|
|
76
|
+
glob = [`${item.from}/**/*`];
|
|
113
77
|
}
|
|
114
78
|
|
|
115
79
|
const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
|
|
116
80
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
117
81
|
glob,
|
|
118
82
|
destPath: item.to,
|
|
119
|
-
module: {
|
|
120
|
-
from,
|
|
121
|
-
to: item.to,
|
|
122
|
-
},
|
|
83
|
+
module: { from, to: item.to },
|
|
123
84
|
srcOption: { allowEmpty: true },
|
|
124
85
|
isDev,
|
|
125
86
|
}));
|
|
@@ -152,12 +113,13 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
|
152
113
|
buildOutputAppJson(tmsConfig, modules, isDev);
|
|
153
114
|
}
|
|
154
115
|
eTime = new Date().getTime() - sTime;
|
|
155
|
-
if (typeof tmsConfig?.hooks?.
|
|
156
|
-
await tmsConfig?.hooks?.
|
|
116
|
+
if (typeof tmsConfig?.hooks?.afterFirstCompile === 'function') {
|
|
117
|
+
await tmsConfig?.hooks?.afterFirstCompile({
|
|
157
118
|
isDev,
|
|
158
119
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
159
120
|
modules,
|
|
160
121
|
});
|
|
122
|
+
report('hooks:afterCompile');
|
|
161
123
|
}
|
|
162
124
|
spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
163
125
|
spinner.stop();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
function mpProjectJson() {
|
|
3
|
+
return function ({ vinyl, next }) {
|
|
4
|
+
if (vinyl.isBuffer()) {
|
|
5
|
+
let contents = String(vinyl.contents);
|
|
6
|
+
contents = contents.replace(/"miniprogramRoot"[^,]+,/g, '');
|
|
7
|
+
vinyl.contents = Buffer.from(contents);
|
|
8
|
+
}
|
|
9
|
+
next();
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = mpProjectJson;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
2
|
function replaceEnv(reg = /process\.env(\.(\w*))?/g, envData) {
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
let contents = String(
|
|
3
|
+
return function ({ vinyl, next }) {
|
|
4
|
+
if (vinyl.isBuffer()) {
|
|
5
|
+
let contents = String(vinyl.contents);
|
|
6
6
|
let resReg;
|
|
7
|
-
// eslint-disable-next-line
|
|
8
7
|
while ((resReg = reg.exec(contents)) !== null) {
|
|
9
8
|
const [reg1, reg2, reg3] = resReg;
|
|
10
9
|
if (reg1 && reg2 && reg3) {
|
|
@@ -14,16 +13,10 @@ function replaceEnv(reg = /process\.env(\.(\w*))?/g, envData) {
|
|
|
14
13
|
contents = contents.replace(reg1, JSON.stringify(envData));
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line
|
|
19
|
-
file.contents = Buffer.from(contents);
|
|
16
|
+
vinyl.contents = Buffer.from(contents);
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
cb();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return stream;
|
|
18
|
+
next();
|
|
19
|
+
};
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
module.exports = replaceEnv;
|
package/src/compile/watch.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
const watch = require('./plugins/gulp-watch');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const shellJs = require('shelljs');
|
|
5
|
+
const { series } = require('gulp');
|
|
5
6
|
const { info, warn, fail } = require('../utils/log');
|
|
6
|
-
const { resolve } = require('../utils/widgets');
|
|
7
|
+
const { resolve, filterField } = require('../utils/widgets');
|
|
7
8
|
const { global } = require('../utils/global');
|
|
8
9
|
const { checkPackageVersion } = require('../core/checkDependencies');
|
|
9
|
-
const
|
|
10
|
+
const report = require('../core/report');
|
|
10
11
|
|
|
11
12
|
const TIP_MAP = {
|
|
12
13
|
'package.json': {
|
|
@@ -58,27 +59,58 @@ module.exports = function (globValue, watchOptions, callback, module) {
|
|
|
58
59
|
|
|
59
60
|
const tmsConfig = global.getData('tmsConfig');
|
|
60
61
|
|
|
61
|
-
if (vinyl.event === 'addDir') {
|
|
62
|
-
info(`更新${sourceFileName}目录`);
|
|
63
|
-
const files = findAllFilesOfDir(sourceFile);
|
|
64
|
-
for (const file of files) {
|
|
65
|
-
const fileDirArr = file.replace(/\\/g, '/').split('/');
|
|
66
|
-
const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
|
|
67
|
-
const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
|
|
68
|
-
logTip(fileName, sourceFile, targetFile, TIP_MAP);
|
|
69
|
-
callback([file], path.dirname(targetFile));
|
|
70
|
-
}
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
62
|
const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
|
|
75
63
|
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
76
64
|
info(`删除${sourceFileName}`);
|
|
77
65
|
shellJs.rm('-rf', targetFile);
|
|
66
|
+
updateFileHook(tmsConfig, sourceFile, targetFile, vinyl.event);
|
|
78
67
|
return;
|
|
79
68
|
}
|
|
80
|
-
|
|
69
|
+
runCallback({
|
|
70
|
+
tmsConfig,
|
|
71
|
+
sourceFile,
|
|
72
|
+
targetFile,
|
|
73
|
+
callback,
|
|
74
|
+
type: vinyl.event,
|
|
75
|
+
});
|
|
81
76
|
logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
|
|
82
|
-
return callback([sourceFile], path.dirname(targetFile));
|
|
83
77
|
});
|
|
84
78
|
};
|
|
79
|
+
|
|
80
|
+
// 开始执行watch 文件的 callback函数
|
|
81
|
+
async function runCallback({
|
|
82
|
+
tmsConfig,
|
|
83
|
+
sourceFile,
|
|
84
|
+
targetFile,
|
|
85
|
+
callback,
|
|
86
|
+
type,
|
|
87
|
+
}) {
|
|
88
|
+
// callbacl.name === taskFn 代表进入gulp编译流程
|
|
89
|
+
// series为gulp编译串行执行,callback执行完毕后,执行updateFileHooks钩子
|
|
90
|
+
if (callback.name === 'taskFn') {
|
|
91
|
+
series(
|
|
92
|
+
callback.bind(null, [sourceFile], path.dirname(targetFile)),
|
|
93
|
+
(cb) => {
|
|
94
|
+
cb();
|
|
95
|
+
updateFileHook(tmsConfig, sourceFile, targetFile, type);
|
|
96
|
+
},
|
|
97
|
+
)();
|
|
98
|
+
} else {
|
|
99
|
+
// 普通的callback函数
|
|
100
|
+
await callback([sourceFile], path.dirname(targetFile));
|
|
101
|
+
await updateFileHook(tmsConfig, sourceFile, targetFile, type);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 执行源码文件更新的钩子
|
|
106
|
+
async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
|
|
107
|
+
if (typeof tmsConfig?.hooks?.updateFile === 'function') {
|
|
108
|
+
await tmsConfig.hooks.updateFile({
|
|
109
|
+
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
110
|
+
sourceFile,
|
|
111
|
+
targetFile,
|
|
112
|
+
type,
|
|
113
|
+
});
|
|
114
|
+
report('hooks:updateFile');
|
|
115
|
+
}
|
|
116
|
+
}
|
package/src/config/constant.js
CHANGED
|
@@ -7,18 +7,29 @@ const HOME_DIR = os.homedir();
|
|
|
7
7
|
// 所有文件的缓存目录
|
|
8
8
|
const CACHE_DIR = path.resolve(HOME_DIR, '.tmskit');
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
const
|
|
10
|
+
// 版本管理的CDN地址
|
|
11
|
+
const VERSION_URL = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json';
|
|
12
|
+
|
|
13
|
+
// version缓存文件
|
|
14
|
+
const VERSION_CACHE_FILE = path.resolve(CACHE_DIR, 'version_cache_file.json');
|
|
15
|
+
|
|
16
|
+
// npm缓存文件
|
|
17
|
+
const NPM_CACHE_FILE = path.resolve(CACHE_DIR, 'npm_cache_file.json');
|
|
12
18
|
|
|
13
19
|
// 脚手架模板代码所在目录
|
|
14
20
|
const TEMPLATE_DIR = path.resolve(CACHE_DIR, 'template');
|
|
15
21
|
|
|
16
|
-
// 模板的名称
|
|
17
|
-
const TEMPLATE_NAME = 'tmskit-template';
|
|
18
|
-
|
|
19
22
|
// 第三方模块源码存放的临时缓存目录
|
|
20
23
|
const MODULE_CODE_DIR = path.resolve(CACHE_DIR, 'modules_code');
|
|
21
24
|
|
|
25
|
+
// 缓存分包node_modules的目录
|
|
26
|
+
const NODE_MODULES_DIR = path.resolve(CACHE_DIR, 'node_modules');
|
|
27
|
+
|
|
28
|
+
// 扩展命令源码的存放处
|
|
29
|
+
const EXTEND_CMD = path.resolve(CACHE_DIR, 'cmd');
|
|
30
|
+
|
|
31
|
+
// 创建模板的名称
|
|
32
|
+
const TEMPLATE_NAME = 'tmskit-template';
|
|
22
33
|
|
|
23
34
|
// 脚手架模板的远程地址
|
|
24
35
|
const TEMPLATE_URL = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip';
|
|
@@ -46,7 +57,7 @@ const DEFAULT_WEBPACK_ENTRY = {
|
|
|
46
57
|
};
|
|
47
58
|
|
|
48
59
|
// 默认从源码拷贝到编译后的配置
|
|
49
|
-
const DEFAULT_COPY_CONFIG = ['package.json', 'sitemap.json'];
|
|
60
|
+
const DEFAULT_COPY_CONFIG = ['package.json', 'sitemap.json', 'project.config.json'];
|
|
50
61
|
|
|
51
62
|
const ENV = {
|
|
52
63
|
dev: 'development',
|
|
@@ -66,15 +77,22 @@ const CREATE_TEMPLATE_QUESTION = [
|
|
|
66
77
|
}, {
|
|
67
78
|
name: '小程序模块',
|
|
68
79
|
value: 'mp-module',
|
|
80
|
+
}, {
|
|
81
|
+
name: '构建工具扩展命令',
|
|
82
|
+
value: 'cmd',
|
|
83
|
+
}, {
|
|
84
|
+
name: '构建工具编译插件',
|
|
85
|
+
value: 'plugin',
|
|
69
86
|
}],
|
|
70
87
|
},
|
|
71
88
|
];
|
|
72
89
|
|
|
73
90
|
|
|
74
|
-
|
|
91
|
+
module.exports = {
|
|
75
92
|
HOME_DIR,
|
|
76
93
|
CACHE_DIR,
|
|
77
|
-
|
|
94
|
+
NPM_CACHE_FILE,
|
|
95
|
+
VERSION_CACHE_FILE,
|
|
78
96
|
TEMPLATE_DIR,
|
|
79
97
|
TEMPLATE_NAME,
|
|
80
98
|
TMS_NAME,
|
|
@@ -82,12 +100,15 @@ export {
|
|
|
82
100
|
TMS_PRIVATE_FILENAME,
|
|
83
101
|
DEFAULT_MODULE_DIR,
|
|
84
102
|
MODULE_CONFIG_FILENAME,
|
|
103
|
+
EXTEND_CMD,
|
|
85
104
|
DEFAULT_WEBPACK_ENTRY,
|
|
86
105
|
DEFAULT_COPY_CONFIG,
|
|
87
106
|
MODULE_CODE_DIR,
|
|
107
|
+
NODE_MODULES_DIR,
|
|
88
108
|
ENV,
|
|
89
109
|
TEMPLATE_TKIT_DIR,
|
|
90
110
|
DEFAULT_CLOUD_MODULE_DIR,
|
|
91
111
|
CREATE_TEMPLATE_QUESTION,
|
|
92
112
|
TEMPLATE_URL,
|
|
113
|
+
VERSION_URL,
|
|
93
114
|
};
|
package/src/core/buildAppJson.js
CHANGED
|
@@ -8,6 +8,8 @@ const { fail, info } = require('../utils/log');
|
|
|
8
8
|
const { resolve, filterField } = require('../utils/widgets');
|
|
9
9
|
const { handleError } = require('./handleError');
|
|
10
10
|
const { global } = require('../utils/global');
|
|
11
|
+
const report = require('../core/report');
|
|
12
|
+
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* 更新appJson里面的主包配置
|
|
@@ -145,6 +147,7 @@ function buildOutputAppJson(tmsConfig, modules) {
|
|
|
145
147
|
appJson,
|
|
146
148
|
isDev: global.getData('isDev'),
|
|
147
149
|
});
|
|
150
|
+
report('hooks:updateAppJson');
|
|
148
151
|
}
|
|
149
152
|
return appJson;
|
|
150
153
|
} catch (e) {
|
|
@@ -7,7 +7,10 @@ const { handleError } = require('./handleError');
|
|
|
7
7
|
|
|
8
8
|
const getLatestVersion = (npmName) => {
|
|
9
9
|
const data = shelljs.exec(`npm view ${npmName} version`);
|
|
10
|
-
|
|
10
|
+
if (data.code === 0) {
|
|
11
|
+
return data.stdout;
|
|
12
|
+
}
|
|
13
|
+
return '0.0.0';
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
// 收集package.json
|
package/src/core/cloneModules.js
CHANGED
|
@@ -39,6 +39,9 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
39
39
|
* @returns { undefined } no return
|
|
40
40
|
*/
|
|
41
41
|
function moveFile(sourceDir, targetDir, ignore = []) {
|
|
42
|
+
if (fs.existsSync(targetDir)) {
|
|
43
|
+
shelljs.rm('-rf', targetDir);
|
|
44
|
+
}
|
|
42
45
|
// 删除不是文件夹的文件
|
|
43
46
|
return new Promise((resolve, reject) => {
|
|
44
47
|
MetalSmith(__dirname)
|
package/src/core/npm.js
CHANGED
|
@@ -6,10 +6,10 @@ const fsExtra = require('fs-extra');
|
|
|
6
6
|
const crypto = require('crypto');
|
|
7
7
|
const path = require('path');
|
|
8
8
|
const shell = require('shelljs');
|
|
9
|
-
const glob = require('glob-ignore');
|
|
10
9
|
const log = require('../utils/log');
|
|
11
10
|
const { npmInstall } = require('../utils/widgets');
|
|
12
11
|
const { handleError } = require('./handleError');
|
|
12
|
+
const { global } = require('../utils/global');
|
|
13
13
|
|
|
14
14
|
const shellJsOption = { async: false, silent: true };
|
|
15
15
|
const dirPath = process.cwd(); // 项目根目录
|
|
@@ -76,7 +76,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
76
76
|
fsExtra.emptydirSync(cacheNMPath);
|
|
77
77
|
shell.cp('-f', packageJsonPath, cacheNMPath);
|
|
78
78
|
log.info(`npm install: ${packageJsonPath}`);
|
|
79
|
-
|
|
79
|
+
const tmsConfig = global.getData('tmsConfig');
|
|
80
|
+
return npmInstall(cacheNMPath, tmsConfig.npm).then(() => {
|
|
80
81
|
const newShellJsOption = {
|
|
81
82
|
...shellJsOption,
|
|
82
83
|
cwd: cacheNMPath,
|
|
@@ -198,25 +199,8 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
|
|
|
198
199
|
return result;
|
|
199
200
|
};
|
|
200
201
|
|
|
201
|
-
function cloudNpmInstall(contextDir) {
|
|
202
|
-
return new Promise((resolve, reject) => {
|
|
203
|
-
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
204
|
-
if (err) {
|
|
205
|
-
reject(err);
|
|
206
|
-
}
|
|
207
|
-
files.forEach((file) => {
|
|
208
|
-
const dir = path.dirname(file);
|
|
209
|
-
shell.cd(dir);
|
|
210
|
-
shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', { silent: false });
|
|
211
|
-
});
|
|
212
|
-
resolve();
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
202
|
|
|
218
203
|
module.exports = {
|
|
219
|
-
cloudNpmInstall,
|
|
220
204
|
npmInstallAll,
|
|
221
205
|
findAllPackageJson,
|
|
222
206
|
findFilesByFilter,
|