From dd84b9d64fb98746a230cd24233ff50a562c39c9 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Fri, 28 Apr 2023 01:36:44 +0800 Subject: --- packages/turbo-codemod/src/cli.ts | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 packages/turbo-codemod/src/cli.ts (limited to 'packages/turbo-codemod/src/cli.ts') diff --git a/packages/turbo-codemod/src/cli.ts b/packages/turbo-codemod/src/cli.ts new file mode 100644 index 0000000..451816f --- /dev/null +++ b/packages/turbo-codemod/src/cli.ts @@ -0,0 +1,73 @@ +#!/usr/bin/env node + +import chalk from "chalk"; +import { Command } from "commander"; + +import { transform, migrate } from "./commands"; +import notifyUpdate from "./utils/notifyUpdate"; +import cliPkg from "../package.json"; + +const codemodCli = new Command(); + +codemodCli + .name("@turbo/codemod") + .description( + "Codemod transformations to help upgrade your Turborepo codebase when a feature is deprecated." + ) + .version(cliPkg.version, "-v, --version", "output the current version"); + +// migrate +codemodCli + .command("migrate") + .aliases(["update", "upgrade"]) + .description("Migrate a project to the latest version of Turborepo") + .argument("[path]", "Directory where the transforms should be applied") + .option( + "--from ", + "Specify the version to migrate from (default: current version)" + ) + .option( + "--to ", + "Specify the version to migrate to (default: latest)" + ) + .option("--install", "Install new version of turbo after migration", true) + .option( + "--force", + "Bypass Git safety checks and forcibly run codemods", + false + ) + .option("--dry", "Dry run (no changes are made to files)", false) + .option("--print", "Print transformed files to your terminal", false) + .action(migrate); + +// transform +codemodCli + .command("transform", { isDefault: true }) + .description("Apply a single code transformation to a project") + .argument("[transform]", "The transformer to run") + .argument("[path]", "Directory where the transforms should be applied") + .option( + "--force", + "Bypass Git safety checks and forcibly run codemods", + false + ) + .option("--list", "List all available transforms", false) + .option("--dry", "Dry run (no changes are made to files)", false) + .option("--print", "Print transformed files to your terminal", false) + .action(transform); + +codemodCli + .parseAsync() + .then(notifyUpdate) + .catch(async (reason) => { + console.log(); + if (reason.command) { + console.log(` ${chalk.cyan(reason.command)} has failed.`); + } else { + console.log(chalk.red("Unexpected error. Please report it as a bug:")); + console.log(reason); + } + console.log(); + await notifyUpdate(); + process.exit(1); + }); -- cgit v1.2.3-70-g09d2