import type { Command, LifecycleCommandInput } from './lib/types.js'; import { createProjectGraphAsync, workspaceRoot } from '@nx/devkit'; import { isCI } from 'ci-info'; import { bind } from 'haywire'; import { lifecycleInternal } from '#internal/lifecycle/lifecycle-internal.js'; import { commandId } from './lib/types.js'; interface LifecycleCommandExtendedInput extends LifecycleCommandInput { configFile: string; ci: boolean; dryRun: boolean; } /** * Main `nx-lifecycle` command */ export const lifecycleCommand: Command = { command: ['$0', 'lifecycle'], describe: 'Inject Nx targets as high level workflows', builder: yargs => yargs .options({ configFile: { describe: 'Config file with `stages` and `bindings`', type: 'string', default: 'lifecycle.json', }, ci: { describe: 'Fail if file is not up to date. Implies --dry-run', type: 'boolean', default: isCI, alias: 'check', }, dryRun: { describe: 'Do not write file', type: 'boolean', default: false, }, }) .strict(), handler: async options => { const projectGraph = await createProjectGraphAsync(); await lifecycleInternal( { configFile: options.configFile, cwd: options.cwd, check: options.ci, dryRun: options.dryRun, }, { root: workspaceRoot, projects: Object.values(projectGraph.nodes).map(node => ({ name: node.name, root: node.data.root, })), } ); }, }; export const lifecycleCommandBinding = bind(commandId).withInstance(cli => cli.command(lifecycleCommand) );