harmonyos-dev-pro

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

HarmonyOS Development Skill (Pro Template Initialization)

HarmonyOS开发技能(专业模板初始化)

Directives

指令说明

  • Single Purpose: This skill is strictly for project scaffolding and initial build verification.
  • Templates: Supports two templates: Standard (ArkTS only) and Native C++ (ArkTS + Native API).
  • Post-Initialization: After successful build and git initialization, suggest using Conductor for project orchestration.
  • PowerShell Compatibility: All commands MUST be PowerShell-compatible.
    • Use
      ;
      as a statement separator.
    • Use
      New-Item -ItemType Directory -Path <path> -Force
      instead of
      mkdir -p
      .
    • Use
      (Get-ChildItem -Name)
      instead of
      ls /b
      or
      dir /b
      .
    • Use
      Test-Path <path>
      to check for existence before operating on files.
  • 单一用途: 本技能仅用于项目脚手架搭建与初始构建验证。
  • 模板支持: 支持两种模板:标准模板(仅ArkTS)和Native C++模板(ArkTS + Native API)。
  • 初始化后操作: 构建与Git初始化成功后,建议使用Conductor进行项目编排。
  • PowerShell兼容性: 所有命令必须兼容PowerShell。
    • 使用
      ;
      作为语句分隔符。
    • 使用
      New-Item -ItemType Directory -Path <path> -Force
      替代
      mkdir -p
    • 使用
      (Get-ChildItem -Name)
      替代
      ls /b
      dir /b
    • 在操作文件前,使用
      Test-Path <path>
      检查路径是否存在。

Initialization Workflow

初始化工作流

  1. Environment Check: Verify
    ohpm
    ,
    hvigorw
    , and
    codelinter
    are installed by running
    ohpm -v; hvigorw -v; codelinter -h
    .
  2. Template Selection: Default to Standard ArkTS project unless the user explicitly mentions "Native C++" or "Native API". Do not ask for confirmation if the request is generic.
  3. Directory Check: Ensure the target directory is suitable for a new project.
  4. Execution:
    • Project Files: Use
      xcopy /E /I /Y "assets/harmonyos-project-template/*" "."
      (or the native template path) to copy project files.
    • Scripts: Use
      xcopy /E /I /Y "scripts/*" "scripts/"
      to copy verification scripts.
    • Dependency Installation: Run
      ohpm install
      .
    • Environment Check: Run
      node scripts/check_env.cjs
      .
    • Git Initialization: If the build succeeds, run
      git init ; git add . ; git commit -m "Initial commit from HarmonyOS template"
      .
    • User Hint: Advise the user that they can now use the
      conductor-dev
      skill to initialize a
      conductor/
      directory for project orchestration and further implementation.
    • Shell Usage: Always use
      ;
      as the command separator. Prefer
      xcopy
      or
      robocopy
      for directory copies on Windows to ensure recursive copying and directory creation. Avoid
      mkdir -p
      and
      &&
      .
  1. 环境检查: 通过运行
    ohpm -v; hvigorw -v; codelinter -h
    验证
    ohpm
    hvigorw
    codelinter
    是否已安装。
  2. 模板选择: 默认使用标准ArkTS项目模板,除非用户明确要求“Native C++”或“Native API”。如果请求为通用类型,无需确认。
  3. 目录检查: 确保目标目录适合创建新项目。
  4. 执行步骤:
    • 项目文件: 使用
      xcopy /E /I /Y "assets/harmonyos-project-template/*" "."
      (或Native模板路径)复制项目文件。
    • 脚本文件: 使用
      xcopy /E /I /Y "scripts/*" "scripts/"
      复制验证脚本。
    • 依赖安装: 运行
      ohpm install
    • 环境检查: 运行
      node scripts/check_env.cjs
    • Git初始化: 构建成功后,运行
      git init ; git add . ; git commit -m "Initial commit from HarmonyOS template"
    • 用户提示: 告知用户现在可以使用
      conductor-dev
      技能初始化
      conductor/
      目录,用于项目编排与后续开发。
    • Shell使用规范: 始终使用
      ;
      作为命令分隔符。在Windows系统上优先使用
      xcopy
      robocopy
      进行目录复制,确保递归复制与目录创建。避免使用
      mkdir -p
      &&

Implementation Workflow

