@@ -14,6 +14,7 @@ import { |
14 | 14 | } from 'node:fs/promises'; |
15 | 15 | import os from 'node:os'; |
16 | 16 | import path from 'node:path'; |
| 17 | +import { spawn } from 'node:child_process'; |
17 | 18 | import { fileURLToPath } from 'node:url'; |
18 | 19 |
|
19 | 20 | // supported skill installer shortcuts and their default homes |
@@ -128,7 +129,7 @@ function parseArgs(args) { |
128 | 129 | const [command, ...rest] = args; |
129 | 130 |
|
130 | 131 | if (!command) { |
131 | | - throw new Error('Missing command. Usage: stackpress <skills|create>'); |
| 132 | + throw new Error('Missing command. Usage: stackpress <event|skills|create>'); |
132 | 133 | } |
133 | 134 |
|
134 | 135 | if (command === 'create') { |
@@ -139,7 +140,17 @@ function parseArgs(args) { |
139 | 140 | return parseSkillsArgs(rest); |
140 | 141 | } |
141 | 142 |
|
142 | | - throw new Error(`Unknown command "${command}". Usage: stackpress <skills|create>`); |
| 143 | + return parseRuntimeArgs(args); |
| 144 | +} |
| 145 | + |
| 146 | +/** |
| 147 | + * Treats every non-installer command as a Stackpress runtime event. |
| 148 | + */ |
| 149 | +function parseRuntimeArgs(args) { |
| 150 | + return { |
| 151 | + command: 'runtime', |
| 152 | + args |
| 153 | + }; |
143 | 154 | } |
144 | 155 |
|
145 | 156 | /** |
@@ -287,6 +298,11 @@ async function main() { |
287 | 298 | return; |
288 | 299 | } |
289 | 300 |
|
| 301 | + if (options.command === 'runtime') { |
| 302 | + await runRuntimeCommand(root, options); |
| 303 | + return; |
| 304 | + } |
| 305 | + |
290 | 306 | await runSkillsCommand(root, options); |
291 | 307 | } |
292 | 308 |
|
@@ -450,6 +466,68 @@ async function runSkillsCommand(root, options) { |
450 | 466 | } |
451 | 467 | } |
452 | 468 |
|
| 469 | +/** |
| 470 | + * Returns the executable used to run the TypeScript Stackpress runtime CLI. |
| 471 | + */ |
| 472 | +async function resolveRuntimeCommand(root) { |
| 473 | + const runtimeBin = path.join(root, 'packages', 'stackpress-server', 'bin.ts'); |
| 474 | + |
| 475 | + if (!await safeStat(runtimeBin)) { |
| 476 | + throw new Error( |
| 477 | + 'This lightweight Stackpress executable only bundles the create and ' |
| 478 | + + 'skills commands. Run framework events from an installed Stackpress ' |
| 479 | + + 'project, or install this monorepo before using runtime commands.' |
| 480 | + ); |
| 481 | + } |
| 482 | + |
| 483 | + const extension = process.platform === 'win32' ? '.cmd' : ''; |
| 484 | + const localTsx = path.join(root, 'node_modules', '.bin', `tsx${extension}`); |
| 485 | + const runner = await safeStat(localTsx) ? localTsx : `tsx${extension}`; |
| 486 | + |
| 487 | + return { |
| 488 | + args: [runtimeBin], |
| 489 | + runner |
| 490 | + }; |
| 491 | +} |
| 492 | + |
| 493 | +/** |
| 494 | + * Delegates normal Stackpress events to the framework runtime CLI. |
| 495 | + */ |
| 496 | +async function runRuntimeCommand(root, options) { |
| 497 | + const command = await resolveRuntimeCommand(root); |
| 498 | + |
| 499 | + return await new Promise((resolve, reject) => { |
| 500 | + const child = spawn(command.runner, [...command.args, ...options.args], { |
| 501 | + cwd: process.cwd(), |
| 502 | + env: process.env, |
| 503 | + stdio: 'inherit' |
| 504 | + }); |
| 505 | + |
| 506 | + child.on('error', (error) => { |
| 507 | + if (error?.code === 'ENOENT') { |
| 508 | + reject(new Error( |
| 509 | + 'Unable to run Stackpress runtime commands because tsx was not ' |
| 510 | + + 'found. Run yarn install from the repository root, then try again.' |
| 511 | + )); |
| 512 | + return; |
| 513 | + } |
| 514 | + |
| 515 | + reject(error); |
| 516 | + }); |
| 517 | + |
| 518 | + child.on('exit', (code, signal) => { |
| 519 | + if (signal) { |
| 520 | + process.kill(process.pid, signal); |
| 521 | + return; |
| 522 | + } |
| 523 | + |
| 524 | + process.exitCode = code ?? 1; |
| 525 | + resolve(); |
| 526 | + }); |
| 527 | + }); |
| 528 | +} |
| 529 | + |
| 530 | + |
453 | 531 | /** |
454 | 532 | * Reads file metadata and treats missing files as undefined. |
455 | 533 | */ |
@@ -471,10 +549,13 @@ async function safeStat(file) { |
471 | 549 | function usage() { |
472 | 550 | return [ |
473 | 551 | 'Usage:', |
| 552 | + ' stackpress <event> [options]', |
474 | 553 | ' stackpress create [--dry-run]', |
475 | 554 | ' stackpress skills --target <codex|claude|opencode|path> [--force] [--dry-run]', |
476 | 555 | '', |
477 | 556 | 'Examples:', |
| 557 | + ' stackpress develop --b config/develop -v', |
| 558 | + ' stackpress serve --b config/preview -v', |
478 | 559 | ' stackpress create', |
479 | 560 | ' stackpress skills --target codex', |
480 | 561 | ' stackpress skills --target claude', |
@@ -499,6 +580,7 @@ export { |
499 | 580 | copySkills, |
500 | 581 | createProject, |
501 | 582 | parseArgs, |
| 583 | + resolveRuntimeCommand, |
502 | 584 | resolveTargetDirectory |
503 | 585 | }; |
504 | 586 |
|
|