@hagicode/hagiscript 0.1.6 → 0.1.8
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 +144 -201
- package/bin/runtime +16 -0
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/pm2-commands.d.ts +2 -0
- package/dist/commands/pm2-commands.js +54 -0
- package/dist/commands/pm2-commands.js.map +1 -0
- package/dist/commands/runtime-commands.d.ts +2 -0
- package/dist/commands/runtime-commands.js +136 -0
- package/dist/commands/runtime-commands.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/command-launch.js +1 -0
- package/dist/runtime/command-launch.js.map +1 -1
- package/dist/runtime/pm2-manager.d.ts +54 -0
- package/dist/runtime/pm2-manager.js +258 -0
- package/dist/runtime/pm2-manager.js.map +1 -0
- package/dist/runtime/runtime-executor.d.ts +45 -0
- package/dist/runtime/runtime-executor.js +153 -0
- package/dist/runtime/runtime-executor.js.map +1 -0
- package/dist/runtime/runtime-manager.d.ts +79 -0
- package/dist/runtime/runtime-manager.js +651 -0
- package/dist/runtime/runtime-manager.js.map +1 -0
- package/dist/runtime/runtime-manifest.d.ts +77 -0
- package/dist/runtime/runtime-manifest.js +277 -0
- package/dist/runtime/runtime-manifest.js.map +1 -0
- package/dist/runtime/runtime-paths.d.ts +31 -0
- package/dist/runtime/runtime-paths.js +77 -0
- package/dist/runtime/runtime-paths.js.map +1 -0
- package/dist/runtime/runtime-state.d.ts +45 -0
- package/dist/runtime/runtime-state.js +82 -0
- package/dist/runtime/runtime-state.js.map +1 -0
- package/package.json +9 -5
- package/runtime/lib/runtime-script-lib.mjs +531 -0
- package/runtime/manifest.yaml +136 -0
- package/runtime/scripts/configure-code-server.mjs +14 -0
- package/runtime/scripts/configure-omniroute.mjs +16 -0
- package/runtime/scripts/install-code-server.mjs +53 -0
- package/runtime/scripts/install-dotnet.mjs +24 -0
- package/runtime/scripts/install-node.mjs +4 -0
- package/runtime/scripts/install-npm-packages.mjs +4 -0
- package/runtime/scripts/install-omniroute.mjs +60 -0
- package/runtime/scripts/remove-npm-packages.mjs +4 -0
- package/runtime/scripts/update-npm-packages.mjs +4 -0
- package/runtime/scripts/verify-dotnet.mjs +10 -0
- package/runtime/scripts/verify-node.mjs +4 -0
- package/runtime/templates/code-server-config.yaml +5 -0
- package/runtime/templates/omniroute-config.yaml +4 -0
- package/README_cn.md +0 -266
package/README.md
CHANGED
|
@@ -1,288 +1,231 @@
|
|
|
1
|
-
# Hagiscript
|
|
1
|
+
# Hagiscript Runtime Guide
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@hagicode/hagiscript)
|
|
4
4
|
[](https://www.npmjs.com/package/@hagicode/hagiscript)
|
|
5
5
|
[](./LICENSE)
|
|
6
6
|
|
|
7
|
-
`@hagicode/hagiscript` is the
|
|
7
|
+
`@hagicode/hagiscript` is the runtime management CLI behind the `hagicode-runtime` contract. Use it to install, inspect, update, remove, and operate a managed HagiCode runtime without depending on system Node.js, system PM2, or host-global npm packages.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Install
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- 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
|
+
```bash
|
|
12
|
+
npm install -g @hagicode/hagiscript
|
|
13
|
+
```
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
Primary entrypoints:
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
- `hagiscript`
|
|
18
|
+
- `hagicode-runtime` (`hagiscript runtime ...` wrapper)
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
npm install @hagicode/hagiscript
|
|
22
|
-
```
|
|
20
|
+
Node.js 20 or newer is required to run the package itself.
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
## Runtime Model
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
By default, Hagiscript loads `runtime/manifest.yaml` and manages the runtime under `~/.hagicode/runtime`.
|
|
27
25
|
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
npm
|
|
33
|
-
|
|
26
|
+
```text
|
|
27
|
+
<runtime-root>/
|
|
28
|
+
program/
|
|
29
|
+
bin/
|
|
30
|
+
npm/
|
|
31
|
+
components/
|
|
32
|
+
runtime-data/
|
|
33
|
+
config/
|
|
34
|
+
logs/
|
|
35
|
+
data/
|
|
36
|
+
components/
|
|
37
|
+
state.json
|
|
34
38
|
```
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
The split is intentional:
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
node dist/cli.js install-node --target .tmp/node-runtime
|
|
43
|
-
node dist/cli.js check-node --target .tmp/node-runtime
|
|
44
|
-
node dist/cli.js npm-sync --runtime .tmp/node-runtime --manifest manifest.json
|
|
45
|
-
```
|
|
42
|
+
- `program/` holds managed executables, vendored payloads, wrappers, and the managed npm prefix.
|
|
43
|
+
- `runtime-data/` holds mutable config, logs, state, PM2 data, and component-specific writable files.
|
|
44
|
+
|
|
45
|
+
The packaged manifest currently manages:
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
- `node` - managed Node.js runtime
|
|
48
|
+
- `dotnet` - managed .NET runtime
|
|
49
|
+
- `npm-packages` - managed npm prefix, including `pm2`
|
|
50
|
+
- `omniroute` - vendored bundled runtime
|
|
51
|
+
- `code-server` - vendored bundled runtime
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
## Core Runtime Commands
|
|
54
|
+
|
|
55
|
+
Install the full runtime:
|
|
50
56
|
|
|
51
57
|
```bash
|
|
52
|
-
hagiscript install
|
|
53
|
-
hagiscript install-node --target /opt/hagiscript/node20 --version 20
|
|
54
|
-
hagiscript install-node --target /opt/hagiscript/lts --version lts
|
|
58
|
+
hagiscript runtime install
|
|
55
59
|
```
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
Install selected components only:
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
```bash
|
|
64
|
+
hagiscript runtime install --components node,npm-packages
|
|
65
|
+
```
|
|
60
66
|
|
|
61
|
-
|
|
67
|
+
Preview planned changes without mutating files:
|
|
62
68
|
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Node.js runtime installed successfully.
|
|
67
|
-
Target: /opt/hagiscript/node
|
|
68
|
-
Node.js: v22.12.0
|
|
69
|
-
npm: 10.9.0
|
|
70
|
-
node: /opt/hagiscript/node/bin/node
|
|
71
|
-
npm: /opt/hagiscript/node/bin/npm
|
|
69
|
+
```bash
|
|
70
|
+
hagiscript runtime install --dry-run
|
|
71
|
+
hagiscript runtime update --check-only
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
Inspect the canonical runtime state:
|
|
75
75
|
|
|
76
76
|
```bash
|
|
77
|
-
hagiscript
|
|
77
|
+
hagiscript runtime state
|
|
78
|
+
hagiscript runtime state --json
|
|
78
79
|
```
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
Update or remove managed components:
|
|
81
82
|
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
Node.js: v22.12.0
|
|
86
|
-
npm: 10.9.0
|
|
87
|
-
node: /opt/hagiscript/node/bin/node
|
|
88
|
-
npm: /opt/hagiscript/node/bin/npm
|
|
83
|
+
```bash
|
|
84
|
+
hagiscript runtime update
|
|
85
|
+
hagiscript runtime remove --components code-server --purge
|
|
89
86
|
```
|
|
90
87
|
|
|
91
|
-
|
|
88
|
+
Override the runtime root or manifest when needed:
|
|
92
89
|
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
Reason: missing executable
|
|
90
|
+
```bash
|
|
91
|
+
hagiscript runtime install --runtime-root /srv/hagicode/runtime
|
|
92
|
+
hagiscript runtime state --from-manifest /path/to/runtime-manifest.yaml --json
|
|
97
93
|
```
|
|
98
94
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
`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.
|
|
95
|
+
If you prefer the runtime-oriented wrapper:
|
|
102
96
|
|
|
103
97
|
```bash
|
|
104
|
-
|
|
105
|
-
hagiscript npm-sync --runtime /opt/hagiscript/node --manifest ./manifest.json
|
|
106
|
-
hagiscript npm-sync --manifest ./manifest.json --force
|
|
107
|
-
hagiscript npm-sync --manifest ./manifest.json --registry-mirror https://registry.npmmirror.com/
|
|
108
|
-
hagiscript npm-sync --manifest ./manifest.json --registry-mirror https://registry.npmmirror.com/ --mirror-only
|
|
98
|
+
hagicode-runtime install --runtime-root /srv/hagicode/runtime
|
|
109
99
|
```
|
|
110
100
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
```json
|
|
114
|
-
{
|
|
115
|
-
"registryMirror": "https://registry.npmmirror.com/",
|
|
116
|
-
"packages": {
|
|
117
|
-
"<npm-package-name>": {
|
|
118
|
-
"version": "<semver range>",
|
|
119
|
-
"target": "<optional npm install selector>"
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
```
|
|
101
|
+
## Runtime State and Maintenance
|
|
124
102
|
|
|
125
|
-
|
|
103
|
+
`hagiscript runtime state --json` is the canonical inspection surface for automation. It reports:
|
|
126
104
|
|
|
127
|
-
|
|
105
|
+
- resolved runtime root
|
|
106
|
+
- `program/` and `runtime-data/` locations
|
|
107
|
+
- per-component install status
|
|
108
|
+
- per-component runtime data homes
|
|
109
|
+
- derived PM2 homes for managed services
|
|
110
|
+
- program/data path separation
|
|
128
111
|
|
|
129
|
-
|
|
112
|
+
Use it before and after maintenance work to confirm the expected component set and writable paths.
|
|
130
113
|
|
|
131
|
-
|
|
114
|
+
Typical maintenance flow:
|
|
132
115
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
]
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
```
|
|
116
|
+
1. Check current state: `hagiscript runtime state --json`
|
|
117
|
+
2. Apply changes: `hagiscript runtime install`, `update`, or `remove`
|
|
118
|
+
3. Re-check state to confirm the final layout
|
|
119
|
+
4. Operate services through `hagiscript pm2 ...`
|
|
120
|
+
|
|
121
|
+
Lifecycle commands print the resolved manifest, managed root, changed component count, skipped entries, and log file path when a log is generated.
|
|
122
|
+
|
|
123
|
+
## Managed PM2 Services
|
|
124
|
+
|
|
125
|
+
Hagiscript manages runtime-scoped PM2 services for:
|
|
148
126
|
|
|
149
|
-
|
|
127
|
+
- `omniroute`
|
|
128
|
+
- `code-server`
|
|
150
129
|
|
|
151
|
-
|
|
130
|
+
Supported actions:
|
|
152
131
|
|
|
153
|
-
|
|
132
|
+
- `start`
|
|
133
|
+
- `stop`
|
|
134
|
+
- `status`
|
|
154
135
|
|
|
155
|
-
|
|
136
|
+
Examples:
|
|
156
137
|
|
|
157
138
|
```bash
|
|
158
|
-
hagiscript
|
|
159
|
-
hagiscript
|
|
139
|
+
hagiscript pm2 omniroute status
|
|
140
|
+
hagiscript pm2 omniroute start
|
|
141
|
+
hagiscript pm2 code-server stop
|
|
160
142
|
```
|
|
161
143
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
```json
|
|
165
|
-
{
|
|
166
|
-
"packages": {
|
|
167
|
-
"@openspec/cli": {
|
|
168
|
-
"version": "^1.0.0"
|
|
169
|
-
},
|
|
170
|
-
"@hagicode/skills": {
|
|
171
|
-
"version": ">=0.5.0 <1.0.0",
|
|
172
|
-
"target": "0.5.4"
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
```
|
|
144
|
+
The PM2 flow is runtime-scoped:
|
|
177
145
|
|
|
178
|
-
|
|
146
|
+
- PM2 is installed into the managed npm prefix, not the host environment.
|
|
147
|
+
- Hagiscript resolves the runtime manifest before every PM2 action.
|
|
148
|
+
- PM2 runs with the managed Node runtime and managed PATH ordering.
|
|
149
|
+
- `PM2_HOME` is derived from the managed runtime layout, so service state stays inside the runtime data boundary.
|
|
179
150
|
|
|
180
|
-
|
|
151
|
+
This means maintenance scripts should call `hagiscript pm2 ...` instead of a system `pm2` binary.
|
|
181
152
|
|
|
182
|
-
|
|
183
|
-
Manifest validated: ./manifest.json (2 packages, mode=packages)
|
|
184
|
-
Registry mirror: https://registry.npmmirror.com/
|
|
185
|
-
Fallback policy: auto
|
|
186
|
-
Runtime validated: /opt/hagiscript/node
|
|
187
|
-
node: /opt/hagiscript/node/bin/node (v22.12.0)
|
|
188
|
-
npm: /opt/hagiscript/node/bin/npm (10.9.0)
|
|
189
|
-
Detected global packages: 4
|
|
190
|
-
Plan: @openspec/cli noop installed=1.0.2 required=^1.0.0 selector=@openspec/cli@^1.0.0
|
|
191
|
-
Skip: @openspec/cli already satisfies range
|
|
192
|
-
Plan: @hagicode/skills upgrade installed=0.4.0 required=>=0.5.0 <1.0.0 selector=@hagicode/skills@0.5.4
|
|
193
|
-
Install: @hagicode/skills using @hagicode/skills@0.5.4
|
|
194
|
-
Synced: @hagicode/skills (upgrade)
|
|
195
|
-
npm-sync complete.
|
|
196
|
-
Runtime: /opt/hagiscript/node
|
|
197
|
-
Manifest: ./manifest.json
|
|
198
|
-
Mode: packages
|
|
199
|
-
Registry mirror: https://registry.npmmirror.com/
|
|
200
|
-
Fallback policy: auto
|
|
201
|
-
Fallback used: no
|
|
202
|
-
Packages: 2
|
|
203
|
-
No-op: 1
|
|
204
|
-
Changed: 1
|
|
205
|
-
```
|
|
153
|
+
## Runtime Environment Contract
|
|
206
154
|
|
|
207
|
-
|
|
155
|
+
Runtime lifecycle scripts and managed services receive a stable environment contract:
|
|
208
156
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
Synced: @openspec/cli (sync)
|
|
214
|
-
```
|
|
157
|
+
- `HAGICODE_RUNTIME_HOME` - runtime program home
|
|
158
|
+
- `HAGICODE_RUNTIME_DATA_HOME` - writable runtime data home for the current component
|
|
159
|
+
- `PM2_HOME` - PM2 state directory for the current managed service
|
|
160
|
+
- `PATH` - rebuilt so managed Node, managed npm, and managed wrappers come first
|
|
215
161
|
|
|
216
|
-
|
|
162
|
+
This contract is what keeps installs, updates, wrappers, and PM2-managed services aligned to the same runtime root.
|
|
217
163
|
|
|
218
|
-
|
|
164
|
+
## Manifest Customization
|
|
219
165
|
|
|
220
|
-
|
|
221
|
-
import { createRuntimeInfo, getPackageMetadata } from "@hagicode/hagiscript";
|
|
166
|
+
`runtime/manifest.yaml` controls the runtime shape. Common override points:
|
|
222
167
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
168
|
+
- `paths.runtimeRoot`
|
|
169
|
+
- `paths.runtimeHome`
|
|
170
|
+
- `paths.runtimeDataRoot`
|
|
171
|
+
- `paths.componentDataRoot`
|
|
172
|
+
- `paths.defaultPm2Home`
|
|
173
|
+
- component `runtimeDataDir`
|
|
174
|
+
- service `pm2.appName`
|
|
175
|
+
- service `pm2.cwd`
|
|
176
|
+
- service `pm2.script`
|
|
177
|
+
- service `pm2.args`
|
|
178
|
+
- service `pm2.env`
|
|
179
|
+
- service `pm2.pm2Home`
|
|
226
180
|
|
|
227
|
-
|
|
181
|
+
For deployment-specific behavior, keep the packaged manifest as the baseline and pass `--from-manifest` with an override manifest rather than mutating the installed package in place.
|
|
228
182
|
|
|
229
|
-
|
|
183
|
+
## Related Runtime Tooling
|
|
230
184
|
|
|
231
|
-
|
|
232
|
-
npm install
|
|
233
|
-
npm run lint
|
|
234
|
-
npm run format:check
|
|
235
|
-
npm test
|
|
236
|
-
npm run build
|
|
237
|
-
npm run pack:check
|
|
238
|
-
```
|
|
185
|
+
### Managed Node Runtime
|
|
239
186
|
|
|
240
|
-
|
|
187
|
+
Install a standalone managed Node.js runtime:
|
|
241
188
|
|
|
242
189
|
```bash
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
npm run test:watch
|
|
246
|
-
npm run publish:prepare-dev-version
|
|
247
|
-
npm run publish:verify-release -- v0.1.0
|
|
190
|
+
hagiscript install-node --target /opt/hagiscript/node
|
|
191
|
+
hagiscript install-node --target /opt/hagiscript/node22 --version 22
|
|
248
192
|
```
|
|
249
193
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
`npm run build` compiles TypeScript with strict NodeNext settings into `dist/`. Expected entry points include:
|
|
194
|
+
Validate an existing managed Node.js runtime:
|
|
253
195
|
|
|
254
|
-
|
|
255
|
-
-
|
|
256
|
-
|
|
257
|
-
- `dist/cli.js`
|
|
258
|
-
- `dist/cli.d.ts`
|
|
259
|
-
- `dist/cli.js.map`
|
|
196
|
+
```bash
|
|
197
|
+
hagiscript check-node --target /opt/hagiscript/node
|
|
198
|
+
```
|
|
260
199
|
|
|
261
|
-
|
|
200
|
+
### Managed npm Package Sync
|
|
262
201
|
|
|
263
|
-
|
|
202
|
+
Sync npm global packages into a managed runtime instead of the host environment:
|
|
264
203
|
|
|
265
|
-
|
|
204
|
+
```bash
|
|
205
|
+
hagiscript npm-sync --manifest ./manifest.json
|
|
206
|
+
hagiscript npm-sync --runtime /opt/hagiscript/node --manifest ./manifest.json
|
|
207
|
+
```
|
|
266
208
|
|
|
267
|
-
|
|
209
|
+
This is mainly useful when runtime maintenance also needs a controlled agent CLI or package inventory inside the managed runtime.
|
|
268
210
|
|
|
269
|
-
|
|
211
|
+
## Development
|
|
270
212
|
|
|
271
|
-
|
|
272
|
-
- `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.
|
|
273
|
-
- `npm-publish.yml` also publishes stable GitHub releases tagged as `vX.Y.Z` to the `latest` dist-tag after validating the tag format, rejecting tags older than the repository base version, and stamping the stable version the same way.
|
|
274
|
-
- `release-drafter.yml` keeps a categorized release draft using `.github/release-drafter.yml`.
|
|
213
|
+
Run from `repos/hagiscript/`:
|
|
275
214
|
|
|
276
|
-
|
|
215
|
+
```bash
|
|
216
|
+
npm install
|
|
217
|
+
npm test
|
|
218
|
+
npm run build
|
|
219
|
+
npm run pack:check
|
|
220
|
+
```
|
|
277
221
|
|
|
278
|
-
|
|
222
|
+
Useful runtime-focused checks:
|
|
279
223
|
|
|
280
224
|
```bash
|
|
281
|
-
npm run
|
|
225
|
+
npm run integration:runtime-management
|
|
226
|
+
npm run integration:installed-runtime
|
|
282
227
|
```
|
|
283
228
|
|
|
284
|
-
For local manual releases, run plain `npm publish` after logging in with an npm account that can publish under `@hagicode`.
|
|
285
|
-
|
|
286
229
|
## License
|
|
287
230
|
|
|
288
231
|
MIT. See [LICENSE](./LICENSE).
|
package/bin/runtime
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { runCli } from "../dist/cli.js"
|
|
4
|
+
|
|
5
|
+
const argv = [
|
|
6
|
+
process.argv[0] ?? process.execPath,
|
|
7
|
+
"hagicode-runtime",
|
|
8
|
+
"runtime",
|
|
9
|
+
...process.argv.slice(2)
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
runCli(argv).catch((error) => {
|
|
13
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
14
|
+
process.stderr.write(`${message}\n`)
|
|
15
|
+
process.exitCode = 1
|
|
16
|
+
})
|
package/dist/cli.js
CHANGED
|
@@ -5,6 +5,8 @@ import { Command } from "commander";
|
|
|
5
5
|
import { createRuntimeInfo, packageVersion } from "./index.js";
|
|
6
6
|
import { registerNpmSyncCommand } from "./commands/npm-sync-commands.js";
|
|
7
7
|
import { registerNodeRuntimeCommands } from "./commands/node-runtime-commands.js";
|
|
8
|
+
import { registerPm2Commands } from "./commands/pm2-commands.js";
|
|
9
|
+
import { registerRuntimeCommands } from "./commands/runtime-commands.js";
|
|
8
10
|
export function createCli() {
|
|
9
11
|
const program = new Command();
|
|
10
12
|
program
|
|
@@ -20,6 +22,8 @@ export function createCli() {
|
|
|
20
22
|
});
|
|
21
23
|
registerNodeRuntimeCommands(program);
|
|
22
24
|
registerNpmSyncCommand(program);
|
|
25
|
+
registerPm2Commands(program);
|
|
26
|
+
registerRuntimeCommands(program);
|
|
23
27
|
program.action(() => {
|
|
24
28
|
program.outputHelp();
|
|
25
29
|
});
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +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;
|
|
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;AAClF,O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AC,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,54 @@
|
|
|
1
|
+
import { InvalidArgumentError } from "commander";
|
|
2
|
+
import { renderManagedPm2StatusText, runManagedPm2Command, supportedPm2Services } from "../runtime/pm2-manager.js";
|
|
3
|
+
export function registerPm2Commands(program) {
|
|
4
|
+
program
|
|
5
|
+
.command("pm2")
|
|
6
|
+
.description("manage PM2-backed hagicode-runtime services")
|
|
7
|
+
.argument("<service>", "managed service name", parseManagedPm2Service)
|
|
8
|
+
.argument("<action>", "pm2 action", parseManagedPm2Action)
|
|
9
|
+
.option("--from-manifest <path>", "override the default runtime manifest")
|
|
10
|
+
.option("--runtime-root <path>", "managed runtime root override")
|
|
11
|
+
.action(async (service, action, options, command) => {
|
|
12
|
+
try {
|
|
13
|
+
const result = await runManagedPm2Command({
|
|
14
|
+
manifestPath: validatePathOption(options.fromManifest, "--from-manifest"),
|
|
15
|
+
runtimeRoot: validatePathOption(options.runtimeRoot, "--runtime-root"),
|
|
16
|
+
service,
|
|
17
|
+
action
|
|
18
|
+
});
|
|
19
|
+
process.stdout.write(`${renderManagedPm2StatusText(result)}\n`);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
command.error(formatPm2Error(error), { exitCode: 1 });
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function parseManagedPm2Service(value) {
|
|
27
|
+
if (supportedPm2Services.includes(value)) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
throw new InvalidArgumentError(`Unsupported managed PM2 service "${value}". Supported services: ${supportedPm2Services.join(", ")}.`);
|
|
31
|
+
}
|
|
32
|
+
function parseManagedPm2Action(value) {
|
|
33
|
+
if (value === "start" || value === "stop" || value === "status") {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
throw new InvalidArgumentError(`Unsupported PM2 action "${value}". Supported actions: start, stop, status.`);
|
|
37
|
+
}
|
|
38
|
+
function validatePathOption(value, optionName) {
|
|
39
|
+
if (value === undefined) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const normalized = value.trim();
|
|
43
|
+
if (!normalized) {
|
|
44
|
+
throw new InvalidArgumentError(`${optionName} must be a non-empty path.`);
|
|
45
|
+
}
|
|
46
|
+
if (normalized.includes("\0")) {
|
|
47
|
+
throw new InvalidArgumentError(`${optionName} contains an invalid null byte.`);
|
|
48
|
+
}
|
|
49
|
+
return normalized;
|
|
50
|
+
}
|
|
51
|
+
function formatPm2Error(error) {
|
|
52
|
+
return error instanceof Error ? error.message : String(error);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=pm2-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pm2-commands.js","sourceRoot":"","sources":["../../src/commands/pm2-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACzD,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,EAGrB,MAAM,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