@deveco-test/deveco-cli 0.3.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.
Files changed (30) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +107 -0
  3. package/SKILL.md +119 -0
  4. package/THIRD-PARTY-LICENSES +5181 -0
  5. package/dist/cli.js +1257 -0
  6. package/docs.zip +0 -0
  7. package/package.json +73 -0
  8. package/templates/application/AppScope/app.json5 +10 -0
  9. package/templates/application/AppScope/resources/base/element/string.json +8 -0
  10. package/templates/application/AppScope/resources/base/media/layered_image.json +7 -0
  11. package/templates/application/build-profile.json5 +42 -0
  12. package/templates/application/code-linter.json5 +32 -0
  13. package/templates/application/entry/build-profile.json5 +33 -0
  14. package/templates/application/entry/hvigorfile.ts +7 -0
  15. package/templates/application/entry/obfuscation-rules.txt +20 -0
  16. package/templates/application/entry/oh-package.json5 +10 -0
  17. package/templates/application/entry/src/main/ets/entryability/EntryAbility.ets +63 -0
  18. package/templates/application/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +31 -0
  19. package/templates/application/entry/src/main/ets/pages/Index.ets +38 -0
  20. package/templates/application/entry/src/main/module.json5 +50 -0
  21. package/templates/application/entry/src/main/resources/base/element/color.json +8 -0
  22. package/templates/application/entry/src/main/resources/base/element/float.json +8 -0
  23. package/templates/application/entry/src/main/resources/base/element/string.json +16 -0
  24. package/templates/application/entry/src/main/resources/base/media/layered_image.json +7 -0
  25. package/templates/application/entry/src/main/resources/base/profile/backup_config.json +3 -0
  26. package/templates/application/entry/src/main/resources/base/profile/main_pages.json +5 -0
  27. package/templates/application/entry/src/main/resources/dark/element/color.json +8 -0
  28. package/templates/application/hvigor/hvigor-config.json5 +23 -0
  29. package/templates/application/hvigorfile.ts +7 -0
  30. package/templates/application/oh-package.json5 +10 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Huawei Device Co., Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # deveco-cli
