hcordova 1.0.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/LICENSE +204 -0
- package/README.md +346 -0
- package/bin/hcordova +27 -0
- package/package.json +39 -0
- package/src/base-cli.js +1181 -0
- package/src/utils/DependencyChecker.js +382 -0
- package/src/utils/PlatformProject.js +452 -0
- package/src/utils/PluginConfigParser.js +408 -0
- package/src/utils/PluginDownloader.js +181 -0
- package/src/utils/PluginHandler.js +1097 -0
- package/src/utils/VariableValidator.js +369 -0
- package/src/utils/args-processor.js +79 -0
- package/templates/project/AppScope/app.json5 +10 -0
- package/templates/project/AppScope/resources/base/element/string.json +8 -0
- package/templates/project/AppScope/resources/base/media/background.png +0 -0
- package/templates/project/AppScope/resources/base/media/foreground.png +0 -0
- package/templates/project/AppScope/resources/base/media/layered_image.json +7 -0
- package/templates/project/build-profile.json5 +46 -0
- package/templates/project/code-linter.json5 +32 -0
- package/templates/project/entry/build-profile.json5 +28 -0
- package/templates/project/entry/hvigorfile.ts +6 -0
- package/templates/project/entry/obfuscation-rules.txt +23 -0
- package/templates/project/entry/oh-package.json5 +12 -0
- package/templates/project/entry/src/main/ets/entryability/EntryAbility.ets +62 -0
- package/templates/project/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +32 -0
- package/templates/project/entry/src/main/ets/pages/Index.ets +40 -0
- package/templates/project/entry/src/main/module.json5 +52 -0
- package/templates/project/entry/src/main/resources/base/element/color.json +8 -0
- package/templates/project/entry/src/main/resources/base/element/float.json +8 -0
- package/templates/project/entry/src/main/resources/base/element/string.json +16 -0
- package/templates/project/entry/src/main/resources/base/media/background.png +0 -0
- package/templates/project/entry/src/main/resources/base/media/foreground.png +0 -0
- package/templates/project/entry/src/main/resources/base/media/layered_image.json +7 -0
- package/templates/project/entry/src/main/resources/base/media/startIcon.png +0 -0
- package/templates/project/entry/src/main/resources/base/profile/backup_config.json +3 -0
- package/templates/project/entry/src/main/resources/base/profile/main_pages.json +5 -0
- package/templates/project/entry/src/main/resources/dark/element/color.json +8 -0
- package/templates/project/entry/src/main/resources/rawfile/config.xml +26 -0
- package/templates/project/entry/src/main/resources/rawfile/www/cordova.js +1925 -0
- package/templates/project/entry/src/main/resources/rawfile/www/css/index.css +158 -0
- package/templates/project/entry/src/main/resources/rawfile/www/img/cordova.png +0 -0
- package/templates/project/entry/src/main/resources/rawfile/www/img/logo.png +0 -0
- package/templates/project/entry/src/main/resources/rawfile/www/index.html +110 -0
- package/templates/project/entry/src/main/resources/rawfile/www/js/index.js +68 -0
- package/templates/project/entry/src/mock/mock-config.json5 +2 -0
- package/templates/project/entry/src/ohosTest/ets/test/Ability.test.ets +35 -0
- package/templates/project/entry/src/ohosTest/ets/test/List.test.ets +5 -0
- package/templates/project/entry/src/ohosTest/module.json5 +13 -0
- package/templates/project/entry/src/test/List.test.ets +5 -0
- package/templates/project/entry/src/test/LocalUnit.test.ets +33 -0
- package/templates/project/hvigor/hvigor-config.json5 +22 -0
- package/templates/project/hvigorfile.ts +6 -0
- package/templates/project/local.properties +9 -0
- package/templates/project/oh-package-lock.json5 +27 -0
- package/templates/project/oh-package.json5 +10 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device, Inc. Ltd. and <马弓手>.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
class VariableValidator {
|
|
18
|
+
constructor(api) {
|
|
19
|
+
this.api = api;
|
|
20
|
+
this.events = api.events;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 收集变量并验证必需变量
|
|
25
|
+
*/
|
|
26
|
+
collectAndValidateVariables(pluginConfig, installOptions) {
|
|
27
|
+
const vars = Object.fromEntries(installOptions.cli_variables)
|
|
28
|
+
const variables = {
|
|
29
|
+
// 内置变量
|
|
30
|
+
PLUGIN_ID: pluginConfig.id,
|
|
31
|
+
PLUGIN_NAME: pluginConfig.name,
|
|
32
|
+
PLUGIN_VERSION: pluginConfig.package.version,
|
|
33
|
+
// 从安装选项继承的变量
|
|
34
|
+
...vars
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 获取插件声明的所有变量要求(合并全局和平台特定)
|
|
38
|
+
const pluginVariables = this._getAllPluginVariables(pluginConfig);
|
|
39
|
+
|
|
40
|
+
// 验证必需变量
|
|
41
|
+
const missingVariables = [];
|
|
42
|
+
const validatedVariables = { ...variables }; // 复制已有变量
|
|
43
|
+
|
|
44
|
+
for (const [varName, varInfo] of Object.entries(pluginVariables)) {
|
|
45
|
+
if (varInfo.required) {
|
|
46
|
+
// 检查必需变量
|
|
47
|
+
const currentValue = validatedVariables[varName];
|
|
48
|
+
if (currentValue === undefined || currentValue === null || currentValue === '') {
|
|
49
|
+
missingVariables.push({
|
|
50
|
+
name: varName,
|
|
51
|
+
info: varInfo
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
// 可选变量,使用默认值或提供的值
|
|
56
|
+
if (validatedVariables[varName] === undefined) {
|
|
57
|
+
validatedVariables[varName] = varInfo.default || '';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 如果有缺失的必需变量,抛出错误
|
|
63
|
+
if (missingVariables.length > 0) {
|
|
64
|
+
const errorMessage = this._formatMissingVariablesError(pluginConfig.id, missingVariables);
|
|
65
|
+
throw new Error(errorMessage);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 记录验证结果
|
|
69
|
+
this._logVariableValidation(pluginConfig.id, validatedVariables, pluginVariables);
|
|
70
|
+
|
|
71
|
+
return validatedVariables;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 获取插件声明的所有变量(合并全局和平台特定)
|
|
76
|
+
*/
|
|
77
|
+
_getAllPluginVariables(pluginConfig) {
|
|
78
|
+
const variables = {};
|
|
79
|
+
|
|
80
|
+
// 添加全局preference变量
|
|
81
|
+
if (pluginConfig.preferences) {
|
|
82
|
+
for (const [name, pref] of Object.entries(pluginConfig.preferences)) {
|
|
83
|
+
variables[name] = {
|
|
84
|
+
name: name,
|
|
85
|
+
default: pref.default,
|
|
86
|
+
required: pref.required,
|
|
87
|
+
description: `Global preference: ${name}`,
|
|
88
|
+
source: 'global'
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 添加平台特定preference变量
|
|
94
|
+
if (pluginConfig.platform && pluginConfig.platform.preferences) {
|
|
95
|
+
for (const [name, pref] of Object.entries(pluginConfig.platform.preferences)) {
|
|
96
|
+
// 如果变量已存在,平台特定的优先级更高
|
|
97
|
+
variables[name] = {
|
|
98
|
+
name: name,
|
|
99
|
+
default: pref.default,
|
|
100
|
+
required: pref.required,
|
|
101
|
+
description: `Platform preference: ${name}`,
|
|
102
|
+
source: 'platform',
|
|
103
|
+
platformSpecific: true
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 从config-file中提取变量引用
|
|
109
|
+
const configFileVariables = this._extractVariablesFromConfigFiles(pluginConfig);
|
|
110
|
+
for (const [name, varInfo] of Object.entries(configFileVariables)) {
|
|
111
|
+
// 如果变量尚未声明,添加它
|
|
112
|
+
if (!variables[name]) {
|
|
113
|
+
variables[name] = {
|
|
114
|
+
name: name,
|
|
115
|
+
default: '',
|
|
116
|
+
required: true, // config-file中引用的变量默认必需
|
|
117
|
+
description: `Referenced in config-file: ${name}`,
|
|
118
|
+
source: 'config-file'
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return variables;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 从config-file内容中提取变量引用
|
|
128
|
+
*/
|
|
129
|
+
_extractVariablesFromConfigFiles(pluginConfig) {
|
|
130
|
+
const variables = {};
|
|
131
|
+
|
|
132
|
+
if (pluginConfig.platform && pluginConfig.platform.configFiles) {
|
|
133
|
+
pluginConfig.platform.configFiles.forEach(configFile => {
|
|
134
|
+
// 查找 $VARIABLE 格式的变量引用
|
|
135
|
+
const variableMatches = configFile.content.match(/\$([A-Z_][A-Z0-9_]*)/g) || [];
|
|
136
|
+
variableMatches.forEach(match => {
|
|
137
|
+
const varName = match.substring(1); // 去掉 $ 符号
|
|
138
|
+
if (!variables[varName]) {
|
|
139
|
+
variables[varName] = {
|
|
140
|
+
name: varName,
|
|
141
|
+
configFile: configFile.target
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// 查找preference元素中的变量引用
|
|
147
|
+
const preferenceMatches = configFile.content.match(/<preference\s+name="([^"]+)"\s+value="([^"]+)"\s*\/>/g) || [];
|
|
148
|
+
preferenceMatches.forEach(match => {
|
|
149
|
+
const nameMatch = match.match(/name="([^"]+)"/);
|
|
150
|
+
const valueMatch = match.match(/value="([^"]+)"/);
|
|
151
|
+
if (nameMatch && valueMatch) {
|
|
152
|
+
const prefName = nameMatch[1];
|
|
153
|
+
const prefValue = valueMatch[1];
|
|
154
|
+
|
|
155
|
+
// 如果值以 $ 开头,说明这是一个变量引用
|
|
156
|
+
if (prefValue.startsWith('$')) {
|
|
157
|
+
const varName = prefValue.substring(1);
|
|
158
|
+
if (!variables[varName]) {
|
|
159
|
+
variables[varName] = {
|
|
160
|
+
name: varName,
|
|
161
|
+
configFile: configFile.target,
|
|
162
|
+
usedInPreference: prefName
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return variables;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 格式化缺失变量的错误信息
|
|
176
|
+
*/
|
|
177
|
+
_formatMissingVariablesError(pluginId, missingVariables) {
|
|
178
|
+
const lines = [
|
|
179
|
+
`Missing required variables for plugin "${pluginId}":`,
|
|
180
|
+
''
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
missingVariables.forEach(({ name, info }) => {
|
|
184
|
+
lines.push(` Variable: ${name}`);
|
|
185
|
+
if (info.description) {
|
|
186
|
+
lines.push(` Description: ${info.description}`);
|
|
187
|
+
}
|
|
188
|
+
if (info.source) {
|
|
189
|
+
lines.push(` Source: ${info.source}`);
|
|
190
|
+
}
|
|
191
|
+
if (info.default) {
|
|
192
|
+
lines.push(` Default: ${info.default}`);
|
|
193
|
+
}
|
|
194
|
+
if (info.configFile) {
|
|
195
|
+
lines.push(` Used in: ${info.configFile}`);
|
|
196
|
+
}
|
|
197
|
+
if (info.usedInPreference) {
|
|
198
|
+
lines.push(` Preference: ${info.usedInPreference}`);
|
|
199
|
+
}
|
|
200
|
+
lines.push('');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
lines.push('Please provide these variables using:');
|
|
204
|
+
lines.push('');
|
|
205
|
+
|
|
206
|
+
// 生成命令行示例
|
|
207
|
+
const varExamples = missingVariables.map(({ name }) => `--variable ${name}=VALUE`);
|
|
208
|
+
lines.push(` cordova plugin add ${pluginId} ${varExamples.join(' ')}`);
|
|
209
|
+
lines.push('');
|
|
210
|
+
lines.push('Or set them in your config.xml:');
|
|
211
|
+
lines.push('');
|
|
212
|
+
lines.push(' <plugin name="' + pluginId + '">');
|
|
213
|
+
missingVariables.forEach(({ name }) => {
|
|
214
|
+
lines.push(` <variable name="${name}" value="YOUR_VALUE" />`);
|
|
215
|
+
});
|
|
216
|
+
lines.push(' </plugin>');
|
|
217
|
+
|
|
218
|
+
return lines.join('\n');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 记录变量验证结果
|
|
223
|
+
*/
|
|
224
|
+
_logVariableValidation(pluginId, validatedVariables, pluginVariables) {
|
|
225
|
+
const providedVars = Object.keys(validatedVariables).filter(name =>
|
|
226
|
+
pluginVariables[name] && validatedVariables[name] && validatedVariables[name] !== pluginVariables[name].default
|
|
227
|
+
);
|
|
228
|
+
const defaultVars = Object.keys(validatedVariables).filter(name =>
|
|
229
|
+
pluginVariables[name] && validatedVariables[name] === pluginVariables[name].default
|
|
230
|
+
);
|
|
231
|
+
const unusedVars = Object.keys(validatedVariables).filter(name =>
|
|
232
|
+
!pluginVariables[name] &&
|
|
233
|
+
!['PLUGIN_ID', 'PLUGIN_NAME', 'PLUGIN_VERSION'].includes(name)
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
if (providedVars.length > 0) {
|
|
237
|
+
this.events.emit('verbose', `Provided variables for ${pluginId}: ${providedVars.join(', ')}`);
|
|
238
|
+
}
|
|
239
|
+
if (defaultVars.length > 0) {
|
|
240
|
+
this.events.emit('verbose', `Using default values for ${pluginId}: ${defaultVars.join(', ')}`);
|
|
241
|
+
}
|
|
242
|
+
if (unusedVars.length > 0) {
|
|
243
|
+
this.events.emit('warn', `Unused variables provided for ${pluginId}: ${unusedVars.join(', ')}`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 记录所有验证通过的变量
|
|
247
|
+
const allVars = Object.keys(pluginVariables);
|
|
248
|
+
if (allVars.length > 0) {
|
|
249
|
+
this.events.emit('log', `Validated ${allVars.length} variables for plugin ${pluginId}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 验证单个变量值
|
|
255
|
+
*/
|
|
256
|
+
validateVariableValue(variableName, value, variableDefinition) {
|
|
257
|
+
if (variableDefinition.required && (!value || value.trim() === '')) {
|
|
258
|
+
return {
|
|
259
|
+
valid: false,
|
|
260
|
+
error: `Variable ${variableName} is required but value is empty`
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 可以添加更多验证规则
|
|
265
|
+
if (variableDefinition.pattern && value) {
|
|
266
|
+
const regex = new RegExp(variableDefinition.pattern);
|
|
267
|
+
if (!regex.test(value)) {
|
|
268
|
+
return {
|
|
269
|
+
valid: false,
|
|
270
|
+
error: `Variable ${variableName} value "${value}" does not match pattern ${variableDefinition.pattern}`
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (variableDefinition.options && value) {
|
|
276
|
+
const validOptions = variableDefinition.options.split(',').map(opt => opt.trim());
|
|
277
|
+
if (!validOptions.includes(value)) {
|
|
278
|
+
return {
|
|
279
|
+
valid: false,
|
|
280
|
+
error: `Variable ${variableName} value "${value}" is not one of: ${validOptions.join(', ')}`
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return { valid: true };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* 获取插件的变量文档
|
|
290
|
+
*/
|
|
291
|
+
getVariableDocumentation(pluginConfig) {
|
|
292
|
+
const pluginVariables = this._getAllPluginVariables(pluginConfig);
|
|
293
|
+
const documentation = {
|
|
294
|
+
pluginId: pluginConfig.id,
|
|
295
|
+
pluginName: pluginConfig.name,
|
|
296
|
+
variables: {}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
for (const [varName, varInfo] of Object.entries(pluginVariables)) {
|
|
300
|
+
documentation.variables[varName] = {
|
|
301
|
+
required: varInfo.required,
|
|
302
|
+
default: varInfo.default || '(none)',
|
|
303
|
+
description: varInfo.description || 'No description provided',
|
|
304
|
+
source: varInfo.source,
|
|
305
|
+
...(varInfo.configFile && { usedIn: varInfo.configFile }),
|
|
306
|
+
...(varInfo.usedInPreference && { preference: varInfo.usedInPreference })
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return documentation;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* 生成变量使用报告
|
|
315
|
+
*/
|
|
316
|
+
generateVariableReport(pluginConfig, validatedVariables) {
|
|
317
|
+
const pluginVariables = this._getAllPluginVariables(pluginConfig);
|
|
318
|
+
const report = {
|
|
319
|
+
plugin: {
|
|
320
|
+
id: pluginConfig.id,
|
|
321
|
+
name: pluginConfig.name
|
|
322
|
+
},
|
|
323
|
+
variables: [],
|
|
324
|
+
summary: {
|
|
325
|
+
total: Object.keys(pluginVariables).length,
|
|
326
|
+
required: Object.values(pluginVariables).filter(v => v.required).length,
|
|
327
|
+
provided: 0,
|
|
328
|
+
usingDefault: 0
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
for (const [varName, varInfo] of Object.entries(pluginVariables)) {
|
|
333
|
+
const value = validatedVariables[varName];
|
|
334
|
+
const isUsingDefault = value === varInfo.default;
|
|
335
|
+
const isProvided = value && value !== varInfo.default;
|
|
336
|
+
|
|
337
|
+
if (isProvided) report.summary.provided++;
|
|
338
|
+
if (isUsingDefault) report.summary.usingDefault++;
|
|
339
|
+
|
|
340
|
+
report.variables.push({
|
|
341
|
+
name: varName,
|
|
342
|
+
value: this._maskSensitiveValue(varName, value),
|
|
343
|
+
required: varInfo.required,
|
|
344
|
+
source: varInfo.source,
|
|
345
|
+
status: isProvided ? 'provided' : (isUsingDefault ? 'default' : 'missing'),
|
|
346
|
+
description: varInfo.description
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return report;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* 屏蔽敏感值(如密码、密钥等)
|
|
355
|
+
*/
|
|
356
|
+
_maskSensitiveValue(variableName, value) {
|
|
357
|
+
const sensitiveKeywords = ['KEY', 'SECRET', 'PASSWORD', 'TOKEN', 'AUTH'];
|
|
358
|
+
const isSensitive = sensitiveKeywords.some(keyword =>
|
|
359
|
+
variableName.toUpperCase().includes(keyword)
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
if (isSensitive && value) {
|
|
363
|
+
return value.substring(0, 4) + '***' + value.substring(value.length - 4);
|
|
364
|
+
}
|
|
365
|
+
return value;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
module.exports = VariableValidator;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device, Inc. Ltd. and <马弓手>.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
class ArgsProcessor {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.harmonyAliases = ['harmonyos', 'harmony', 'hongmeng', 'ohos'];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
preprocess(args) {
|
|
23
|
+
return args.map(arg => {
|
|
24
|
+
// 将鸿蒙别名统一为 harmonyos
|
|
25
|
+
if (this.harmonyAliases.includes(arg.toLowerCase())) {
|
|
26
|
+
return 'harmonyos';
|
|
27
|
+
}
|
|
28
|
+
return arg;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
isHarmonyCommand(args) {
|
|
33
|
+
return args.some(arg =>
|
|
34
|
+
this.harmonyAliases.includes(arg.toLowerCase()) ||
|
|
35
|
+
arg === 'harmonyos'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getCommand(args) {
|
|
40
|
+
return args[0] || '';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getSubCommand(args) {
|
|
44
|
+
return args[1] || '';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getTargets(args) {
|
|
48
|
+
return args.slice(2);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
extractOptions(args) {
|
|
52
|
+
const options = {};
|
|
53
|
+
const nonOptionArgs = [];
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < args.length; i++) {
|
|
56
|
+
const arg = args[i];
|
|
57
|
+
if (arg.startsWith('--')) {
|
|
58
|
+
const key = arg.slice(2);
|
|
59
|
+
const nextArg = args[i + 1];
|
|
60
|
+
if (nextArg && !nextArg.startsWith('-')) {
|
|
61
|
+
options[key] = nextArg;
|
|
62
|
+
i++; // Skip next arg
|
|
63
|
+
} else {
|
|
64
|
+
options[key] = true;
|
|
65
|
+
}
|
|
66
|
+
} else if (arg.startsWith('-')) {
|
|
67
|
+
// Handle short options
|
|
68
|
+
const key = arg.slice(1);
|
|
69
|
+
options[key] = true;
|
|
70
|
+
} else {
|
|
71
|
+
nonOptionArgs.push(arg);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { options, nonOptionArgs };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = ArgsProcessor;
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app": {
|
|
3
|
+
"signingConfigs": [],
|
|
4
|
+
"products": [
|
|
5
|
+
{
|
|
6
|
+
"name": "default",
|
|
7
|
+
"signingConfig": "default",
|
|
8
|
+
"targetSdkVersion": "5.0.5(17)",
|
|
9
|
+
"compatibleSdkVersion": "5.0.0(12)",
|
|
10
|
+
"runtimeOS": "HarmonyOS",
|
|
11
|
+
"buildOption": {
|
|
12
|
+
"strictMode": {
|
|
13
|
+
"caseSensitiveCheck": true,
|
|
14
|
+
"useNormalizedOHMUrl": true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"buildModeSet": [
|
|
20
|
+
{
|
|
21
|
+
"name": "debug",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "release"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"modules": [
|
|
29
|
+
{
|
|
30
|
+
"name": "entry",
|
|
31
|
+
"srcPath": "./entry",
|
|
32
|
+
"targets": [
|
|
33
|
+
{
|
|
34
|
+
"name": "default",
|
|
35
|
+
"applyToProducts": [
|
|
36
|
+
"default"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "cordova",
|
|
43
|
+
"srcPath": "./cordova"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": [
|
|
3
|
+
"**/*.ets"
|
|
4
|
+
],
|
|
5
|
+
"ignore": [
|
|
6
|
+
"**/src/ohosTest/**/*",
|
|
7
|
+
"**/src/test/**/*",
|
|
8
|
+
"**/src/mock/**/*",
|
|
9
|
+
"**/node_modules/**/*",
|
|
10
|
+
"**/oh_modules/**/*",
|
|
11
|
+
"**/build/**/*",
|
|
12
|
+
"**/.preview/**/*"
|
|
13
|
+
],
|
|
14
|
+
"ruleSet": [
|
|
15
|
+
"plugin:@performance/recommended",
|
|
16
|
+
"plugin:@typescript-eslint/recommended"
|
|
17
|
+
],
|
|
18
|
+
"rules": {
|
|
19
|
+
"@security/no-unsafe-aes": "error",
|
|
20
|
+
"@security/no-unsafe-hash": "error",
|
|
21
|
+
"@security/no-unsafe-mac": "warn",
|
|
22
|
+
"@security/no-unsafe-dh": "error",
|
|
23
|
+
"@security/no-unsafe-dsa": "error",
|
|
24
|
+
"@security/no-unsafe-ecdsa": "error",
|
|
25
|
+
"@security/no-unsafe-rsa-encrypt": "error",
|
|
26
|
+
"@security/no-unsafe-rsa-sign": "error",
|
|
27
|
+
"@security/no-unsafe-rsa-key": "error",
|
|
28
|
+
"@security/no-unsafe-dsa-key": "error",
|
|
29
|
+
"@security/no-unsafe-dh-key": "error",
|
|
30
|
+
"@security/no-unsafe-3des": "error"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"apiType": "stageMode",
|
|
3
|
+
"buildOption": {
|
|
4
|
+
},
|
|
5
|
+
"buildOptionSet": [
|
|
6
|
+
{
|
|
7
|
+
"name": "release",
|
|
8
|
+
"arkOptions": {
|
|
9
|
+
"obfuscation": {
|
|
10
|
+
"ruleOptions": {
|
|
11
|
+
"enable": false,
|
|
12
|
+
"files": [
|
|
13
|
+
"./obfuscation-rules.txt"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
"targets": [
|
|
21
|
+
{
|
|
22
|
+
"name": "default"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "ohosTest",
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Define project specific obfuscation rules here.
|
|
2
|
+
# You can include the obfuscation configuration files in the current module's build-profile.json5.
|
|
3
|
+
#
|
|
4
|
+
# For more details, see
|
|
5
|
+
# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5
|
|
6
|
+
|
|
7
|
+
# Obfuscation options:
|
|
8
|
+
# -disable-obfuscation: disable all obfuscations
|
|
9
|
+
# -enable-property-obfuscation: obfuscate the property names
|
|
10
|
+
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
|
|
11
|
+
# -compact: remove unnecessary blank spaces and all line feeds
|
|
12
|
+
# -remove-log: remove all console.* statements
|
|
13
|
+
# -print-namecache: print the name cache that contains the mapping from the old names to new names
|
|
14
|
+
# -apply-namecache: reuse the given cache file
|
|
15
|
+
|
|
16
|
+
# Keep options:
|
|
17
|
+
# -keep-property-name: specifies property names that you want to keep
|
|
18
|
+
# -keep-global-name: specifies names that you want to keep in the global scope
|
|
19
|
+
|
|
20
|
+
-enable-property-obfuscation
|
|
21
|
+
-enable-toplevel-obfuscation
|
|
22
|
+
-enable-filename-obfuscation
|
|
23
|
+
-enable-export-obfuscation
|