@tmsfe/tmskit 0.0.19 → 0.0.20
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 +6 -1
- package/dist/index.cjs.js +963 -812
- package/package.json +10 -8
- package/src/compile/build.js +2 -2
- package/src/compile/dev.js +30 -25
- package/src/compile/watch.js +31 -12
- package/src/config/constant.js +24 -3
- package/src/core/buildAppJson.js +14 -21
- package/src/core/checkDependencies.js +34 -17
- package/src/core/cloneModules.js +5 -7
- package/src/core/handleError.js +7 -1
- package/src/core/npm.js +7 -2
- package/src/core/tmsMpconfig.js +87 -74
- package/src/entry.js +3 -3
- package/src/scripts/create/generator.js +1 -2
- package/src/scripts/create/index.js +73 -32
- package/src/scripts/run/build/index.js +5 -4
- package/src/scripts/run/dev/index.js +14 -13
- package/src/scripts/run/index.js +68 -54
- package/src/scripts/run/init/index.js +13 -12
- package/src/scripts/run/install/index.js +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "tmskit",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"bin": {
|
|
@@ -41,21 +41,16 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"ansi-colors": "1.1.0",
|
|
43
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",
|
|
51
44
|
"async": "^3.2.2",
|
|
52
45
|
"chalk": "^4.1.0",
|
|
53
46
|
"chokidar": "^3.5.3",
|
|
54
47
|
"commander": "^8.3.0",
|
|
55
48
|
"copy-webpack-plugin": "^9.1.0",
|
|
56
49
|
"ejs": "^3.1.5",
|
|
50
|
+
"fancy-log": "1.3.2",
|
|
57
51
|
"fs-extra": "^10.0.1",
|
|
58
52
|
"glob-ignore": "^1.0.2",
|
|
53
|
+
"glob-parent": "^3.0.1",
|
|
59
54
|
"gulp": "^4.0.2",
|
|
60
55
|
"gulp-watch": "^5.0.1",
|
|
61
56
|
"htmlparser2": "^7.2.0",
|
|
@@ -67,13 +62,20 @@
|
|
|
67
62
|
"moment": "^2.29.2",
|
|
68
63
|
"object-assign": "^4.0.1",
|
|
69
64
|
"ora": "^5.1.0",
|
|
65
|
+
"path-is-absolute": "^1.0.1",
|
|
70
66
|
"plugin-error": "^1.0.0",
|
|
71
67
|
"postcss": "^8.4.6",
|
|
72
68
|
"precinct": "^8.3.1",
|
|
69
|
+
"readable-stream": "^2.2.2",
|
|
73
70
|
"replace-ext": "^2.0.0",
|
|
71
|
+
"request": "^2.88.2",
|
|
74
72
|
"shelljs": "^0.8.4",
|
|
73
|
+
"slash": "^1.0.0",
|
|
75
74
|
"strip-comments": "^2.0.1",
|
|
76
75
|
"through2": "^4.0.2",
|
|
76
|
+
"unzipper": "^0.10.11",
|
|
77
|
+
"vinyl": "^2.1.0",
|
|
78
|
+
"vinyl-file": "^2.0.0",
|
|
77
79
|
"vinyl-sourcemaps-apply": "^0.2.0"
|
|
78
80
|
},
|
|
79
81
|
"engines": {
|
package/src/compile/build.js
CHANGED
package/src/compile/dev.js
CHANGED
|
@@ -30,21 +30,19 @@ function excludeGlob(glob) {
|
|
|
30
30
|
return Array.from(otherArr);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function adaptPath(pathDir) {
|
|
33
|
+
function adaptPath(pathDir, cwd = '') {
|
|
34
34
|
let newPath = pathDir;
|
|
35
|
-
newPath = newPath.startsWith('/') ? newPath : resolve(newPath);
|
|
35
|
+
newPath = newPath.startsWith('/') ? newPath : resolve(cwd, newPath);
|
|
36
36
|
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
37
37
|
return newPath;
|
|
38
38
|
}
|
|
39
|
-
module.exports = async (tmsConfig,
|
|
39
|
+
module.exports = async (tmsConfig, modules, subPackages, isDev = true) => {
|
|
40
40
|
const compileTasksMap = new Map();
|
|
41
41
|
|
|
42
42
|
// 监听根目录的文件
|
|
43
43
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
44
44
|
glob: {
|
|
45
45
|
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
46
|
-
// wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
47
|
-
// js: ['app.js', 'app.ts'].map(item => resolve(item)),
|
|
48
46
|
},
|
|
49
47
|
module: { from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
50
48
|
destPath: resolve(tmsConfig.outputDir),
|
|
@@ -53,40 +51,47 @@ module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
|
53
51
|
}));
|
|
54
52
|
|
|
55
53
|
// 监听模块的文件
|
|
56
|
-
for (let
|
|
54
|
+
for (let pkg of subPackages) {
|
|
57
55
|
// 处理默认参数
|
|
58
|
-
|
|
56
|
+
pkg = {
|
|
59
57
|
...{ exclude: [] },
|
|
60
|
-
...
|
|
58
|
+
...pkg,
|
|
61
59
|
};
|
|
62
|
-
const
|
|
60
|
+
const packagePath = adaptPath(pkg.path);
|
|
63
61
|
|
|
64
62
|
if (isDev) {
|
|
65
63
|
// 监听模块配置文件
|
|
66
64
|
watch(
|
|
67
|
-
[`${
|
|
65
|
+
[`${packagePath}/**/module.config.json`],
|
|
68
66
|
{ events: watchEvents },
|
|
69
|
-
() => buildOutputAppJson(tmsConfig,
|
|
70
|
-
{ from:
|
|
67
|
+
() => buildOutputAppJson(tmsConfig, modules, isDev),
|
|
68
|
+
{ from: packagePath, to: packagePath },
|
|
71
69
|
);
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
const excludes =
|
|
72
|
+
const excludes = pkg.exclude.map((ePath) => {
|
|
73
|
+
const newPath = adaptPath(ePath, packagePath);
|
|
74
|
+
const ext = path.extname(ePath).slice(1);
|
|
75
|
+
if (ext) {
|
|
76
|
+
return `!${resolve(packagePath, newPath)}`;
|
|
77
|
+
}
|
|
78
|
+
return `!${resolve(packagePath, newPath)}/**/*`;
|
|
79
|
+
});
|
|
75
80
|
const glob = {
|
|
76
|
-
js: [`${
|
|
77
|
-
json: [`${
|
|
78
|
-
wxss: [`${
|
|
79
|
-
wxml: [`${
|
|
80
|
-
image: [`${
|
|
81
|
+
js: [`${packagePath}/**/*.{js,ts,wxs}`, ...excludes],
|
|
82
|
+
json: [`${packagePath}/**/*.json`, `!${packagePath}/**/module.config.json`, ...excludes],
|
|
83
|
+
wxss: [`${packagePath}/**/*.{less,wxss,scss,sass,styl}`, ...excludes],
|
|
84
|
+
wxml: [`${packagePath}/**/*.wxml`, ...excludes],
|
|
85
|
+
image: [`${packagePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes],
|
|
81
86
|
};
|
|
82
87
|
|
|
83
88
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
84
89
|
glob: {
|
|
85
90
|
...glob,
|
|
86
|
-
other: [`${
|
|
91
|
+
other: [`${packagePath}/**/*`, ...excludeGlob(glob)],
|
|
87
92
|
},
|
|
88
|
-
destPath: resolve(tmsConfig.outputDir,
|
|
89
|
-
module: { from:
|
|
93
|
+
destPath: resolve(tmsConfig.outputDir, pkg.root),
|
|
94
|
+
module: { from: pkg.path, to: pkg.root },
|
|
90
95
|
srcOption: { allowEmpty: true },
|
|
91
96
|
isDev,
|
|
92
97
|
}));
|
|
@@ -106,7 +111,7 @@ module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
|
106
111
|
glob = {
|
|
107
112
|
js: [`${item.from}/**/*.{js,ts,wxs}`],
|
|
108
113
|
json: [`${item.from}/**/*.json`],
|
|
109
|
-
wxss: [`${item.from}/**/*.{less,wxss}`],
|
|
114
|
+
wxss: [`${item.from}/**/*.{less,wxss,scss,sass,styl}`],
|
|
110
115
|
wxml: [`${item.from}/**/*.wxml`],
|
|
111
116
|
image: [`${item.from}/**/*.{png,jpg,jpeg,gif,svg}`],
|
|
112
117
|
};
|
|
@@ -142,7 +147,7 @@ module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
|
142
147
|
watch(
|
|
143
148
|
[resolve('app.json')],
|
|
144
149
|
{ ignoreInitial: false, events: watchEvents },
|
|
145
|
-
() => buildOutputAppJson(tmsConfig,
|
|
150
|
+
() => buildOutputAppJson(tmsConfig, modules, isDev),
|
|
146
151
|
{ from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
147
152
|
);
|
|
148
153
|
// 监听其他文件
|
|
@@ -150,14 +155,14 @@ module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
|
150
155
|
watch(globValue, { ignoreInitial: true, events: watchEvents }, taskFn, module);
|
|
151
156
|
});
|
|
152
157
|
} else {
|
|
153
|
-
buildOutputAppJson(tmsConfig,
|
|
158
|
+
buildOutputAppJson(tmsConfig, modules, isDev);
|
|
154
159
|
}
|
|
155
160
|
eTime = new Date().getTime() - sTime;
|
|
156
161
|
if (typeof tmsConfig?.hooks?.afterCompile === 'function') {
|
|
157
162
|
await tmsConfig?.hooks?.afterCompile({
|
|
158
163
|
isDev,
|
|
159
164
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
160
|
-
modules
|
|
165
|
+
modules,
|
|
161
166
|
});
|
|
162
167
|
}
|
|
163
168
|
spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
package/src/compile/watch.js
CHANGED
|
@@ -1,25 +1,44 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
1
2
|
const watch = require('./plugins/gulp-watch');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const shellJs = require('shelljs');
|
|
4
|
-
const { info, warn } = require('../utils/log');
|
|
5
|
+
const { info, warn, fail } = require('../utils/log');
|
|
5
6
|
const { resolve } = require('../utils/widgets');
|
|
6
7
|
const { global } = require('../utils/global');
|
|
8
|
+
const { checkPackageVersion } = require('../core/checkDependencies');
|
|
7
9
|
const { findAllFilesOfDir } = require('../utils/io');
|
|
8
10
|
|
|
9
11
|
const TIP_MAP = {
|
|
10
|
-
'package.json':
|
|
11
|
-
|
|
12
|
+
'package.json': {
|
|
13
|
+
tip: '依赖版本有变动,请重新执行tmskit run dev',
|
|
14
|
+
check: (sourceFile, targetFile) => {
|
|
15
|
+
const targetArr = targetFile.split('/');
|
|
16
|
+
targetArr[targetArr.length - 1] = 'node_modules';
|
|
17
|
+
const packageArr = [{
|
|
18
|
+
srcPackageDir: sourceFile,
|
|
19
|
+
destNpmDir: targetArr.join('/'),
|
|
20
|
+
}];
|
|
21
|
+
return checkPackageVersion(packageArr);
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
'module.config.json': {
|
|
25
|
+
tip: '若dependencies字段有变动,请重新执行tmskit run dev才会生效',
|
|
26
|
+
check: () => true,
|
|
27
|
+
},
|
|
12
28
|
};
|
|
13
29
|
|
|
14
|
-
const logTip = (fileName, tipMap) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
const logTip = (fileName, sourceFile, targetFile, tipMap) => {
|
|
31
|
+
try {
|
|
32
|
+
for (const item in tipMap) {
|
|
33
|
+
if (fileName.indexOf(item) > -1 && tipMap[item].check(sourceFile, targetFile)) {
|
|
34
|
+
warn(`${fileName}有更新, ${tipMap[item].tip}`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
20
37
|
}
|
|
38
|
+
info(`${fileName}有更新`);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
fail(`${sourceFile}文件更新提示出现错误: ${e.message}`);
|
|
21
41
|
}
|
|
22
|
-
info(`${fileName}有更新`);
|
|
23
42
|
};
|
|
24
43
|
|
|
25
44
|
const getTargetFile = (sourceFile, module, outputDir) => {
|
|
@@ -46,7 +65,7 @@ module.exports = function (globValue, watchOptions, callback, module) {
|
|
|
46
65
|
const fileDirArr = file.replace(/\\/g, '/').split('/');
|
|
47
66
|
const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
|
|
48
67
|
const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
|
|
49
|
-
logTip(fileName, TIP_MAP);
|
|
68
|
+
logTip(fileName, sourceFile, targetFile, TIP_MAP);
|
|
50
69
|
callback([file], path.dirname(targetFile));
|
|
51
70
|
}
|
|
52
71
|
return;
|
|
@@ -59,7 +78,7 @@ module.exports = function (globValue, watchOptions, callback, module) {
|
|
|
59
78
|
return;
|
|
60
79
|
}
|
|
61
80
|
|
|
62
|
-
logTip(sourceFileName, TIP_MAP);
|
|
81
|
+
logTip(sourceFileName, sourceFile, targetFile, TIP_MAP);
|
|
63
82
|
return callback([sourceFile], path.dirname(targetFile));
|
|
64
83
|
});
|
|
65
84
|
};
|
package/src/config/constant.js
CHANGED
|
@@ -13,11 +13,15 @@ const CACHE_FILE = 'cache_file.json';
|
|
|
13
13
|
// 脚手架模板代码所在目录
|
|
14
14
|
const TEMPLATE_DIR = path.resolve(CACHE_DIR, 'template');
|
|
15
15
|
|
|
16
|
+
// 模板的名称
|
|
17
|
+
const TEMPLATE_NAME = 'tmskit-template';
|
|
18
|
+
|
|
16
19
|
// 第三方模块源码存放的临时缓存目录
|
|
17
20
|
const MODULE_CODE_DIR = path.resolve(CACHE_DIR, 'modules_code');
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
|
|
23
|
+
// 脚手架模板的远程地址
|
|
24
|
+
const TEMPLATE_URL = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip';
|
|
21
25
|
|
|
22
26
|
// 脚手架的名称
|
|
23
27
|
const TMS_NAME = 'tmskit';
|
|
@@ -51,13 +55,28 @@ const ENV = {
|
|
|
51
55
|
|
|
52
56
|
const TEMPLATE_TKIT_DIR = '_tmskit';
|
|
53
57
|
|
|
58
|
+
const CREATE_TEMPLATE_QUESTION = [
|
|
59
|
+
{
|
|
60
|
+
type: 'list',
|
|
61
|
+
name: 'projectType',
|
|
62
|
+
message: '选择你要创建的模板',
|
|
63
|
+
choices: [{
|
|
64
|
+
name: '小程序项目',
|
|
65
|
+
value: 'mp',
|
|
66
|
+
}, {
|
|
67
|
+
name: '小程序模块',
|
|
68
|
+
value: 'mp-module',
|
|
69
|
+
}],
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
54
73
|
|
|
55
74
|
export {
|
|
56
75
|
HOME_DIR,
|
|
57
76
|
CACHE_DIR,
|
|
58
77
|
CACHE_FILE,
|
|
59
78
|
TEMPLATE_DIR,
|
|
60
|
-
|
|
79
|
+
TEMPLATE_NAME,
|
|
61
80
|
TMS_NAME,
|
|
62
81
|
TMS_CONFIG_FILENAME,
|
|
63
82
|
TMS_PRIVATE_FILENAME,
|
|
@@ -69,4 +88,6 @@ export {
|
|
|
69
88
|
ENV,
|
|
70
89
|
TEMPLATE_TKIT_DIR,
|
|
71
90
|
DEFAULT_CLOUD_MODULE_DIR,
|
|
91
|
+
CREATE_TEMPLATE_QUESTION,
|
|
92
|
+
TEMPLATE_URL,
|
|
72
93
|
};
|
package/src/core/buildAppJson.js
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/* eslint-disable no-param-reassign */
|
|
5
5
|
const fs = require('fs');
|
|
6
|
-
const {
|
|
7
|
-
const {
|
|
8
|
-
const {
|
|
9
|
-
const { resolve, isObject, filterField } = require('../utils/widgets');
|
|
6
|
+
const { getSubPackages, getModulesConfig } = require('./tmsMpconfig');
|
|
7
|
+
const { fail, info } = require('../utils/log');
|
|
8
|
+
const { resolve, filterField } = require('../utils/widgets');
|
|
10
9
|
const { handleError } = require('./handleError');
|
|
11
10
|
const { global } = require('../utils/global');
|
|
12
11
|
|
|
@@ -58,19 +57,7 @@ const getAppJsonContent = (sourceAppJsonPath) => {
|
|
|
58
57
|
appJson.pages = [];
|
|
59
58
|
return appJson;
|
|
60
59
|
};
|
|
61
|
-
|
|
62
|
-
* 更新app.json中的subpackages
|
|
63
|
-
* @param {Object} appJson
|
|
64
|
-
* @param {Object} modulesConfigs
|
|
65
|
-
*/
|
|
66
|
-
const updateSubpackages = (appJson, modulesConfigs) => {
|
|
67
|
-
// eslint-disable-next-line
|
|
68
|
-
for (const modulePath in modulesConfigs) {
|
|
69
|
-
const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
|
|
70
|
-
appJson.subpackages = appJson.subpackages.concat(moduleInfo);
|
|
71
|
-
}
|
|
72
|
-
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
73
|
-
};
|
|
60
|
+
|
|
74
61
|
|
|
75
62
|
/**
|
|
76
63
|
* 处理合并subpackages后的appjson, 整理重复不合法的地方
|
|
@@ -109,7 +96,7 @@ const fixAppJson = (appJson) => {
|
|
|
109
96
|
appJson[key] = preloadRuleMap;
|
|
110
97
|
}
|
|
111
98
|
});
|
|
112
|
-
return filterField(subp, [...arrOfFileType, ...objOfFileType, 'dependencies']);
|
|
99
|
+
return filterField(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
|
|
113
100
|
});
|
|
114
101
|
// 如果plugins重复,则错误提示
|
|
115
102
|
const pluginsErrMsg = Object.keys(pluginsMap).map((pk) => {
|
|
@@ -133,12 +120,17 @@ const fixAppJson = (appJson) => {
|
|
|
133
120
|
*/
|
|
134
121
|
function buildOutputAppJson(tmsConfig, modules) {
|
|
135
122
|
try {
|
|
136
|
-
//
|
|
137
|
-
const
|
|
123
|
+
// 获取所有模块,合并模块依赖的模块
|
|
124
|
+
const modulesConfig = getModulesConfig(modules, tmsConfig.appName, false);
|
|
125
|
+
// 获取所有的分包
|
|
126
|
+
const subPackages = getSubPackages(modulesConfig);
|
|
138
127
|
// 获取app.json的配置
|
|
139
128
|
const appJson = getAppJsonContent(resolve('./app.json'));
|
|
129
|
+
|
|
140
130
|
// 更新app.json中的subpackages
|
|
141
|
-
|
|
131
|
+
appJson.subpackages = subPackages;
|
|
132
|
+
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
133
|
+
|
|
142
134
|
// 处理appJson中重复||冲突的地方
|
|
143
135
|
fixAppJson(appJson);
|
|
144
136
|
// 更新主包,需在subpackages处理完成后执行, pages/
|
|
@@ -157,6 +149,7 @@ function buildOutputAppJson(tmsConfig, modules) {
|
|
|
157
149
|
return appJson;
|
|
158
150
|
} catch (e) {
|
|
159
151
|
handleError(`生成app.json出现错误: ${e}`);
|
|
152
|
+
info(e);
|
|
160
153
|
}
|
|
161
154
|
}
|
|
162
155
|
|
|
@@ -10,15 +10,8 @@ const getLatestVersion = (npmName) => {
|
|
|
10
10
|
return data.stdout || '0.0.0';
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param {*} modules 模块
|
|
16
|
-
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
17
|
-
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
const isDependenciesUpdate = (modules, cwd, outputDir) => {
|
|
21
|
-
// 步骤1. 收集package.json
|
|
13
|
+
// 收集package.json
|
|
14
|
+
function collectHasPackageJson(modules, cwd, outputDir) {
|
|
22
15
|
const packageJsonName = 'package.json'; // 查找文件名
|
|
23
16
|
// 1.1根目录的package.json
|
|
24
17
|
const packageArr = [
|
|
@@ -37,17 +30,40 @@ const isDependenciesUpdate = (modules, cwd, outputDir) => {
|
|
|
37
30
|
});
|
|
38
31
|
}
|
|
39
32
|
});
|
|
33
|
+
return packageArr;
|
|
34
|
+
}
|
|
40
35
|
|
|
36
|
+
// 读取package.json的依赖
|
|
37
|
+
function readPackageDependencies(srcPackageDir) {
|
|
38
|
+
const packageJson = fs.readFileSync(srcPackageDir, 'utf-8');
|
|
39
|
+
let dependencies = {};
|
|
40
|
+
try {
|
|
41
|
+
const json = packageJson ? JSON.parse(packageJson) : {};
|
|
42
|
+
dependencies = json?.dependencies || {};
|
|
43
|
+
} catch (e) {
|
|
44
|
+
handleError(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
45
|
+
}
|
|
46
|
+
return dependencies;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 检查package.json的依赖大于node_module的版本,则返回true
|
|
51
|
+
* @param {*} modules 模块
|
|
52
|
+
* @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
|
|
53
|
+
* @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
const isDependenciesUpdate = (modules, cwd, outputDir) => {
|
|
57
|
+
// 步骤1. 收集package.json
|
|
58
|
+
const packageArr = collectHasPackageJson(modules, cwd, outputDir);
|
|
41
59
|
// 步骤2. 比较package.json的依赖与node_modules依赖的版本号
|
|
60
|
+
return checkPackageVersion(packageArr);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// 比较package.json的依赖与node_modules依赖的版本号
|
|
64
|
+
const checkPackageVersion = (packageArr) => {
|
|
42
65
|
for (const item of packageArr) {
|
|
43
|
-
const
|
|
44
|
-
let dependencies = {};
|
|
45
|
-
try {
|
|
46
|
-
const json = JSON.parse(packageJson);
|
|
47
|
-
dependencies = json?.dependencies ? json?.dependencies : {};
|
|
48
|
-
} catch (e) {
|
|
49
|
-
handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
|
|
50
|
-
}
|
|
66
|
+
const dependencies = readPackageDependencies(item.srcPackageDir);
|
|
51
67
|
const dependenciesKeys = Object.keys(dependencies);
|
|
52
68
|
for (const key of dependenciesKeys) {
|
|
53
69
|
const depPath = path.join(item.destNpmDir, key);
|
|
@@ -74,4 +90,5 @@ const isDependenciesUpdate = (modules, cwd, outputDir) => {
|
|
|
74
90
|
|
|
75
91
|
module.exports = {
|
|
76
92
|
isDependenciesUpdate,
|
|
93
|
+
checkPackageVersion,
|
|
77
94
|
};
|
package/src/core/cloneModules.js
CHANGED
|
@@ -21,9 +21,7 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
21
21
|
const tmsConfig = global.getData('tmsConfig');
|
|
22
22
|
|
|
23
23
|
let gitUrl = httpRepoUrl;
|
|
24
|
-
const { username = '', pass = '' } = tmsConfig?.
|
|
25
|
-
|| tmsConfig?.gitAccount?.[moduleName]
|
|
26
|
-
|| {};
|
|
24
|
+
const { username = '', pass = '' } = tmsConfig?.gitAccount?.[moduleName] || {};
|
|
27
25
|
|
|
28
26
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
29
27
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -122,10 +120,10 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
122
120
|
const downloadTasksMap = new Map();
|
|
123
121
|
for (const moduleInfo of modules) {
|
|
124
122
|
if (moduleInfo.repoInfo) {
|
|
125
|
-
const { repoInfo: { buildGitTag: branch, httpRepoUrl, path: gitPath = '' }, path,
|
|
123
|
+
const { repoInfo: { buildGitTag: branch, httpRepoUrl, path: gitPath = '' }, path, moduleName } = moduleInfo;
|
|
126
124
|
|
|
127
125
|
// 处理仓库权限问题
|
|
128
|
-
const gitUrl = replaceGitUrlAccount(httpRepoUrl,
|
|
126
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
|
|
129
127
|
// 根据gitUrl与branch计算md5
|
|
130
128
|
const md5Key = md5ByGitUrlBranch(gitUrl, branch);
|
|
131
129
|
// git源码临时存在的源目录
|
|
@@ -191,8 +189,8 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
191
189
|
*/
|
|
192
190
|
function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
|
|
193
191
|
if (moduleInfo.repoInfo) {
|
|
194
|
-
const { repoInfo: { buildGitTag, httpRepoUrl },
|
|
195
|
-
const gitUrl = replaceGitUrlAccount(httpRepoUrl,
|
|
192
|
+
const { repoInfo: { buildGitTag, httpRepoUrl }, moduleName } = moduleInfo;
|
|
193
|
+
const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
|
|
196
194
|
const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
|
|
197
195
|
if (!fs.existsSync(`${sourceDir}/${md5Key}`)) {
|
|
198
196
|
return true;
|
package/src/core/handleError.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
const { fail } = require('../utils/log');
|
|
2
2
|
const { global } = require('../utils/global');
|
|
3
3
|
|
|
4
|
-
function handleError(error) {
|
|
4
|
+
function handleError(error, isQuit = false) {
|
|
5
5
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
6
|
+
|
|
7
|
+
if (isQuit) {
|
|
8
|
+
fail(errMsg);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
const isDev = global.getData('isDev');
|
|
7
13
|
if (isDev) {
|
|
8
14
|
fail(errMsg);
|
package/src/core/npm.js
CHANGED
|
@@ -30,7 +30,12 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
|
|
|
30
30
|
const npmTasksMap = new Map();
|
|
31
31
|
for (const packageJsonPath of packageJsonFiles) {
|
|
32
32
|
const packageContent = fs.readFileSync(packageJsonPath);
|
|
33
|
-
|
|
33
|
+
let packageJson;
|
|
34
|
+
try {
|
|
35
|
+
packageJson = JSON.parse(packageContent);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
throw new Error(`${packageJsonPath}json解析出现错误:${e}`);
|
|
38
|
+
}
|
|
34
39
|
const md5Obj = {
|
|
35
40
|
dependencies: packageJson.dependencies || {},
|
|
36
41
|
};
|
|
@@ -118,7 +123,7 @@ const npmInstallAll = async (modules, contextDir, cacheDir) => {
|
|
|
118
123
|
return Promise.all(callArr);
|
|
119
124
|
})
|
|
120
125
|
.catch((e) => {
|
|
121
|
-
handleError(`npm install ${params.packageJsonPath}出现错误:${e}
|
|
126
|
+
handleError(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
|
|
122
127
|
}));
|
|
123
128
|
});
|
|
124
129
|
|