aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/turbo-workspaces/src/cli.ts
blob: 3ae7a4513776fc5665a6c28d42dfcd1d5db4c608 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node

import chalk from "chalk";
import { Command } from "commander";

import { summary, convert } from "./commands";
import cliPkg from "../package.json";
import { ConvertError } from "./errors";

const workspacesCli = new Command();

workspacesCli
  .name("@turbo/workspaces")
  .description("Tools for working with package manager workspaces")
  .version(cliPkg.version, "-v, --version", "output the current version");

// convert
workspacesCli
  .command("convert")
  .description("Convert project between workspace managers")
  .argument("[path]", "Project root")
  .argument("[package-manager]", "Package manager to convert to")
  .option(
    "--skip-install",
    "Do not run a package manager install after conversion",
    false
  )
  .option("--dry", "Dry run (no changes are made to files)", false)
  .option(
    "--force",
    "Bypass Git safety checks and forcibly run conversion",
    false
  )
  .action(convert);

// summary
workspacesCli
  .command("summary")
  .description("Display a summary of the specified project")
  .argument("[path]", "Project root")
  .action(summary);

workspacesCli.parseAsync().catch((error) => {
  console.log();
  if (error instanceof ConvertError) {
    console.log(chalk.red(error.message));
  } else {
    console.log(chalk.red("Unexpected error. Please report it as a bug:"));
    console.log(error.message);
  }
  console.log();
  process.exit(1);
});