@tmsfe/tmskit 0.0.21 → 0.0.24-beta.0
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 +1481 -1405
- package/package.json +5 -8
- package/src/.DS_Store +0 -0
- package/src/compile/compile.js +53 -155
- package/src/compile/dev.js +12 -48
- package/src/compile/plugins/mpProjectJson.js +13 -0
- package/src/compile/plugins/replaceEnv.js +7 -14
- package/src/compile/watch.js +50 -17
- package/src/config/constant.js +29 -8
- package/src/config/defaultTmsConfig.js +24 -0
- package/src/core/buildAppJson.js +4 -0
- package/src/core/checkDependencies.js +4 -1
- package/src/core/cloneModules.js +6 -3
- package/src/core/mpCi.js +62 -14
- package/src/core/npm.js +3 -19
- package/src/core/recommendVersion.js +118 -0
- package/src/core/report.js +25 -0
- package/src/core/tmsMpconfig.js +16 -29
- package/src/entry.js +45 -21
- package/src/index.js +54 -27
- package/src/scripts/.DS_Store +0 -0
- package/src/scripts/create/index.js +3 -1
- package/src/scripts/extend-cmd/index.js +74 -0
- package/src/scripts/run/build/index.js +10 -3
- package/src/scripts/run/cloud/index.js +1 -1
- package/src/scripts/run/dev/index.js +12 -5
- package/src/scripts/run/index.js +27 -11
- package/src/scripts/run/install/cache.js +36 -0
- package/src/scripts/run/install/index.js +3 -3
- package/src/scripts/run/preview/index.js +70 -0
- package/src/scripts/run/preview/utils.js +43 -0
- package/src/scripts/run/upload/index.js +65 -0
- package/src/utils/log.js +3 -0
- package/src/utils/widgets.js +55 -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-beta.0",
|
|
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,13 +47,15 @@
|
|
|
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",
|
|
61
|
-
"
|
|
57
|
+
"minimatch": "^5.1.0",
|
|
58
|
+
"miniprogram-ci": "1.8.25",
|
|
62
59
|
"moment": "^2.29.2",
|
|
63
60
|
"object-assign": "^4.0.1",
|
|
64
61
|
"ora": "^5.1.0",
|
package/src/.DS_Store
ADDED
|
Binary file
|
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,17 @@ 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');
|
|
13
|
+
const { global } = require('../utils/global');
|
|
12
14
|
|
|
13
15
|
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
16
|
|
|
33
17
|
module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
34
18
|
const compileTasksMap = new Map();
|
|
35
19
|
|
|
36
20
|
// 监听根目录的文件
|
|
37
21
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
38
|
-
glob:
|
|
39
|
-
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
40
|
-
},
|
|
22
|
+
glob: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
41
23
|
module: { from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
42
24
|
destPath: resolve(tmsConfig.outputDir),
|
|
43
25
|
srcOption: { allowEmpty: true },
|
|
@@ -71,19 +53,9 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
|
71
53
|
}
|
|
72
54
|
return `!${resolve(srcModulePath, newPath)}/**/*`;
|
|
73
55
|
});
|
|
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
56
|
|
|
82
57
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
83
|
-
glob: {
|
|
84
|
-
...glob,
|
|
85
|
-
other: [`${srcModulePath}/**/*`, ...excludeGlob(glob)],
|
|
86
|
-
},
|
|
58
|
+
glob: [`${srcModulePath}/**/*`, `!${srcModulePath}/**/module.config.json`, ...excludes],
|
|
87
59
|
destPath: buildModulePath,
|
|
88
60
|
module: { from: srcModulePath, to: buildModulePath },
|
|
89
61
|
srcOption: { allowEmpty: true },
|
|
@@ -91,7 +63,7 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
|
91
63
|
}));
|
|
92
64
|
}
|
|
93
65
|
|
|
94
|
-
//
|
|
66
|
+
// static静态资源目录
|
|
95
67
|
if (tmsConfig?.static && tmsConfig?.static.length > 0) {
|
|
96
68
|
for (const item of tmsConfig.static) {
|
|
97
69
|
item.from = getAbsolutePath(item.from);
|
|
@@ -100,26 +72,16 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
|
100
72
|
let glob = {};
|
|
101
73
|
const ext = path.extname(item.from).slice(1);
|
|
102
74
|
if (ext) {
|
|
103
|
-
glob
|
|
75
|
+
glob = [item.from];
|
|
104
76
|
} 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)];
|
|
77
|
+
glob = [`${item.from}/**/*`];
|
|
113
78
|
}
|
|
114
79
|
|
|
115
80
|
const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
|
|
116
81
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
117
82
|
glob,
|
|
118
83
|
destPath: item.to,
|
|
119
|
-
module: {
|
|
120
|
-
from,
|
|
121
|
-
to: item.to,
|
|
122
|
-
},
|
|
84
|
+
module: { from, to: item.to },
|
|
123
85
|
srcOption: { allowEmpty: true },
|
|
124
86
|
isDev,
|
|
125
87
|
}));
|
|
@@ -152,12 +114,14 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
|
152
114
|
buildOutputAppJson(tmsConfig, modules, isDev);
|
|
153
115
|
}
|
|
154
116
|
eTime = new Date().getTime() - sTime;
|
|
155
|
-
if (typeof tmsConfig?.hooks?.
|
|
156
|
-
await tmsConfig?.hooks?.
|
|
117
|
+
if (typeof tmsConfig?.hooks?.afterFirstCompile === 'function') {
|
|
118
|
+
await tmsConfig?.hooks?.afterFirstCompile({
|
|
157
119
|
isDev,
|
|
158
120
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
159
121
|
modules,
|
|
122
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
160
123
|
});
|
|
124
|
+
report('hooks:afterCompile');
|
|
161
125
|
}
|
|
162
126
|
spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
163
127
|
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,59 @@ 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
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
111
|
+
sourceFile,
|
|
112
|
+
targetFile,
|
|
113
|
+
type,
|
|
114
|
+
});
|
|
115
|
+
report('hooks:updateFile');
|
|
116
|
+
}
|
|
117
|
+
}
|
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
|
};
|
|
@@ -13,4 +13,28 @@ module.exports = {
|
|
|
13
13
|
sourceDir: './',
|
|
14
14
|
/** 静态资源目录 */
|
|
15
15
|
static: [],
|
|
16
|
+
/** 上传是的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E7%BC%96%E8%AF%91%E8%AE%BE%E7%BD%AE */
|
|
17
|
+
upload: {
|
|
18
|
+
setting: {
|
|
19
|
+
es6: true,
|
|
20
|
+
es7: true,
|
|
21
|
+
minify: true,
|
|
22
|
+
minifyJS: true,
|
|
23
|
+
minifyWXML: true,
|
|
24
|
+
minifyWXSS: true,
|
|
25
|
+
autoPrefixWXSS: true,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
/** 预览的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88 */
|
|
29
|
+
preview: {
|
|
30
|
+
setting: {
|
|
31
|
+
es6: true,
|
|
32
|
+
es7: true,
|
|
33
|
+
minify: true,
|
|
34
|
+
minifyJS: true,
|
|
35
|
+
minifyWXML: true,
|
|
36
|
+
minifyWXSS: true,
|
|
37
|
+
autoPrefixWXSS: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
16
40
|
};
|
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里面的主包配置
|
|
@@ -141,10 +143,12 @@ function buildOutputAppJson(tmsConfig, modules) {
|
|
|
141
143
|
if (typeof tmsConfig?.hooks?.updateAppJson === 'function') {
|
|
142
144
|
tmsConfig?.hooks?.updateAppJson({
|
|
143
145
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
146
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
144
147
|
modules,
|
|
145
148
|
appJson,
|
|
146
149
|
isDev: global.getData('isDev'),
|
|
147
150
|
});
|
|
151
|
+
report('hooks:updateAppJson');
|
|
148
152
|
}
|
|
149
153
|
return appJson;
|
|
150
154
|
} 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
|