@tmsfe/tmskit 0.0.4 → 0.0.5-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/dist/index.cjs.js +703 -948
- package/package.json +9 -5
- package/src/config/constant.js +1 -1
- package/src/config/defaultTmsConfig.js +3 -4
- package/src/entry.js +48 -8
- package/src/gulp/build.js +78 -0
- package/src/gulp/dev.js +94 -0
- package/src/gulp/replaceEnv.js +28 -0
- package/src/index.js +26 -10
- package/src/init.js +0 -5
- package/src/scripts/run/build/index.js +3 -3
- package/src/scripts/run/dev/index.js +3 -3
- package/src/scripts/run/index.js +7 -7
- package/src/scripts/run/init/index.js +12 -29
- package/src/scripts/run/install/index.js +21 -29
- package/src/utils/buildAppJson.js +1 -1
- package/src/utils/entry.js +150 -0
- package/src/utils/npmUtils.js +23 -4
- package/src/webpack/base.js +0 -65
- package/src/webpack/build.js +0 -21
- package/src/webpack/buildServer.js +0 -34
- package/src/webpack/dev.js +0 -31
- package/src/webpack/devServer.js +0 -37
- package/src/webpack/plugins/entryExtractPlugin/index.js +0 -28
- package/src/webpack/utils.js +0 -244
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5-beta.0",
|
|
4
4
|
"description": "tmskit",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"bin": {
|
|
@@ -31,22 +31,26 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"async": "^3.2.2",
|
|
33
33
|
"chalk": "^4.1.0",
|
|
34
|
-
"commander": "^
|
|
34
|
+
"commander": "^8.3.0",
|
|
35
35
|
"copy-webpack-plugin": "^9.1.0",
|
|
36
36
|
"download-git-repo": "^3.0.2",
|
|
37
37
|
"ejs": "^3.1.5",
|
|
38
38
|
"glob-ignore": "^1.0.2",
|
|
39
|
+
"gulp": "^4.0.2",
|
|
40
|
+
"gulp-less": "^5.0.0",
|
|
41
|
+
"gulp-px-to-rpx": "^1.0.7",
|
|
42
|
+
"gulp-rename": "^2.0.0",
|
|
43
|
+
"gulp-watch": "^5.0.1",
|
|
39
44
|
"inquirer": "^7.3.3",
|
|
40
45
|
"leven": "3.1.0",
|
|
41
46
|
"lodash": "^4.17.21",
|
|
42
47
|
"metalsmith": "^2.3.0",
|
|
43
48
|
"miniprogram-ci": "1.4.13",
|
|
44
49
|
"ora": "^5.1.0",
|
|
50
|
+
"precinct": "^8.3.1",
|
|
45
51
|
"replace-ext": "^2.0.0",
|
|
46
52
|
"shelljs": "^0.8.4",
|
|
47
|
-
"
|
|
48
|
-
"webpack": "^5.64.0",
|
|
49
|
-
"webpack-chain": "^6.5.1"
|
|
53
|
+
"through2": "^4.0.2"
|
|
50
54
|
},
|
|
51
55
|
"engines": {
|
|
52
56
|
"node": "^12.17.0 || >= 14.0.0"
|
package/src/config/constant.js
CHANGED
|
@@ -34,7 +34,7 @@ const DEFAULT_WEBPACK_ENTRY = {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
// 默认从源码拷贝到编译后的配置
|
|
37
|
-
const DEFAULT_COPY_CONFIG = ['package.json', '
|
|
37
|
+
const DEFAULT_COPY_CONFIG = ['package.json', 'sitemap.json'];
|
|
38
38
|
|
|
39
39
|
// 开发模式
|
|
40
40
|
const MODE = {
|
|
@@ -4,14 +4,13 @@ module.exports = {
|
|
|
4
4
|
envData: {},
|
|
5
5
|
// 模块配置信息
|
|
6
6
|
modules: [],
|
|
7
|
-
|
|
7
|
+
cloudDir: 'cloud',
|
|
8
|
+
gulp: {
|
|
8
9
|
/** 编译输出文件夹位置 */
|
|
9
10
|
outputDir: 'dist',
|
|
10
11
|
/** 源码监听路径 */
|
|
11
12
|
sourceDir: './',
|
|
12
13
|
/** 源码Map */
|
|
13
|
-
|
|
14
|
-
/** 别名 */
|
|
15
|
-
alias: {},
|
|
14
|
+
copyDir: [],
|
|
16
15
|
},
|
|
17
16
|
};
|
package/src/entry.js
CHANGED
|
@@ -7,14 +7,54 @@ module.exports = [
|
|
|
7
7
|
},
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
name: 'run',
|
|
11
|
+
type: 'child',
|
|
12
|
+
description: '项目开发使用的命令',
|
|
13
|
+
commands: [
|
|
14
|
+
{
|
|
15
|
+
command: 'install',
|
|
16
|
+
description: '安装依赖',
|
|
17
|
+
options: [
|
|
18
|
+
['-m, --module [moduleName]', '模块名称'],
|
|
19
|
+
['-e, --env [env]', '环境变量'],
|
|
20
|
+
],
|
|
21
|
+
action: (cmd) => {
|
|
22
|
+
require('./scripts/run/index')('install', cmd);
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
command: 'dev',
|
|
27
|
+
description: 'dev 打包编译',
|
|
28
|
+
options: [
|
|
29
|
+
['-m, --module [moduleName]', '模块名称'],
|
|
30
|
+
['-e, --env [env]', '环境变量'],
|
|
31
|
+
],
|
|
32
|
+
action: (cmd) => {
|
|
33
|
+
require('./scripts/run/index')('dev', cmd);
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
command: 'build',
|
|
38
|
+
description: 'prod 打包编译',
|
|
39
|
+
options: [
|
|
40
|
+
['-m, --module [moduleName]', '模块名称'],
|
|
41
|
+
['-e, --env [env]', '环境变量'],
|
|
42
|
+
],
|
|
43
|
+
action: (cmd) => {
|
|
44
|
+
require('./scripts/run/index')('build', cmd);
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
command: 'init',
|
|
49
|
+
description: '根据模块配置初始化项目(eg: 动态拷贝模块、下载依赖、生成app.json等)',
|
|
50
|
+
options: [
|
|
51
|
+
['-m, --module [moduleName]', '模块名称'],
|
|
52
|
+
['-e, --env [env]', '环境变量'],
|
|
53
|
+
],
|
|
54
|
+
action: (cmd) => {
|
|
55
|
+
require('./scripts/run/index')('init', cmd);
|
|
56
|
+
},
|
|
57
|
+
},
|
|
14
58
|
],
|
|
15
|
-
description: '运行模块',
|
|
16
|
-
action: (commandName, cmd) => {
|
|
17
|
-
require('./scripts/run/index')(commandName, cmd);
|
|
18
|
-
},
|
|
19
59
|
},
|
|
20
60
|
];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const { src, dest } = require('gulp');
|
|
3
|
+
const px2rpx = require('gulp-px-to-rpx');
|
|
4
|
+
const less = require('gulp-less');
|
|
5
|
+
const rename = require('gulp-rename');
|
|
6
|
+
const { resolve } = require('../utils/widgets');
|
|
7
|
+
const { buildOutputAppJson } = require('../utils/buildAppJson');
|
|
8
|
+
const { DEFAULT_COPY_CONFIG } = require('../config/constant');
|
|
9
|
+
const replaceEnv = require('./replaceEnv');
|
|
10
|
+
|
|
11
|
+
module.exports = async (tmsConfig, newModules) => {
|
|
12
|
+
// app.json
|
|
13
|
+
buildOutputAppJson(tmsConfig, newModules);
|
|
14
|
+
|
|
15
|
+
// 监听根目录的文件
|
|
16
|
+
DEFAULT_COPY_CONFIG.forEach((item) => {
|
|
17
|
+
if (fs.existsSync(resolve(item))) {
|
|
18
|
+
src(resolve(item))
|
|
19
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir)));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
src([resolve('app.less'), resolve('app.wxss')], { allowEmpty: true })
|
|
23
|
+
.pipe(less())
|
|
24
|
+
.pipe(px2rpx({
|
|
25
|
+
designWidth: 375, // 设计稿宽度,默认为750
|
|
26
|
+
precision: 2, // 小数最大精度,默认为6
|
|
27
|
+
}))
|
|
28
|
+
.pipe(rename({ extname: '.wxss' }))
|
|
29
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir)));
|
|
30
|
+
|
|
31
|
+
src([resolve('app.js'), resolve('app.ts')], { allowEmpty: true })
|
|
32
|
+
.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
33
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir)));
|
|
34
|
+
|
|
35
|
+
// 监听模块的文件
|
|
36
|
+
for (const module of newModules) {
|
|
37
|
+
// 监听模块js文件
|
|
38
|
+
src([
|
|
39
|
+
`${resolve(module.path)}/**/*.js`,
|
|
40
|
+
`${resolve(module.path)}/**/*.ts`,
|
|
41
|
+
`${resolve(module.path)}/**/*.wxs`,
|
|
42
|
+
])
|
|
43
|
+
.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
44
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
|
|
45
|
+
|
|
46
|
+
// 监听json文件
|
|
47
|
+
src([
|
|
48
|
+
`${resolve(module.path)}/**/*.json`,
|
|
49
|
+
])
|
|
50
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
|
|
51
|
+
|
|
52
|
+
// 监听css文件
|
|
53
|
+
src([
|
|
54
|
+
`${resolve(module.path)}/**/*.less`,
|
|
55
|
+
`${resolve(module.path)}/**/*.wxss`,
|
|
56
|
+
])
|
|
57
|
+
.pipe(less())
|
|
58
|
+
.pipe(px2rpx({
|
|
59
|
+
designWidth: 375, // 设计稿宽度,默认为750
|
|
60
|
+
precision: 2, // 小数最大精度,默认为6
|
|
61
|
+
}))
|
|
62
|
+
.pipe(rename({ extname: '.wxss' }))
|
|
63
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
|
|
64
|
+
|
|
65
|
+
// 监听wxml文件
|
|
66
|
+
src([
|
|
67
|
+
`${resolve(module.path)}/**/*.wxml`,
|
|
68
|
+
])
|
|
69
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
|
|
70
|
+
}
|
|
71
|
+
// 监听copy模块
|
|
72
|
+
if (tmsConfig?.gulp?.copyDir.length > 0) {
|
|
73
|
+
for (const item of tmsConfig.gulp?.copyDir) {
|
|
74
|
+
src([item.from])
|
|
75
|
+
.pipe(dest(item.to));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
package/src/gulp/dev.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const { src, dest } = require('gulp');
|
|
3
|
+
const px2rpx = require('gulp-px-to-rpx');
|
|
4
|
+
const less = require('gulp-less');
|
|
5
|
+
const rename = require('gulp-rename');
|
|
6
|
+
const watch = require('gulp-watch');
|
|
7
|
+
const { resolve } = require('../utils/widgets');
|
|
8
|
+
const { buildOutputAppJson } = require('../utils/buildAppJson');
|
|
9
|
+
const { DEFAULT_COPY_CONFIG } = require('../config/constant');
|
|
10
|
+
const replaceEnv = require('./replaceEnv');
|
|
11
|
+
|
|
12
|
+
module.exports = async (tmsConfig, newModules) => {
|
|
13
|
+
// 监听app.json
|
|
14
|
+
watch(resolve('app.json'), { ignoreInitial: false, events: ['add', 'change'] }, () => {
|
|
15
|
+
buildOutputAppJson(tmsConfig, newModules);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// 监听根目录的文件
|
|
19
|
+
DEFAULT_COPY_CONFIG.forEach((item) => {
|
|
20
|
+
if (fs.existsSync(resolve(item))) {
|
|
21
|
+
src(resolve(item))
|
|
22
|
+
.pipe(watch(resolve(item), { events: ['change'] }))
|
|
23
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir)));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
src([resolve('app.less'), resolve('app.wxss')], { allowEmpty: true })
|
|
27
|
+
.pipe(watch(`${resolve()}/(app.less|app.wxss)`, { events: ['change'] }))
|
|
28
|
+
.pipe(less())
|
|
29
|
+
.pipe(px2rpx({
|
|
30
|
+
designWidth: 375, // 设计稿宽度,默认为750
|
|
31
|
+
precision: 2, // 小数最大精度,默认为6
|
|
32
|
+
}))
|
|
33
|
+
.pipe(rename({ extname: '.wxss' }))
|
|
34
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir)));
|
|
35
|
+
|
|
36
|
+
src([resolve('app.js'), resolve('app.ts')], { allowEmpty: true })
|
|
37
|
+
.pipe(watch(`${resolve()}/(app.js|app.ts)`, { events: ['change'] }))
|
|
38
|
+
.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
39
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir)));
|
|
40
|
+
|
|
41
|
+
// 监听模块的文件
|
|
42
|
+
for (const module of newModules) {
|
|
43
|
+
// 监听模块js文件
|
|
44
|
+
src([
|
|
45
|
+
`${resolve(module.path)}/**/*.js`,
|
|
46
|
+
`${resolve(module.path)}/**/*.ts`,
|
|
47
|
+
`${resolve(module.path)}/**/*.wxs`,
|
|
48
|
+
])
|
|
49
|
+
.pipe(watch(`${resolve(module.path)}/**/(*.js|*.ts|*.wxs)`, { events: ['add', 'change'] }))
|
|
50
|
+
.pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
|
|
51
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
|
|
52
|
+
|
|
53
|
+
// 监听json文件
|
|
54
|
+
src([
|
|
55
|
+
`${resolve(module.path)}/**/*.json`,
|
|
56
|
+
])
|
|
57
|
+
.pipe(watch(`${resolve(module.path)}/**/*.json`, { events: ['add', 'change'] }))
|
|
58
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
|
|
59
|
+
|
|
60
|
+
// 监听css文件
|
|
61
|
+
src([
|
|
62
|
+
`${resolve(module.path)}/**/*.less`,
|
|
63
|
+
`${resolve(module.path)}/**/*.wxss`,
|
|
64
|
+
])
|
|
65
|
+
.pipe(watch(`${resolve(module.path)}/**/(*.less|*.wxss)`, { events: ['add', 'change'] }))
|
|
66
|
+
.pipe(less())
|
|
67
|
+
.pipe(px2rpx({
|
|
68
|
+
designWidth: 375, // 设计稿宽度,默认为750
|
|
69
|
+
precision: 2, // 小数最大精度,默认为6
|
|
70
|
+
}))
|
|
71
|
+
.pipe(rename({ extname: '.wxss' }))
|
|
72
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
|
|
73
|
+
|
|
74
|
+
// 监听wxml文件
|
|
75
|
+
src([
|
|
76
|
+
`${resolve(module.path)}/**/*.wxml`,
|
|
77
|
+
])
|
|
78
|
+
.pipe(watch(`${resolve(module.path)}/**/*.wxml`, { events: ['add', 'change'] }))
|
|
79
|
+
.pipe(dest(resolve(tmsConfig.gulp.outputDir, module.root)));
|
|
80
|
+
|
|
81
|
+
// 监听模块配置文件
|
|
82
|
+
watch(`${resolve(module.path)}/**/module.config.json`, { events: ['change'] }, () => {
|
|
83
|
+
buildOutputAppJson(tmsConfig, newModules);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// 监听copy模块
|
|
87
|
+
if (tmsConfig?.gulp?.copyDir.length > 0) {
|
|
88
|
+
for (const item of tmsConfig.gulp?.copyDir) {
|
|
89
|
+
src([item.from])
|
|
90
|
+
.pipe(watch(item.from, { events: ['add', 'change'] }))
|
|
91
|
+
.pipe(dest(item.to));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const through = require('through2');
|
|
2
|
+
function replaceEnv(reg = /process\.env(\.(\w*))?/g, envData) {
|
|
3
|
+
const stream = through.obj(function (file, enc, cb) {
|
|
4
|
+
if (file.isBuffer()) {
|
|
5
|
+
let contents = String(file.contents);
|
|
6
|
+
let resReg;
|
|
7
|
+
// eslint-disable-next-line
|
|
8
|
+
while ((resReg = reg.exec(contents)) !== null) {
|
|
9
|
+
const [reg1, reg2, reg3] = resReg;
|
|
10
|
+
if (reg1 && reg2 && reg3) {
|
|
11
|
+
const value = typeof envData[reg3] === 'object' ? JSON.stringify(envData[reg3]) : envData[reg3];
|
|
12
|
+
contents = contents.replace(reg1, value);
|
|
13
|
+
} else if (reg1 && !reg2 && !reg3) {
|
|
14
|
+
contents = contents.replace(reg1, JSON.stringify(envData));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line
|
|
18
|
+
file.contents = new Buffer(contents);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
this.push(file);
|
|
22
|
+
cb();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return stream;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = replaceEnv;
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
|
-
const
|
|
2
|
+
const commander = require('commander');
|
|
3
3
|
const { log, suggestCommands } = require('./utils/widgets');
|
|
4
4
|
const { TMS_NAME } = require('./config/constant.js');
|
|
5
5
|
const commands = require('./entry');
|
|
@@ -7,24 +7,40 @@ const init = require('./init');
|
|
|
7
7
|
|
|
8
8
|
init();
|
|
9
9
|
|
|
10
|
+
const program = new commander.Command(TMS_NAME);
|
|
11
|
+
|
|
10
12
|
program
|
|
11
|
-
.version(`${TMS_NAME} ${require('../package.json').version}
|
|
13
|
+
.version(`${TMS_NAME} ${require('../package.json').version}`, '-v, -V, --version');
|
|
12
14
|
|
|
13
|
-
commands
|
|
14
|
-
|
|
15
|
+
function registerCommand(program, commands) {
|
|
16
|
+
commands.forEach((cmd) => {
|
|
17
|
+
if (cmd.type === 'child') {
|
|
18
|
+
const childProgram = new commander.Command(cmd.name);
|
|
19
|
+
cmd.usage && childProgram.usage(cmd.usage);
|
|
20
|
+
cmd.description && childProgram.description(cmd.description);
|
|
21
|
+
registerCommand(childProgram, cmd.commands);
|
|
15
22
|
|
|
16
|
-
|
|
23
|
+
program.addCommand(childProgram);
|
|
24
|
+
} else {
|
|
25
|
+
const command = program.command(cmd.command);
|
|
17
26
|
|
|
18
|
-
|
|
27
|
+
cmd.usage && command.usage(cmd.usage);
|
|
19
28
|
|
|
20
|
-
|
|
29
|
+
cmd.description && command.description(cmd.description);
|
|
30
|
+
|
|
31
|
+
cmd.options?.forEach(opt => command.option(...opt));
|
|
32
|
+
|
|
33
|
+
command.action(cmd.action);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
registerCommand(program, commands);
|
|
21
39
|
|
|
22
|
-
command.action(cmd.action);
|
|
23
|
-
});
|
|
24
40
|
|
|
25
41
|
program.on('--help', () => {
|
|
26
42
|
log();
|
|
27
|
-
log(` Run ${chalk.cyan(
|
|
43
|
+
log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
28
44
|
log();
|
|
29
45
|
});
|
|
30
46
|
|
package/src/init.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const { exec } = require('shelljs');
|
|
2
1
|
const semver = require('semver');
|
|
3
2
|
const packageJson = require('../package.json');
|
|
4
3
|
const chalk = require('chalk');
|
|
@@ -29,10 +28,6 @@ function initCliContext() {
|
|
|
29
28
|
// 执行操作前检查node版本
|
|
30
29
|
// 旧版本node直接提示升级,退出脚本
|
|
31
30
|
checkNodeVersion(requiredVersion, packName);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// 执行前配置正确的npm源
|
|
35
|
-
exec('npm config set registry https://mirrors.tencent.com/npm/ --global', { silent: true });
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
module.exports = initCliContext;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const shelljs = require('shelljs');
|
|
2
|
-
const webpackBuildServer = require('../../../webpack/buildServer');
|
|
3
2
|
const { resolve } = require('../../../utils/widgets');
|
|
4
3
|
const init = require('../init/index');
|
|
4
|
+
const gulpBuild = require('../../../gulp/build');
|
|
5
5
|
|
|
6
6
|
async function build(tmsConfig, targetModules, env) {
|
|
7
7
|
// 开始构建前,清理输出目录
|
|
8
|
-
await shelljs.rm('-rf', resolve(
|
|
8
|
+
await shelljs.rm('-rf', resolve(tmsConfig.gulp.outputDir));
|
|
9
9
|
|
|
10
10
|
const { targetModules: newModules } = await init(tmsConfig, targetModules);
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
gulpBuild(tmsConfig, newModules, env);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
module.exports = build;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const gulpDev = require('../../../gulp/dev');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const { resolve } = require('../../../utils/widgets');
|
|
4
4
|
const init = require('../init/index');
|
|
@@ -45,7 +45,7 @@ function isInit(tmsConfig, targetModules, contextDir) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// 判断package.json的版本是否有新的版本
|
|
48
|
-
return checkDependencies(targetModules, resolve('./'), tmsConfig.
|
|
48
|
+
return checkDependencies(targetModules, resolve('./'), tmsConfig.gulp.outputDir);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
async function dev(tmsConfig, targetModules, env) {
|
|
@@ -60,7 +60,7 @@ async function dev(tmsConfig, targetModules, env) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
console.log('当前dev启动的有效模块', newModules.map(item => item.name));
|
|
63
|
-
|
|
63
|
+
gulpDev(tmsConfig, newModules, env);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
module.exports = dev;
|
package/src/scripts/run/index.js
CHANGED
|
@@ -2,7 +2,7 @@ const init = require('./init/index');
|
|
|
2
2
|
const dev = require('./dev/index');
|
|
3
3
|
const build = require('./build/index');
|
|
4
4
|
const install = require('./install/index');
|
|
5
|
-
const { createTask
|
|
5
|
+
const { createTask } = require('../../utils/widgets');
|
|
6
6
|
const { MODE } = require('../../config/constant');
|
|
7
7
|
const { readTmsConfig, checkModules } = require('../../utils/tkitUtils');
|
|
8
8
|
|
|
@@ -12,10 +12,12 @@ const handleModulesArg = (cmd) => {
|
|
|
12
12
|
return MODE.main;
|
|
13
13
|
}
|
|
14
14
|
// 单模块 或 多模块开发
|
|
15
|
+
const { argv } = process;
|
|
16
|
+
const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
|
|
15
17
|
if (cmd.module) {
|
|
16
18
|
return [
|
|
17
19
|
cmd.module,
|
|
18
|
-
...
|
|
20
|
+
...reset,
|
|
19
21
|
];
|
|
20
22
|
}
|
|
21
23
|
// 全量模块
|
|
@@ -23,11 +25,6 @@ const handleModulesArg = (cmd) => {
|
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
async function run(commandName, cmd) {
|
|
26
|
-
if (commandName === 'install') {
|
|
27
|
-
install(resolve('./'));
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
28
|
const moduleArg = handleModulesArg(cmd);
|
|
32
29
|
const { env } = cmd;
|
|
33
30
|
|
|
@@ -52,6 +49,9 @@ async function run(commandName, cmd) {
|
|
|
52
49
|
case 'dev':
|
|
53
50
|
dev(tmsConfig, modules, env);
|
|
54
51
|
return;
|
|
52
|
+
case 'install':
|
|
53
|
+
install(tmsConfig, modules, env);
|
|
54
|
+
return;
|
|
55
55
|
case 'build':
|
|
56
56
|
build(tmsConfig, modules, env);
|
|
57
57
|
return;
|
|
@@ -3,44 +3,38 @@ const fs = require('fs');
|
|
|
3
3
|
const io = require('../../../utils/io');
|
|
4
4
|
const { resolve, createTask } = require('../../../utils/widgets');
|
|
5
5
|
const { buildOutputAppJson } = require('../../../utils/buildAppJson');
|
|
6
|
-
const {
|
|
7
|
-
const { buildMpNpm } = require('../../../utils/mpCiUtils');
|
|
8
|
-
const { MODULE_CODE_DIR, CACHE_DIR, DEFAULT_COPY_CONFIG, DEFAULT_MODULE_DIR } = require('../../../config/constant');
|
|
6
|
+
const { MODULE_CODE_DIR, DEFAULT_COPY_CONFIG, DEFAULT_MODULE_DIR } = require('../../../config/constant');
|
|
9
7
|
const { cloneModules } = require('../../../utils/cloneModules');
|
|
10
8
|
const { tmsModulesMergeLocalModuleCfg } = require('../../../utils/tkitUtils');
|
|
11
9
|
const { fail } = require('../../../utils/log');
|
|
10
|
+
const install = require('../install');
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* 拷贝相关配置文件到编译输出目录
|
|
15
14
|
* @param { object } tmsConfig
|
|
16
15
|
* @param { array } modules
|
|
17
16
|
* @param { array } defaultFiles 默认需要拷贝的配置项
|
|
18
17
|
* @returns
|
|
19
18
|
*/
|
|
20
19
|
const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
21
|
-
const outputDir = resolve(tmsConfig.
|
|
20
|
+
const outputDir = resolve(tmsConfig.gulp.outputDir);
|
|
22
21
|
io.ensureDirExist(outputDir);
|
|
23
22
|
defaultFiles.forEach((item) => {
|
|
24
23
|
if (fs.existsSync(resolve(item))) {
|
|
25
|
-
shelljs.cp('-rf', resolve(item), resolve(tmsConfig.
|
|
24
|
+
shelljs.cp('-rf', resolve(item), resolve(tmsConfig.gulp.outputDir, item));
|
|
26
25
|
}
|
|
27
26
|
});
|
|
28
27
|
|
|
29
|
-
//
|
|
28
|
+
// 拷贝模块的package.json到编译输出目录
|
|
30
29
|
targetModules.forEach((item) => {
|
|
31
|
-
const outputModuleDir = resolve(`${tmsConfig.
|
|
30
|
+
const outputModuleDir = resolve(`${tmsConfig.gulp.outputDir}/${item.root}`);
|
|
32
31
|
if (!fs.existsSync(resolve(item.path))) {
|
|
33
32
|
fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
34
33
|
process.exit(1);
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// 删除除了node_modules、miniprogram_npm 的其他文件
|
|
40
|
-
// eslint-disable-next-line
|
|
41
|
-
shelljs.exec('find . -not \( -name node_modules -or -name miniprogram_npm \) -delete', { silent: true });
|
|
42
|
-
}
|
|
43
|
-
shelljs.cp('-Rf', `${resolve(item.path)}/*`, outputModuleDir);
|
|
35
|
+
io.ensureDirExist(outputModuleDir);
|
|
36
|
+
const modulePackagePath = resolve(item.path, 'package.json');
|
|
37
|
+
if (fs.existsSync(modulePackagePath)) shelljs.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
44
38
|
});
|
|
45
39
|
};
|
|
46
40
|
|
|
@@ -63,19 +57,8 @@ async function task(tmsConfig, targetModules) {
|
|
|
63
57
|
'拷贝文件到编译输出目录完成',
|
|
64
58
|
)(tmsConfig, newModules, DEFAULT_COPY_CONFIG);
|
|
65
59
|
|
|
66
|
-
//
|
|
67
|
-
await
|
|
68
|
-
npmInstallAll,
|
|
69
|
-
'开始npm install',
|
|
70
|
-
'npm install 完成',
|
|
71
|
-
)(newModules, resolve(tmsConfig.webpack.outputDir), `${CACHE_DIR}/node_modules`);
|
|
72
|
-
|
|
73
|
-
// 构建miniprograme_npm
|
|
74
|
-
await createTask(
|
|
75
|
-
buildMpNpm,
|
|
76
|
-
'开始构建miniprograme_npm',
|
|
77
|
-
'构建miniprograme_npm 完成',
|
|
78
|
-
)({ appId: tmsConfig.appId, projectPath: resolve('./'), privateKey: tmsConfig.privateKey });
|
|
60
|
+
// install
|
|
61
|
+
await install(tmsConfig, newModules, false);
|
|
79
62
|
|
|
80
63
|
// 动态生成编译后的app.json;
|
|
81
64
|
await createTask(
|
|
@@ -1,39 +1,31 @@
|
|
|
1
|
-
const
|
|
2
|
-
const { createTask } = require('../../../utils/widgets');
|
|
1
|
+
const { createTask, resolve } = require('../../../utils/widgets');
|
|
3
2
|
const { buildMpNpm } = require('../../../utils/mpCiUtils');
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
const { CACHE_DIR, DEFAULT_MODULE_DIR } = require('../../../config/constant');
|
|
4
|
+
const { cloudNpmInstall, mpNpmInstallAll } = require('../../../utils/npmUtils');
|
|
5
|
+
const { tmsModulesMergeLocalModuleCfg } = require('../../../utils/tkitUtils');
|
|
6
6
|
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (err) {
|
|
11
|
-
reject(err);
|
|
12
|
-
}
|
|
13
|
-
files.forEach((file) => {
|
|
14
|
-
const dir = path.dirname(file);
|
|
15
|
-
shelljs.cd(dir);
|
|
16
|
-
shelljs.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', { silent: false });
|
|
17
|
-
});
|
|
18
|
-
resolve();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function install(contextDir) {
|
|
24
|
-
// npm install
|
|
7
|
+
async function install(tmsConfig, modules, isCloud = true) {
|
|
8
|
+
const newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName, DEFAULT_MODULE_DIR);
|
|
9
|
+
// 小程序npm install
|
|
25
10
|
await createTask(
|
|
26
|
-
|
|
27
|
-
'开始npm install',
|
|
28
|
-
'npm install完成',
|
|
29
|
-
)(
|
|
11
|
+
mpNpmInstallAll,
|
|
12
|
+
'小程序 开始npm install',
|
|
13
|
+
'小程序npm install 完成',
|
|
14
|
+
)(newModules, resolve(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`);
|
|
30
15
|
|
|
31
16
|
// 构建miniprograme_npm
|
|
32
17
|
await createTask(
|
|
33
18
|
buildMpNpm,
|
|
34
|
-
'开始构建
|
|
35
|
-
'构建
|
|
36
|
-
)({ appId:
|
|
19
|
+
'开始构建miniprograme_npm',
|
|
20
|
+
'构建miniprograme_npm 完成',
|
|
21
|
+
)({ appId: tmsConfig.appId, projectPath: resolve('./'), privateKey: tmsConfig.privateKey });
|
|
22
|
+
|
|
23
|
+
// 安装云函数的
|
|
24
|
+
isCloud && createTask(
|
|
25
|
+
cloudNpmInstall,
|
|
26
|
+
'云函数npm install',
|
|
27
|
+
'云函数npm install安装完毕',
|
|
28
|
+
)(resolve(tmsConfig.cloudDir));
|
|
37
29
|
}
|
|
38
30
|
|
|
39
31
|
module.exports = install;
|
|
@@ -133,7 +133,7 @@ function buildOutputAppJson(tmsConfig, modules) {
|
|
|
133
133
|
// 更新主包,需在subpackages处理完成后执行, pages/
|
|
134
134
|
updateMainPackages(appJson, tmsConfig.mainPackages, DEFAULT_MODULE_DIR);
|
|
135
135
|
|
|
136
|
-
fs.writeFileSync(resolve(`${tmsConfig.
|
|
136
|
+
fs.writeFileSync(resolve(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
137
137
|
|
|
138
138
|
return appJson;
|
|
139
139
|
}
|