2
+
3
+ > HarmonyOS application development command line tool.
4
+
5
+ `devecocli` is a unified CLI wrapper around the DevEco Studio toolchain — `ohpm`, `hvigor`, `hdc`, `emulator`, `hilog` — plus the HMOS skills installer, a project-scaffolding template, a local HarmonyOS documentation search service, and a bundled MCP server. Drive the full HarmonyOS workflow (create → build → install → run → log → install AI skills) from one binary, with no `PATH` / `DEVECO_SDK_HOME` / `JAVA_HOME` setup.
6
+
7
+ ## Quick Start
8
+
9
+ **Prerequisites:** Node.js >= 20, DevEco Studio installed (Windows or macOS).
10
+
11
+ > Not published yet — until then, build from source (see [Development](#development)) and run `node ./dist/cli.js`. After release, self-update via `devecocli update`.
12
+
13
+ End-to-end on the command line:
14
+
15
+ ```bash
16
+ devecocli create --app-name MyApp # scaffold (default path: ./MyApp)
17
+ cd MyApp
18
+ devecocli build # package .hap
19
+ devecocli run # install + launch
20
+ devecocli log --level E # tail logs
21
+ ```
22
+
23
+ Run any command with `--help` for full options. Set `DEVECO_CLI_DEBUG=1` to print the raw underlying tool invocations.
24
+
25
+ ### Search offline documentation
26
+
27
+ ```bash
28
+ devecocli doc search List # search by keyword
29
+ devecocli doc search @State @Prop --limit 10 # multi-keyword OR search
30
+ devecocli doc read harmonyos-guides/application-models/arkts-page-start-overview # read a doc
31
+ devecocli doc catalog # list all catalogs
32
+ ```
33
+
34
+ ### Drive devecocli from an AI agent (opencode example)
35
+
36
+ Instead of typing the commands above by hand, let an agent (`opencode`, `claude`, `cursor`, …) drive `devecocli` for you. The flow below uses [opencode](https://opencode.ai/):
37
+
38
+ 1. **Teach the agent how `devecocli` works** — install the bundled `deveco-cli` skill into opencode:
39
+
40
+ ```bash
41
+ devecocli init --agent opencode
42
+ # writes the skill to ~/.config/opencode/skills/deveco-cli/
43
+ ```
44
+
45
+ (Run `devecocli init` with no flags to install into every detected agent at once.)
46
+
47
+ 2. **Enable syntax checking** — configure the `deveco-mcp` MCP server for your project:
48
+
49
+ ```bash
50
+ devecocli init --mcp --project ./MyApp
51
+ # writes MCP config to MyApp/.opencode/opencode.json, MyApp/.cursor/mcp.json, etc.
52
+ ```
53
+
54
+ The MCP server provides a unified `check` tool (auto-dispatches by file extension: `.ets` → ArkTS LSP, C/C++ → clangd) for syntax checking. Once configured, the AI agent will auto-spawn the MCP server when you open the project.
55
+
56
+ 3. **Open a project and start opencode**:
57
+
58
+ ```bash
59
+ cd MyApp # any HarmonyOS project (with build-profile.json5 / oh-package.json5)
60
+ opencode
61
+ ```
62
+
63
+ 4. **Ask in natural language** — opencode auto-loads the `deveco-cli` skill and turns prompts like the following into the right `devecocli` invocations:
64
+
65
+ - `Scaffold a new HarmonyOS app called Demo at ./Demo and build it`
66
+ - `Build this project in release mode and run it on my emulator`
67
+ - `Tail the last error logs from this app`
68
+ - `Check for syntax errors in src/main/ets/pages/Index.ets`
69
+
70
+ If the agent doesn't pick up the skill automatically, prompt it explicitly: *"Use the `deveco-cli` skill."*
71
+
72
+ ## Commands
73
+
74
+ | Command | Purpose |
75
+ | --- | --- |
76
+ | `devecocli create` | Scaffold a new HarmonyOS application project from the bundled template |
77
+ | `devecocli build` | Build / package a project or modules into `.hap` / `.hsp` / `.har` / `.app`; `build clean` removes build outputs |
78
+ | `devecocli run` | Install (with HSP deps) and launch on a device / emulator; `--skip-build` deploys existing artifacts |
79
+ | `devecocli device` | List / inspect connected devices and emulators |
80
+ | `devecocli emulator` | Manage local emulators: list / start / stop / create / delete, system images (`image download|remove|list`), and license helpers (`license view` / `license accept`) |
81
+ | `devecocli log` | Fetch hilog or crash logs (with level / bundle / keyword / from/to / tail / follow filters) |
82
+ | `devecocli doc` | Search and read HarmonyOS documentation from a local docs directory |
83
+ | `devecocli init` | Install the bundled `deveco-cli` skill into AI agents; `--mcp` configures the `deveco-mcp` MCP server for ArkTS `.ets` and C/C++ syntax checking |
84
+ | `devecocli skills` | List / find / add / remove HMOS skills for AI agents and projects |
85
+ | `devecocli serve mcp` | Host the bundled MCP (Model Context Protocol) server over stdio so AI clients (Trae / Claude / …) can call its unified `check` tool for ArkTS `.ets` and C/C++ syntax checking |
86
+ | `devecocli update` | Update the CLI itself (`npm install -g deveco-cli@latest`) |
87
+
88
+ Run `devecocli <cmd> --help` for full options, or see [`SKILL.md`](./SKILL.md) for the detailed reference (also consumed by AI agents).
89
+
90
+ Cross-platform: works on **Windows** and **macOS**; Linux is not yet supported (DevEco Studio's bundled toolchain isn't officially distributed for Linux).
91
+
92
+ ## Development
93
+
94
+ ```bash
95
+ npm install
96
+ npm run dev # Watch mode
97
+ npm start -- <command> # tsx (no build step)
98
+ npm run lint # add :fix to autofix
99
+ npm run format
100
+ npm run build # tsup → dist/cli.js
101
+ ```
102
+
103
+ See [`AGENTS.md`](./AGENTS.md) for the architecture overview.
104
+
105
+ ## License
106
+
107
+ [MIT](./LICENSE)
package/SKILL.md ADDED
@@ -0,0 +1,119 @@
1
+ ---
2
+ name: deveco-cli
3
+ description: >-
4
+ Use 'devecocli' to scaffold, build, run, and debug HarmonyOS apps — managing
5
+ devices, emulators, hilog/log, and HMOS/HarmonyOS skills. Use when the workspace has
6
+ build-profile.json5 or oh-package.json5, or the user mentions HarmonyOS/鸿蒙,
7
+ DevEco, ArkTS, ArkUI, or HMOS/HarmonyOS skills.
8
+ ---
9
+
10
+ # DevEco CLI
11
+
12
+ `devecocli` wraps DevEco Studio's `hvigor`, `ohpm`, `hdc`, emulator toolchain, and HMOS-skills installer. **Prefer `devecocli` over invoking underlying tools directly.**
13
+
14
+ Available commands: `build`, `run`, `update`, `device`, `emulator`, `skills`, `log`, `create`, `init`, `serve`, `doc`.
15
+
16
+ **Sandbox Rule**: Commands tagged `[Outside sandbox]` must be run outside the sandbox.
17
+
18
+ ## 1. Code → Build → Deploy → Run → Debug
19
+
20
+ ### `devecocli create`
21
+ Scaffold a new HarmonyOS project.
22
+ - `--app-name <name>` (Req): 1–200 chars, `^[a-zA-Z][a-zA-Z0-9_]*$`
23
+ - `--project-path <path>`: Auto-created if omitted (`./<app-name>`). Must be empty if exists.
24
+ - `--bundle-name <bundle>`: Default `com.example.<appname-lowercase>`. 7–128 chars, ≥3 segments.
25
+ - `--api-level <level>`: int ≥17 (default: auto or 23).
26
+ *Ex*: `devecocli create --app-name MyApp --project-path ./CustomDir --api-level 23`
27
+
28
+ ### `devecocli build` `[Outside sandbox]`
29
+ Compile and package project/modules. (Defaults: `--product default`, `--build-mode debug`)
30
+ | Goal | Command |
31
+ |---|---|
32
+ | Single-module / single-`entry` | `devecocli build` |
33
+ | Specific modules | `devecocli build --modules <m1> <m2>@<target>` |
34
+ | Whole product bundle (.app) | `devecocli build --product <name>` |
35
+ | Clean build outputs | `devecocli build clean` |
36
+
37
+ ### `devecocli emulator`
38
+ Manage local emulator instances and system images.
39
+ - `list`: Show instances (status, serial, device type).
40
+ - `start <names...>`: Start instances. Quote names with spaces. (See Troubleshooting if blocked).
41
+ - `stop <names...>`: Stop by name or serial (`127.0.0.1:<port>`).
42
+ - `create <name>` (Req: `--device-type`, `--os-version`): Create instance. Optional: `--force`.
43
+ - `delete <name>`: Delete instance.
44
+ - `image list`: List downloaded images. Opts: `--device-type <type>`, `--all`, `--format <table|json>`.
45
+ - `image download` / `image remove` (Req: `--device-type`, `--os-version`): Download/remove image. (Takes 30+ min, set long timeout).
46
+ *Device types*: `phone`, `foldable`, `widefold`, `triplefold`, `tablet`, `2in1`, `2in1 foldable`, `wearable`, `tv`.
47
+
48
+ ### `devecocli doc`
49
+ Search/read local HarmonyOS docs.
50
+ - `search <keywords...>`: Match any keyword. Opts: `--catalog <name>`, `--format <default|json>`, `--limit <n>`.
51
+ - `read <documentId>`: Read full content by ID.
52
+ - `catalog`: List available catalogs.
53
+
54
+ ### `devecocli device`
55
+ - `list`: Show active real devices and running emulators.
56
+ - `view`: Detailed info. Req `-t <name|serial>` on multi-device hosts.
57
+
58
+ ### `devecocli run` `[Outside sandbox]`
59
+ Build, install, and launch.
60
+ - `--module <module>`: Target module (auto-selected if only one runnable).
61
+ - `--device <name|serial>`: Target device (Req if multiple connected).
62
+ - `--product <product>` / `--build-mode <mode>`: Defaults: `default` / `debug`.
63
+ - `--ability <ability>`: Default from `module.json5`.
64
+ - `--uninstall`: Uninstall existing app first (Fixes signing key issues).
65
+ - `--skip-build`: Deploy existing artifacts.
66
+
67
+ ### `devecocli log`
68
+ Fetch hilog or crash logs. Req `--device <name|serial>` on multi-device hosts.
69
+ - `--crash`: Dump crash logs.
70
+ - `--level D|I|W|E|F`: Filter by level.
71
+ - `--bundle-name` / `--keyword`: Filter output.
72
+ - `--from <start>` / `--to <end>`: Relative offsets (`30s`, `5m`).
73
+ - `--tail <num>` / `--follow`: Keep last N lines / stream real-time (no `--to`).
74
+ *Ex*: `devecocli log --crash --bundle-name com.example.app`, `devecocli log --level E --from 5m --tail 200`
75
+
76
+ ## 2. Setup
77
+
78
+ ### `devecocli init`
79
+ MUTUALLY EXCLUSIVE modes for setup:
80
+ 1. `--skill` (Default): Install `deveco-cli` skill to AI agents.
81
+ 2. `--mcp`: Configure `deveco-mcp` server (ArkTS/C++ syntax checking).
82
+ *Options*:
83
+ - `--agent <agents>`: Comma-separated (e.g. `opencode,cursor`). Omitting targets all.
84
+ - `--project <path>`: Project-level config (Abs path for MCP).
85
+ - `--path <path>`: Direct skill install path.
86
+ - `-f, --force`: Overwrite existing config.
87
+ *MCP Rules*: Global MCP (no `--project`) only supports `opencode` and `cursor`. Others require `--project`.
88
+
89
+ ### `devecocli skills`
90
+ Manage HMOS skills in AI agents/projects.
91
+ - `list [-l|--long]` / `find <keyword>`: List or search skills.
92
+ - `add (--all | --skill <name>) [--agent <a,b…>] [--project <path>] [--path <path>] [-f]`: Install.
93
+ - `remove --skill <name> [...]`: Uninstall.
94
+
95
+ ## 3. Maintenance
96
+
97
+ - **`devecocli update`** `[Outside sandbox]`: Update CLI to latest version.
98
+ - **`devecocli serve mcp`**: Host stdio MCP server (`check` tool for `.ets`/C/C++). Used via `init --mcp`. (Env: `PROJECT_PATH`, `DEVECO_PATH`, `NODE_MAX_OLD_SPACE_SIZE`, `DEBUG=1`).
99
+
100
+ ## Recipes
101
+
102
+ - **Fresh checkout to emulator**:
103
+ `devecocli build` -> `devecocli emulator list` -> `devecocli emulator start "Name"` -> `devecocli run`
104
+ - **Diagnose crash**:
105
+ `devecocli log --crash --bundle-name <bundle>`
106
+ - **Release build**:
107
+ `devecocli build --product oversea --build-mode release`
108
+
109
+ ## Troubleshooting
110
+
111
+ - **"Product / Build mode `<x>` not found"**: Check `build-profile.json5`.
112
+ - **"Multiple entry modules" / "No entry module"**: Pass `--modules` (build) or `--module` (run).
113
+ - **"No active devices" / "Multiple devices connected"**: Connect/start emulator. Pass `-t <serial>` (device view) or `--device <name|serial>` (run/log).
114
+ - **`error:install sign info inconsistent`**: Signing key changed. Run `devecocli run --uninstall`.
115
+ - **`skills add` agent not found**: Valid: `codebuddy`, `cursor`, `opencode`, `qoder`, `trae-cn`.
116
+ - **`emulator start` / `image download` blocked on agreement**: User MUST run `devecocli emulator license accept` in interactive TTY. Agents cannot do this. Do not retry until accepted.
117
+ - **`image download` failure / timeout**: Do NOT auto-retry. Give the command to the user to run manually in their terminal.
118
+ - **`emulator create` timeout**: Treat as user-action step. Ask user to open DevEco Studio -> Device Manager. Check `emulator list` after user confirms. Do NOT auto-retry or edit SDK files.
119
+ - **`image list` duplicate OS rows**: `phone`/`foldable`/`widefold`/`triplefold` share the same image. Download/remove ONCE per OS version.