UNPKG

rajt

Version:

A serverless bundler layer, fully typed for AWS Lambda (Node.js and LLRT) and Cloudflare Workers.

82 lines (73 loc) 2.22 kB
import { defineCommand, runMain, renderUsage } from 'citty' import type { ArgsDef, CommandDef } from 'citty' import { createConsola } from 'consola' import { logo } from '../utils/log' import { isColorSupported, gray } from '../utils/colors' import { version as rajtVersion } from '../../package.json' import dev from './commands/dev' import build from './commands/build' import deploy from './commands/deploy' import routes from './commands/routes' import migrate from './commands/migrate' import make from './commands/make' /** * The main entrypoint for the CLI. * main only gets called when the script is run directly, not when it's imported as a module. */ const directly = () => { try { // @ts-ignore return typeof vitest == 'undefined' && import.meta.url == `file://${process.argv[1].replace(/\\/g, '/')}` } catch { return false } } const name = 'Rajt CLI' const version = [name, isColorSupported ? gray('v'+rajtVersion) : rajtVersion].join(' ') if (directly()) { const _args = process.argv.slice(2) const length = _args.length if (!length || (length == 1 && ['-v', '--version', '--v', '-version'].includes(_args[0]))) { console.log(version) process.exit(0) } console.log(`\n${logo} ${version}\n`) const consola = createConsola({ formatOptions: {date: false} }) async function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>) { try { consola.log((await renderUsage(cmd, parent)).split('\n').slice(1).join('\n') + '\n') } catch (error) { consola.error(error) } } const main = defineCommand({ meta: { name: 'rajt', version: '', description: name, }, subCommands: { dev, build, deploy, routes, endpoints: routes, migrate, make, 'make:config': make, 'make:enum': make, 'make:route': make, 'make:action': make, 'make:endpoint': make, 'make:migrate': make, 'make:migration': make, 'make:model': make, 'make:job': make, 'make:seed': make, 'make:seeder': make, 'make:test': make, }, }) runMain(main, { rawArgs: length ? undefined : ['-h'], showUsage }) }