Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/scripts-init-repo-shorthand.md
Original file line number Diff line number Diff line change
@@ -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`.
27 changes: 18 additions & 9 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
21 changes: 18 additions & 3 deletions packages/cli/src/commands/scripts/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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.
*
Expand All @@ -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<InitArgs>({
Expand Down Expand Up @@ -102,6 +113,7 @@ export const scriptsInitCommand = defineCommand<InitArgs>({
})
.option(ARG_TEMPLATE_REPO, {
type: "string",
alias: ARG_TEMPLATE_REPO_ALIAS,
describe: ARG_TEMPLATE_REPO_DESCRIPTION,
})
.option(ARG_DEPLOY, {
Expand Down Expand Up @@ -150,6 +162,9 @@ export const scriptsInitCommand = defineCommand<InitArgs>({
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",
Expand Down Expand Up @@ -179,7 +194,7 @@ export const scriptsInitCommand = defineCommand<InitArgs>({
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]) {
Expand Down