Files
lifeforge/scripts/forge/cli/setup.ts
Melvin Chia 9f17cfd33b feat(cli): implement module management commands (add, remove, list) and enhance CLI logging
Former-commit-id: a27df1846c1fbc898c62a97e34f5f30eaa25325d [formerly ffc7fa7d80b1036f7f0fb4021fc166a58c413d40] [formerly e65c86c6674076e461d8cb804c009161aad7006d [formerly 64368a36e380a93f2d62808d6255826f11da9fee]]
Former-commit-id: c0efbb95a1243aa8c1316a34ce852c98b9b0cd66 [formerly 2c7aa0860c82d25d90901e89a7d70f161308d027]
Former-commit-id: c3e346e2d6b78be92c66c348e5f9df003a15dadf
2025-10-10 13:20:33 +08:00

96 lines
2.5 KiB
TypeScript

import { program } from 'commander'
import fs from 'fs'
import { devHandler, getAvailableServices } from '../commands/dev-commands'
import * as moduleHandlers from '../commands/module-commands'
import {
createCommandHandler,
getAvailableCommands
} from '../commands/project-commands'
import { PROJECTS_ALLOWED } from '../constants/constants'
const VERSION_NUMBER = JSON.parse(
fs.readFileSync('package.json', 'utf-8')
).version
/**
* Sets up the CLI program with all commands
*/
export function setupCLI(): void {
program
.name('Lifeforge Forge')
.description('Build and manage Lifeforge projects')
.version(VERSION_NUMBER)
setupProjectCommands()
setupDevCommand()
setupModulesCommand()
}
/**
* Sets up project commands (build, types, lint)
*/
function setupProjectCommands(): void {
const availableCommands = getAvailableCommands()
for (const commandType of availableCommands) {
program
.command(commandType)
.description(`Run ${commandType} for specified projects`)
.argument(
'<projects...>',
`Project names to run ${commandType} on. Use 'all' for all projects. Available: all, ${Object.keys(PROJECTS_ALLOWED).join(', ')}`
)
.action(createCommandHandler(commandType))
}
}
/**
* Sets up the dev command for starting services in development mode
*/
function setupDevCommand(): void {
const availableServices = getAvailableServices()
program
.command('dev')
.description('Start Lifeforge services for development')
.argument(
'<service>',
`Service to start. Use all for starting db, server, and client. Available: ${availableServices.join(', ')}`
)
.action(devHandler)
}
/**
* Sets up commands for managing modules
*/
function setupModulesCommand(): void {
const command = program
.command('modules')
.description('Manage Lifeforge modules')
.argument(
'[action]',
'Action to perform on modules. Available: list, add, remove'
)
command.command('list').action(moduleHandlers.listModulesHandler)
command
.command('add')
.argument('<module>', 'Module to add, e.g., lifeforge-app/wallet')
.action(moduleHandlers.addModuleHandler)
command
.command('remove')
.argument(
'[module]',
'Module to remove, e.g., wallet (optional, will show list if not provided)'
)
.action(moduleHandlers.removeModuleHandler)
}
/**
* Parses command line arguments and runs the CLI
*/
export function runCLI(): void {
program.parse()
}