@hagicode/hagiscript 0.1.0-dev.9.1.ba06982

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 (46) hide show
  1. package/README.md +251 -0
  2. package/README_cn.md +251 -0
  3. package/dist/cli.d.ts +5 -0
  4. package/dist/cli.js +50 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/node-runtime-commands.d.ts +2 -0
  7. package/dist/commands/node-runtime-commands.js +88 -0
  8. package/dist/commands/node-runtime-commands.js.map +1 -0
  9. package/dist/commands/npm-sync-commands.d.ts +2 -0
  10. package/dist/commands/npm-sync-commands.js +155 -0
  11. package/dist/commands/npm-sync-commands.js.map +1 -0
  12. package/dist/index.d.ts +11 -0
  13. package/dist/index.js +14 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/runtime/node-download.d.ts +13 -0
  16. package/dist/runtime/node-download.js +78 -0
  17. package/dist/runtime/node-download.js.map +1 -0
  18. package/dist/runtime/node-extract.d.ts +6 -0
  19. package/dist/runtime/node-extract.js +155 -0
  20. package/dist/runtime/node-extract.js.map +1 -0
  21. package/dist/runtime/node-installer.d.ts +39 -0
  22. package/dist/runtime/node-installer.js +85 -0
  23. package/dist/runtime/node-installer.js.map +1 -0
  24. package/dist/runtime/node-platform.d.ts +14 -0
  25. package/dist/runtime/node-platform.js +41 -0
  26. package/dist/runtime/node-platform.js.map +1 -0
  27. package/dist/runtime/node-release.d.ts +28 -0
  28. package/dist/runtime/node-release.js +146 -0
  29. package/dist/runtime/node-release.js.map +1 -0
  30. package/dist/runtime/node-verify.d.ts +20 -0
  31. package/dist/runtime/node-verify.js +66 -0
  32. package/dist/runtime/node-verify.js.map +1 -0
  33. package/dist/runtime/npm-global.d.ts +20 -0
  34. package/dist/runtime/npm-global.js +53 -0
  35. package/dist/runtime/npm-global.js.map +1 -0
  36. package/dist/runtime/npm-sync.d.ts +114 -0
  37. package/dist/runtime/npm-sync.js +398 -0
  38. package/dist/runtime/npm-sync.js.map +1 -0
  39. package/dist/runtime/tool-sync-catalog.config.json +59 -0
  40. package/dist/runtime/tool-sync-catalog.d.ts +48 -0
  41. package/dist/runtime/tool-sync-catalog.js +189 -0
  42. package/dist/runtime/tool-sync-catalog.js.map +1 -0
  43. package/dist/version.d.ts +7 -0
  44. package/dist/version.js +9 -0
  45. package/dist/version.js.map +1 -0
  46. package/package.json +73 -0
