@htyf-mp/cli 0.2.0-alpha.2 → 0.2.0-alpha.4
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 +1 -1
- package/package.json +20 -6
- package/src/HtyfImportsPlugin.mjs +190 -0
- package/src/build.mjs +146 -0
- package/src/clean.mjs +83 -0
- package/src/command-executor.mjs +133 -0
- package/src/config.mjs +52 -0
- package/src/constants.mjs +54 -0
- package/src/debug.mjs +132 -0
- package/src/file-system.mjs +96 -0
- package/src/index.mjs +48 -1084
- package/src/logger.mjs +72 -0
- package/src/project-initializer.mjs +247 -0
- package/src/shared-output.json +1 -2
- package/src/template-processor.mjs +137 -0
- package/src/utils-functions.mjs +76 -0
- package/src/utils.mjs +4 -63
- package/src/validators.mjs +82 -0
- package/src/webpack.config.mjs +16 -4
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import lodash from 'lodash';
|
|
2
|
+
import si from 'systeminformation';
|
|
3
|
+
import { Logger } from './logger.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 配置验证工具类
|
|
7
|
+
*/
|
|
8
|
+
export class ConfigValidator {
|
|
9
|
+
static validateAppConfig(config) {
|
|
10
|
+
const errors = [];
|
|
11
|
+
const warnings = [];
|
|
12
|
+
|
|
13
|
+
// 必需字段检查
|
|
14
|
+
const requiredFields = ['productName', 'versionName', 'versionCode'];
|
|
15
|
+
requiredFields.forEach(field => {
|
|
16
|
+
if (!config[field]) {
|
|
17
|
+
errors.push(`缺少必需字段: ${field}`);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// 平台配置检查
|
|
22
|
+
if (config.iosBuild) {
|
|
23
|
+
if (!config.iosBuild.appId) {
|
|
24
|
+
warnings.push('iOS配置缺少appId');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (config.andBuild) {
|
|
29
|
+
if (!config.andBuild.appId) {
|
|
30
|
+
warnings.push('Android配置缺少appId');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { errors, warnings, isValid: errors.length === 0 };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static async validateNetworkConfig() {
|
|
38
|
+
try {
|
|
39
|
+
const networkInfo = await si.networkInterfaces();
|
|
40
|
+
const defaultNet = (lodash.isArray(networkInfo) ? networkInfo : [networkInfo])
|
|
41
|
+
.find(i => lodash.get(i, 'default', false));
|
|
42
|
+
|
|
43
|
+
if (!defaultNet || !defaultNet.ip4) {
|
|
44
|
+
return { isValid: false, error: '无法获取网络配置' };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
isValid: true,
|
|
49
|
+
host: defaultNet.ip4,
|
|
50
|
+
interface: defaultNet.iface
|
|
51
|
+
};
|
|
52
|
+
} catch (error) {
|
|
53
|
+
Logger.error(`网络配置验证失败: ${error.message}`);
|
|
54
|
+
return { isValid: false, error: error.message };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 验证版本号格式
|
|
60
|
+
* @param {string} versionName - 版本名称
|
|
61
|
+
* @param {string} versionCode - 版本代码
|
|
62
|
+
* @returns {boolean} 是否有效
|
|
63
|
+
*/
|
|
64
|
+
static validateVersion(versionName, versionCode) {
|
|
65
|
+
const VERSION_NAME_REGEX = /^\d+(\.\d+){2}$/g;
|
|
66
|
+
const VERSION_CODE_REGEX = /^\d+$/g;
|
|
67
|
+
|
|
68
|
+
const isVersionNameValid = VERSION_NAME_REGEX.test(versionName);
|
|
69
|
+
const isVersionCodeValid = VERSION_CODE_REGEX.test(versionCode);
|
|
70
|
+
|
|
71
|
+
if (!isVersionNameValid) {
|
|
72
|
+
Logger.error(`版本名称格式错误: ${versionName},应为 x.y.z 格式`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!isVersionCodeValid) {
|
|
76
|
+
Logger.error(`版本代码格式错误: ${versionCode},应为数字格式`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return isVersionNameValid && isVersionCodeValid;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
package/src/webpack.config.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import TerserPlugin from 'terser-webpack-plugin';
|
|
|
7
7
|
import * as Repack from '@callstack/repack';
|
|
8
8
|
import { ExpoModulesPlugin } from '@callstack/repack-plugin-expo-modules';
|
|
9
9
|
import { ReanimatedPlugin } from '@callstack/repack-plugin-reanimated';
|
|
10
|
-
import { HtyfModulesPlugin } from './
|
|
10
|
+
import { HtyfModulesPlugin } from './HtyfImportsPlugin.mjs';
|
|
11
11
|
import { getProjectRoot } from './utils.mjs';
|
|
12
12
|
|
|
13
13
|
// 获取当前文件和目录路径
|
|
@@ -60,7 +60,17 @@ export default (env = {}) => {
|
|
|
60
60
|
if (appExposesOptions) {
|
|
61
61
|
mpOptions = JSON.parse(decodeURI(appExposesOptions));
|
|
62
62
|
}
|
|
63
|
+
console.log('\n');
|
|
64
|
+
console.log('=====mpOptions=====');
|
|
65
|
+
console.log('\n');
|
|
66
|
+
console.log('context:', projectRoot);
|
|
67
|
+
console.log('\n');
|
|
68
|
+
console.log('entry:', entry);
|
|
69
|
+
console.log('\n');
|
|
63
70
|
console.log(JSON.stringify(mpOptions, null, 2));
|
|
71
|
+
console.log('\n');
|
|
72
|
+
console.log('=====mpOptions=====');
|
|
73
|
+
console.log('\n');
|
|
64
74
|
// 基础Webpack配置
|
|
65
75
|
const mpConfig = {
|
|
66
76
|
context,
|
|
@@ -71,6 +81,8 @@ export default (env = {}) => {
|
|
|
71
81
|
output: {
|
|
72
82
|
// 默认输出路径,host模式下会被覆盖
|
|
73
83
|
path: mpOptions.outputPath,
|
|
84
|
+
publicPath: mpOptions.outputPath,
|
|
85
|
+
// uniqueName: `htyf_mp_for_${mpOptions.name}`,
|
|
74
86
|
},
|
|
75
87
|
module: {
|
|
76
88
|
rules: [
|
|
@@ -79,9 +91,9 @@ export default (env = {}) => {
|
|
|
79
91
|
test: /\.[cm]?[jt]sx?$/,
|
|
80
92
|
use: {
|
|
81
93
|
loader: 'babel-loader',
|
|
82
|
-
options: {
|
|
83
|
-
|
|
84
|
-
}
|
|
94
|
+
// options: {
|
|
95
|
+
// configFile: path.resolve(__dirname, './babel.config.js'),
|
|
96
|
+
// }
|
|
85
97
|
},
|
|
86
98
|
type: 'javascript/auto',
|
|
87
99
|
},
|