apaas-oapi-client 0.1.38 → 0.1.39

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 CHANGED
@@ -51,7 +51,13 @@ mkdir -p "${CODEX_HOME:-$HOME/.codex}/skills"
51
51
  cp -R skills/apaas-* "${CODEX_HOME:-$HOME/.codex}/skills/"
52
52
  ```
53
53
 
54
- 从 npm 包所在项目安装:
54
+ 通过 npx 从 npm 直接安装:
55
+
56
+ ```bash
57
+ npx apaas-oapi-client install-skills
58
+ ```
59
+
60
+ 从已安装 npm 包的项目安装:
55
61
 
56
62
  ```bash
57
63
  mkdir -p "${CODEX_HOME:-$HOME/.codex}/skills"
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const os = require("os");
5
+ const path = require("path");
6
+
7
+ const packageRoot = path.resolve(__dirname, "..");
8
+ const skillsRoot = path.join(packageRoot, "skills");
9
+
10
+ function usage() {
11
+ console.log(`Usage:
12
+ npx apaas-oapi-client install-skills [--target <dir>] [--dry-run]
13
+
14
+ Commands:
15
+ install-skills Install bundled aPaaS Codex skills.
16
+
17
+ Options:
18
+ --target <dir> Skill install directory. Defaults to $CODEX_HOME/skills or ~/.codex/skills.
19
+ --dry-run Print planned copies without writing files.
20
+ -h, --help Show this help.`);
21
+ }
22
+
23
+ function parseArgs(argv) {
24
+ const args = {
25
+ command: argv[0],
26
+ target: process.env.CODEX_HOME
27
+ ? path.join(process.env.CODEX_HOME, "skills")
28
+ : path.join(os.homedir(), ".codex", "skills"),
29
+ dryRun: false
30
+ };
31
+
32
+ if (args.command === "-h" || args.command === "--help") {
33
+ args.command = "help";
34
+ return args;
35
+ }
36
+
37
+ for (let i = 1; i < argv.length; i += 1) {
38
+ const arg = argv[i];
39
+
40
+ if (arg === "--dry-run") {
41
+ args.dryRun = true;
42
+ continue;
43
+ }
44
+
45
+ if (arg === "--target") {
46
+ const target = argv[i + 1];
47
+ if (!target) {
48
+ throw new Error("--target requires a directory");
49
+ }
50
+ args.target = path.resolve(target);
51
+ i += 1;
52
+ continue;
53
+ }
54
+
55
+ if (arg === "-h" || arg === "--help") {
56
+ args.command = "help";
57
+ continue;
58
+ }
59
+
60
+ throw new Error(`Unknown option: ${arg}`);
61
+ }
62
+
63
+ return args;
64
+ }
65
+
66
+ function listBundledSkills() {
67
+ if (!fs.existsSync(skillsRoot)) {
68
+ throw new Error(`Bundled skills directory not found: ${skillsRoot}`);
69
+ }
70
+
71
+ return fs.readdirSync(skillsRoot, { withFileTypes: true })
72
+ .filter(entry => entry.isDirectory() && entry.name.startsWith("apaas-"))
73
+ .map(entry => entry.name)
74
+ .sort();
75
+ }
76
+
77
+ function installSkills(args) {
78
+ const skillNames = listBundledSkills();
79
+
80
+ if (skillNames.length === 0) {
81
+ throw new Error(`No bundled apaas-* skills found in ${skillsRoot}`);
82
+ }
83
+
84
+ console.log(`Installing ${skillNames.length} aPaaS skill(s) to ${args.target}`);
85
+
86
+ if (!args.dryRun) {
87
+ fs.mkdirSync(args.target, { recursive: true });
88
+ }
89
+
90
+ for (const skillName of skillNames) {
91
+ const source = path.join(skillsRoot, skillName);
92
+ const target = path.join(args.target, skillName);
93
+ console.log(`${args.dryRun ? "Would copy" : "Copying"} ${skillName}`);
94
+
95
+ if (!args.dryRun) {
96
+ fs.cpSync(source, target, {
97
+ recursive: true,
98
+ force: true,
99
+ errorOnExist: false
100
+ });
101
+ }
102
+ }
103
+
104
+ console.log(args.dryRun ? "Dry run complete." : "Done. Restart or refresh Codex to load the skills.");
105
+ }
106
+
107
+ function main() {
108
+ const args = parseArgs(process.argv.slice(2));
109
+
110
+ if (!args.command || args.command === "help") {
111
+ usage();
112
+ return;
113
+ }
114
+
115
+ if (args.command !== "install-skills") {
116
+ throw new Error(`Unknown command: ${args.command}`);
117
+ }
118
+
119
+ installSkills(args);
120
+ }
121
+
122
+ try {
123
+ main();
124
+ } catch (error) {
125
+ console.error(error instanceof Error ? error.message : String(error));
126
+ console.error("");
127
+ usage();
128
+ process.exitCode = 1;
129
+ }
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "apaas-oapi-client",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "main": "dist/index.js",
5
+ "bin": {
6
+ "apaas-oapi-client": "./bin/apaas-oapi-client.js"
7
+ },
5
8
  "exports": {
6
9
  ".": "./dist/index.js",
7
10
  "./node-sdk": "./dist/index.js"