@harmonyos-arkts/d2h 0.1.0 → 0.1.1
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 +9 -0
- package/bin/install-opencode.mjs +15 -9
- package/package.json +35 -8
- package/src/install-opencode.mjs +5 -3
package/README.md
CHANGED
|
@@ -60,6 +60,15 @@ npx --yes @harmonyos-arkts/d2h --dry-run
|
|
|
60
60
|
npx --yes @harmonyos-arkts/d2h --config-dir /path/to/opencode
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
+
默认目标为 OpenCode,也可显式使用 `--agent opencode`。安装到 DevEco Code:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
npx --yes @harmonyos-arkts/d2h --agent deveco
|
|
67
|
+
npx --yes @harmonyos-arkts/d2h@latest --agent deveco --force
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
DevEco Code 默认安装到 `~/.config/deveco`(Windows 为 `%USERPROFILE%\.config\deveco`),目录优先级为 `--config-dir` → `DEVECO_CONFIG_DIR` → `$XDG_CONFIG_HOME/deveco` → `~/.config/deveco`。OpenCode 使用 `OPENCODE_CONFIG_DIR`,两者互不混用。安装完成后重启对应应用;已有配置 JSON 保留。`--config-dir` 与 `--agent` 的参数顺序不影响结果。
|
|
71
|
+
|
|
63
72
|
默认目录按 `OPENCODE_CONFIG_DIR` → `$XDG_CONFIG_HOME/opencode` → `~/.config/opencode` 解析;Windows 默认 `%USERPROFILE%\.config\opencode`。不会读取或修改 `opencode.json`,不会复制仓库的 `AGENTS.md`。已有相同内容保持不变,冲突时提示 `--force`,其他用户 Agent/Skill 保留。
|
|
64
73
|
|
|
65
74
|
从仓库安装仍可使用原 Shell 脚本:
|
package/bin/install-opencode.mjs
CHANGED
|
@@ -4,28 +4,29 @@ import path from 'node:path';
|
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import { installOpenCode } from '../src/install-opencode.mjs';
|
|
6
6
|
|
|
7
|
-
const help = `Install this package's skills and agents into OpenCode.
|
|
7
|
+
const help = `Install this package's skills and agents into OpenCode or DevEco Code.
|
|
8
8
|
|
|
9
9
|
Usage: d2h [options]
|
|
10
10
|
|
|
11
11
|
--source-dir <path> Source root (defaults to this package)
|
|
12
|
-
--
|
|
13
|
-
|
|
12
|
+
--agent <name> opencode (default) or deveco
|
|
13
|
+
--config-dir <path> Override the selected agent's config root
|
|
14
|
+
OPENCODE_CONFIG_DIR / DEVECO_CONFIG_DIR, or
|
|
15
|
+
$XDG_CONFIG_HOME/<agent>, or ~/.config/<agent>
|
|
14
16
|
--link Create absolute symbolic links (development only)
|
|
15
17
|
--force Replace conflicting installed skills and agents
|
|
16
18
|
--dry-run Print operations without writing files
|
|
17
19
|
-h, --help Show this help
|
|
18
20
|
|
|
19
21
|
Only skills/*/SKILL.md trees and agents/*.md are installed.
|
|
20
|
-
|
|
22
|
+
Existing application configuration and AGENTS.md are not modified.
|
|
21
23
|
With npx, prefer the default copy mode: its cache can be removed.
|
|
22
24
|
`;
|
|
23
25
|
|
|
24
26
|
try {
|
|
25
27
|
const options = {
|
|
26
28
|
sourceDir: path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'),
|
|
27
|
-
|
|
28
|
-
process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'opencode'),
|
|
29
|
+
agent: 'opencode',
|
|
29
30
|
};
|
|
30
31
|
const args = process.argv.slice(2);
|
|
31
32
|
for (let index = 0; index < args.length; index++) {
|
|
@@ -34,16 +35,21 @@ try {
|
|
|
34
35
|
console.log(help);
|
|
35
36
|
process.exit(0);
|
|
36
37
|
}
|
|
37
|
-
if (arg === '--source-dir' || arg === '--config-dir') {
|
|
38
|
+
if (arg === '--source-dir' || arg === '--config-dir' || arg === '--agent') {
|
|
38
39
|
const value = args[++index];
|
|
39
|
-
if (!value || value.startsWith('--')) throw new Error(`${arg} requires a
|
|
40
|
-
options[
|
|
40
|
+
if (!value || value.startsWith('--')) throw new Error(`${arg} requires a value`);
|
|
41
|
+
options[{ '--source-dir': 'sourceDir', '--config-dir': 'configDir', '--agent': 'agent' }[arg]] = value;
|
|
41
42
|
} else if (arg === '--link' || arg === '--force' || arg === '--dry-run') {
|
|
42
43
|
options[{ '--link': 'link', '--force': 'force', '--dry-run': 'dryRun' }[arg]] = true;
|
|
43
44
|
} else {
|
|
44
45
|
throw new Error(`unknown option: ${arg}`);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
48
|
+
if (!['opencode', 'deveco'].includes(options.agent)) {
|
|
49
|
+
throw new Error(`unsupported agent: ${options.agent}; choose opencode or deveco`);
|
|
50
|
+
}
|
|
51
|
+
options.configDir ??= process.env[options.agent === 'deveco' ? 'DEVECO_CONFIG_DIR' : 'OPENCODE_CONFIG_DIR'] || path.join(
|
|
52
|
+
process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), options.agent);
|
|
47
53
|
installOpenCode(options);
|
|
48
54
|
} catch (error) {
|
|
49
55
|
console.error(`install-opencode: ${error.message}`);
|
package/package.json
CHANGED
|
@@ -1,18 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harmonyos-arkts/d2h",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Install Android-to-HarmonyOS migration agents and skills into OpenCode",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Install Android-to-HarmonyOS migration agents and skills into OpenCode or DevEco Code",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
|
|
6
|
+
"bin": {
|
|
7
|
+
"d2h": "bin/install-opencode.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"src/",
|
|
12
|
+
"skills/",
|
|
13
|
+
"agents/",
|
|
14
|
+
"schemas/",
|
|
15
|
+
"opencode/",
|
|
16
|
+
".claude-plugin/",
|
|
17
|
+
"install-opencode.sh",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
8
21
|
"scripts": {
|
|
9
22
|
"check": "node --check bin/install-opencode.mjs && node --check src/install-opencode.mjs && node scripts/check-skill-refs.mjs",
|
|
10
23
|
"test": "node --test test/*.test.mjs",
|
|
11
24
|
"prepublishOnly": "npm run check && npm test"
|
|
12
25
|
},
|
|
13
|
-
"engines": {
|
|
14
|
-
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20 <25"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/Harmony-Ai-Tool/android-to-hmos-migration.git"
|
|
32
|
+
},
|
|
15
33
|
"license": "MIT",
|
|
16
|
-
"publishConfig": {
|
|
17
|
-
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"android",
|
|
40
|
+
"harmonyos",
|
|
41
|
+
"arkts",
|
|
42
|
+
"migration",
|
|
43
|
+
"opencode"
|
|
44
|
+
]
|
|
18
45
|
}
|
package/src/install-opencode.mjs
CHANGED
|
@@ -38,7 +38,9 @@ function resolvedLocation(directory) {
|
|
|
38
38
|
return parent === directory ? directory : path.join(resolvedLocation(parent), path.basename(directory));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export function installOpenCode({ sourceDir, configDir, link = false, force = false, dryRun = false, log = console.log }) {
|
|
41
|
+
export function installOpenCode({ sourceDir, configDir, agent = 'opencode', link = false, force = false, dryRun = false, log = console.log }) {
|
|
42
|
+
if (!['opencode', 'deveco'].includes(agent)) throw new Error(`unsupported agent: ${agent}`);
|
|
43
|
+
const application = agent === 'deveco' ? 'DevEco Code' : 'OpenCode';
|
|
42
44
|
if (!configDir || ['.', '..'].includes(configDir)) throw new Error(`refusing unsafe OpenCode config directory: ${configDir}`);
|
|
43
45
|
const sourceRoot = fs.realpathSync(path.resolve(sourceDir));
|
|
44
46
|
const configRoot = resolvedLocation(path.resolve(configDir));
|
|
@@ -101,8 +103,8 @@ export function installOpenCode({ sourceDir, configDir, link = false, force = fa
|
|
|
101
103
|
}
|
|
102
104
|
const skills = entries.filter(entry => entry.kind === 'skills').length;
|
|
103
105
|
const agents = entries.filter(entry => entry.kind === 'agents').length;
|
|
104
|
-
log(`${dryRun ? '
|
|
106
|
+
log(`${application} installation ${dryRun ? 'preview' : 'complete'}: ${skills} skill(s), ${agents} agent(s).`);
|
|
105
107
|
log(`Config directory: ${configRoot}`);
|
|
106
|
-
if (!dryRun) log(
|
|
108
|
+
if (!dryRun) log(`Quit and restart ${application} to load the installed definitions.`);
|
|
107
109
|
return { skills, agents, configRoot };
|
|
108
110
|
}
|