@tmsfe/tmskit 0.0.12 → 0.0.15-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 +32 -0
- package/README.md +6 -1
- package/dist/index.cjs.js +667 -546
- package/main.js +0 -0
- package/package.json +6 -5
- package/src/compile/compile.js +131 -50
- package/src/compile/dev.js +64 -24
- package/src/compile/watch.js +46 -0
- package/src/core/buildAppJson.js +3 -0
- package/src/core/cloneModules.js +7 -3
- package/src/core/isInIt.js +2 -6
- package/src/core/mpCi.js +1 -1
- package/src/core/npm.js +9 -6
- package/src/core/symbolicLink.js +13 -7
- package/src/core/tmsMpconfig.js +13 -8
- package/src/entry.js +1 -1
- package/src/index.js +1 -4
- package/src/scripts/run/dev/index.js +12 -8
- package/src/scripts/run/index.js +11 -6
- package/src/scripts/run/init/index.js +26 -9
- package/src/scripts/run/install/index.js +2 -9
- package/src/utils/io.js +3 -2
- package/src/utils/log.js +5 -4
- package/src/utils/widgets.js +22 -5
package/main.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15-beta.0",
|
|
4
4
|
"description": "tmskit",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"bin": {
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
16
|
"dev": "rollup -wc --environment TARGET:tmskit",
|
|
17
|
-
"build": "rollup -c --environment TARGET:tmskit"
|
|
17
|
+
"build": "rollup -c --environment TARGET:tmskit",
|
|
18
|
+
"pub:patch": "sh build/publish.sh patch",
|
|
19
|
+
"pub:minor": "sh build/publish.sh minor",
|
|
20
|
+
"pub:major": "sh build/publish.sh major"
|
|
18
21
|
},
|
|
19
22
|
"author": "tms·web",
|
|
20
23
|
"license": "ISC",
|
|
@@ -43,9 +46,6 @@
|
|
|
43
46
|
"fs-extra": "^10.0.1",
|
|
44
47
|
"glob-ignore": "^1.0.2",
|
|
45
48
|
"gulp": "^4.0.2",
|
|
46
|
-
"gulp-cache": "^1.1.3",
|
|
47
|
-
"gulp-postcss": "^9.0.1",
|
|
48
|
-
"gulp-px-to-rpx": "^1.0.7",
|
|
49
49
|
"gulp-watch": "^5.0.1",
|
|
50
50
|
"htmlparser2": "^7.2.0",
|
|
51
51
|
"inquirer": "^7.3.3",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"lodash": "^4.17.21",
|
|
54
54
|
"metalsmith": "^2.3.0",
|
|
55
55
|
"miniprogram-ci": "1.4.13",
|
|
56
|
+
"moment": "^2.29.1",
|
|
56
57
|
"object-assign": "^4.0.1",
|
|
57
58
|
"ora": "^5.1.0",
|
|
58
59
|
"plugin-error": "^1.0.0",
|
package/src/compile/compile.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const { src, dest
|
|
2
|
-
const px2rpx = require('gulp-px-to-rpx');
|
|
3
|
-
const watch = require('gulp-watch');
|
|
1
|
+
const { src, dest } = require('gulp');
|
|
2
|
+
// const px2rpx = require('gulp-px-to-rpx');
|
|
4
3
|
// const cache = require('gulp-cache');
|
|
5
4
|
// const image = require('gulp-image');
|
|
6
5
|
// const replaceEnv = require('./plugins/replaceEnv');
|
|
@@ -11,7 +10,7 @@ const { mpWxmlDep } = require('./plugins/mpWxmlDep');
|
|
|
11
10
|
// const base64 = require('./plugins/postcss-font-base64');
|
|
12
11
|
const { fail } = require('../utils/log');
|
|
13
12
|
|
|
14
|
-
const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
|
|
13
|
+
// const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
|
|
15
14
|
module.exports = function (
|
|
16
15
|
tmsConfig,
|
|
17
16
|
{
|
|
@@ -19,72 +18,154 @@ module.exports = function (
|
|
|
19
18
|
destPath,
|
|
20
19
|
srcOption,
|
|
21
20
|
module,
|
|
22
|
-
|
|
23
|
-
isWatch,
|
|
21
|
+
isDev,
|
|
24
22
|
},
|
|
25
23
|
) {
|
|
24
|
+
const compileTasksMap = new Map();
|
|
26
25
|
Object.keys(glob).forEach((globKey) => {
|
|
27
26
|
const globValue = glob[globKey];
|
|
28
|
-
const task = () => src(globValue, { ...srcOption, since: since(task) });
|
|
29
|
-
let srcPipe = task();
|
|
30
|
-
|
|
31
|
-
if (isWatch) {
|
|
32
|
-
srcPipe = srcPipe.pipe(watch(globValue, watchOption));
|
|
33
|
-
}
|
|
34
27
|
|
|
35
28
|
switch (globKey) {
|
|
36
29
|
case 'js':
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
compileTasksMap.set(
|
|
31
|
+
globValue,
|
|
32
|
+
{
|
|
33
|
+
module,
|
|
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
|
+
return srcPipe
|
|
39
|
+
// .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
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 }))
|
|
45
|
+
.on('error', (err) => {
|
|
46
|
+
fail(`js编译报错${err}`);
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
);
|
|
44
51
|
break;
|
|
45
52
|
case 'wxss':
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
);
|
|
60
81
|
break;
|
|
61
82
|
case 'json':
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
);
|
|
68
103
|
break;
|
|
69
104
|
case 'wxml':
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
+
);
|
|
73
125
|
break;
|
|
74
126
|
case 'image':
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
+
);
|
|
81
147
|
break;
|
|
82
148
|
case 'other':
|
|
83
|
-
|
|
84
|
-
|
|
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
|
+
);
|
|
85
165
|
break;
|
|
86
166
|
default:
|
|
87
167
|
break;
|
|
88
168
|
}
|
|
89
169
|
});
|
|
170
|
+
return compileTasksMap;
|
|
90
171
|
};
|
package/src/compile/dev.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs');
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
3
|
+
const ora = require('ora');
|
|
4
|
+
const { parallel, series } = require('gulp');
|
|
5
|
+
const { resolve, mergeMap } = require('../utils/widgets');
|
|
5
6
|
const { buildOutputAppJson } = require('../core/buildAppJson');
|
|
6
7
|
const { DEFAULT_COPY_CONFIG } = require('../config/constant');
|
|
7
8
|
const compile = require('./compile');
|
|
9
|
+
const watch = require('./watch');
|
|
10
|
+
const { info } = require('../utils/log');
|
|
8
11
|
|
|
12
|
+
const watchEvents = ['add', 'change', 'unlink', 'unlinkDir'];
|
|
9
13
|
function excludeGlob(glob) {
|
|
10
14
|
const otherArr = new Set();
|
|
11
15
|
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
@@ -31,29 +35,32 @@ function adaptPath(pathDir) {
|
|
|
31
35
|
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
32
36
|
return newPath;
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
39
|
+
const compileTasksMap = new Map();
|
|
36
40
|
// 监听app.json
|
|
37
|
-
if (
|
|
38
|
-
watch(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
if (isDev) {
|
|
42
|
+
watch(
|
|
43
|
+
[resolve('app.json')],
|
|
44
|
+
{ ignoreInitial: false, events: watchEvents },
|
|
45
|
+
() => buildOutputAppJson(tmsConfig, newModules, isDev),
|
|
46
|
+
{ from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
47
|
+
);
|
|
41
48
|
} else {
|
|
42
|
-
buildOutputAppJson(tmsConfig, newModules,
|
|
49
|
+
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
// 监听根目录的文件
|
|
46
|
-
compile(tmsConfig, {
|
|
53
|
+
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
47
54
|
glob: {
|
|
48
55
|
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
49
56
|
// wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
50
57
|
// js: ['app.js', 'app.ts'].map(item => resolve(item)),
|
|
51
58
|
},
|
|
52
|
-
module: { from:
|
|
59
|
+
module: { from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
53
60
|
destPath: resolve(tmsConfig.outputDir),
|
|
54
61
|
srcOption: { allowEmpty: true },
|
|
55
|
-
|
|
56
|
-
});
|
|
62
|
+
isDev,
|
|
63
|
+
}));
|
|
57
64
|
|
|
58
65
|
// 监听模块的文件
|
|
59
66
|
for (let module of newModules) {
|
|
@@ -62,25 +69,28 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
|
62
69
|
...{ exclude: [] },
|
|
63
70
|
...module,
|
|
64
71
|
};
|
|
72
|
+
const modulePath = adaptPath(module.path);
|
|
65
73
|
|
|
66
|
-
if (
|
|
74
|
+
if (isDev) {
|
|
67
75
|
// 监听模块配置文件
|
|
68
|
-
watch(
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
watch(
|
|
77
|
+
[`${modulePath}/**/module.config.json`],
|
|
78
|
+
{ events: watchEvents },
|
|
79
|
+
() => buildOutputAppJson(tmsConfig, newModules, isDev),
|
|
80
|
+
{ from: modulePath, to: modulePath },
|
|
81
|
+
);
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
74
|
-
const modulePath = adaptPath(module.path);
|
|
75
85
|
const glob = {
|
|
76
86
|
js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
77
|
-
json: [`${modulePath}/**/*.json`, ...excludes],
|
|
87
|
+
json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
|
|
78
88
|
wxss: [`${modulePath}/**/*.{less,wxss}`, ...excludes],
|
|
79
89
|
wxml: [`${modulePath}/**/*.wxml`, ...excludes],
|
|
80
90
|
image: [`${modulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes],
|
|
81
91
|
};
|
|
82
92
|
|
|
83
|
-
compile(tmsConfig, {
|
|
93
|
+
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
84
94
|
glob: {
|
|
85
95
|
...glob,
|
|
86
96
|
other: [`${modulePath}/**/*`, ...excludeGlob(glob)],
|
|
@@ -88,8 +98,8 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
|
88
98
|
destPath: resolve(tmsConfig.outputDir, module.root),
|
|
89
99
|
module: { from: module.path, to: module.root },
|
|
90
100
|
srcOption: { allowEmpty: true },
|
|
91
|
-
|
|
92
|
-
});
|
|
101
|
+
isDev,
|
|
102
|
+
}));
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
// 静态资源目录-拷贝
|
|
@@ -114,7 +124,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
|
114
124
|
}
|
|
115
125
|
|
|
116
126
|
const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
|
|
117
|
-
compile(tmsConfig, {
|
|
127
|
+
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
118
128
|
glob,
|
|
119
129
|
destPath: item.to,
|
|
120
130
|
module: {
|
|
@@ -122,8 +132,38 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
|
122
132
|
to: item.to,
|
|
123
133
|
},
|
|
124
134
|
srcOption: { allowEmpty: true },
|
|
125
|
-
|
|
135
|
+
isDev,
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let sTime;
|
|
141
|
+
let eTime;
|
|
142
|
+
const spinner = ora();
|
|
143
|
+
function start(cb) {
|
|
144
|
+
info('启动编译...');
|
|
145
|
+
spinner.start();
|
|
146
|
+
sTime = new Date().getTime();
|
|
147
|
+
cb();
|
|
148
|
+
}
|
|
149
|
+
function end(cb) {
|
|
150
|
+
if (isDev) {
|
|
151
|
+
compileTasksMap.forEach(({ taskFn, module }, globValue) => {
|
|
152
|
+
watch(globValue, { ignoreInitial: true, events: watchEvents }, taskFn, module);
|
|
126
153
|
});
|
|
127
154
|
}
|
|
155
|
+
eTime = new Date().getTime() - sTime;
|
|
156
|
+
if (typeof tmsConfig?.hooks?.afterCompile === 'function') {
|
|
157
|
+
tmsConfig?.hooks?.afterCompile({ isDev, tmsConfig, modules: newModules });
|
|
158
|
+
}
|
|
159
|
+
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
|
|
160
|
+
spinner.stop();
|
|
161
|
+
cb();
|
|
128
162
|
}
|
|
163
|
+
|
|
164
|
+
const compileTasks = [];
|
|
165
|
+
compileTasksMap.forEach(({ taskFn }) => {
|
|
166
|
+
compileTasks.push(taskFn);
|
|
167
|
+
});
|
|
168
|
+
series(start, parallel(...compileTasks), end)();
|
|
129
169
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const watch = require('gulp-watch');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const shellJs = require('shelljs');
|
|
4
|
+
const { info, warn } = require('../utils/log');
|
|
5
|
+
const { resolve } = require('../utils/widgets');
|
|
6
|
+
const { global } = require('../utils/global');
|
|
7
|
+
|
|
8
|
+
const TIP_MAP = {
|
|
9
|
+
'package.json': '若依赖有变动,请重新执行tmskit run dev',
|
|
10
|
+
'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const logTip = (fileName, tipMap) => {
|
|
14
|
+
// eslint-disable-next-line
|
|
15
|
+
for (const item in tipMap) {
|
|
16
|
+
if (fileName.indexOf(item) > -1) {
|
|
17
|
+
warn(`${fileName}有更新, ${tipMap[item]}`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
info(`${fileName}有更新`);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
module.exports = function (globValue, watchOptions, callback, module) {
|
|
25
|
+
watch(globValue, {
|
|
26
|
+
// readDelay: 100,
|
|
27
|
+
...watchOptions,
|
|
28
|
+
}, (vinyl) => {
|
|
29
|
+
const sourceFile = vinyl.history[0];
|
|
30
|
+
const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
|
|
31
|
+
const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
|
|
32
|
+
|
|
33
|
+
const tmsConfig = global.getData('tmsConfig');
|
|
34
|
+
const sourceFileRelativeModule = path.relative(resolve(module.from), sourceFile);
|
|
35
|
+
const targetFile = resolve(tmsConfig.outputDir, module.to, sourceFileRelativeModule);
|
|
36
|
+
|
|
37
|
+
if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
|
|
38
|
+
info(`删除${sourceFileName}`);
|
|
39
|
+
shellJs.rm('-rf', targetFile);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
logTip(sourceFileName, TIP_MAP);
|
|
44
|
+
return callback([sourceFile], path.dirname(targetFile));
|
|
45
|
+
});
|
|
46
|
+
};
|
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/core/cloneModules.js
CHANGED
|
@@ -21,7 +21,9 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
21
21
|
const tmsPrivateCf = global.getData('tmsPrivateCf');
|
|
22
22
|
|
|
23
23
|
let gitUrl = httpRepoUrl;
|
|
24
|
-
const { username = '', pass = '' } = tmsPrivateCf?.gitAccout?.[moduleName]
|
|
24
|
+
const { username = '', pass = '' } = tmsPrivateCf?.gitAccout?.[moduleName]
|
|
25
|
+
|| tmsPrivateCf?.gitAccount?.[moduleName]
|
|
26
|
+
|| {};
|
|
25
27
|
|
|
26
28
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
27
29
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -74,6 +76,7 @@ function md5ByGitUrlBranch(gitUrl, branch) {
|
|
|
74
76
|
* @returns { array } modules 描述模块的列表
|
|
75
77
|
*/
|
|
76
78
|
async function cloneModules(sourceDir, targetDir, modules) {
|
|
79
|
+
const cwd = process.cwd();
|
|
77
80
|
// 收集下载模块代码的任务
|
|
78
81
|
const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules);
|
|
79
82
|
|
|
@@ -94,6 +97,7 @@ async function cloneModules(sourceDir, targetDir, modules) {
|
|
|
94
97
|
});
|
|
95
98
|
|
|
96
99
|
await Promise.all(arrPromises);
|
|
100
|
+
shelljs.cd(cwd);
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
/**
|
|
@@ -154,12 +158,12 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
154
158
|
let promiseTask;
|
|
155
159
|
if (fs.existsSync(sourcePath) && fs.existsSync(`${sourcePath}/.git`)) {
|
|
156
160
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
157
|
-
info(`git pull
|
|
161
|
+
info(`git pull:${httpRepoUrl}`);
|
|
158
162
|
return pullRepoForGit(sourcePath, branch);
|
|
159
163
|
};
|
|
160
164
|
} else {
|
|
161
165
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
162
|
-
info(`git clone
|
|
166
|
+
info(`git clone: ${httpRepoUrl}`);
|
|
163
167
|
return downloadRepoForGit(gitUrl, sourcePath, branch);
|
|
164
168
|
};
|
|
165
169
|
}
|
package/src/core/isInIt.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const { resolve } = require('../utils/widgets');
|
|
3
|
-
const {
|
|
3
|
+
const { MODULE_CODE_DIR } = require('../config/constant');
|
|
4
4
|
const { checkRemoteModGitUrlBranch } = require('./cloneModules');
|
|
5
5
|
const { checkDependencies } = require('./checkDependencies');
|
|
6
6
|
const { fail } = require('../utils/log');
|
|
7
7
|
|
|
8
|
-
function checkModule(targetModules
|
|
8
|
+
function checkModule(targetModules) {
|
|
9
9
|
// 判断\源码\dist\是否存在用户指定的模块
|
|
10
10
|
for (const item of targetModules) {
|
|
11
11
|
// 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
|
|
12
12
|
if (!item.root) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
|
-
// 判断dist目录是否有该模块
|
|
16
|
-
if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
15
|
|
|
20
16
|
// 判断第三方远程模块git地址与branch是否有更新
|
|
21
17
|
if (checkRemoteModGitUrlBranch(MODULE_CODE_DIR, item)) {
|
package/src/core/mpCi.js
CHANGED
package/src/core/npm.js
CHANGED
|
@@ -10,7 +10,6 @@ const glob = require('glob-ignore');
|
|
|
10
10
|
const log = require('../utils/log');
|
|
11
11
|
const { npmInstall } = require('../utils/widgets');
|
|
12
12
|
const { handleError } = require('./handleError');
|
|
13
|
-
const { info } = require('console');
|
|
14
13
|
|
|
15
14
|
const shellJsOption = { async: false, silent: true };
|
|
16
15
|
const dirPath = process.cwd(); // 项目根目录
|
|
@@ -52,8 +51,9 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
52
51
|
...shellJsOption,
|
|
53
52
|
cwd: packageJsonDir,
|
|
54
53
|
};
|
|
55
|
-
shell.
|
|
56
|
-
shell.exec('
|
|
54
|
+
shell.cd(packageJsonDir);
|
|
55
|
+
shell.exec('tar -xvf ./node_modules.tar.gz -C ./', newShellJsOption);
|
|
56
|
+
shell.rm('-rf', './node_modules.tar.gz');
|
|
57
57
|
},
|
|
58
58
|
};
|
|
59
59
|
|
|
@@ -70,14 +70,15 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
70
70
|
promiseTask = (packageJsonPath, cacheNMPath, shell) => {
|
|
71
71
|
fsExtra.emptydirSync(cacheNMPath);
|
|
72
72
|
shell.cp('-f', packageJsonPath, cacheNMPath);
|
|
73
|
-
info(`npm install: ${packageJsonPath}`);
|
|
73
|
+
log.info(`npm install: ${packageJsonPath}`);
|
|
74
74
|
return npmInstall(cacheNMPath).then(() => {
|
|
75
75
|
const newShellJsOption = {
|
|
76
76
|
...shellJsOption,
|
|
77
77
|
cwd: cacheNMPath,
|
|
78
78
|
};
|
|
79
|
-
shell.
|
|
80
|
-
shell.exec('
|
|
79
|
+
shell.cd(cacheNMPath);
|
|
80
|
+
shell.exec('tar -cvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
|
|
81
|
+
shell.rm('-rf', './node_modules');
|
|
81
82
|
});
|
|
82
83
|
};
|
|
83
84
|
}
|
|
@@ -99,6 +100,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
99
100
|
|
|
100
101
|
// 遍历安装指定目录下所有项目的npm依赖
|
|
101
102
|
const mpNpmInstallAll = async (modules, contextDir, cacheDir) => {
|
|
103
|
+
const cwd = process.cwd();
|
|
102
104
|
const packageJsonFiles = await findAllPackageJson(modules, contextDir);
|
|
103
105
|
|
|
104
106
|
// 收集npm install的任务
|
|
@@ -121,6 +123,7 @@ const mpNpmInstallAll = async (modules, contextDir, cacheDir) => {
|
|
|
121
123
|
});
|
|
122
124
|
|
|
123
125
|
await Promise.all(arrPromises);
|
|
126
|
+
shell.cd(cwd);
|
|
124
127
|
};
|
|
125
128
|
|
|
126
129
|
/**
|
package/src/core/symbolicLink.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const { resolve } = require('../utils/widgets');
|
|
3
3
|
const { handleError } = require('./handleError');
|
|
4
|
-
const {
|
|
4
|
+
const { ensureDirExist } = require('../utils/io');
|
|
5
|
+
const { warn } = require('../utils/log');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 根据相关配置创建软链接
|
|
@@ -9,14 +10,19 @@ const { DEFAULT_CLOUD_MODULE_DIR } = require('../config/constant');
|
|
|
9
10
|
*/
|
|
10
11
|
const symLink = (tmsConfig) => {
|
|
11
12
|
try {
|
|
13
|
+
ensureDirExist(resolve(tmsConfig.cloudDir));
|
|
12
14
|
if (tmsConfig.cloudModules) {
|
|
13
15
|
tmsConfig.cloudModules.forEach((item) => {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
16
|
+
const sourcePath = resolve(item.path);
|
|
17
|
+
const targetPath = resolve(tmsConfig.cloudDir, item.name);
|
|
18
|
+
|
|
19
|
+
if (!fs.existsSync(sourcePath)) {
|
|
20
|
+
warn(`云函数${sourcePath}不存在`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!fs.existsSync(targetPath)) {
|
|
24
|
+
fs.symlinkSync(sourcePath, targetPath);
|
|
25
|
+
}
|
|
20
26
|
});
|
|
21
27
|
}
|
|
22
28
|
} catch (e) {
|