diff --git a/.changeset/scripts-init-repo-shorthand.md b/.changeset/scripts-init-repo-shorthand.md new file mode 100644 index 0000000..b2bcfb3 --- /dev/null +++ b/.changeset/scripts-init-repo-shorthand.md @@ -0,0 +1,5 @@ +--- +"@bunny.net/cli": minor +--- + +Add `--repo` alias for `--template-repo` on `bunny scripts init` and accept GitHub `owner/repo` shorthand. When a custom template repo is given without `--type`, the script type now defaults to `standalone`. diff --git a/packages/cli/README.md b/packages/cli/README.md index db39e65..5a58247 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -395,17 +395,26 @@ bunny scripts init --name my-script --type standalone --template Empty --deploy- # Non-interactive with GitHub Actions bunny scripts init --name my-script --type standalone --template Empty --deploy-method github --deploy + +# Use a custom template repo (GitHub owner/repo shorthand) +bunny scripts init --repo owner/my-template + +# Use a custom template repo (full git URL) +bunny scripts init --template-repo https://github.com/owner/my-template ``` -| Flag | Description | -| ----------------- | ---------------------------------------------------- | -| `--name` | Project directory name | -| `--type` | Script type: `standalone` or `middleware` | -| `--template` | Template name | -| `--deploy-method` | Deployment method: `github` or `cli` | -| `--deploy` | Create script on bunny.net after scaffolding | -| `--skip-git` | Skip git initialization (CLI deploy method only) | -| `--skip-install` | Skip dependency installation | +| Flag | Description | +| ------------------------ | --------------------------------------------------------------------- | +| `--name` | Project directory name | +| `--type` | Script type: `standalone` or `middleware` | +| `--template` | Template name | +| `--template-repo`, `--repo` | Git repository URL or GitHub `owner/repo` shorthand to use as template | +| `--deploy-method` | Deployment method: `github` or `cli` | +| `--deploy` | Create script on bunny.net after scaffolding | +| `--skip-git` | Skip git initialization (CLI deploy method only) | +| `--skip-install` | Skip dependency installation | + +When `--repo` / `--template-repo` is given without `--type`, the script type defaults to `standalone`. When choosing **GitHub Actions**, git is initialized automatically, GitHub-specific workflow files are kept, and after creating the script you'll be shown the `SCRIPT_ID` to add as a GitHub repo secret. diff --git a/packages/cli/src/commands/scripts/init.ts b/packages/cli/src/commands/scripts/init.ts index 724b4bf..7ae3908 100644 --- a/packages/cli/src/commands/scripts/init.ts +++ b/packages/cli/src/commands/scripts/init.ts @@ -25,7 +25,9 @@ const ARG_TYPE_DESCRIPTION = "Script type"; const ARG_TEMPLATE = "template"; const ARG_TEMPLATE_DESCRIPTION = "Template name"; const ARG_TEMPLATE_REPO = "template-repo"; -const ARG_TEMPLATE_REPO_DESCRIPTION = "Git repository URL to use as template"; +const ARG_TEMPLATE_REPO_ALIAS = "repo"; +const ARG_TEMPLATE_REPO_DESCRIPTION = + "Git repository URL or GitHub owner/repo shorthand to use as template"; const ARG_DEPLOY = "deploy"; const ARG_DEPLOY_DESCRIPTION = "Deploy after creation"; const ARG_DEPLOY_METHOD = "deploy-method"; @@ -49,6 +51,12 @@ interface InitArgs { [ARG_SKIP_INSTALL]?: boolean; } +const GITHUB_SHORTHAND = /^[\w.-]+\/[\w.-]+$/; + +function resolveTemplateRepo(input: string): string { + return GITHUB_SHORTHAND.test(input) ? `https://github.com/${input}` : input; +} + /** * Create a new Edge Script project from a template. * @@ -70,8 +78,11 @@ interface InitArgs { * # Skip dependency installation * bunny scripts init --name my-script --skip-install * - * # Use a custom template repo + * # Use a custom template repo (full URL) * bunny scripts init --name my-script --type standalone --template-repo https://github.com/user/my-template + * + * # Use a custom template repo (GitHub owner/repo shorthand) + * bunny scripts init --repo user/my-template * ``` */ export const scriptsInitCommand = defineCommand({ @@ -102,6 +113,7 @@ export const scriptsInitCommand = defineCommand({ }) .option(ARG_TEMPLATE_REPO, { type: "string", + alias: ARG_TEMPLATE_REPO_ALIAS, describe: ARG_TEMPLATE_REPO_DESCRIPTION, }) .option(ARG_DEPLOY, { @@ -150,6 +162,9 @@ export const scriptsInitCommand = defineCommand({ let scriptType: EdgeScriptTypes | undefined; if (args[ARG_TYPE]) { scriptType = args[ARG_TYPE] === "standalone" ? 1 : 2; + } else if (args[ARG_TEMPLATE_REPO]) { + // Custom template repo implies the user knows what they're doing — default to standalone + scriptType = 1; } else { const { value } = await prompts({ type: "select", @@ -179,7 +194,7 @@ export const scriptsInitCommand = defineCommand({ selected = { name: "Custom", description: "Custom template repository", - repo: args[ARG_TEMPLATE_REPO], + repo: resolveTemplateRepo(args[ARG_TEMPLATE_REPO]), scriptType: finalScriptType, }; } else if (args[ARG_TEMPLATE]) {