@tmsfe/tmskit 0.0.15 → 0.0.16
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/build/publish.sh +34 -0
- package/dist/index.cjs.js +700 -415
- package/main.js +0 -0
- package/package.json +12 -1
- package/src/compile/compile.js +56 -35
- package/src/compile/dev.js +27 -23
- package/src/compile/plugins/gulp-watch/index.js +172 -0
- package/src/compile/watch.js +51 -15
- package/src/core/buildAppJson.js +3 -0
- package/src/entry.js +1 -1
- package/src/scripts/run/dev/index.js +12 -8
- package/src/scripts/run/init/index.js +27 -15
- package/src/scripts/run/install/index.js +18 -9
- package/src/utils/io.js +20 -0
- package/src/utils/log.js +4 -4
- package/src/utils/widgets.js +3 -3
- package/CHANGELOG.md +0 -26
package/main.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "tmskit",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"bin": {
|
|
7
7
|
"tmskit": "main.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
+
"build",
|
|
10
11
|
"src",
|
|
11
12
|
"dist",
|
|
12
13
|
"main.js",
|
|
@@ -38,8 +39,18 @@
|
|
|
38
39
|
"rollup-plugin-typescript2": "0.27.0"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
42
|
+
"ansi-colors": "1.1.0",
|
|
43
|
+
"anymatch": "^1.3.0",
|
|
44
|
+
"fancy-log": "1.3.2",
|
|
45
|
+
"glob-parent": "^3.0.1",
|
|
46
|
+
"path-is-absolute": "^1.0.1",
|
|
47
|
+
"readable-stream": "^2.2.2",
|
|
48
|
+
"slash": "^1.0.0",
|
|
49
|
+
"vinyl": "^2.1.0",
|
|
50
|
+
"vinyl-file": "^2.0.0",
|
|
41
51
|
"async": "^3.2.2",
|
|
42
52
|
"chalk": "^4.1.0",
|
|
53
|
+
"chokidar": "^3.5.3",
|
|
43
54
|
"commander": "^8.3.0",
|
|
44
55
|
"copy-webpack-plugin": "^9.1.0",
|
|
45
56
|
"ejs": "^3.1.5",
|
package/src/compile/compile.js
CHANGED
|
@@ -18,7 +18,7 @@ module.exports = function (
|
|
|
18
18
|
destPath,
|
|
19
19
|
srcOption,
|
|
20
20
|
module,
|
|
21
|
-
|
|
21
|
+
isDev,
|
|
22
22
|
},
|
|
23
23
|
) {
|
|
24
24
|
const compileTasksMap = new Map();
|
|
@@ -31,14 +31,17 @@ module.exports = function (
|
|
|
31
31
|
globValue,
|
|
32
32
|
{
|
|
33
33
|
module,
|
|
34
|
-
taskFn: () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const srcPipe = src(
|
|
34
|
+
taskFn: (sourceFile, targetPath) => {
|
|
35
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
36
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
37
|
+
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
38
38
|
return srcPipe
|
|
39
39
|
// .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
40
|
-
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'],
|
|
41
|
-
.
|
|
40
|
+
.pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev))
|
|
41
|
+
.on('error', (err) => {
|
|
42
|
+
fail(`mpCommonDep编译报错${err}`);
|
|
43
|
+
})
|
|
44
|
+
.pipe(dest(newDestPath, { overwrite: true }))
|
|
42
45
|
.on('error', (err) => {
|
|
43
46
|
fail(`js编译报错${err}`);
|
|
44
47
|
});
|
|
@@ -51,12 +54,12 @@ module.exports = function (
|
|
|
51
54
|
globValue,
|
|
52
55
|
{
|
|
53
56
|
module,
|
|
54
|
-
taskFn: () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const srcPipe = src(
|
|
57
|
+
taskFn: (sourceFile, targetPath) => {
|
|
58
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
59
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
60
|
+
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
58
61
|
return srcPipe
|
|
59
|
-
.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'],
|
|
62
|
+
.pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev))
|
|
60
63
|
.on('error', (err) => {
|
|
61
64
|
fail(`mpCommonDep编译报错${err}`);
|
|
62
65
|
})
|
|
@@ -68,7 +71,10 @@ module.exports = function (
|
|
|
68
71
|
// designWidth: 375, // 设计稿宽度,默认为750
|
|
69
72
|
// precision: 2, // 小数最大精度,默认为6
|
|
70
73
|
// }))
|
|
71
|
-
.pipe(dest(
|
|
74
|
+
.pipe(dest(newDestPath))
|
|
75
|
+
.on('error', (err) => {
|
|
76
|
+
fail(`wxss编译报错${err}`);
|
|
77
|
+
});
|
|
72
78
|
},
|
|
73
79
|
},
|
|
74
80
|
);
|
|
@@ -78,16 +84,19 @@ module.exports = function (
|
|
|
78
84
|
globValue,
|
|
79
85
|
{
|
|
80
86
|
module,
|
|
81
|
-
taskFn: () => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const srcPipe = src(
|
|
87
|
+
taskFn: (sourceFile, targetPath) => {
|
|
88
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
89
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
90
|
+
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
85
91
|
return srcPipe
|
|
86
|
-
.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'],
|
|
92
|
+
.pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev))
|
|
87
93
|
.on('error', (err) => {
|
|
88
94
|
fail(`mpJsonDep编译报错${err}`);
|
|
89
95
|
})
|
|
90
|
-
.pipe(dest(
|
|
96
|
+
.pipe(dest(newDestPath))
|
|
97
|
+
.on('error', (err) => {
|
|
98
|
+
fail(`json编译报错${err}`);
|
|
99
|
+
});
|
|
91
100
|
},
|
|
92
101
|
},
|
|
93
102
|
);
|
|
@@ -97,13 +106,19 @@ module.exports = function (
|
|
|
97
106
|
globValue,
|
|
98
107
|
{
|
|
99
108
|
module,
|
|
100
|
-
taskFn: () => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const srcPipe = src(
|
|
109
|
+
taskFn: (sourceFile, targetPath) => {
|
|
110
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
111
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
112
|
+
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
104
113
|
return srcPipe
|
|
105
|
-
.pipe(mpWxmlDep(tmsConfig, module,
|
|
106
|
-
.
|
|
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
|
+
});
|
|
107
122
|
},
|
|
108
123
|
},
|
|
109
124
|
);
|
|
@@ -113,16 +128,19 @@ module.exports = function (
|
|
|
113
128
|
globValue,
|
|
114
129
|
{
|
|
115
130
|
module,
|
|
116
|
-
taskFn: () => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const srcPipe = src(
|
|
131
|
+
taskFn: (sourceFile, targetPath) => {
|
|
132
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
133
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
134
|
+
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
120
135
|
return srcPipe
|
|
121
136
|
// .pipe(cache(image()))
|
|
122
137
|
// .on('error', (err) => {
|
|
123
138
|
// fail(`image编译报错${err}`);
|
|
124
139
|
// })
|
|
125
|
-
.pipe(dest(
|
|
140
|
+
.pipe(dest(newDestPath))
|
|
141
|
+
.on('error', (err) => {
|
|
142
|
+
fail(`image编译报错${err}`);
|
|
143
|
+
});
|
|
126
144
|
},
|
|
127
145
|
},
|
|
128
146
|
);
|
|
@@ -132,12 +150,15 @@ module.exports = function (
|
|
|
132
150
|
globValue,
|
|
133
151
|
{
|
|
134
152
|
module,
|
|
135
|
-
taskFn: () => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const srcPipe = src(
|
|
153
|
+
taskFn: (sourceFile, targetPath) => {
|
|
154
|
+
const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
|
|
155
|
+
const newDestPath = targetPath ? targetPath : destPath;
|
|
156
|
+
const srcPipe = src(newGlobValue, { ...srcOption });
|
|
139
157
|
return srcPipe
|
|
140
|
-
.pipe(dest(
|
|
158
|
+
.pipe(dest(newDestPath))
|
|
159
|
+
.on('error', (err) => {
|
|
160
|
+
fail(`编译报错${err}`);
|
|
161
|
+
});
|
|
141
162
|
},
|
|
142
163
|
},
|
|
143
164
|
);
|
package/src/compile/dev.js
CHANGED
|
@@ -9,7 +9,7 @@ const compile = require('./compile');
|
|
|
9
9
|
const watch = require('./watch');
|
|
10
10
|
const { info } = require('../utils/log');
|
|
11
11
|
|
|
12
|
-
const watchEvents = ['add', 'change', 'unlink', 'unlinkDir'];
|
|
12
|
+
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
13
13
|
function excludeGlob(glob) {
|
|
14
14
|
const otherArr = new Set();
|
|
15
15
|
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
@@ -35,17 +35,18 @@ function adaptPath(pathDir) {
|
|
|
35
35
|
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
36
36
|
return newPath;
|
|
37
37
|
}
|
|
38
|
-
module.exports = async (tmsConfig, newModules,
|
|
38
|
+
module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
39
39
|
const compileTasksMap = new Map();
|
|
40
40
|
// 监听app.json
|
|
41
|
-
if (
|
|
41
|
+
if (isDev) {
|
|
42
42
|
watch(
|
|
43
43
|
[resolve('app.json')],
|
|
44
44
|
{ ignoreInitial: false, events: watchEvents },
|
|
45
|
-
() => buildOutputAppJson(tmsConfig, newModules,
|
|
45
|
+
() => buildOutputAppJson(tmsConfig, newModules, isDev),
|
|
46
|
+
{ from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
46
47
|
);
|
|
47
48
|
} else {
|
|
48
|
-
buildOutputAppJson(tmsConfig, newModules,
|
|
49
|
+
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
// 监听根目录的文件
|
|
@@ -55,10 +56,10 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
|
55
56
|
// wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
56
57
|
// js: ['app.js', 'app.ts'].map(item => resolve(item)),
|
|
57
58
|
},
|
|
58
|
-
module: { from:
|
|
59
|
+
module: { from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
59
60
|
destPath: resolve(tmsConfig.outputDir),
|
|
60
61
|
srcOption: { allowEmpty: true },
|
|
61
|
-
|
|
62
|
+
isDev,
|
|
62
63
|
}));
|
|
63
64
|
|
|
64
65
|
// 监听模块的文件
|
|
@@ -68,18 +69,19 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
|
68
69
|
...{ exclude: [] },
|
|
69
70
|
...module,
|
|
70
71
|
};
|
|
72
|
+
const modulePath = adaptPath(module.path);
|
|
71
73
|
|
|
72
|
-
if (
|
|
74
|
+
if (isDev) {
|
|
73
75
|
// 监听模块配置文件
|
|
74
76
|
watch(
|
|
75
|
-
[`${
|
|
77
|
+
[`${modulePath}/**/module.config.json`],
|
|
76
78
|
{ events: watchEvents },
|
|
77
|
-
() => buildOutputAppJson(tmsConfig, newModules,
|
|
79
|
+
() => buildOutputAppJson(tmsConfig, newModules, isDev),
|
|
80
|
+
{ from: modulePath, to: modulePath },
|
|
78
81
|
);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
82
|
-
const modulePath = adaptPath(module.path);
|
|
83
85
|
const glob = {
|
|
84
86
|
js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
85
87
|
json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
|
|
@@ -96,7 +98,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
|
96
98
|
destPath: resolve(tmsConfig.outputDir, module.root),
|
|
97
99
|
module: { from: module.path, to: module.root },
|
|
98
100
|
srcOption: { allowEmpty: true },
|
|
99
|
-
|
|
101
|
+
isDev,
|
|
100
102
|
}));
|
|
101
103
|
}
|
|
102
104
|
|
|
@@ -130,7 +132,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
|
130
132
|
to: item.to,
|
|
131
133
|
},
|
|
132
134
|
srcOption: { allowEmpty: true },
|
|
133
|
-
|
|
135
|
+
isDev,
|
|
134
136
|
}));
|
|
135
137
|
}
|
|
136
138
|
}
|
|
@@ -138,25 +140,27 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
|
138
140
|
let sTime;
|
|
139
141
|
let eTime;
|
|
140
142
|
const spinner = ora();
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
+
function start(cb) {
|
|
144
|
+
info('启动编译...');
|
|
145
|
+
spinner.start();
|
|
146
|
+
sTime = new Date().getTime();
|
|
147
|
+
cb();
|
|
148
|
+
}
|
|
149
|
+
async function end(cb) {
|
|
150
|
+
if (isDev) {
|
|
143
151
|
compileTasksMap.forEach(({ taskFn, module }, globValue) => {
|
|
144
152
|
watch(globValue, { ignoreInitial: true, events: watchEvents }, taskFn, module);
|
|
145
153
|
});
|
|
146
154
|
}
|
|
147
155
|
eTime = new Date().getTime() - sTime;
|
|
148
|
-
|
|
156
|
+
if (typeof tmsConfig?.hooks?.afterCompile === 'function') {
|
|
157
|
+
await tmsConfig?.hooks?.afterCompile({ isDev, tmsConfig, modules: newModules });
|
|
158
|
+
}
|
|
159
|
+
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
|
|
149
160
|
spinner.stop();
|
|
150
161
|
cb();
|
|
151
162
|
}
|
|
152
163
|
|
|
153
|
-
function start(cb) {
|
|
154
|
-
info('启动编译...');
|
|
155
|
-
spinner.start();
|
|
156
|
-
sTime = new Date().getTime();
|
|
157
|
-
cb();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
164
|
const compileTasks = [];
|
|
161
165
|
compileTasksMap.forEach(({ taskFn }) => {
|
|
162
166
|
compileTasks.push(taskFn);
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
|
|
4
|
+
const assign = require('object-assign');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const PluginError = require('plugin-error');
|
|
7
|
+
const fancyLog = require('fancy-log');
|
|
8
|
+
const colors = require('ansi-colors');
|
|
9
|
+
const chokidar = require('chokidar');
|
|
10
|
+
const { Duplex } = require('readable-stream');
|
|
11
|
+
const vinyl = require('vinyl-file');
|
|
12
|
+
const File = require('vinyl');
|
|
13
|
+
const anymatch = require('anymatch');
|
|
14
|
+
const pathIsAbsolute = require('path-is-absolute');
|
|
15
|
+
const globParent = require('glob-parent');
|
|
16
|
+
const slash = require('slash');
|
|
17
|
+
|
|
18
|
+
function normalizeGlobs(globs) {
|
|
19
|
+
if (!globs) {
|
|
20
|
+
throw new PluginError('gulp-watch', 'glob argument required');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof globs === 'string') {
|
|
24
|
+
globs = [globs];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!Array.isArray(globs)) {
|
|
28
|
+
throw new PluginError('gulp-watch', `glob should be String or Array, not ${typeof globs}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return globs;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function watch(globs, opts, cb) {
|
|
35
|
+
const originalGlobs = globs;
|
|
36
|
+
globs = normalizeGlobs(globs);
|
|
37
|
+
|
|
38
|
+
if (typeof opts === 'function') {
|
|
39
|
+
cb = opts;
|
|
40
|
+
opts = {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
opts = assign({}, watch._defaultOptions, opts);
|
|
44
|
+
cb = cb || function () {};
|
|
45
|
+
|
|
46
|
+
function resolveFilepath(filepath) {
|
|
47
|
+
if (pathIsAbsolute(filepath)) {
|
|
48
|
+
return path.normalize(filepath);
|
|
49
|
+
}
|
|
50
|
+
return path.resolve(opts.cwd || process.cwd(), filepath);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function resolveGlob(glob) {
|
|
54
|
+
let mod = '';
|
|
55
|
+
|
|
56
|
+
if (glob[0] === '!') {
|
|
57
|
+
mod = glob[0];
|
|
58
|
+
glob = glob.slice(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return mod + slash(resolveFilepath(glob));
|
|
62
|
+
}
|
|
63
|
+
globs = globs.map(resolveGlob);
|
|
64
|
+
|
|
65
|
+
const baseForced = Boolean(opts.base);
|
|
66
|
+
const outputStream = new Duplex({ objectMode: true, allowHalfOpen: true });
|
|
67
|
+
|
|
68
|
+
outputStream._write = function _write(file, enc, done) {
|
|
69
|
+
cb(file);
|
|
70
|
+
this.push(file);
|
|
71
|
+
done();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
outputStream._read = function _read() { };
|
|
75
|
+
|
|
76
|
+
const watcher = chokidar.watch(globs, opts);
|
|
77
|
+
|
|
78
|
+
opts.events.forEach((ev) => {
|
|
79
|
+
watcher.on(ev, processEvent.bind(undefined, ev));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
['add', 'change', 'unlink', 'addDir', 'unlinkDir', 'error', 'ready', 'raw']
|
|
83
|
+
.forEach((ev) => {
|
|
84
|
+
watcher.on(ev, outputStream.emit.bind(outputStream, ev));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
outputStream.add = function add(newGlobs) {
|
|
88
|
+
newGlobs = normalizeGlobs(newGlobs)
|
|
89
|
+
.map(resolveGlob);
|
|
90
|
+
watcher.add(newGlobs);
|
|
91
|
+
globs.push.apply(globs, newGlobs);
|
|
92
|
+
};
|
|
93
|
+
outputStream.unwatch = watcher.unwatch.bind(watcher);
|
|
94
|
+
outputStream.close = function () {
|
|
95
|
+
watcher.close();
|
|
96
|
+
this.emit('end');
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
function processEvent(event, filepath) {
|
|
100
|
+
filepath = resolveFilepath(filepath);
|
|
101
|
+
const fileOpts = assign({}, opts);
|
|
102
|
+
|
|
103
|
+
let glob;
|
|
104
|
+
let currentFilepath = filepath;
|
|
105
|
+
while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
|
|
106
|
+
|
|
107
|
+
if (!glob) {
|
|
108
|
+
console.error('[gulp-watch]没有匹配到glob')
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!baseForced) {
|
|
113
|
+
fileOpts.base = path.normalize(globParent(glob));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Do not stat deleted files
|
|
117
|
+
if (event === 'unlink' || event === 'unlinkDir' || event === 'addDir') {
|
|
118
|
+
fileOpts.path = filepath;
|
|
119
|
+
|
|
120
|
+
write(event, null, new File(fileOpts));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Workaround for early read
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
vinyl.read(filepath, fileOpts).then((file) => {
|
|
127
|
+
write(event, null, file);
|
|
128
|
+
});
|
|
129
|
+
}, opts.readDelay);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function write(event, err, file) {
|
|
133
|
+
if (err) {
|
|
134
|
+
outputStream.emit('error', err);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (opts.verbose) {
|
|
139
|
+
log(event, file);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
file.event = event;
|
|
143
|
+
outputStream.push(file);
|
|
144
|
+
cb(file);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function log(event, file) {
|
|
148
|
+
event = event[event.length - 1] === 'e' ? `${event}d` : `${event}ed`;
|
|
149
|
+
|
|
150
|
+
const msg = [colors.magenta(file.relative), 'was', event];
|
|
151
|
+
|
|
152
|
+
if (opts.name) {
|
|
153
|
+
msg.unshift(`${colors.cyan(opts.name)} saw`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
fancyLog.info.apply(null, msg);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return outputStream;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// This is not part of the public API as that would lead to global state (singleton) pollution,
|
|
163
|
+
// and allow unexpected interference between unrelated modules that make use of gulp-watch.
|
|
164
|
+
// This can be useful for unit tests and root application configuration, though.
|
|
165
|
+
// Avoid modifying gulp-watch's default options inside a library/reusable package, please.
|
|
166
|
+
watch._defaultOptions = {
|
|
167
|
+
events: ['add', 'change', 'unlink'],
|
|
168
|
+
ignoreInitial: true,
|
|
169
|
+
readDelay: 10,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
module.exports = watch;
|
package/src/compile/watch.js
CHANGED
|
@@ -1,29 +1,65 @@
|
|
|
1
|
-
const watch = require('gulp-watch');
|
|
1
|
+
const watch = require('./plugins/gulp-watch');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const shellJs = require('shelljs');
|
|
4
|
-
const { info } = require('../utils/log');
|
|
4
|
+
const { info, warn } = require('../utils/log');
|
|
5
5
|
const { resolve } = require('../utils/widgets');
|
|
6
6
|
const { global } = require('../utils/global');
|
|
7
|
+
const { findAllFilesOfDir } = require('../utils/io');
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const TIP_MAP = {
|
|
10
|
+
'package.json': '若依赖有变动,请重新执行tmskit run dev',
|
|
11
|
+
'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const logTip = (fileName, tipMap) => {
|
|
15
|
+
// eslint-disable-next-line
|
|
16
|
+
for (const item in tipMap) {
|
|
17
|
+
if (fileName.indexOf(item) > -1) {
|
|
18
|
+
warn(`${fileName}有更新, ${tipMap[item]}`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
info(`${fileName}有更新`);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
26
|
+
const sourceFileRelativeModule = path.relative(resolve(module.from), sourceFile);
|
|
27
|
+
const targetFile = resolve(outputDir, module.to, sourceFileRelativeModule);
|
|
28
|
+
return targetFile;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
module.exports = function (globValue, watchOptions, callback, module) {
|
|
32
|
+
watch(globValue, {
|
|
33
|
+
// readDelay: 100,
|
|
11
34
|
...watchOptions,
|
|
12
35
|
}, (vinyl) => {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
36
|
+
const sourceFile = vinyl.history[0];
|
|
37
|
+
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
38
|
+
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
39
|
+
|
|
40
|
+
const tmsConfig = global.getData('tmsConfig');
|
|
41
|
+
|
|
42
|
+
if (vinyl.event === 'addDir') {
|
|
43
|
+
info(`更新${sourceFileName}目录`);
|
|
44
|
+
const files = findAllFilesOfDir(sourceFile);
|
|
45
|
+
for (const file of files) {
|
|
46
|
+
const fileDirArr = file.replace(/\\/g, '/').split('/');
|
|
47
|
+
const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
|
|
48
|
+
const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
|
|
49
|
+
logTip(fileName, TIP_MAP);
|
|
50
|
+
callback([file], path.dirname(targetFile));
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
16
54
|
|
|
55
|
+
const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
|
|
17
56
|
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const anaFileDestFile = resolve(tmsConfig.outputDir, module.to, anaFileRelativeModule);
|
|
21
|
-
info(`删除${fileName}`);
|
|
22
|
-
shellJs.rm('-rf', anaFileDestFile);
|
|
57
|
+
info(`删除${sourceFileName}`);
|
|
58
|
+
shellJs.rm('-rf', targetFile);
|
|
23
59
|
return;
|
|
24
60
|
}
|
|
25
61
|
|
|
26
|
-
|
|
27
|
-
return callback(
|
|
62
|
+
logTip(sourceFileName, TIP_MAP);
|
|
63
|
+
return callback([sourceFile], path.dirname(targetFile));
|
|
28
64
|
});
|
|
29
65
|
};
|
package/src/core/buildAppJson.js
CHANGED
|
@@ -154,6 +154,9 @@ function buildOutputAppJson(tmsConfig, modules) {
|
|
|
154
154
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
155
155
|
|
|
156
156
|
fs.writeFileSync(resolve(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
157
|
+
if (typeof tmsConfig?.hooks?.updateAppJson === 'function') {
|
|
158
|
+
tmsConfig?.hooks?.updateAppJson(appJson);
|
|
159
|
+
}
|
|
157
160
|
|
|
158
161
|
return appJson;
|
|
159
162
|
} catch (e) {
|
package/src/entry.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = [
|
|
|
28
28
|
options: [
|
|
29
29
|
['-m, --module [moduleName]', '模块名称'],
|
|
30
30
|
['-e, --env [env]', '环境变量'],
|
|
31
|
-
['-
|
|
31
|
+
['-noCache, --noCache', '不使用缓存功能'],
|
|
32
32
|
],
|
|
33
33
|
action: (cmd) => {
|
|
34
34
|
require('./scripts/run/index')('dev', cmd);
|
|
@@ -2,10 +2,10 @@ const shelljs = require('shelljs');
|
|
|
2
2
|
const compileDev = require('../../../compile/dev');
|
|
3
3
|
const { resolve } = require('../../../utils/widgets');
|
|
4
4
|
const init = require('../init/index');
|
|
5
|
-
const { isInit } = require('../../../core/isInIt');
|
|
6
5
|
const { tmsModulesMergeLocalModuleCfg } = require('../../../core/tmsMpconfig');
|
|
7
6
|
const { info } = require('../../../utils/log');
|
|
8
7
|
const { global } = require('../../../utils/global');
|
|
8
|
+
const { CACHE_DIR } = require('../../../config/constant');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
// 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
@@ -24,16 +24,20 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
24
24
|
|
|
25
25
|
async function dev(tmsConfig, targetModules, env) {
|
|
26
26
|
let newModules = targetModules;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
|
|
32
|
-
const initData = await init(tmsConfig, newModules);
|
|
33
|
-
newModules = initData.targetModules;
|
|
27
|
+
const { noCache } = global.getData('cmd');
|
|
28
|
+
if (noCache) {
|
|
29
|
+
shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
30
|
+
shelljs.rm('-rf', CACHE_DIR);
|
|
34
31
|
}
|
|
35
32
|
|
|
33
|
+
// 初始化操作
|
|
34
|
+
const initData = await init(tmsConfig, newModules);
|
|
35
|
+
newModules = initData.targetModules;
|
|
36
|
+
|
|
36
37
|
info('当前dev启动的有效模块', newModules.map(item => item.name).sort());
|
|
38
|
+
if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
|
|
39
|
+
await tmsConfig?.hooks?.beforeCompile({ isDev: true, tmsConfig, modules: newModules });
|
|
40
|
+
};
|
|
37
41
|
delOtherModule(tmsConfig, newModules);
|
|
38
42
|
compileDev(tmsConfig, newModules, env);
|
|
39
43
|
}
|