|
| 1 | +import { Argv, CommandModule } from "yargs"; |
| 2 | +import { |
| 3 | + initCICD, |
| 4 | + generateCICD, |
| 5 | + listPlatforms, |
| 6 | + validatePipelines |
| 7 | +} from "./form"; |
| 8 | + |
| 9 | +// eslint-disable-next-line @typescript-eslint/ban-types |
| 10 | +type CommandModuleArgs = {}; |
| 11 | + |
| 12 | +export type CIPlatform = "github" | "gitlab" | "circleci" | "jenkins" | "bitbucket" | "azure"; |
| 13 | +export type CIStrategy = "basic" | "comprehensive" | "security-focused"; |
| 14 | + |
| 15 | +const cicdCommand = (): CommandModule<CommandModuleArgs, any> => { |
| 16 | + return { |
| 17 | + command: "cicd <action> [platform]", |
| 18 | + describe: "Generate and manage CI/CD pipeline configurations.", |
| 19 | + aliases: ["ci", "pipeline"], |
| 20 | + builder: (yargs: Argv): Argv => { |
| 21 | + yargs.positional("action", { |
| 22 | + choices: ["init", "generate", "list", "validate"] as const, |
| 23 | + describe: "Action to perform", |
| 24 | + type: "string", |
| 25 | + demandOption: true, |
| 26 | + }); |
| 27 | + |
| 28 | + yargs.positional("platform", { |
| 29 | + choices: ["github", "gitlab", "circleci", "jenkins", "bitbucket", "azure", "all"] as const, |
| 30 | + describe: "CI/CD platform to generate for", |
| 31 | + type: "string", |
| 32 | + }); |
| 33 | + |
| 34 | + yargs.option("strategy", { |
| 35 | + choices: ["basic", "comprehensive", "security-focused"] as const, |
| 36 | + describe: "CI/CD pipeline strategy", |
| 37 | + type: "string", |
| 38 | + alias: "s", |
| 39 | + default: "comprehensive", |
| 40 | + }); |
| 41 | + |
| 42 | + yargs.option("include-security", { |
| 43 | + describe: "Include security scanning (Trivy, Snyk)", |
| 44 | + type: "boolean", |
| 45 | + default: true, |
| 46 | + }); |
| 47 | + |
| 48 | + yargs.option("include-e2e", { |
| 49 | + describe: "Include end-to-end tests", |
| 50 | + type: "boolean", |
| 51 | + default: false, |
| 52 | + }); |
| 53 | + |
| 54 | + yargs.option("include-coverage", { |
| 55 | + describe: "Include code coverage reporting", |
| 56 | + type: "boolean", |
| 57 | + default: true, |
| 58 | + }); |
| 59 | + |
| 60 | + yargs.option("docker-registry", { |
| 61 | + describe: "Docker registry URL (e.g., ghcr.io, docker.io)", |
| 62 | + type: "string", |
| 63 | + alias: "r", |
| 64 | + }); |
| 65 | + |
| 66 | + yargs.option("deploy-target", { |
| 67 | + choices: ["kubernetes", "ecs", "cloudrun", "railway", "render", "fly", "none"] as const, |
| 68 | + describe: "Deployment target platform", |
| 69 | + type: "string", |
| 70 | + default: "none", |
| 71 | + }); |
| 72 | + |
| 73 | + yargs.option("branch", { |
| 74 | + describe: "Branch to trigger CI/CD on", |
| 75 | + type: "string", |
| 76 | + alias: "b", |
| 77 | + default: "main", |
| 78 | + }); |
| 79 | + |
| 80 | + yargs.option("node-version", { |
| 81 | + describe: "Node.js version for CI", |
| 82 | + type: "string", |
| 83 | + default: "20", |
| 84 | + }); |
| 85 | + |
| 86 | + yargs.option("output-dir", { |
| 87 | + describe: "Output directory for generated files", |
| 88 | + type: "string", |
| 89 | + alias: "o", |
| 90 | + }); |
| 91 | + |
| 92 | + return yargs; |
| 93 | + }, |
| 94 | + handler: async (argv) => { |
| 95 | + const { |
| 96 | + action, |
| 97 | + platform, |
| 98 | + strategy, |
| 99 | + includeSecurity, |
| 100 | + includeE2e, |
| 101 | + includeCoverage, |
| 102 | + dockerRegistry, |
| 103 | + deployTarget, |
| 104 | + branch, |
| 105 | + nodeVersion, |
| 106 | + outputDir, |
| 107 | + } = argv; |
| 108 | + |
| 109 | + const options = { |
| 110 | + platform: platform as CIPlatform | "all" | undefined, |
| 111 | + strategy: strategy as CIStrategy, |
| 112 | + includeSecurity, |
| 113 | + includeE2E: includeE2e, |
| 114 | + includeCoverage, |
| 115 | + dockerRegistry, |
| 116 | + deployTarget, |
| 117 | + branch, |
| 118 | + nodeVersion, |
| 119 | + outputDir, |
| 120 | + }; |
| 121 | + |
| 122 | + switch (action) { |
| 123 | + case "init": |
| 124 | + await initCICD(options); |
| 125 | + break; |
| 126 | + case "generate": |
| 127 | + await generateCICD(options); |
| 128 | + break; |
| 129 | + case "list": |
| 130 | + await listPlatforms(); |
| 131 | + break; |
| 132 | + case "validate": |
| 133 | + await validatePipelines(); |
| 134 | + break; |
| 135 | + default: |
| 136 | + console.log(`Unknown action: ${action}`); |
| 137 | + } |
| 138 | + }, |
| 139 | + }; |
| 140 | +}; |
| 141 | + |
| 142 | +export { cicdCommand }; |
0 commit comments