开发工作流

  1. Lint Before Commit: Execute
    codelinter
    on all modified
    .ets
    or
    .ts
    files immediately after editing.
    • Command:
      codelinter <file_path>
    • Requirement: All linting errors must be resolved or explicitly justified before proceeding. Do NOT run unit tests (
      hvigorw test
      ) or full project builds (
      assembleHap
      ) during task implementation.
  2. UI Component Optimization: When implementing UI components, prioritize performance by minimizing nested containers and using efficient layout managers.
  3. Self-Learning & Optimization: After completing a task, analyze the implementation for potential optimizations or reusable patterns. Document these "lessons learned" in the task summary or the project's internal knowledge base to improve future development speed and quality.
  1. 提交前代码检查: 编辑完
    .ets
    .ts
    文件后,立即对所有修改文件执行
    codelinter
    • 命令:
      codelinter <file_path>
    • 要求: 所有代码检查错误必须修复或给出明确理由才能继续。任务开发过程中,请勿运行单元测试(
      hvigorw test
      )或完整项目构建(
      assembleHap
      )。
  2. UI组件优化: 实现UI组件时,应优先考虑性能,尽量减少嵌套容器并使用高效布局管理器。
  3. 自我学习与优化: 完成任务后,分析实现方案,寻找潜在优化点或可复用模式。将这些“经验总结”记录在任务总结或项目内部知识库中,以提升未来开发速度与质量。

Core Capabilities

核心能力

1. Initialize Project

1. 项目初始化

Spatially sets up the project structure and installs dependencies.
  • Trigger: "Initialize new project", "Create new HarmonyOS app", "Scaffold template"
  • Action:
    1. Default to Standard ArkTS template unless Native C++ is requested.
    2. Copies the selected template (
      assets/harmonyos-project-template/
      or
      assets/nativec-template/
      ) to the root.
    3. Copies
      scripts/*
      into the
      scripts/
      directory.
    4. Installs dependencies, runs the environment check, and performs an initial build.
    5. Runs
      git init
      upon successful build completion.
    6. Hint: Provide a clear hint that the user are adviced to use
      conductor
      for advanced project orchestration.
    7. Shell Usage: Always use
      ;
      as the command separator and ensure PowerShell compatibility. Use
      New-Item -ItemType Directory -Force
      for directory creation.
快速搭建项目结构并安装依赖。
  • 触发指令: “初始化新项目”、“创建新HarmonyOS应用”、“搭建脚手架模板”
  • 执行操作:
    1. 除非明确要求Native C++,否则默认使用标准ArkTS模板。
    2. 将选中的模板(
      assets/harmonyos-project-template/
      assets/nativec-template/
      )复制到根目录。
    3. scripts/*
      复制到
      scripts/
      目录。
    4. 安装依赖、运行环境检查并执行初始构建。
    5. 构建成功后运行
      git init
    6. 提示信息: 明确告知用户建议使用
      conductor
      进行高级项目编排。
    7. Shell使用规范: 始终使用
      ;
      作为命令分隔符,确保PowerShell兼容性。使用
      New-Item -ItemType Directory -Force
      创建目录。

2. Build & Verify

2. 构建与验证

Ensures the application compiles correctly and uses correct SDK versions.
  • Trigger: "Build the app", "Check for errors", "Verify template"
  • Action:
    1. SDK Verification: You MUST read
      build-profile.json5
      to identify the
      targetSdkVersion
      and
      compatibleSdkVersion
      . Use the "Version to API Level Mapping" table below to cross-reference and verify the versioning.
    2. Build: Run
      ohpm install; node scripts/check_env.cjs
      .
确保应用编译正确且使用正确的SDK版本。
  • 触发指令: “构建应用”、“检查错误”、“验证模板”
  • 执行操作:
    1. SDK版本验证: 必须读取
      build-profile.json5
      文件,确认
      targetSdkVersion
      compatibleSdkVersion
      。使用下方的“版本与API级别对应表”进行交叉验证。
    2. 构建操作: 运行
      ohpm install; node scripts/check_env.cjs

Resources

资源文件

  • Standard Template:
    assets/harmonyos-project-template/
  • NativeC Template:
    assets/nativec-template/
  • Environment Scripts:
    scripts/
  • 标准模板:
    assets/harmonyos-project-template/
  • NativeC模板:
    assets/nativec-template/
  • 环境脚本:
    scripts/

Reference: Version to API Level Mapping

参考:版本与API级别对应表

VersionAPI Level
4.010
4.111
5.0.012
5.0.113
5.0.214
5.0.315
5.1.018
5.1.119
6.020
Note: If the version string in
build-profile.json5
includes a number in parentheses, such as
6.0.0(20)
, the number in the parentheses is the API Level.
版本号API级别
4.010
4.111
5.0.012
5.0.113
5.0.214
5.0.315
5.1.018
5.1.119
6.020
注意: 如果
build-profile.json5
中的版本字符串包含括号内的数字,例如
6.0.0(20)
,则括号内的数字即为API级别。