Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/cli/bin/sh1pt.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#!/usr/bin/env node
import('../dist/index.js');
import('../dist/index.js')
.then(({ run }) => run(process.argv.slice(2)))
.catch((err) => {
console.error(err?.message || err);
process.exit(1);
});
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"scripts": {
"build": "tsc -p tsconfig.json",
"dev": "tsx src/index.ts",
"test": "cd ../.. && pnpm exec vitest run packages/cli/src/**/*.test.ts",
"typecheck": "tsc -p tsconfig.json --noEmit",
"prepublishOnly": "pnpm build"
},
Expand Down
21 changes: 17 additions & 4 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Command } from 'commander';
import kleur from 'kleur';
import { createRequire } from 'node:module';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { logError } from './lib/logger.js';
import { buildCmd } from './commands/build.js';
import { createActionsCmd } from './commands/build-actions.js';
import { promoteCmd } from './commands/promote.js';
Expand Down Expand Up @@ -66,7 +69,17 @@ for (const cat of CATEGORIES) {
program.addCommand(makeCategoryCmd(cat));
}

program.parseAsync(process.argv).catch((err) => {
console.error(kleur.red(`error: ${err.message}`));
process.exit(1);
});
export async function run(argv = process.argv.slice(2)): Promise<void> {
await program.parseAsync(argv, { from: 'user' });
}

const invokedPath = process.argv[1] ? resolve(process.argv[1]) : '';
const modulePath = fileURLToPath(import.meta.url);
const isDirectExecution = invokedPath !== '' && invokedPath === modulePath;
if (isDirectExecution) {
run().catch((err) => {
const message = err instanceof Error ? err.message : String(err);
logError(kleur.red(`error: ${message}`));
process.exit(1);
});
}
3 changes: 3 additions & 0 deletions packages/cli/src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function logError(message: string): void {
console.error(message);
}