deveco-harness 0.1.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.en.md +71 -0
- package/README.md +71 -0
- package/deveco-harness.example.jsonc +32 -0
- package/dist/index.js +758 -0
- package/package.json +48 -0
- package/prompts/build.txt +164 -0
- package/prompts/plan.txt +118 -0
- package/skills/arkts-error-fixes/README.md +151 -0
- package/skills/arkts-error-fixes/SKILL.md +150 -0
- package/skills/arkts-error-fixes/assets/AnyTypeError.ets +269 -0
- package/skills/arkts-error-fixes/assets/AppStorageError.ets +22 -0
- package/skills/arkts-error-fixes/assets/ArrowFunctionConversionError.ets +42 -0
- package/skills/arkts-error-fixes/assets/AvoidAreaTypeError.ets +43 -0
- package/skills/arkts-error-fixes/assets/BreakpointTypeError.ets +71 -0
- package/skills/arkts-error-fixes/assets/CatchClauseTypeError.ets +54 -0
- package/skills/arkts-error-fixes/assets/ColorConsistencyError.ets +88 -0
- package/skills/arkts-error-fixes/assets/ColorPropertyError.ets +39 -0
- package/skills/arkts-error-fixes/assets/ContextTypeError.ets +105 -0
- package/skills/arkts-error-fixes/assets/DecoratorStateError.ets +64 -0
- package/skills/arkts-error-fixes/assets/DisplayListenerTypeError.ets +129 -0
- package/skills/arkts-error-fixes/assets/DuplicateEntryError.ets +35 -0
- package/skills/arkts-error-fixes/assets/ESObjectTypeError.ets +137 -0
- package/skills/arkts-error-fixes/assets/FontColorPropertyError.ets +42 -0
- package/skills/arkts-error-fixes/assets/FunctionReturnTypeError.ets +41 -0
- package/skills/arkts-error-fixes/assets/IDataSourceError.ets +79 -0
- package/skills/arkts-error-fixes/assets/ImplementationNotAllowedError.ets +38 -0
- package/skills/arkts-error-fixes/assets/InterfaceMethodSignatureError.ets +43 -0
- package/skills/arkts-error-fixes/assets/NotificationError.ets +34 -0
- package/skills/arkts-error-fixes/assets/ObjectLiteralInterfaceError.ets +49 -0
- package/skills/arkts-error-fixes/assets/ObjectLiteralTypeError.ets +54 -0
- package/skills/arkts-error-fixes/assets/ObjectSpreadError.ets +29 -0
- package/skills/arkts-error-fixes/assets/PossiblyNullError.ets +32 -0
- package/skills/arkts-error-fixes/assets/ResourceConversionError.ets +159 -0
- package/skills/arkts-error-fixes/assets/StandaloneFunctionContext.ets +116 -0
- package/skills/arkts-error-fixes/assets/StandaloneFunctionError.ets +85 -0
- package/skills/arkts-error-fixes/assets/StorageLinkDefaultError.ets +41 -0
- package/skills/arkts-error-fixes/assets/TitleButtonRectTypeError.ets +86 -0
- package/skills/arkts-error-fixes/assets/UnusedVariableWarning.ets +102 -0
- package/skills/arkts-error-fixes/assets/UtilityTypeError.ets +176 -0
- package/skills/arkts-error-fixes/assets/WindowRectSizeError.ets +65 -0
- package/skills/arkts-error-fixes/assets/WindowTypeError.ets +37 -0
- package/skills/arkts-error-fixes/reference/any_type_errors.md +433 -0
- package/skills/arkts-error-fixes/reference/appstorage_errors.md +95 -0
- package/skills/arkts-error-fixes/reference/arrow_function_conversion_errors.md +163 -0
- package/skills/arkts-error-fixes/reference/avoid_area_type_errors.md +59 -0
- package/skills/arkts-error-fixes/reference/breakpoint_type_errors.md +122 -0
- package/skills/arkts-error-fixes/reference/catch_clause_type_errors.md +89 -0
- package/skills/arkts-error-fixes/reference/color_consistency_errors.md +209 -0
- package/skills/arkts-error-fixes/reference/color_property_errors.md +136 -0
- package/skills/arkts-error-fixes/reference/context_type_errors.md +260 -0
- package/skills/arkts-error-fixes/reference/decorator_state_errors.md +109 -0
- package/skills/arkts-error-fixes/reference/display_listener_type_errors.md +149 -0
- package/skills/arkts-error-fixes/reference/duplicate_entry_errors.md +193 -0
- package/skills/arkts-error-fixes/reference/esobject_type_errors.md +110 -0
- package/skills/arkts-error-fixes/reference/fontcolor_property_errors.md +104 -0
- package/skills/arkts-error-fixes/reference/function_return_type_errors.md +194 -0
- package/skills/arkts-error-fixes/reference/idata_source_errors.md +77 -0
- package/skills/arkts-error-fixes/reference/implementation_not_allowed_errors.md +191 -0
- package/skills/arkts-error-fixes/reference/interface_method_signature_errors.md +143 -0
- package/skills/arkts-error-fixes/reference/notification_errors.md +110 -0
- package/skills/arkts-error-fixes/reference/object_literal_interface_errors.md +156 -0
- package/skills/arkts-error-fixes/reference/object_literal_type_errors.md +110 -0
- package/skills/arkts-error-fixes/reference/object_spread_errors.md +105 -0
- package/skills/arkts-error-fixes/reference/possibly_null_errors.md +156 -0
- package/skills/arkts-error-fixes/reference/resource_conversion_errors.md +154 -0
- package/skills/arkts-error-fixes/reference/standalone_function_errors.md +68 -0
- package/skills/arkts-error-fixes/reference/storage_link_default_errors.md +124 -0
- package/skills/arkts-error-fixes/reference/title_button_rect_type_errors.md +167 -0
- package/skills/arkts-error-fixes/reference/unused_variable_warnings.md +295 -0
- package/skills/arkts-error-fixes/reference/utility_type_errors.md +290 -0
- package/skills/arkts-error-fixes/reference/window_rect_size_errors.md +70 -0
- package/skills/arkts-error-fixes/reference/window_type_errors.md +95 -0
- package/skills/arkts-grammar-standards/SKILL.md +71 -0
- package/skills/arkts-grammar-standards/references/basic-syntax.md +103 -0
- package/skills/arkts-grammar-standards/references/restrictions.md +100 -0
- package/skills/arkts-grammar-standards/references/topic-aliases.json +93 -0
- package/skills/arkts-grammar-standards/references/ts-diff.md +108 -0
- package/skills/arkts-runtime-fix/SKILL.md +152 -0
- package/skills/arkts-runtime-fix/SKILL_CN.md +123 -0
- package/skills/arkts-runtime-fix/evals/evals.json +17 -0
- package/skills/arkts-runtime-fix/scripts/collect-hilog.mjs +116 -0
- package/skills/arkts-runtime-fix/scripts/collect-hilog.ts +115 -0
- package/skills/arkts-runtime-fix/scripts/fetch-faultlog.mjs +117 -0
- package/skills/arkts-runtime-fix/scripts/fetch-faultlog.ts +116 -0
- package/skills/arkts-runtime-fix/scripts/jscrash-report.mjs +149 -0
- package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.mjs +126 -0
- package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.ts +126 -0
- package/skills/arkts-runtime-fix/scripts/probe-faultlogger.mjs +160 -0
- package/skills/arkts-runtime-fix/scripts/probe-faultlogger.ts +160 -0
- package/skills/arkts-runtime-fix/scripts/shared/hdc.mjs +107 -0
- package/skills/arkts-runtime-fix/scripts/shared/hdc.ts +58 -0
- package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.mjs +143 -0
- package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.ts +148 -0
- package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.mjs +389 -0
- package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.ts +409 -0
- package/skills/arkts-runtime-fix/scripts/shared/utils.mjs +27 -0
- package/skills/arkts-runtime-fix/scripts/shared/utils.ts +27 -0
- package/skills/arkui-knowledge/SKILL.md +90 -0
- package/skills/arkui-knowledge/references/api-guardrails.md +60 -0
- package/skills/arkui-knowledge/references/common-mistakes.md +119 -0
- package/skills/arkui-knowledge/references/component-cookbook.md +135 -0
- package/skills/arkui-knowledge/references/ui-quality-checklist.md +36 -0
- package/skills/deveco-create-project/SKILL.md +144 -0
- package/skills/deveco-create-project/application/AppScope/app.json5 +10 -0
- package/skills/deveco-create-project/application/AppScope/resources/base/element/string.json +8 -0
- package/skills/deveco-create-project/application/AppScope/resources/base/media/background.png +0 -0
- package/skills/deveco-create-project/application/AppScope/resources/base/media/foreground.png +0 -0
- package/skills/deveco-create-project/application/AppScope/resources/base/media/layered_image.json +7 -0
- package/skills/deveco-create-project/application/build-profile.json5 +42 -0
- package/skills/deveco-create-project/application/code-linter.json5 +32 -0
- package/skills/deveco-create-project/application/entry/build-profile.json5 +33 -0
- package/skills/deveco-create-project/application/entry/hvigorfile.ts +7 -0
- package/skills/deveco-create-project/application/entry/obfuscation-rules.txt +23 -0
- package/skills/deveco-create-project/application/entry/oh-package.json5 +10 -0
- package/skills/deveco-create-project/application/entry/src/main/ets/entryability/EntryAbility.ets +63 -0
- package/skills/deveco-create-project/application/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +31 -0
- package/skills/deveco-create-project/application/entry/src/main/ets/pages/Index.ets +38 -0
- package/skills/deveco-create-project/application/entry/src/main/module.json5 +50 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/element/color.json +8 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/element/float.json +8 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/element/string.json +16 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/media/background.png +0 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/media/foreground.png +0 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/media/layered_image.json +7 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/media/startIcon.png +0 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/backup_config.json +3 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/main_pages.json +5 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/dark/element/color.json +8 -0
- package/skills/deveco-create-project/application/hvigor/hvigor-config.json5 +23 -0
- package/skills/deveco-create-project/application/hvigorfile.ts +7 -0
- package/skills/deveco-create-project/application/oh-package.json5 +10 -0
- package/skills/deveco-create-project/scripts/copy-template.mjs +216 -0
- package/skills/deveco-create-project/scripts/copy-template.ts +214 -0
- package/skills/deveco-create-project/scripts/detect-sdk.mjs +82 -0
- package/skills/deveco-create-project/scripts/detect-sdk.ts +95 -0
package/skills/deveco-create-project/application/entry/src/main/ets/entryability/EntryAbility.ets
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
|
|
17
|
+
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
18
|
+
import { window } from '@kit.ArkUI';
|
|
19
|
+
|
|
20
|
+
const DOMAIN = 0x0000;
|
|
21
|
+
|
|
22
|
+
export default class EntryAbility extends UIAbility {
|
|
23
|
+
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
|
24
|
+
try {
|
|
25
|
+
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err));
|
|
28
|
+
}
|
|
29
|
+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
onDestroy(): void {
|
|
33
|
+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
onWindowStageCreate(windowStage: window.WindowStage): void {
|
|
37
|
+
// Main window is created, set main page for this ability
|
|
38
|
+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
|
39
|
+
|
|
40
|
+
windowStage.loadContent('pages/Index', (err) => {
|
|
41
|
+
if (err.code) {
|
|
42
|
+
hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onWindowStageDestroy(): void {
|
|
50
|
+
// Main window is destroyed, release UI related resources
|
|
51
|
+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onForeground(): void {
|
|
55
|
+
// Ability has brought to foreground
|
|
56
|
+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onBackground(): void {
|
|
60
|
+
// Ability has back to background
|
|
61
|
+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
17
|
+
import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
|
|
18
|
+
|
|
19
|
+
const DOMAIN = 0x0000;
|
|
20
|
+
|
|
21
|
+
export default class EntryBackupAbility extends BackupExtensionAbility {
|
|
22
|
+
async onBackup() {
|
|
23
|
+
hilog.info(DOMAIN, 'testTag', 'onBackup ok');
|
|
24
|
+
await Promise.resolve();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async onRestore(bundleVersion: BundleVersion) {
|
|
28
|
+
hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion));
|
|
29
|
+
await Promise.resolve();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
@Entry
|
|
17
|
+
@Component
|
|
18
|
+
struct Index {
|
|
19
|
+
@State message: string = 'Hello World';
|
|
20
|
+
|
|
21
|
+
build() {
|
|
22
|
+
RelativeContainer() {
|
|
23
|
+
Text(this.message)
|
|
24
|
+
.id('HelloWorld')
|
|
25
|
+
.fontSize($r('app.float.page_text_font_size'))
|
|
26
|
+
.fontWeight(FontWeight.Bold)
|
|
27
|
+
.alignRules({
|
|
28
|
+
center: { anchor: '__container__', align: VerticalAlign.Center },
|
|
29
|
+
middle: { anchor: '__container__', align: HorizontalAlign.Center }
|
|
30
|
+
})
|
|
31
|
+
.onClick(() => {
|
|
32
|
+
this.message = 'Welcome';
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
.height('100%')
|
|
36
|
+
.width('100%')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"module": {
|
|
3
|
+
"name": "entry",
|
|
4
|
+
"type": "entry",
|
|
5
|
+
"description": "$string:module_desc",
|
|
6
|
+
"mainElement": "EntryAbility",
|
|
7
|
+
"deviceTypes": [
|
|
8
|
+
"phone"
|
|
9
|
+
],
|
|
10
|
+
"deliveryWithInstall": true,
|
|
11
|
+
"installationFree": false,
|
|
12
|
+
"pages": "$profile:main_pages",
|
|
13
|
+
"abilities": [
|
|
14
|
+
{
|
|
15
|
+
"name": "EntryAbility",
|
|
16
|
+
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
|
17
|
+
"description": "$string:EntryAbility_desc",
|
|
18
|
+
"icon": "$media:layered_image",
|
|
19
|
+
"label": "$string:EntryAbility_label",
|
|
20
|
+
"startWindowIcon": "$media:startIcon",
|
|
21
|
+
"startWindowBackground": "$color:start_window_background",
|
|
22
|
+
"exported": true,
|
|
23
|
+
"skills": [
|
|
24
|
+
{
|
|
25
|
+
"entities": [
|
|
26
|
+
"entity.system.home"
|
|
27
|
+
],
|
|
28
|
+
"actions": [
|
|
29
|
+
"ohos.want.action.home"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"extensionAbilities": [
|
|
36
|
+
{
|
|
37
|
+
"name": "EntryBackupAbility",
|
|
38
|
+
"srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets",
|
|
39
|
+
"type": "backup",
|
|
40
|
+
"exported": false,
|
|
41
|
+
"metadata": [
|
|
42
|
+
{
|
|
43
|
+
"name": "ohos.extension.backup",
|
|
44
|
+
"resource": "$profile:backup_config"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|
package/skills/deveco-create-project/application/entry/src/main/resources/base/media/background.png
ADDED
|
Binary file
|
package/skills/deveco-create-project/application/entry/src/main/resources/base/media/foreground.png
ADDED
|
Binary file
|
package/skills/deveco-create-project/application/entry/src/main/resources/base/media/startIcon.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"modelVersion": "6.0.2",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
},
|
|
5
|
+
"execution": {
|
|
6
|
+
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */
|
|
7
|
+
// "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
|
|
8
|
+
// "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
|
|
9
|
+
// "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */
|
|
10
|
+
// "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */
|
|
11
|
+
// "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */
|
|
12
|
+
},
|
|
13
|
+
"logging": {
|
|
14
|
+
// "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
|
|
15
|
+
},
|
|
16
|
+
"debugging": {
|
|
17
|
+
// "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */
|
|
18
|
+
},
|
|
19
|
+
"nodeOptions": {
|
|
20
|
+
// "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/
|
|
21
|
+
// "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @ts-nocheck – HarmonyOS template file, only used when copied into a DevEco project
|
|
2
|
+
import { appTasks } from '@ohos/hvigor-ohos-plugin';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
|
6
|
+
plugins: [] /* Custom plugin to extend the functionality of Hvigor. */
|
|
7
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import process from 'node:process';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { detectApiLevel } from './detect-sdk.mjs';
|
|
21
|
+
|
|
22
|
+
const API_CONFIGS = {
|
|
23
|
+
17: { sdkVersion: '5.0.5(17)', modelVersion: '5.0.5' },
|
|
24
|
+
18: { sdkVersion: '5.0.6(18)', modelVersion: '5.0.6' },
|
|
25
|
+
19: { sdkVersion: '5.0.7(19)', modelVersion: '5.0.7' },
|
|
26
|
+
20: { sdkVersion: '6.0.0(20)', modelVersion: '6.0.0' },
|
|
27
|
+
21: { sdkVersion: '6.0.1(21)', modelVersion: '6.0.1' },
|
|
28
|
+
22: { sdkVersion: '6.0.2(22)', modelVersion: '6.0.2' },
|
|
29
|
+
23: { sdkVersion: '6.1.0(23)', modelVersion: '6.1.0' },
|
|
30
|
+
24: { sdkVersion: '6.1.1(24)', modelVersion: '6.1.1' }
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const REQUIRED_FILES = [
|
|
34
|
+
'build-profile.json5',
|
|
35
|
+
'AppScope/resources/base/media/layered_image.json',
|
|
36
|
+
'AppScope/resources/base/media/background.png',
|
|
37
|
+
'AppScope/resources/base/media/foreground.png',
|
|
38
|
+
'entry/src/main/resources/base/media/layered_image.json',
|
|
39
|
+
'entry/src/main/resources/base/media/background.png',
|
|
40
|
+
'entry/src/main/resources/base/media/foreground.png',
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const APP_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,127}$/;
|
|
44
|
+
|
|
45
|
+
function parseArgs(argv) {
|
|
46
|
+
const values = new Map();
|
|
47
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
48
|
+
const token = argv[index];
|
|
49
|
+
if (!token.startsWith('--')) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const key = token.slice(2);
|
|
53
|
+
const value = argv[index + 1];
|
|
54
|
+
if (!value || value.startsWith('--')) {
|
|
55
|
+
throw new Error(`Missing value for --${key}`);
|
|
56
|
+
}
|
|
57
|
+
values.set(key, value);
|
|
58
|
+
index += 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
62
|
+
const templateDir = values.get('template-dir') ??
|
|
63
|
+
path.resolve(scriptDir, '../../deveco-create-project/application');
|
|
64
|
+
const projectPath = values.get('project-path');
|
|
65
|
+
const appName = values.get('app-name');
|
|
66
|
+
const bundleName = values.get('bundle-name') ?? (appName
|
|
67
|
+
? `com.example.${appName.toLowerCase()}`
|
|
68
|
+
: undefined);
|
|
69
|
+
const apiLevelRaw = values.get('api-level');
|
|
70
|
+
const apiLevel = apiLevelRaw ? Number(apiLevelRaw) : undefined;
|
|
71
|
+
|
|
72
|
+
if (!projectPath) {
|
|
73
|
+
throw new Error('Missing required argument --project-path');
|
|
74
|
+
}
|
|
75
|
+
if (!appName) {
|
|
76
|
+
throw new Error('Missing required argument --app-name');
|
|
77
|
+
}
|
|
78
|
+
if (!bundleName) {
|
|
79
|
+
throw new Error('Missing required argument --bundle-name');
|
|
80
|
+
}
|
|
81
|
+
if (apiLevelRaw && (apiLevel === undefined || !Number.isInteger(apiLevel) || !API_CONFIGS[apiLevel])) {
|
|
82
|
+
throw new Error(`Unsupported apiLevel: ${apiLevelRaw}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
projectPath: path.resolve(projectPath),
|
|
87
|
+
appName,
|
|
88
|
+
bundleName,
|
|
89
|
+
apiLevel,
|
|
90
|
+
templateDir: path.resolve(templateDir),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function resolve(args) {
|
|
95
|
+
if (args.apiLevel) {
|
|
96
|
+
return {
|
|
97
|
+
apiLevel: args.apiLevel,
|
|
98
|
+
source: 'user_input',
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return detectApiLevel();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function copyDirectoryContents(sourceDir, targetDir) {
|
|
105
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
106
|
+
for (const entry of fs.readdirSync(sourceDir, { withFileTypes: true })) {
|
|
107
|
+
const sourcePath = path.join(sourceDir, entry.name);
|
|
108
|
+
const targetPath = path.join(targetDir, entry.name);
|
|
109
|
+
if (entry.isDirectory()) {
|
|
110
|
+
copyDirectoryContents(sourcePath, targetPath);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (fs.existsSync(targetPath)) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
117
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function replaceInFile(filePath, pairs) {
|
|
122
|
+
const original = fs.readFileSync(filePath, 'utf-8');
|
|
123
|
+
let next = original;
|
|
124
|
+
for (const [from, to] of pairs) {
|
|
125
|
+
next = next.replaceAll(from, to);
|
|
126
|
+
}
|
|
127
|
+
if (next !== original) {
|
|
128
|
+
fs.writeFileSync(filePath, next, 'utf-8');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function updateApiLevel(targetRoot, apiLevel) {
|
|
133
|
+
if (apiLevel === 22) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const config = API_CONFIGS[apiLevel];
|
|
137
|
+
replaceInFile(path.join(targetRoot, 'build-profile.json5'), [
|
|
138
|
+
['6.0.2(22)', config.sdkVersion],
|
|
139
|
+
]);
|
|
140
|
+
replaceInFile(path.join(targetRoot, 'hvigor/hvigor-config.json5'), [
|
|
141
|
+
['6.0.2', config.modelVersion],
|
|
142
|
+
]);
|
|
143
|
+
replaceInFile(path.join(targetRoot, 'oh-package.json5'), [
|
|
144
|
+
['6.0.2', config.modelVersion],
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function verifyFiles(targetRoot) {
|
|
149
|
+
return REQUIRED_FILES.filter((relativePath) => !fs.existsSync(path.join(targetRoot, relativePath)));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function main() {
|
|
153
|
+
const args = parseArgs(process.argv.slice(2));
|
|
154
|
+
|
|
155
|
+
if (!APP_NAME_PATTERN.test(args.appName)) {
|
|
156
|
+
console.error(JSON.stringify({
|
|
157
|
+
code: 'APP_NAME_INVALID',
|
|
158
|
+
message: `appName "${args.appName}" is invalid. It must start with an English letter and contain only [A-Za-z0-9_], length 1-128.`,
|
|
159
|
+
rawAppName: args.appName,
|
|
160
|
+
hint: '请通过 AskUserQuestion 给出 2-3 个符合规范的 UpperCamelCase 英文候选名(中文按语义翻译,如 "购物车" → ShoppingCart / ShopCart / Cart),让用户选择,然后用新的 --app-name 重新运行脚本。不要自己替用户决定。',
|
|
161
|
+
}, null, 2));
|
|
162
|
+
process.exit(4);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const resolved = await resolve(args);
|
|
166
|
+
if (!fs.existsSync(args.templateDir)) {
|
|
167
|
+
throw new Error(`Template directory not found: ${args.templateDir}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
fs.mkdirSync(args.projectPath, { recursive: true });
|
|
171
|
+
const targetRoot = path.join(args.projectPath, args.appName);
|
|
172
|
+
|
|
173
|
+
if (fs.existsSync(targetRoot) && fs.readdirSync(targetRoot).length > 0) {
|
|
174
|
+
console.error(JSON.stringify({
|
|
175
|
+
code: 'PROJECT_EXISTS',
|
|
176
|
+
message: `Target "${targetRoot}" already exists and is not empty.`,
|
|
177
|
+
targetRoot,
|
|
178
|
+
hint: '请通过 AskUserQuestion 向用户提供"覆盖 / 重命名 / 取消"三个选项后再决定如何继续。Never overwrite without explicit user confirmation.',
|
|
179
|
+
}, null, 2));
|
|
180
|
+
process.exit(2);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
copyDirectoryContents(args.templateDir, targetRoot);
|
|
184
|
+
|
|
185
|
+
replaceInFile(path.join(targetRoot, 'AppScope/resources/base/element/string.json'), [
|
|
186
|
+
['MyApplication', args.appName],
|
|
187
|
+
]);
|
|
188
|
+
replaceInFile(path.join(targetRoot, 'AppScope/app.json5'), [
|
|
189
|
+
['com.example.myapplication', args.bundleName],
|
|
190
|
+
]);
|
|
191
|
+
updateApiLevel(targetRoot, resolved.apiLevel);
|
|
192
|
+
|
|
193
|
+
const missingFiles = verifyFiles(targetRoot);
|
|
194
|
+
if (missingFiles.length > 0) {
|
|
195
|
+
throw new Error(`Template copy incomplete. Missing files: ${missingFiles.join(', ')}`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
console.log(JSON.stringify({
|
|
199
|
+
projectRoot: targetRoot,
|
|
200
|
+
appName: args.appName,
|
|
201
|
+
bundleName: args.bundleName,
|
|
202
|
+
apiLevel: resolved.apiLevel,
|
|
203
|
+
source: resolved.source,
|
|
204
|
+
detectedFrom: resolved.detectedFrom,
|
|
205
|
+
devecoHome: resolved.devecoHome,
|
|
206
|
+
verified: true,
|
|
207
|
+
}, null, 2));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
await main();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
214
|
+
console.error(message);
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|