2026-05-10 23:12:26 +02:00
|
|
|
import { resolve } from 'node:path';
|
|
|
|
|
import type { Command } from '@commander-js/extra-typings';
|
2026-05-10 23:51:24 +02:00
|
|
|
import { type CommandWithGlobalOptions, type KtxCliCommandContext, resolveCommandProjectDir } from './cli-program.js';
|
2026-05-12 23:51:46 +02:00
|
|
|
import { registerRuntimeCommands } from './commands/runtime-commands.js';
|
2026-05-10 23:12:26 +02:00
|
|
|
import { profileMark } from './startup-profile.js';
|
|
|
|
|
|
|
|
|
|
profileMark('module:dev');
|
|
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
export function registerDevCommands(program: Command, context: KtxCliCommandContext): void {
|
2026-05-10 23:12:26 +02:00
|
|
|
const dev = program
|
2026-05-14 01:43:06 +02:00
|
|
|
.command('dev')
|
2026-05-13 12:00:08 +02:00
|
|
|
.description('Low-level project initialization and runtime management')
|
2026-05-10 23:12:26 +02:00
|
|
|
.showHelpAfterError();
|
|
|
|
|
|
|
|
|
|
dev.hook('preAction', (_thisCommand, actionCommand) => {
|
|
|
|
|
context.writeDebug?.('dev', actionCommand);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dev.action(() => {
|
|
|
|
|
dev.outputHelp();
|
|
|
|
|
context.setExitCode(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dev
|
|
|
|
|
.command('init')
|
2026-05-10 23:51:24 +02:00
|
|
|
.description('Initialize a Git-backed KTX project directory for maintenance scripts')
|
2026-05-10 23:12:26 +02:00
|
|
|
.argument('[directory]', 'Project directory')
|
2026-05-10 23:51:24 +02:00
|
|
|
.option('--name <name>', 'Project name written to ktx.yaml')
|
|
|
|
|
.option('--force', 'Rewrite ktx.yaml and scaffold files in an existing project', false)
|
2026-05-10 23:12:26 +02:00
|
|
|
.action(
|
|
|
|
|
async (
|
|
|
|
|
projectDir: string | undefined,
|
|
|
|
|
commandOptions: { name?: string; force?: boolean },
|
|
|
|
|
command: CommandWithGlobalOptions,
|
|
|
|
|
) => {
|
|
|
|
|
context.setExitCode(
|
|
|
|
|
await context.runInit(
|
|
|
|
|
{
|
|
|
|
|
projectDir: projectDir ? resolve(projectDir) : resolveCommandProjectDir(command),
|
|
|
|
|
...(commandOptions.name ? { projectName: commandOptions.name } : {}),
|
|
|
|
|
force: commandOptions.force === true,
|
|
|
|
|
},
|
|
|
|
|
context.io,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2026-05-12 23:51:46 +02:00
|
|
|
registerRuntimeCommands(dev, context);
|
2026-05-10 23:12:26 +02:00
|
|
|
}
|