@tmsfe/tmskit 0.0.1 → 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/README.md +5 -17
- package/dist/index.cjs.js +710 -907
- package/package.json +16 -27
- package/src/config/constant.js +4 -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/create/ask.js +7 -5
- package/src/scripts/create/generator.js +0 -2
- package/src/scripts/create/index.js +13 -6
- package/src/scripts/run/build/index.js +3 -3
- package/src/scripts/run/dev/index.js +3 -3
- package/src/scripts/run/index.js +8 -2
- package/src/scripts/run/init/index.js +12 -29
- package/src/scripts/run/install/index.js +31 -0
- package/src/utils/buildAppJson.js +1 -1
- package/src/utils/entry.js +150 -0
- package/src/utils/npmUtils.js +23 -4
- package/src/utils/widgets.js +4 -11
- 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 -29
- package/src/webpack/plugins/px2rpx/index.js +0 -14
- 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": {
|
|
@@ -18,50 +18,39 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@babel/core": "^7.15.0",
|
|
22
|
-
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
|
|
23
|
-
"@babel/preset-env": "^7.16.0",
|
|
24
21
|
"@rollup/plugin-babel": "^5.0.2",
|
|
25
22
|
"@rollup/plugin-commonjs": "^19.0.0",
|
|
26
23
|
"@rollup/plugin-dynamic-import-vars": "^1.1.1",
|
|
27
24
|
"@rollup/plugin-json": "^4.0.3",
|
|
28
|
-
"async": "^3.2.2",
|
|
29
|
-
"babel-core": "^6.26.3",
|
|
30
|
-
"babel-loader": "^8.2.3",
|
|
31
|
-
"copy-webpack-plugin": "^9.1.0",
|
|
32
|
-
"cross-env": "^7.0.3",
|
|
33
|
-
"leven": "3.1.0",
|
|
34
|
-
"metalsmith": "^2.3.0",
|
|
35
|
-
"minimist": "^1.2.5",
|
|
36
25
|
"rollup": "^2.6.1",
|
|
37
26
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
27
|
+
"rollup-plugin-replace": "^2.2.0",
|
|
38
28
|
"rollup-plugin-terser": "^6.1.0",
|
|
39
|
-
"rollup-plugin-typescript2": "0.27.0"
|
|
40
|
-
"ts-loader": "^9.2.6",
|
|
41
|
-
"url-loader": "^4.1.1",
|
|
42
|
-
"webpack": "^5.64.0",
|
|
43
|
-
"webpack-cli": "^4.9.1"
|
|
29
|
+
"rollup-plugin-typescript2": "0.27.0"
|
|
44
30
|
},
|
|
45
31
|
"dependencies": {
|
|
46
|
-
"
|
|
32
|
+
"async": "^3.2.2",
|
|
47
33
|
"chalk": "^4.1.0",
|
|
48
|
-
"commander": "^
|
|
34
|
+
"commander": "^8.3.0",
|
|
35
|
+
"copy-webpack-plugin": "^9.1.0",
|
|
49
36
|
"download-git-repo": "^3.0.2",
|
|
50
37
|
"ejs": "^3.1.5",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
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",
|
|
53
44
|
"inquirer": "^7.3.3",
|
|
45
|
+
"leven": "3.1.0",
|
|
54
46
|
"lodash": "^4.17.21",
|
|
55
|
-
"
|
|
47
|
+
"metalsmith": "^2.3.0",
|
|
56
48
|
"miniprogram-ci": "1.4.13",
|
|
57
49
|
"ora": "^5.1.0",
|
|
50
|
+
"precinct": "^8.3.1",
|
|
58
51
|
"replace-ext": "^2.0.0",
|
|
59
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
60
52
|
"shelljs": "^0.8.4",
|
|
61
|
-
"
|
|
62
|
-
"typescript": "^3.8.3",
|
|
63
|
-
"username": "5.1.0",
|
|
64
|
-
"webpack-chain": "^6.5.1"
|
|
53
|
+
"through2": "^4.0.2"
|
|
65
54
|
},
|
|
66
55
|
"engines": {
|
|
67
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 = {
|
|
@@ -48,6 +48,8 @@ const ENV = {
|
|
|
48
48
|
prod: 'production',
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
const TEMPLATE_TKIT_DIR = '_tmskit';
|
|
52
|
+
|
|
51
53
|
export {
|
|
52
54
|
HOME_DIR,
|
|
53
55
|
CACHE_DIR,
|
|
@@ -62,4 +64,5 @@ export {
|
|
|
62
64
|
MODULE_CODE_DIR,
|
|
63
65
|
MODE,
|
|
64
66
|
ENV,
|
|
67
|
+
TEMPLATE_TKIT_DIR,
|
|
65
68
|
};
|
|
@@ -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,17 +1,19 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const inquirer = require('inquirer');
|
|
3
|
+
const { resolve } = require('../../utils/widgets');
|
|
4
|
+
const { TEMPLATE_TKIT_DIR } = require('../../config/constant');
|
|
3
5
|
/**
|
|
4
6
|
* 获取模板内的问题
|
|
5
|
-
* @param {string}
|
|
7
|
+
* @param {string} dir questions.json所在的目录
|
|
6
8
|
* @returns {Array} inquirer 问题数组
|
|
7
9
|
*/
|
|
8
|
-
const parseTemplateQuestions = (
|
|
10
|
+
const parseTemplateQuestions = (dir) => {
|
|
9
11
|
let prompts = [];
|
|
10
|
-
if (!fs.existsSync(`${
|
|
12
|
+
if (!fs.existsSync(`${dir}/questions.json`)) {
|
|
11
13
|
return prompts;
|
|
12
14
|
}
|
|
13
15
|
try {
|
|
14
|
-
const json = JSON.parse(fs.readFileSync(`${
|
|
16
|
+
const json = JSON.parse(fs.readFileSync(`${dir}/questions.json`));
|
|
15
17
|
if (Array.isArray(json) && json.length > 0) {
|
|
16
18
|
json.forEach((item, index) => {
|
|
17
19
|
if (!isQuestionType(item)) {
|
|
@@ -38,7 +40,7 @@ const isQuestionType = (result) => {
|
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
const ask = templateDir => (files, metalsmith, next) => {
|
|
41
|
-
const prompts = parseTemplateQuestions(templateDir);
|
|
43
|
+
const prompts = parseTemplateQuestions(resolve(templateDir, TEMPLATE_TKIT_DIR));
|
|
42
44
|
const metadata = metalsmith.metadata();
|
|
43
45
|
const filteredPrompts = prompts.filter((prompt) => {
|
|
44
46
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const Metalsmith = require('metalsmith');
|
|
2
|
-
const fs = require('fs');
|
|
3
2
|
const render = require('./render');
|
|
4
3
|
const ask = require('./ask');
|
|
5
4
|
const FILES_TO_IGNORE = require('./ignoreFiles');
|
|
@@ -18,7 +17,6 @@ const generator = (buildDir, distDir, preMetadata) => new Promise((resolve, reje
|
|
|
18
17
|
if (err) {
|
|
19
18
|
reject(err);
|
|
20
19
|
} else {
|
|
21
|
-
fs.unlinkSync(`${distDir}/questions.json`);
|
|
22
20
|
resolve('finish');
|
|
23
21
|
}
|
|
24
22
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const shelljs = require('shelljs');
|
|
4
|
-
const { TEMPLATE_DIR, TEMPLATE_PATH } = require('../../config/constant.js');
|
|
4
|
+
const { TEMPLATE_DIR, TEMPLATE_PATH, TEMPLATE_TKIT_DIR } = require('../../config/constant.js');
|
|
5
5
|
const { downloadRepoForGit, createTask, resolve } = require('../../utils/widgets');
|
|
6
6
|
const io = require('../../utils/io');
|
|
7
7
|
const { fail, succeed } = require('../../utils/log');
|
|
@@ -33,7 +33,7 @@ async function create(appName) {
|
|
|
33
33
|
const cwd = process.cwd();
|
|
34
34
|
const targetDir = path.resolve(cwd, appName);
|
|
35
35
|
const appType = 'mp';
|
|
36
|
-
createAppDir(targetDir);
|
|
36
|
+
await createAppDir(targetDir);
|
|
37
37
|
|
|
38
38
|
// 创建缓存目录
|
|
39
39
|
io.ensureDirExist(TEMPLATE_DIR);
|
|
@@ -49,12 +49,19 @@ async function create(appName) {
|
|
|
49
49
|
appName,
|
|
50
50
|
appType,
|
|
51
51
|
}).then(() => {
|
|
52
|
-
succeed('项目创建完成,开始初始化...');
|
|
53
52
|
shelljs.cd(appName);
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
53
|
+
const hooks = require(resolve(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
54
|
+
if (hooks.afterCreate) {
|
|
55
|
+
hooks.afterCreate.forEach((item) => {
|
|
56
|
+
if (typeof item === 'function') {
|
|
57
|
+
item.call(null, shelljs, { appName });
|
|
58
|
+
} else {
|
|
59
|
+
shelljs.exec(item);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
57
62
|
}
|
|
63
|
+
shelljs.rm('-rf', resolve(appName, TEMPLATE_TKIT_DIR));
|
|
64
|
+
succeed('项目创建完成.');
|
|
58
65
|
})
|
|
59
66
|
.catch((err) => {
|
|
60
67
|
fail(err.message);
|
|
@@ -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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const init = require('./init/index');
|
|
2
2
|
const dev = require('./dev/index');
|
|
3
3
|
const build = require('./build/index');
|
|
4
|
-
const
|
|
4
|
+
const install = require('./install/index');
|
|
5
|
+
const { createTask } = require('../../utils/widgets');
|
|
5
6
|
const { MODE } = require('../../config/constant');
|
|
6
7
|
const { readTmsConfig, checkModules } = require('../../utils/tkitUtils');
|
|
7
8
|
|
|
@@ -11,10 +12,12 @@ const handleModulesArg = (cmd) => {
|
|
|
11
12
|
return MODE.main;
|
|
12
13
|
}
|
|
13
14
|
// 单模块 或 多模块开发
|
|
15
|
+
const { argv } = process;
|
|
16
|
+
const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
|
|
14
17
|
if (cmd.module) {
|
|
15
18
|
return [
|
|
16
19
|
cmd.module,
|
|
17
|
-
...
|
|
20
|
+
...reset,
|
|
18
21
|
];
|
|
19
22
|
}
|
|
20
23
|
// 全量模块
|
|
@@ -46,6 +49,9 @@ async function run(commandName, cmd) {
|
|
|
46
49
|
case 'dev':
|
|
47
50
|
dev(tmsConfig, modules, env);
|
|
48
51
|
return;
|
|
52
|
+
case 'install':
|
|
53
|
+
install(tmsConfig, modules, env);
|
|
54
|
+
return;
|
|
49
55
|
case 'build':
|
|
50
56
|
build(tmsConfig, modules, env);
|
|
51
57
|
return;
|