@tmsfe/tmskit 0.0.20 → 0.0.23
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 +1632 -1868
- package/package.json +4 -7
- 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 +25 -69
- 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 +11 -8
- package/src/core/cloneModules.js +3 -0
- package/src/core/npm.js +6 -25
- 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 +148 -69
- package/src/entry.js +13 -14
- package/src/index.js +61 -20
- 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/cloud/index.js +0 -2
- package/src/scripts/run/dev/index.js +9 -3
- package/src/scripts/run/index.js +52 -76
- package/src/scripts/run/init/index.js +2 -24
- package/src/{core → scripts/run/install}/cache.js +4 -4
- package/src/scripts/run/install/index.js +15 -19
- package/src/utils/log.js +3 -0
- package/src/utils/widgets.js +58 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
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/{init.js → check.js}
RENAMED
|
@@ -22,12 +22,11 @@ const checkNodeVersion = (wanted, id) => {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* 检查运行环境
|
|
25
|
-
* @returns {Undefined} 无需返回值
|
|
26
25
|
*/
|
|
27
|
-
function
|
|
26
|
+
function check() {
|
|
28
27
|
// 执行操作前检查node版本
|
|
29
28
|
// 旧版本node直接提示升级,退出脚本
|
|
30
29
|
checkNodeVersion(requiredVersion, packName);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
module.exports =
|
|
32
|
+
module.exports = check;
|
package/src/compile/build.js
CHANGED
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
|
@@ -3,129 +3,84 @@ const fs = require('fs');
|
|
|
3
3
|
const ora = require('ora');
|
|
4
4
|
const chalk = require('chalk');
|
|
5
5
|
const { parallel, series } = require('gulp');
|
|
6
|
-
const { resolve, mergeMap, filterField } = require('../utils/widgets');
|
|
6
|
+
const { resolve, mergeMap, filterField, getAbsolutePath } = require('../utils/widgets');
|
|
7
7
|
const { buildOutputAppJson } = require('../core/buildAppJson');
|
|
8
8
|
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
|
-
|
|
34
|
-
let newPath = pathDir;
|
|
35
|
-
newPath = newPath.startsWith('/') ? newPath : resolve(cwd, newPath);
|
|
36
|
-
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
37
|
-
return newPath;
|
|
38
|
-
}
|
|
39
|
-
module.exports = async (tmsConfig, modules, subPackages, isDev = true) => {
|
|
16
|
+
module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
40
17
|
const compileTasksMap = new Map();
|
|
41
18
|
|
|
42
19
|
// 监听根目录的文件
|
|
43
20
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
44
|
-
glob:
|
|
45
|
-
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
46
|
-
},
|
|
21
|
+
glob: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
47
22
|
module: { from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
48
23
|
destPath: resolve(tmsConfig.outputDir),
|
|
49
24
|
srcOption: { allowEmpty: true },
|
|
50
25
|
isDev,
|
|
51
26
|
}));
|
|
52
|
-
|
|
53
27
|
// 监听模块的文件
|
|
54
|
-
for (let
|
|
28
|
+
for (let moduleItem of modules) {
|
|
55
29
|
// 处理默认参数
|
|
56
|
-
|
|
30
|
+
moduleItem = {
|
|
57
31
|
...{ exclude: [] },
|
|
58
|
-
...
|
|
32
|
+
...moduleItem,
|
|
59
33
|
};
|
|
60
|
-
const
|
|
34
|
+
const srcModulePath = getAbsolutePath(moduleItem.path);
|
|
35
|
+
const buildModulePath = resolve(tmsConfig.outputDir, moduleItem.modulePath);
|
|
61
36
|
|
|
62
37
|
if (isDev) {
|
|
63
38
|
// 监听模块配置文件
|
|
64
39
|
watch(
|
|
65
|
-
[`${
|
|
40
|
+
[`${srcModulePath}/**/module.config.json`],
|
|
66
41
|
{ events: watchEvents },
|
|
67
42
|
() => buildOutputAppJson(tmsConfig, modules, isDev),
|
|
68
|
-
{ from:
|
|
43
|
+
{ from: srcModulePath, to: buildModulePath },
|
|
69
44
|
);
|
|
70
45
|
}
|
|
71
46
|
|
|
72
|
-
const excludes =
|
|
73
|
-
const newPath =
|
|
47
|
+
const excludes = moduleItem.exclude.map((ePath) => {
|
|
48
|
+
const newPath = getAbsolutePath(ePath, srcModulePath);
|
|
74
49
|
const ext = path.extname(ePath).slice(1);
|
|
75
50
|
if (ext) {
|
|
76
|
-
return `!${resolve(
|
|
51
|
+
return `!${resolve(srcModulePath, newPath)}`;
|
|
77
52
|
}
|
|
78
|
-
return `!${resolve(
|
|
53
|
+
return `!${resolve(srcModulePath, newPath)}/**/*`;
|
|
79
54
|
});
|
|
80
|
-
const glob = {
|
|
81
|
-
js: [`${packagePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
82
|
-
json: [`${packagePath}/**/*.json`, `!${packagePath}/**/module.config.json`, ...excludes],
|
|
83
|
-
wxss: [`${packagePath}/**/*.{less,wxss,scss,sass,styl}`, ...excludes],
|
|
84
|
-
wxml: [`${packagePath}/**/*.wxml`, ...excludes],
|
|
85
|
-
image: [`${packagePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes],
|
|
86
|
-
};
|
|
87
55
|
|
|
88
56
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
89
|
-
glob: {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
destPath: resolve(tmsConfig.outputDir, pkg.root),
|
|
94
|
-
module: { from: pkg.path, to: pkg.root },
|
|
57
|
+
glob: [`${srcModulePath}/**/*`, `!${srcModulePath}/**/module.config.json`, ...excludes],
|
|
58
|
+
destPath: buildModulePath,
|
|
59
|
+
module: { from: srcModulePath, to: buildModulePath },
|
|
95
60
|
srcOption: { allowEmpty: true },
|
|
96
61
|
isDev,
|
|
97
62
|
}));
|
|
98
63
|
}
|
|
99
64
|
|
|
100
|
-
//
|
|
65
|
+
// static静态资源目录
|
|
101
66
|
if (tmsConfig?.static && tmsConfig?.static.length > 0) {
|
|
102
67
|
for (const item of tmsConfig.static) {
|
|
103
|
-
item.from =
|
|
104
|
-
item.to =
|
|
68
|
+
item.from = getAbsolutePath(item.from);
|
|
69
|
+
item.to = getAbsolutePath(item.to);
|
|
105
70
|
|
|
106
71
|
let glob = {};
|
|
107
72
|
const ext = path.extname(item.from).slice(1);
|
|
108
73
|
if (ext) {
|
|
109
|
-
glob
|
|
74
|
+
glob = [item.from];
|
|
110
75
|
} else {
|
|
111
|
-
glob = {
|
|
112
|
-
js: [`${item.from}/**/*.{js,ts,wxs}`],
|
|
113
|
-
json: [`${item.from}/**/*.json`],
|
|
114
|
-
wxss: [`${item.from}/**/*.{less,wxss,scss,sass,styl}`],
|
|
115
|
-
wxml: [`${item.from}/**/*.wxml`],
|
|
116
|
-
image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`],
|
|
117
|
-
};
|
|
118
|
-
glob.other = [`${item.from}/**/*`, ...excludeGlob(glob)];
|
|
76
|
+
glob = [`${item.from}/**/*`];
|
|
119
77
|
}
|
|
120
78
|
|
|
121
79
|
const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
|
|
122
80
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
123
81
|
glob,
|
|
124
82
|
destPath: item.to,
|
|
125
|
-
module: {
|
|
126
|
-
from,
|
|
127
|
-
to: item.to,
|
|
128
|
-
},
|
|
83
|
+
module: { from, to: item.to },
|
|
129
84
|
srcOption: { allowEmpty: true },
|
|
130
85
|
isDev,
|
|
131
86
|
}));
|
|
@@ -164,6 +119,7 @@ module.exports = async (tmsConfig, modules, subPackages, isDev = true) => {
|
|
|
164
119
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
165
120
|
modules,
|
|
166
121
|
});
|
|
122
|
+
report('hooks:afterCompile');
|
|
167
123
|
}
|
|
168
124
|
spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
169
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
|
};
|