package/README.md ADDED
@@ -0,0 +1,251 @@
1
+ # Hagiscript
2
+
3
+ `@hagicode/hagiscript` is the scoped npm package foundation for future Hagiscript language tooling. This initial package intentionally keeps runtime behavior small: it exposes version metadata, a baseline runtime-info API, and an executable CLI placeholder that can be built, tested, packed, and published safely.
4
+
5
+ ## Installation Assumptions
6
+
7
+ - Node.js 20 or newer is required.
8
+ - npm is the package manager for this standalone repository.
9
+ - The npm package name is `@hagicode/hagiscript`.
10
+ - GitHub Actions publishing uses `npm publish --provenance`. Local manual publishing should use plain `npm publish` unless you are inside a supported trusted publishing environment.
11
+
12
+ ## Usage
13
+
14
+ Install the package from npm:
15
+
16
+ ```bash
17
+ npm install @hagicode/hagiscript
18
+ ```
19
+
20
+ The installed CLI command remains `hagiscript`.
21
+
22
+ Run the CLI locally during development:
23
+
24
+ ```bash
25
+ npm run dev -- --help
26
+ npm run dev -- info
27
+ npm run dev -- install-node --target .tmp/node-runtime
28
+ npm run dev -- check-node --target .tmp/node-runtime
29
+ npm run dev -- npm-sync --runtime .tmp/node-runtime --manifest manifest.json
30
+ ```
31
+
32
+ After building, run the compiled CLI:
33
+
34
+ ```bash
35
+ npm run build
36
+ node dist/cli.js --version
37
+ node dist/cli.js info
38
+ node dist/cli.js install-node --target .tmp/node-runtime
39
+ node dist/cli.js check-node --target .tmp/node-runtime
40
+ node dist/cli.js npm-sync --runtime .tmp/node-runtime --manifest manifest.json
41
+ ```
42
+
43
+ ### Managed Node.js Runtime Commands
44
+
45
+ `install-node` downloads an official Node.js archive from `https://nodejs.org/dist`, extracts it into the target directory, and verifies both `node` and `npm` before reporting success.
46
+
47
+ ```bash
48
+ hagiscript install-node --target /opt/hagiscript/node
49
+ hagiscript install-node --target /opt/hagiscript/node20 --version 20
50
+ hagiscript install-node --target /opt/hagiscript/lts --version lts
51
+ ```
52
+
53
+ When `--version` is omitted, Hagiscript installs the latest available Node.js 22 release. Supported selectors are `lts`, `latest`, `current`, a major version such as `22`, an exact version such as `22.12.0`, or an exact version with a `v` prefix such as `v22.12.0`.
54
+
55
+ The target path must be missing or empty. Hagiscript refuses to install into a non-empty target directory and does not delete existing user files. During installation, temporary staging files are created beside the target directory and cleaned up after success or failure.
56
+
57
+ Example success output:
58
+
59
+ ```text
60
+ Installing Node.js 22 into /opt/hagiscript/node
61
+ Download progress: 100%
62
+ Node.js runtime installed successfully.
63
+ Target: /opt/hagiscript/node
64
+ Node.js: v22.12.0
65
+ npm: 10.9.0
66
+ node: /opt/hagiscript/node/bin/node
67
+ npm: /opt/hagiscript/node/bin/npm
68
+ ```
69
+
70
+ `check-node` validates an existing runtime directory and exits with code `0` only when both `node --version` and `npm --version` succeed.
71
+
72
+ ```bash
73
+ hagiscript check-node --target /opt/hagiscript/node
74
+ ```
75
+
76
+ Example valid output:
77
+
78
+ ```text
79
+ Node.js runtime is valid.
80
+ Target: /opt/hagiscript/node
81
+ Node.js: v22.12.0
82
+ npm: 10.9.0
83
+ node: /opt/hagiscript/node/bin/node
84
+ npm: /opt/hagiscript/node/bin/npm
85
+ ```
86
+
87
+ Example invalid output exits non-zero and includes the failure reason:
88
+
89
+ ```text
90
+ Node.js runtime is invalid.
91
+ Target: /opt/hagiscript/node
92
+ Reason: missing executable
93
+ ```
94
+
95
+ ### npm Global Package Synchronization
96
+
97
+ `npm-sync` aligns npm global packages inside a HagiScript-managed Node.js runtime with a JSON manifest. By default, it verifies or installs the managed runtime at `~/.hagiscript/node-runtime` and uses that runtime's `npm`; it does not use or mutate npm from the ambient shell `PATH`. Existing automation can keep passing `--runtime` to use an explicit runtime directory.
98
+
99
+ ```bash
100
+ hagiscript npm-sync --manifest ./manifest.json
101
+ hagiscript npm-sync --runtime /opt/hagiscript/node --manifest ./manifest.json
102
+ ```
103
+
104
+ Compatibility manifest schema:
105
+
106
+ ```json
107
+ {
108
+ "packages": {
109
+ "<npm-package-name>": {
110
+ "version": "<semver range>",
111
+ "target": "<optional npm install selector>"
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ The required `version` field accepts package.json-style semver ranges such as `^1.2.0`, `>=1.0.0 <2.0.0`, or `1.0.0 || 2.0.0`. The optional `target` field controls the selector used for `npm install -g`; when omitted, Hagiscript installs `<package>@<version>`.
118
+
119
+ Product-managed tool sync can use the expanded `tools` manifest shape. Mandatory tools are always included using internally pinned versions from `src/runtime/tool-sync-catalog.config.json`: OpenSpec skills (`skills@1.5.1`), OmniRoute (`omniroute@3.6.9`), and code-server (`code-server@4.117.0`). Optional agent CLI sync is enabled explicitly; selected built-in CLIs or custom npm packages are added when provided.
120
+
121
+ ```json
122
+ {
123
+ "tools": {
124
+ "optionalAgentCliSyncEnabled": true,
125
+ "selectedOptionalAgentCliIds": ["codex", "opencode"],
126
+ "customAgentClis": [
127
+ {
128
+ "packageName": "@scope/agent-cli",
129
+ "version": "^1.0.0"
130
+ }
131
+ ]
132
+ }
133
+ }
134
+ ```
135
+
136
+ The first built-in optional agent CLI IDs are `codex` (`@openai/codex@0.125.0`), `qoder` (`@qoder-ai/qodercli@0.1.48`), and `opencode` (`opencode-ai@1.14.24`). These built-in package versions are pinned in `src/runtime/tool-sync-catalog.config.json`. HagiScript validates unknown tool IDs, npm package names, and version selectors before `npm list` or `npm install` runs.
137
+
138
+ For simple product-managed requests, optional CLI selections can be provided directly without writing a manifest:
139
+
140
+ ```bash
141
+ hagiscript npm-sync --selected-agent-cli codex
142
+ hagiscript npm-sync --selected-agent-cli codex --custom-agent-cli @scope/agent-cli@^1.0.0
143
+ ```
144
+
145
+ Example manifest for openspec and skills tooling:
146
+
147
+ ```json
148
+ {
149
+ "packages": {
150
+ "@openspec/cli": {
151
+ "version": "^1.0.0"
152
+ },
153
+ "@hagicode/skills": {
154
+ "version": ">=0.5.0 <1.0.0",
155
+ "target": "0.5.4"
156
+ }
157
+ }
158
+ }
159
+ ```
160
+
161
+ During execution, Hagiscript validates the manifest and runtime before any npm install command runs, lists global packages with `/opt/hagiscript/node/bin/npm list -g --depth=0 --json`, plans no-op, install, upgrade, downgrade, or sync actions, and then runs `npm install -g <package>@<selector>` only for packages that need changes.
162
+
163
+ Example output:
164
+
165
+ ```text
166
+ Manifest validated: ./manifest.json (2 packages, mode=packages)
167
+ Runtime validated: /opt/hagiscript/node
168
+ node: /opt/hagiscript/node/bin/node (v22.12.0)
169
+ npm: /opt/hagiscript/node/bin/npm (10.9.0)
170
+ Detected global packages: 4
171
+ Plan: @openspec/cli noop installed=1.0.2 required=^1.0.0 selector=@openspec/cli@^1.0.0
172
+ Skip: @openspec/cli already satisfies range
173
+ Plan: @hagicode/skills upgrade installed=0.4.0 required=>=0.5.0 <1.0.0 selector=@hagicode/skills@0.5.4
174
+ Install: @hagicode/skills using @hagicode/skills@0.5.4
175
+ Synced: @hagicode/skills (upgrade)
176
+ npm-sync complete.
177
+ Runtime: /opt/hagiscript/node
178
+ Manifest: ./manifest.json
179
+ Mode: packages
180
+ Packages: 2
181
+ No-op: 1
182
+ Changed: 1
183
+ ```
184
+
185
+ Use the library API from ESM consumers:
186
+
187
+ ```ts
188
+ import { createRuntimeInfo, getPackageMetadata } from "@hagicode/hagiscript";
189
+
190
+ console.log(getPackageMetadata());
191
+ console.log(createRuntimeInfo());
192
+ ```
193
+
194
+ ## Development Commands
195
+
196
+ Run all commands from `repos/hagiscript/`:
197
+
198
+ ```bash
199
+ npm install
200
+ npm run lint
201
+ npm run format:check
202
+ npm test
203
+ npm run build
204
+ npm run pack:check
205
+ ```
206
+
207
+ Additional commands:
208
+
209
+ ```bash
210
+ npm run clean
211
+ npm run format
212
+ npm run test:watch
213
+ npm run publish:prepare-dev-version
214
+ npm run publish:verify-release -- v0.1.0
215
+ ```
216
+
217
+ ## Build Outputs
218
+
219
+ `npm run build` compiles TypeScript with strict NodeNext settings into `dist/`. Expected entry points include:
220
+
221
+ - `dist/index.js`
222
+ - `dist/index.d.ts`
223
+ - `dist/index.js.map`
224
+ - `dist/cli.js`
225
+ - `dist/cli.d.ts`
226
+ - `dist/cli.js.map`
227
+
228
+ The package `exports` field points consumers to `dist/index.js` and `dist/index.d.ts`. The published package name is `@hagicode/hagiscript`, and the `bin.hagiscript` entry points to `dist/cli.js`.
229
+
230
+ ## Package Verification
231
+
232
+ `npm run pack:check` runs a dry-run package inspection and fails if required runtime files are missing or source-only files are accidentally included. The published package should contain generated `dist` files and documentation, not raw tests, scripts, coverage, or temporary files.
233
+
234
+ ## Release Automation
235
+
236
+ GitHub Actions provide three automation paths:
237
+
238
+ - `ci.yml` installs dependencies with `npm ci`, then runs lint, format check, tests, build, and package verification.
239
+ - `npm-publish.yml` resolves a unique prerelease version from `main`, stamps both `package.json` and `package-lock.json` with `npm version --no-git-tag-version`, then publishes to the `dev` dist-tag.
240
+ - `npm-publish.yml` also publishes stable GitHub releases tagged as `vX.Y.Z` to the `latest` dist-tag after validating and stamping the stable version the same way.
241
+ - `release-drafter.yml` keeps a categorized release draft using `.github/release-drafter.yml`.
242
+
243
+ Before the first publish, make sure the npm organization or user scope `hagicode` exists on npm and grant publish access for `@hagicode/hagiscript`. For GitHub Actions releases, configure npm trusted publishing with package `@hagicode/hagiscript`, owner `HagiCode-org`, repository `hagiscript`, and workflow filename `npm-publish.yml`. Do not enter the full workflow path as the filename; leave the npm environment field empty unless the workflow job explicitly declares an environment. If the scope is missing or the workflow identity cannot create packages under it, npm returns `E404 Not Found` during the final `PUT https://registry.npmjs.org/@hagicode%2fhagiscript` publish request.
244
+
245
+ Run the publish prerequisite check before retrying a failed release:
246
+
247
+ ```bash
248
+ npm run publish:check-prereqs
249
+ ```
250
+
251
+ For local manual releases, run plain `npm publish` after logging in with an npm account that can publish under `@hagicode`.
package/README_cn.md ADDED
@@ -0,0 +1,251 @@
1
+ # Hagiscript
2
+
3
+ `@hagicode/hagiscript` 是 Hagiscript 语言工具链的作用域 npm 包基础工程。本次初始化只提供最小运行能力:版本元数据、基础运行时信息 API,以及一个可构建、可测试、可打包、可发布的 CLI 占位入口。
4
+
5
+ ## 安装假设
6
+
7
+ - 需要 Node.js 20 或更高版本。
8
+ - 该独立仓库使用 npm 作为包管理器。
9
+ - npm 包名为 `@hagicode/hagiscript`。
10
+ - GitHub Actions 发布使用 `npm publish --provenance`。本地手动发布时,应直接使用普通 `npm publish`,除非当前环境本身就是受支持的 trusted publishing 环境。
11
+
12
+ ## 使用方式
13
+
14
+ 先从 npm 安装该包:
15
+
16
+ ```bash
17
+ npm install @hagicode/hagiscript
18
+ ```
19
+
20
+ 安装后的 CLI 命令仍然是 `hagiscript`。
21
+
22
+ 开发时运行 CLI:
23
+
24
+ ```bash
25
+ npm run dev -- --help
26
+ npm run dev -- info
27
+ npm run dev -- install-node --target .tmp/node-runtime
28
+ npm run dev -- check-node --target .tmp/node-runtime
29
+ npm run dev -- npm-sync --runtime .tmp/node-runtime --manifest manifest.json
30
+ ```
31
+
32
+ 构建后运行编译产物:
33
+
34
+ ```bash
35
+ npm run build
36
+ node dist/cli.js --version
37
+ node dist/cli.js info
38
+ node dist/cli.js install-node --target .tmp/node-runtime
39
+ node dist/cli.js check-node --target .tmp/node-runtime
40
+ node dist/cli.js npm-sync --runtime .tmp/node-runtime --manifest manifest.json
41
+ ```
42
+
43
+ ### 托管 Node.js 运行时命令
44
+
45
+ `install-node` 会从 `https://nodejs.org/dist` 下载官方 Node.js 归档包,解压到目标目录,并在成功前验证 `node` 与 `npm` 都可执行。
46
+
47
+ ```bash
48
+ hagiscript install-node --target /opt/hagiscript/node
49
+ hagiscript install-node --target /opt/hagiscript/node20 --version 20
50
+ hagiscript install-node --target /opt/hagiscript/lts --version lts
51
+ ```
52
+
53
+ 省略 `--version` 时,Hagiscript 默认安装最新可用的 Node.js 22 版本。支持的选择器包括 `lts`、`latest`、`current`、类似 `22` 的主版本号、类似 `22.12.0` 的精确版本,以及类似 `v22.12.0` 的带 `v` 精确版本。
54
+
55
+ 目标路径必须不存在或为空目录。Hagiscript 会拒绝安装到非空目标目录,也不会删除已有用户文件。安装期间,临时 staging 文件会创建在目标目录旁边,并在成功或失败后清理。
56
+
57
+ 成功输出示例:
58
+
59
+ ```text
60
+ Installing Node.js 22 into /opt/hagiscript/node
61
+ Download progress: 100%
62
+ Node.js runtime installed successfully.
63
+ Target: /opt/hagiscript/node
64
+ Node.js: v22.12.0
65
+ npm: 10.9.0
66
+ node: /opt/hagiscript/node/bin/node
67
+ npm: /opt/hagiscript/node/bin/npm
68
+ ```
69
+
70
+ `check-node` 会验证已有运行时目录;只有 `node --version` 和 `npm --version` 都成功时才以退出码 `0` 结束。
71
+
72
+ ```bash
73
+ hagiscript check-node --target /opt/hagiscript/node
74
+ ```
75
+
76
+ 有效运行时输出示例:
77
+
78
+ ```text
79
+ Node.js runtime is valid.
80
+ Target: /opt/hagiscript/node
81
+ Node.js: v22.12.0
82
+ npm: 10.9.0
83
+ node: /opt/hagiscript/node/bin/node
84
+ npm: /opt/hagiscript/node/bin/npm
85
+ ```
86
+
87
+ 无效运行时会以非零退出码结束,并输出失败原因:
88
+
89
+ ```text
90
+ Node.js runtime is invalid.
91
+ Target: /opt/hagiscript/node
92
+ Reason: missing executable
93
+ ```
94
+
95
+ ### npm 全局包同步
96
+
97
+ `npm-sync` 会根据 JSON manifest,把 HagiScript 托管 Node.js 运行时中的 npm 全局包版本同步到约束范围内。默认情况下,它会验证或安装 `~/.hagiscript/node-runtime`,并使用该运行时内的 `npm`;它不会使用或修改当前 shell `PATH` 中的 npm。已有自动化仍可继续传入 `--runtime` 使用显式运行时目录。
98
+
99
+ ```bash
100
+ hagiscript npm-sync --manifest ./manifest.json
101
+ hagiscript npm-sync --runtime /opt/hagiscript/node --manifest ./manifest.json
102
+ ```
103
+
104
+ 兼容模式 manifest 结构:
105
+
106
+ ```json
107
+ {
108
+ "packages": {
109
+ "<npm-package-name>": {
110
+ "version": "<semver range>",
111
+ "target": "<optional npm install selector>"
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ 必填的 `version` 字段使用 package.json 风格的 semver 范围,例如 `^1.2.0`、`>=1.0.0 <2.0.0` 或 `1.0.0 || 2.0.0`。可选的 `target` 字段用于指定实际执行 `npm install -g` 时使用的选择器;如果省略,Hagiscript 会安装 `<package>@<version>`。
118
+
119
+ 产品托管的工具同步可使用扩展后的 `tools` manifest。必选工具始终会按 `src/runtime/tool-sync-catalog.config.json` 中的内部固定版本纳入同步:OpenSpec skills(`skills@1.5.1`)、OmniRoute(`omniroute@3.6.9`)和 code-server(`code-server@4.117.0`)。可选 agent CLI 同步需要显式启用;如果传入内置 CLI 或自定义 npm 包选择,它们会被加入同步。
120
+
121
+ ```json
122
+ {
123
+ "tools": {
124
+ "optionalAgentCliSyncEnabled": true,
125
+ "selectedOptionalAgentCliIds": ["codex", "opencode"],
126
+ "customAgentClis": [
127
+ {
128
+ "packageName": "@scope/agent-cli",
129
+ "version": "^1.0.0"
130
+ }
131
+ ]
132
+ }
133
+ }
134
+ ```
135
+
136
+ 首批内置可选 agent CLI ID 为 `codex`(`@openai/codex@0.125.0`)、`qoder`(`@qoder-ai/qodercli@0.1.48`)和 `opencode`(`opencode-ai@1.14.24`)。这些内置包版本固定在 `src/runtime/tool-sync-catalog.config.json` 中。HagiScript 会在执行 `npm list` 或 `npm install` 前校验未知工具 ID、npm 包名和版本选择器。
137
+
138
+ 简单的产品托管请求也可以直接通过 CLI 选项传入可选 CLI,而不必先写 manifest:
139
+
140
+ ```bash
141
+ hagiscript npm-sync --selected-agent-cli codex
142
+ hagiscript npm-sync --selected-agent-cli codex --custom-agent-cli @scope/agent-cli@^1.0.0
143
+ ```
144
+
145
+ openspec 和 skills 工具同步示例:
146
+
147
+ ```json
148
+ {
149
+ "packages": {
150
+ "@openspec/cli": {
151
+ "version": "^1.0.0"
152
+ },
153
+ "@hagicode/skills": {
154
+ "version": ">=0.5.0 <1.0.0",
155
+ "target": "0.5.4"
156
+ }
157
+ }
158
+ }
159
+ ```
160
+
161
+ 执行时,Hagiscript 会先验证 manifest 和运行时,再执行任何 npm install 操作;它会用 `/opt/hagiscript/node/bin/npm list -g --depth=0 --json` 检测全局包,生成 no-op、install、upgrade、downgrade 或 sync 计划,然后只对需要变更的包执行 `npm install -g <package>@<selector>`。
162
+
163
+ 输出示例:
164
+
165
+ ```text
166
+ Manifest validated: ./manifest.json (2 packages, mode=packages)
167
+ Runtime validated: /opt/hagiscript/node
168
+ node: /opt/hagiscript/node/bin/node (v22.12.0)
169
+ npm: /opt/hagiscript/node/bin/npm (10.9.0)
170
+ Detected global packages: 4
171
+ Plan: @openspec/cli noop installed=1.0.2 required=^1.0.0 selector=@openspec/cli@^1.0.0
172
+ Skip: @openspec/cli already satisfies range
173
+ Plan: @hagicode/skills upgrade installed=0.4.0 required=>=0.5.0 <1.0.0 selector=@hagicode/skills@0.5.4
174
+ Install: @hagicode/skills using @hagicode/skills@0.5.4
175
+ Synced: @hagicode/skills (upgrade)
176
+ npm-sync complete.
177
+ Runtime: /opt/hagiscript/node
178
+ Manifest: ./manifest.json
179
+ Mode: packages
180
+ Packages: 2
181
+ No-op: 1
182
+ Changed: 1
183
+ ```
184
+
185
+ 在 ESM 项目中使用库 API:
186
+
187
+ ```ts
188
+ import { createRuntimeInfo, getPackageMetadata } from "@hagicode/hagiscript";
189
+
190
+ console.log(getPackageMetadata());
191
+ console.log(createRuntimeInfo());
192
+ ```
193
+
194
+ ## 开发命令
195
+
196
+ 所有命令都应在 `repos/hagiscript/` 下执行:
197
+
198
+ ```bash
199
+ npm install
200
+ npm run lint
201
+ npm run format:check
202
+ npm test
203
+ npm run build
204
+ npm run pack:check
205
+ ```
206
+
207
+ 其他常用命令:
208
+
209
+ ```bash
210
+ npm run clean
211
+ npm run format
212
+ npm run test:watch
213
+ npm run publish:prepare-dev-version
214
+ npm run publish:verify-release -- v0.1.0
215
+ ```
216
+
217
+ ## 构建输出
218
+
219
+ `npm run build` 会使用严格的 NodeNext TypeScript 配置编译到 `dist/`。预期入口文件包括:
220
+
221
+ - `dist/index.js`
222
+ - `dist/index.d.ts`
223
+ - `dist/index.js.map`
224
+ - `dist/cli.js`
225
+ - `dist/cli.d.ts`
226
+ - `dist/cli.js.map`
227
+
228
+ `package.json` 的 `exports` 字段指向 `dist/index.js` 和 `dist/index.d.ts`。发布到 npm 后的包名是 `@hagicode/hagiscript`,`bin.hagiscript` 指向 `dist/cli.js`。
229
+
230
+ ## 包内容校验
231
+
232
+ `npm run pack:check` 会执行 dry-run 打包检查。如果缺少必要运行文件,或错误包含源码测试、脚本、覆盖率、临时目录等只应存在于开发环境的文件,脚本会失败。
233
+
234
+ ## 发布自动化
235
+
236
+ GitHub Actions 提供三类自动化流程:
237
+
238
+ - `ci.yml` 使用 `npm ci` 安装依赖,并执行 lint、格式检查、测试、构建和包内容校验。
239
+ - `npm-publish.yml` 在 `main` 分支解析唯一预发布版本,用 `npm version --no-git-tag-version` 同步 `package.json` 和 `package-lock.json`,再发布到 `dev` dist-tag。
240
+ - `npm-publish.yml` 也会在非草稿、非 prerelease 的 GitHub Release 发布时,校验 `vX.Y.Z` 标签,用同样方式写入稳定版本并发布到 `latest` dist-tag。
241
+ - `release-drafter.yml` 通过 `.github/release-drafter.yml` 维护分类清晰的发布草稿。
242
+
243
+ 首次发布前,需要先确保 npm 上已经存在组织或用户 scope `hagicode`,并且 `@hagicode/hagiscript` 已授权当前发布主体。GitHub Actions 发布时,需要在 npm trusted publishing 中配置:package `@hagicode/hagiscript`、owner `HagiCode-org`、repository `hagiscript`、workflow filename `npm-publish.yml`。不要把 workflow filename 填成完整路径;如果 npm 表单有 environment 字段,除非 workflow job 显式声明了 environment,否则保持为空。如果 scope 不存在,或 workflow 身份无权在该 scope 下创建包,npm 会在最后的 `PUT https://registry.npmjs.org/@hagicode%2fhagiscript` 发布请求中返回 `E404 Not Found`。
244
+
245
+ 重试失败的发布前,先运行发布前置检查:
246
+
247
+ ```bash
248
+ npm run publish:check-prereqs
249
+ ```
250
+
251
+ 本地手动发布时,先登录一个有权发布到 `@hagicode` scope 的 npm 账号,再直接执行普通 `npm publish`。
package/dist/cli.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ export declare function createCli(): Command;
4
+ export declare function runCli(argv?: string[]): Promise<void>;
5
+ export declare function isCliEntrypoint(moduleUrl?: string, argvPath?: string): boolean;
package/dist/cli.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import { realpathSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import { Command } from "commander";
5
+ import { createRuntimeInfo, packageVersion } from "./index.js";
6
+ import { registerNpmSyncCommand } from "./commands/npm-sync-commands.js";
7
+ import { registerNodeRuntimeCommands } from "./commands/node-runtime-commands.js";
8
+ export function createCli() {
9
+ const program = new Command();
10
+ program
11
+ .name("hagiscript")
12
+ .description("Hagiscript language tooling CLI foundation.")
13
+ .version(packageVersion, "-v, --version", "print the hagiscript version");
14
+ program
15
+ .command("info")
16
+ .description("print package foundation metadata")
17
+ .action(() => {
18
+ const info = createRuntimeInfo();
19
+ process.stdout.write(`${JSON.stringify(info, null, 2)}\n`);
20
+ });
21
+ registerNodeRuntimeCommands(program);
22
+ registerNpmSyncCommand(program);
23
+ program.action(() => {
24
+ program.outputHelp();
25
+ });
26
+ return program;
27
+ }
28
+ export async function runCli(argv = process.argv) {
29
+ const program = createCli();
30
+ await program.parseAsync(argv);
31
+ }
32
+ export function isCliEntrypoint(moduleUrl = import.meta.url, argvPath = process.argv[1]) {
33
+ if (!argvPath) {
34
+ return false;
35
+ }
36
+ try {
37
+ return realpathSync(fileURLToPath(moduleUrl)) === realpathSync(argvPath);
38
+ }
39
+ catch {
40
+ return false;
41
+ }
42
+ }
43
+ if (isCliEntrypoint()) {
44
+ runCli().catch((error) => {
45
+ const message = error instanceof Error ? error.message : String(error);
46
+ process.stderr.write(`${message}\n`);
47
+ process.exitCode = 1;
48
+ });
49
+ }
50
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAElF,MAAM,UAAU,SAAS;IACvB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,OAAO;SACJ,IAAI,CAAC,YAAY,CAAC;SAClB,WAAW,CAAC,6CAA6C,CAAC;SAC1D,OAAO,CAAC,cAAc,EAAE,eAAe,EAAE,8BAA8B,CAAC,CAAC;IAE5E,OAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,mCAAmC,CAAC;SAChD,MAAM,CAAC,GAAG,EAAE;QACX,MAAM,IAAI,GAAG,iBAAiB,EAAE,CAAC;QACjC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEL,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACrC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAEhC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE;QAClB,OAAO,CAAC,UAAU,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI;IAC9C,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;IAC5B,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAC3B,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAE1B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC3E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,IAAI,eAAe,EAAE,EAAE,CAAC;IACtB,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QAChC,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerNodeRuntimeCommands(program: Command): void;
@@ -0,0 +1,88 @@
1
+ import { InvalidArgumentError } from "commander";
2
+ import { installNodeRuntime } from "../runtime/node-installer.js";
3
+ import { validateVersionSelector } from "../runtime/node-release.js";
4
+ import { verifyNodeRuntime } from "../runtime/node-verify.js";
5
+ export function registerNodeRuntimeCommands(program) {
6
+ program
7
+ .command("install-node")
8
+ .description("install an official Node.js runtime into a target directory")
9
+ .requiredOption("--target <path>", "empty target directory for the managed runtime")
10
+ .option("--version <selector>", "Node.js selector: lts, latest, current, 22, 22.11.0, or v22.11.0", validateVersionOption)
11
+ .action(async (options, command) => {
12
+ const target = validateTargetOption(options.target);
13
+ const versionSelector = options.version;
14
+ try {
15
+ process.stdout.write(`Installing Node.js ${versionSelector ?? "22"} into ${target}\n`);
16
+ const result = await installNodeRuntime({
17
+ targetDirectory: target,
18
+ versionSelector,
19
+ onProgress: (progress) => {
20
+ if (progress.totalBytes && progress.totalBytes > 0) {
21
+ const percent = Math.floor((progress.receivedBytes / progress.totalBytes) * 100);
22
+ process.stdout.write(`Download progress: ${percent}%\r`);
23
+ }
24
+ else {
25
+ process.stdout.write(`Downloaded ${progress.receivedBytes} bytes\r`);
26
+ }
27
+ }
28
+ });
29
+ process.stdout.write("\n");
30
+ process.stdout.write(`Node.js runtime installed successfully.\n`);
31
+ process.stdout.write(`Target: ${result.targetDirectory}\n`);
32
+ process.stdout.write(`Node.js: ${result.version}\n`);
33
+ process.stdout.write(`npm: ${result.npmVersion}\n`);
34
+ process.stdout.write(`node: ${result.nodePath}\n`);
35
+ process.stdout.write(`npm: ${result.npmPath}\n`);
36
+ }
37
+ catch (error) {
38
+ command.error(formatCommandError("install-node failed", error), {
39
+ exitCode: 1
40
+ });
41
+ }
42
+ });
43
+ program
44
+ .command("check-node")
45
+ .description("validate an existing HagicScript-managed Node.js runtime")
46
+ .requiredOption("--target <path>", "target runtime directory to validate")
47
+ .action(async (options, command) => {
48
+ const target = validateTargetOption(options.target);
49
+ const result = await verifyNodeRuntime(target);
50
+ if (!result.valid) {
51
+ process.stderr.write(`Node.js runtime is invalid.\n`);
52
+ process.stderr.write(`Target: ${result.targetDirectory}\n`);
53
+ process.stderr.write(`Reason: ${result.failureReason ?? "unknown failure"}\n`);
54
+ command.error("check-node failed", { exitCode: 1 });
55
+ return;
56
+ }
57
+ process.stdout.write(`Node.js runtime is valid.\n`);
58
+ process.stdout.write(`Target: ${result.targetDirectory}\n`);
59
+ process.stdout.write(`Node.js: ${result.nodeVersion}\n`);
60
+ process.stdout.write(`npm: ${result.npmVersion}\n`);
61
+ process.stdout.write(`node: ${result.nodePath}\n`);
62
+ process.stdout.write(`npm: ${result.npmPath}\n`);
63
+ });
64
+ }
65
+ function validateVersionOption(value) {
66
+ try {
67
+ validateVersionSelector(value);
68
+ return value;
69
+ }
70
+ catch (error) {
71
+ throw new InvalidArgumentError(error instanceof Error ? error.message : String(error));
72
+ }
73
+ }
74
+ function validateTargetOption(value) {
75
+ const target = value?.trim();
76
+ if (!target) {
77
+ throw new InvalidArgumentError("--target must be a non-empty path.");
78
+ }
79
+ if (target.includes("\0")) {
80
+ throw new InvalidArgumentError("--target contains an invalid null byte.");
81
+ }
82
+ return target;
83
+ }
84
+ function formatCommandError(prefix, error) {
85
+ const message = error instanceof Error ? error.message : String(error);
86
+ return `${prefix}: ${message}`;
87
+ }
88
+ //# sourceMappingURL=node-runtime-commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-runtime-commands.js","sourceRoot":"","sources":["../../src/commands/node-runtime-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAW9D,MAAM,UAAU,2BAA2B,CAAC,OAAgB;IAC1D,OAAO;SACJ,OAAO,CAAC,cAAc,CAAC;SACvB,WAAW,CAAC,6DAA6D,CAAC;SAC1E,cAAc,CACb,iBAAiB,EACjB,gDAAgD,CACjD;SACA,MAAM,CACL,sBAAsB,EACtB,kEAAkE,EAClE,qBAAqB,CACtB;SACA,MAAM,CAAC,KAAK,EAAE,OAA2B,EAAE,OAAgB,EAAE,E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