|
1 | | -import { Command } from "@commander-js/extra-typings"; |
| 1 | +import { Command, Option } from "@commander-js/extra-typings"; |
2 | 2 | import chalk from "chalk"; |
| 3 | +import ora from "ora"; |
| 4 | +import { download } from "../template.js"; |
| 5 | + |
| 6 | +export const DEFAULT_TEMPLATES_BRANCH = "prerelease/sdk-12"; |
| 7 | + |
| 8 | +const TEMPLATES = [ |
| 9 | + "cpp", |
| 10 | + "cpp-low-level", |
| 11 | + "go", |
| 12 | + "javascript", |
| 13 | + "lua", |
| 14 | + "python", |
| 15 | + "ruby", |
| 16 | + "rust", |
| 17 | + "typescript", |
| 18 | +] as const; |
3 | 19 |
|
4 | 20 | export const createCreateCommand = () => { |
5 | 21 | return new Command("create") |
6 | | - .summary("DEPRECATED: use 'rollups create' instead") |
7 | | - .action(async () => { |
8 | | - console.warn( |
9 | | - chalk.yellow( |
10 | | - "create command is deprecated, use 'rollups create' instead", |
11 | | - ), |
12 | | - ); |
| 22 | + .argument("<name>", "application and directory name") |
| 23 | + .addOption( |
| 24 | + new Option("-t, --template <template>", "template name to use") |
| 25 | + .choices(TEMPLATES) |
| 26 | + .makeOptionMandatory(), |
| 27 | + ) |
| 28 | + .option( |
| 29 | + "-b, --branch <branch>", |
| 30 | + "cartesi/application-templates repository branch name to use", |
| 31 | + DEFAULT_TEMPLATES_BRANCH, |
| 32 | + ) |
| 33 | + .action(async (name, { branch, template }) => { |
| 34 | + const spinner = ora("Creating application...").start(); |
| 35 | + try { |
| 36 | + const { dir } = await download(template, branch, name); |
| 37 | + spinner.succeed(`Application created at ${chalk.cyan(dir)}`); |
| 38 | + } catch (e: unknown) { |
| 39 | + spinner.fail( |
| 40 | + e instanceof Error |
| 41 | + ? `Error creating application: ${chalk.red(e.message)}` |
| 42 | + : String(e), |
| 43 | + ); |
| 44 | + } |
13 | 45 | }); |
14 | 46 | }; |
0 commit comments