From fa9015cd1473751a402fcb4bc228af56f55eee73 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Mon, 17 Apr 2023 17:38:41 -0700 Subject: [PATCH] WIP --- .../workflows/bun-create-templates.yml | 11 +- docs/templates.md | 5 +- src/cli/create_command.zig | 10 +- templates/README.md | 66 +++++++ templates/apollo-sever/package.json | 2 +- templates/bun-bakery/package.json | 2 +- templates/bun-examples-all/package.json | 72 ++++---- templates/discord-interactions/package.json | 2 +- templates/elysia/package.json | 2 +- templates/hono/package.json | 2 +- templates/kingworld/package.json | 2 +- templates/next/package.json | 2 +- templates/package.json | 8 +- templates/preact/package.json | 2 +- templates/publish.js | 162 ------------------ templates/publish.ts | 139 +++++++++++++++ templates/react/dev.tsx | 33 +++- templates/react/package.json | 19 +- templates/react/public/bunlogo.svg | 16 ++ .../react/{src/App.css => public/index.css} | 22 ++- templates/react/public/index.html | 8 +- templates/react/{src => public}/logo.svg | 0 templates/react/src/App.jsx | 23 --- templates/react/src/App.tsx | 17 ++ templates/react/src/index.css | 13 -- templates/react/src/index.jsx | 17 -- templates/react/src/index.tsx | 16 ++ templates/react/tsconfig.json | 20 +++ templates/svelte-kit/package.json | 2 +- templates/tsconfig.json | 20 +++ templates/websi/package.json | 2 +- 31 files changed, 427 insertions(+), 290 deletions(-) rename templates/.github/workflows/npm-publish.yml => .github/workflows/bun-create-templates.yml (82%) create mode 100644 templates/README.md delete mode 100644 templates/publish.js create mode 100644 templates/publish.ts create mode 100644 templates/react/public/bunlogo.svg rename templates/react/{src/App.css => public/index.css} (50%) rename templates/react/{src => public}/logo.svg (100%) delete mode 100644 templates/react/src/App.jsx create mode 100644 templates/react/src/App.tsx delete mode 100644 templates/react/src/index.css delete mode 100644 templates/react/src/index.jsx create mode 100644 templates/react/src/index.tsx create mode 100644 templates/react/tsconfig.json create mode 100644 templates/tsconfig.json diff --git a/templates/.github/workflows/npm-publish.yml b/.github/workflows/bun-create-templates.yml similarity index 82% rename from templates/.github/workflows/npm-publish.yml rename to .github/workflows/bun-create-templates.yml index b80f34eec0..b5885f36eb 100644 --- a/templates/.github/workflows/npm-publish.yml +++ b/.github/workflows/bun-create-templates.yml @@ -1,12 +1,12 @@ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages -name: Publish NPM Packages +name: Publish bun-create templates on: push: branches: - - 'main' + - "main" jobs: publish-npm: @@ -19,11 +19,14 @@ jobs: node-version: 16 registry-url: https://registry.npmjs.org/ - - run: npm install + - uses: actions/setup-bun - - run: node publish.js + - run: bun install + + - run: bun run publish.ts env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - uses: "EndBug/add-and-commit@v9" + with: default_author: github_actions diff --git a/docs/templates.md b/docs/templates.md index e80e95eda6..f1fa1298a4 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -156,8 +156,7 @@ Each of these can correspond to a string or array of strings. An array of comman }, "bun-create": { "preinstall": "echo 'Installing...'", // a single command - "postinstall": ["echo 'Done!'"], // an array of commands - "start": "bun run echo 'Hello world!'" + "postinstall": ["echo 'Done!'"] // an array of commands } } ``` @@ -246,7 +245,7 @@ ELSE IF local template 5. Auto-detect the npm client, preferring `pnpm`, `yarn` (v1), and lastly `npm` 6. Run any tasks defined in `"bun-create": { "preinstall" }` with the npm client 7. Run `${npmClient} install` unless `--no-install` is passed OR no dependencies are in package.json -8. Run any tasks defined in `"bun-create": { "preinstall" }` with the npm client +8. Run any tasks defined in `"bun-create": { "postinstall" }` with the npm client 9. Run `git init; git add -A .; git commit -am "Initial Commit";` - Rename `gitignore` to `.gitignore`. NPM automatically removes `.gitignore` files from appearing in packages. diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index 8614d10d75..663b55848b 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -1547,7 +1547,7 @@ pub const CreateCommand = struct { Output.pretty( \\ - \\Come hang out in bun's Discord: https://bun.sh/discord + \\Come hang out in Bun's Discord: https://bun.sh/discord \\ , .{}); @@ -2117,18 +2117,18 @@ pub const CreateListExamplesCommand = struct { Output.prettyln("Welcome to bun! Create a new project by pasting any of the following:\n\n", .{}); Output.flush(); - Example.print(examples.items, null); + Example.print(examples.items, "./my-app"); - Output.prettyln("# You can also paste a GitHub repository:\n\n bun create ahfarmer/calculator calc\n\n", .{}); + Output.prettyln("# To clone from a GitHub repository:\n\n bun create ahfarmer/calculator calc\n\n", .{}); if (env_loader.map.get("HOME")) |homedir| { Output.prettyln( - "This command is completely optional. To add a new local template, create a folder in {s}/.bun-create/. To publish a new template, git clone https://github.com/oven-sh/bun, add a new folder to the \"examples\" folder, and submit a PR.", + "This command is completely optional. To add a new local template, create a folder in {s}/.bun-create/. To publish a new template, fork https://github.com/oven-sh/bun, add a new directory to the \"templates\" folder, and submit a PR.", .{homedir}, ); } else { Output.prettyln( - "This command is completely optional. To add a new local template, create a folder in $HOME/.bun-create/. To publish a new template, git clone https://github.com/oven-sh/bun, add a new folder to the \"examples\" folder, and submit a PR.", + "This command is completely optional. To add a new local template, create a folder in $HOME/.bun-create/. To publish a new template, fork https://github.com/oven-sh/bun, add a new directory to the \"templates\" folder, and submit a PR.", .{}, ); } diff --git a/templates/README.md b/templates/README.md new file mode 100644 index 0000000000..b7bb47f4ea --- /dev/null +++ b/templates/README.md @@ -0,0 +1,66 @@ +# Templates for `bun create` + +This repo contains the templates for `bun create`. + +## Usage + +> Refer to the [Bun docs](https://bun.dev/docs/templates) for complete documentation of `bun create`. + +To see a list of all official templates: + +```bash +$ bun create +``` + +To scaffold a new project using a particular template: + +```bash +$ bun create