mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
WIP
This commit is contained in:
@@ -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
|
||||
@@ -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.
|
||||
|
||||
@@ -1547,7 +1547,7 @@ pub const CreateCommand = struct {
|
||||
|
||||
Output.pretty(
|
||||
\\
|
||||
\\<d>Come hang out in bun's Discord: https://bun.sh/discord<r>
|
||||
\\<d>Come hang out in Bun's Discord: https://bun.sh/discord<r>
|
||||
\\
|
||||
, .{});
|
||||
|
||||
@@ -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("<r><d>#<r> You can also paste a GitHub repository:\n\n <b>bun create <cyan>ahfarmer/calculator calc<r>\n\n", .{});
|
||||
Output.prettyln("<r><d>#<r> To clone from a GitHub repository:\n\n <b>bun create <cyan>ahfarmer/calculator calc<r>\n\n", .{});
|
||||
|
||||
if (env_loader.map.get("HOME")) |homedir| {
|
||||
Output.prettyln(
|
||||
"<d>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.<r>",
|
||||
"<d>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.<r>",
|
||||
.{homedir},
|
||||
);
|
||||
} else {
|
||||
Output.prettyln(
|
||||
"<d>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.<r>",
|
||||
"<d>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.<r>",
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
66
templates/README.md
Normal file
66
templates/README.md
Normal file
@@ -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 <template> <dir>
|
||||
```
|
||||
|
||||
To scaffold a new project using a GitHub repo as a template:
|
||||
|
||||
```bash
|
||||
$ bun create user/repo <dir>
|
||||
```
|
||||
|
||||
## Creating a template
|
||||
|
||||
Fork this repo and add your template to the `templates` directory. The name of the directory will be the template name. For example, if you add a template named `my-template`, you can scaffold a new project using it with:
|
||||
|
||||
```bash
|
||||
$ bun create my-template <dir>
|
||||
```
|
||||
|
||||
In the `package.json`, set the `"name"` field to the pattern `@bun-examples/<name>`. The template code will be auto-published to `npm` using this name, where it will later be downloaded by `bun create`.
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "@bun-examples/my-template"
|
||||
}
|
||||
```
|
||||
|
||||
The `package.json` can also contain some initialization logic in the `"bun-create"` field. This defines a set of hooks that `bun create` will run immediately after scaffolding a new project.
|
||||
|
||||
```json
|
||||
{
|
||||
// other fields
|
||||
"bun-create": {
|
||||
"preinstall": "echo 'Installing...'",
|
||||
"postinstall": ["bun install"], // accepts array of commands,
|
||||
"start": "bun run server.ts"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `"start"` field is not executed, but it will be printed when a user scaffolds a new project using your template.
|
||||
|
||||
```bash
|
||||
$ bun create my-template <dir>
|
||||
# ...
|
||||
Created my-template project successfully
|
||||
# To get started, run:
|
||||
|
||||
cd <dir>
|
||||
bun run server.ts # <- copied from the "start" field
|
||||
```
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.14",
|
||||
"version": "1.0.15",
|
||||
"name": "@bun-examples/apollo-server",
|
||||
"dependencies": {
|
||||
"@apollo/server": "^4.3.2",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.95",
|
||||
"version": "1.0.96",
|
||||
"name": "@bun-examples/bun-bakery",
|
||||
"dependencies": {
|
||||
"@kapsonfire/bun-bakery": "^0.3.2"
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
{
|
||||
"name": "bun-examples-all",
|
||||
"private": false,
|
||||
"version": "0.0.1681741054711",
|
||||
"version": "0.0.1681763058946",
|
||||
"description": "All bun-examples",
|
||||
"examples": {
|
||||
"@bun-examples/apollo-server": {
|
||||
"version": "1.0.14",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/bun-bakery": {
|
||||
"version": "1.0.95",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/discord-interactions": {
|
||||
"version": "0.0.100",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/elysia": {
|
||||
"version": "1.0.30",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/hono": {
|
||||
"version": "1.0.89",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/kingworld": {
|
||||
"version": "1.0.30",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/next": {
|
||||
"version": "0.0.137",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/preact": {
|
||||
"version": "0.0.5",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/react": {
|
||||
"version": "0.1.81",
|
||||
"version": "0.0.138",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/svelte-kit": {
|
||||
"version": "0.0.27",
|
||||
"version": "0.0.28",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/websi": {
|
||||
"version": "0.1.10",
|
||||
"version": "0.1.11",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/elysia": {
|
||||
"version": "1.0.31",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/preact": {
|
||||
"version": "0.0.6",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/hono": {
|
||||
"version": "1.0.90",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/discord-interactions": {
|
||||
"version": "0.0.101",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/bun-bakery": {
|
||||
"version": "1.0.96",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/kingworld": {
|
||||
"version": "1.0.31",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/react": {
|
||||
"version": "0.1.82",
|
||||
"description": ""
|
||||
},
|
||||
"@bun-examples/apollo-server": {
|
||||
"version": "1.0.15",
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.0.100",
|
||||
"version": "0.0.101",
|
||||
"name": "@bun-examples/discord-interactions",
|
||||
"dependencies": {
|
||||
"slash-create": "^5.9.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bun-examples/elysia",
|
||||
"version": "1.0.30",
|
||||
"version": "1.0.31",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "bun run --hot src/index.ts"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.89",
|
||||
"version": "1.0.90",
|
||||
"name": "@bun-examples/hono",
|
||||
"devDependencies": {
|
||||
"bun-types": "latest"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bun-examples/kingworld",
|
||||
"version": "1.0.30",
|
||||
"version": "1.0.31",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "nodemon --config nodemon.json"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bun-examples/next",
|
||||
"version": "0.0.137",
|
||||
"version": "0.0.138",
|
||||
"dependencies": {
|
||||
"next": "^12.3.1",
|
||||
"react": "^18",
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"semver": "^7.3.8"
|
||||
}
|
||||
"semver": "^7.3.8",
|
||||
"bun-types": "canary"
|
||||
},
|
||||
"name": "templates",
|
||||
"module": "index.ts",
|
||||
"type": "module"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bun-examples/preact",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.6",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"bun-types": "^0.5.0"
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { execSync } = require("child_process");
|
||||
|
||||
const exec = (cmd, opts = {}) => {
|
||||
console.log("$", cmd);
|
||||
return execSync(cmd, {
|
||||
...opts,
|
||||
env: { CI: "true", ...process.env, ...(opts.env || {}) },
|
||||
});
|
||||
};
|
||||
|
||||
const DRY_RUN = !!process.env.DRY_RUN;
|
||||
|
||||
var count = 0;
|
||||
|
||||
const examplesFolderEntries = fs.readdirSync(
|
||||
path.join(process.cwd(), "."),
|
||||
{ withFileTypes: true }
|
||||
);
|
||||
|
||||
const packageNames = [];
|
||||
|
||||
for (let folder of examplesFolderEntries) {
|
||||
if (!folder.isDirectory()) continue;
|
||||
const absolute = path.resolve(process.cwd(), ".", folder.name);
|
||||
|
||||
let packageJSONText;
|
||||
|
||||
try {
|
||||
packageJSONText = fs.readFileSync(
|
||||
path.join(absolute, "package.json"),
|
||||
"utf8"
|
||||
);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
let packageJSON = JSON.parse(packageJSONText);
|
||||
|
||||
if (!packageJSON.name) continue;
|
||||
if (!packageJSON.name.startsWith("@bun-examples")) continue;
|
||||
|
||||
var version = "0.0.1";
|
||||
try {
|
||||
const _versions = exec(`npm view ${packageJSON.name} versions --json`)
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
if (_versions.length > 0) {
|
||||
const versionsArray = JSON.parse(_versions);
|
||||
version = versionsArray[versionsArray.length - 1];
|
||||
}
|
||||
} catch (exception) {
|
||||
console.error(exception);
|
||||
}
|
||||
var retryCount = 5;
|
||||
|
||||
// Never commit lockfiles
|
||||
try {
|
||||
fs.rmSync(path.join(absolute, "package-lock.json"));
|
||||
} catch (exception) {}
|
||||
|
||||
try {
|
||||
fs.rmSync(path.join(absolute, "yarn.lock"));
|
||||
} catch (exception) {}
|
||||
|
||||
try {
|
||||
fs.rmSync(path.join(absolute, "pnpm-lock.yaml"));
|
||||
} catch (exception) {}
|
||||
|
||||
try {
|
||||
fs.copyFileSync(
|
||||
path.join(absolute, ".gitignore"),
|
||||
path.join(absolute, "gitignore")
|
||||
);
|
||||
} catch (exception) {}
|
||||
|
||||
restart: while (retryCount-- > 0) {
|
||||
packageJSON.version = require("semver").inc(packageJSON.version, "patch");
|
||||
if ("private" in packageJSON) delete packageJSON.private;
|
||||
if ("license" in packageJSON) delete packageJSON.license;
|
||||
if ("main" in packageJSON && !("module" in packageJSON)) {
|
||||
packageJSON.module = packageJSON.main;
|
||||
delete packageJSON.main;
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(absolute, "package.json"),
|
||||
JSON.stringify(packageJSON, null, 2)
|
||||
);
|
||||
try {
|
||||
exec(`npm version patch --force --no-commit-hooks --no-git-tag-version`, {
|
||||
cwd: absolute,
|
||||
});
|
||||
|
||||
packageJSON = JSON.parse(
|
||||
fs.readFileSync(path.join(absolute, "package.json"), "utf8")
|
||||
);
|
||||
version = packageJSON.version;
|
||||
} catch (e) {
|
||||
if (e.code !== "E404") {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
exec(
|
||||
`npm publish ${
|
||||
DRY_RUN ? "--dry-run" : ""
|
||||
} --access public --registry https://registry.npmjs.org/`,
|
||||
{ cwd: absolute }
|
||||
);
|
||||
packageNames.push([
|
||||
packageJSON.name,
|
||||
{
|
||||
version: packageJSON.version,
|
||||
description: packageJSON.description || "",
|
||||
},
|
||||
]);
|
||||
count++;
|
||||
break;
|
||||
} catch (exception) {
|
||||
continue restart;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (packageNames.length > 0) {
|
||||
const packageJSON = {
|
||||
name: "bun-examples-all",
|
||||
private: false,
|
||||
version: `0.0.${Date.now()}`,
|
||||
description: "All bun-examples",
|
||||
examples: Object.fromEntries(packageNames),
|
||||
};
|
||||
const dir = path.join(process.cwd(), "./bun-examples-all");
|
||||
try {
|
||||
fs.rmSync(dir, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
} catch (exception) {}
|
||||
|
||||
try {
|
||||
fs.mkdirSync(dir, {
|
||||
recursive: true,
|
||||
});
|
||||
} catch (exception) {}
|
||||
fs.writeFileSync(
|
||||
path.join(dir, "package.json"),
|
||||
JSON.stringify(packageJSON, null, 2)
|
||||
);
|
||||
exec(
|
||||
`npm publish ${
|
||||
DRY_RUN ? "--dry-run" : ""
|
||||
} --access public --registry https://registry.npmjs.org/`,
|
||||
{ cwd: dir }
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`Published ${count} packages`);
|
||||
139
templates/publish.ts
Normal file
139
templates/publish.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import * as fs from "fs";
|
||||
const path = require("path");
|
||||
const { execSync } = require("child_process");
|
||||
|
||||
const exec = (cmd: string, opts: { cwd?: string; env?: object } = {}) => {
|
||||
console.log("$", cmd);
|
||||
return execSync(cmd, {
|
||||
...opts,
|
||||
env: { CI: "true", ...process.env, ...(opts.env || {}) },
|
||||
});
|
||||
};
|
||||
|
||||
const DRY_RUN = !!process.env.DRY_RUN;
|
||||
|
||||
var count = 0;
|
||||
|
||||
const examplesFolderEntries = fs.readdirSync(path.join(process.cwd(), "."), { withFileTypes: true });
|
||||
|
||||
const packageNames: [string, { version: string; description: string }][] = [];
|
||||
|
||||
for (let folder of examplesFolderEntries) {
|
||||
if (!folder.isDirectory()) continue;
|
||||
|
||||
const absolute = path.resolve(process.cwd(), ".", folder.name);
|
||||
|
||||
let packageJSONText;
|
||||
|
||||
try {
|
||||
packageJSONText = fs.readFileSync(path.join(absolute, "package.json"), "utf8");
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
let packageJSON = JSON.parse(packageJSONText);
|
||||
|
||||
if (!packageJSON.name) continue;
|
||||
if (!packageJSON.name.startsWith("@bun-examples")) continue;
|
||||
|
||||
var version = "0.0.1";
|
||||
try {
|
||||
const _versions = exec(`npm view ${packageJSON.name} versions --json`).toString().trim();
|
||||
|
||||
if (_versions.length > 0) {
|
||||
const versionsArray = JSON.parse(_versions);
|
||||
version = versionsArray[versionsArray.length - 1];
|
||||
}
|
||||
} catch (exception) {
|
||||
console.error(exception);
|
||||
}
|
||||
var retryCount = 5;
|
||||
|
||||
// Never commit lockfiles
|
||||
try {
|
||||
fs.rmSync(path.join(absolute, "package-lock.json"));
|
||||
} catch (exception) {}
|
||||
|
||||
try {
|
||||
fs.rmSync(path.join(absolute, "yarn.lock"));
|
||||
} catch (exception) {}
|
||||
|
||||
try {
|
||||
fs.rmSync(path.join(absolute, "pnpm-lock.yaml"));
|
||||
} catch (exception) {}
|
||||
|
||||
try {
|
||||
fs.copyFileSync(path.join(absolute, ".gitignore"), path.join(absolute, "gitignore"));
|
||||
} catch (exception) {}
|
||||
|
||||
restart: while (retryCount-- > 0) {
|
||||
// no longer necessary with `npm version patch` call
|
||||
// packageJSON.version = require("semver").inc(packageJSON.version, "patch");
|
||||
if ("private" in packageJSON) delete packageJSON.private;
|
||||
if ("license" in packageJSON) delete packageJSON.license;
|
||||
if ("main" in packageJSON && !("module" in packageJSON)) {
|
||||
packageJSON.module = packageJSON.main;
|
||||
delete packageJSON.main;
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(absolute, "package.json"), JSON.stringify(packageJSON, null, 2));
|
||||
try {
|
||||
exec(`npm version patch --force --no-commit-hooks --no-git-tag-version`, {
|
||||
cwd: absolute,
|
||||
});
|
||||
|
||||
packageJSON = JSON.parse(fs.readFileSync(path.join(absolute, "package.json"), "utf8"));
|
||||
version = packageJSON.version;
|
||||
} catch (e: any) {
|
||||
if (e.code !== "E404") {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
exec(`npm publish ${DRY_RUN ? "--dry-run" : ""} --access public --registry https://registry.npmjs.org/`, {
|
||||
cwd: absolute,
|
||||
});
|
||||
packageNames.push([
|
||||
packageJSON.name,
|
||||
{
|
||||
version: packageJSON.version,
|
||||
description: packageJSON.description || "",
|
||||
},
|
||||
]);
|
||||
count++;
|
||||
break;
|
||||
} catch (exception) {
|
||||
continue restart;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (packageNames.length > 0) {
|
||||
const packageJSON = {
|
||||
name: "bun-examples-all",
|
||||
private: false,
|
||||
version: `0.0.${Date.now()}`,
|
||||
description: "All bun-examples",
|
||||
examples: Object.fromEntries(packageNames),
|
||||
};
|
||||
const dir = path.join(process.cwd(), "./bun-examples-all");
|
||||
try {
|
||||
fs.rmSync(dir, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
} catch (exception) {}
|
||||
|
||||
try {
|
||||
fs.mkdirSync(dir, {
|
||||
recursive: true,
|
||||
});
|
||||
} catch (exception) {}
|
||||
fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify(packageJSON, null, 2));
|
||||
exec(`npm publish ${DRY_RUN ? "--dry-run" : ""} --access public --registry https://registry.npmjs.org/`, {
|
||||
cwd: dir,
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Published ${count} packages`);
|
||||
@@ -1 +1,32 @@
|
||||
dev.tsx;
|
||||
import * as path from "path";
|
||||
|
||||
import { existsSync } from "fs";
|
||||
import type { ServeOptions } from "bun";
|
||||
|
||||
const projectRoot = import.meta.dir;
|
||||
const PUBLIC_DIR = path.resolve(projectRoot, "public");
|
||||
const BUILD_DIR = path.resolve(projectRoot, "build");
|
||||
|
||||
export default {
|
||||
fetch(request) {
|
||||
let reqPath = new URL(request.url).pathname;
|
||||
console.log(request.method, reqPath);
|
||||
if (reqPath === "/") reqPath = "/index.html";
|
||||
|
||||
// serve static files
|
||||
const publicFilePath = path.join(PUBLIC_DIR, reqPath);
|
||||
if (existsSync(publicFilePath)) {
|
||||
return new Response(Bun.file(publicFilePath));
|
||||
}
|
||||
|
||||
// serve build files
|
||||
const buildFilePath = path.join(BUILD_DIR, reqPath);
|
||||
if (existsSync(buildFilePath)) {
|
||||
return new Response(Bun.file(buildFilePath));
|
||||
}
|
||||
|
||||
return new Response("File not found", {
|
||||
status: 404,
|
||||
});
|
||||
},
|
||||
} satisfies ServeOptions;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bun-examples/react",
|
||||
"version": "0.1.81",
|
||||
"version": "0.1.82",
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
@@ -12,12 +12,21 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.0.37",
|
||||
"@types/react-dom": "^18.0.11",
|
||||
"bun-types": "canary",
|
||||
"typescript": "latest"
|
||||
},
|
||||
"scripts": {
|
||||
"prestart": "NODE_ENV=development bun build ./src/index.jsx --outfile build/bundle.js",
|
||||
"start": "bun run dev.tsx"
|
||||
},
|
||||
"bun-create": {
|
||||
"postinstall": [
|
||||
"bun bun ./src/index.jsx"
|
||||
"prestart": [
|
||||
"bun bun ./src/index.jsx --outfile ./build/bundle.js --platform browser --splitting --tree-shaking"
|
||||
],
|
||||
"start": "bun dev"
|
||||
}
|
||||
"start": "bun run dev.tsx"
|
||||
},
|
||||
"module": "index.ts",
|
||||
"type": "module"
|
||||
}
|
||||
|
||||
16
templates/react/public/bunlogo.svg
Normal file
16
templates/react/public/bunlogo.svg
Normal file
@@ -0,0 +1,16 @@
|
||||
<svg width="435" height="435" viewBox="0 0 435 435" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M384.167 143.033C383.348 142.139 382.477 141.246 381.606 140.405C380.735 139.563 379.916 138.617 379.045 137.776C378.174 136.935 377.354 135.989 376.483 135.147C375.613 134.306 374.793 133.36 373.922 132.519C373.051 131.678 372.232 130.731 371.361 129.89C370.49 129.049 369.67 128.103 368.799 127.262C367.929 126.421 367.109 125.474 366.238 124.633C391.647 150.26 406.204 185.123 406.758 221.68C406.758 308.791 320.596 379.657 214.66 379.657C155.34 379.657 102.269 357.419 66.9745 322.565L69.5358 325.193L72.0971 327.822L74.6584 330.45L77.2197 333.079L79.781 335.707L82.3424 338.336L84.9037 340.965C120.147 377.291 174.396 400.686 235.15 400.686C341.086 400.686 427.249 329.819 427.249 242.971C427.249 205.856 411.676 170.686 384.167 143.033Z" fill="black"/>
|
||||
<path d="M393.951 221.68C393.951 301.641 313.68 366.462 214.66 366.462C115.639 366.462 35.3678 301.641 35.3678 221.68C35.3678 172.105 66.1035 128.313 113.334 102.343C160.565 76.3726 189.969 49.7714 214.66 49.7714C239.351 49.7714 260.456 71.4834 315.985 102.343C363.216 128.313 393.951 172.105 393.951 221.68Z" fill="#FBF0DF"/>
|
||||
<path d="M393.951 221.68C393.926 211.408 392.548 201.187 389.853 191.294C375.868 366.356 167.788 374.768 85.9794 322.407C122.755 351.659 168.136 367.196 214.66 366.462C313.526 366.462 393.951 301.536 393.951 221.68Z" fill="#F6DECE"/>
|
||||
<path d="M145.658 92.7223C168.556 78.6332 198.984 52.1897 228.901 52.1372C224.298 50.6105 219.496 49.8127 214.66 49.7714C202.263 49.7714 189.047 56.3429 172.398 66.2263C166.609 69.696 160.616 73.5337 154.264 77.5292C142.328 85.0994 128.651 93.6686 113.283 102.238C64.5155 129.312 35.3678 173.945 35.3678 221.68C35.3678 223.783 35.3678 225.886 35.3678 227.936C66.4109 115.381 122.811 106.811 145.658 92.7223Z" fill="#FFFEFC"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M199.906 63.072C199.978 75.4853 197.439 87.7682 192.461 99.0821C187.484 110.396 180.186 120.474 171.066 128.629C169.632 129.943 170.759 132.466 172.603 131.73C189.866 124.843 213.174 104.235 203.339 62.6514C202.929 60.2857 199.906 60.9166 199.906 63.072ZM211.535 63.072C217.803 73.5675 221.785 85.3299 223.208 97.5527C224.632 109.776 223.463 122.17 219.782 133.886C219.167 135.726 221.37 137.303 222.6 135.778C233.818 121.058 243.602 91.8286 214.301 60.2857C212.815 58.9189 210.51 61.0217 211.535 62.8617V63.072ZM225.673 62.1783C235.489 69.3099 243.7 78.5187 249.753 89.1837C255.807 99.8487 259.561 111.722 260.763 124.002C260.711 124.445 260.827 124.891 261.087 125.248C261.347 125.605 261.731 125.846 262.159 125.92C262.588 125.994 263.027 125.897 263.387 125.647C263.747 125.398 264 125.016 264.093 124.581C268.806 106.233 266.142 74.9531 227.364 58.7086C225.315 57.8674 223.983 60.7063 225.673 61.968V62.1783ZM131.11 116.853C142.785 113.273 153.596 107.209 162.837 99.0574C172.078 90.9054 179.542 80.8474 184.743 69.5383C185.666 67.6457 188.585 68.3817 188.124 70.4846C179.262 112.542 149.602 121.321 131.161 120.165C129.214 120.217 129.266 117.431 131.11 116.853Z" fill="#CCBEA7"/>
|
||||
<path d="M214.66 379.657C108.724 379.657 22.5613 308.791 22.5613 221.68C22.5613 169.109 54.2191 120.059 107.238 90.672C122.606 82.2606 135.771 73.7966 147.502 66.384C153.957 62.2834 160.052 58.4457 165.944 54.8709C183.924 43.936 199.292 36.6286 214.66 36.6286C230.028 36.6286 243.449 42.9371 260.251 53.136C265.374 56.1326 270.496 59.392 275.977 62.9669C288.733 71.0629 303.127 80.2103 322.081 90.672C375.1 120.059 406.758 169.056 406.758 221.68C406.758 308.791 320.596 379.657 214.66 379.657ZM214.66 49.7714C202.263 49.7714 189.047 56.3429 172.398 66.2263C166.609 69.696 160.616 73.5337 154.264 77.5292C142.328 85.0995 128.651 93.6686 113.283 102.238C64.5156 129.312 35.3678 173.945 35.3678 221.68C35.3678 301.536 115.793 366.515 214.66 366.515C313.526 366.515 393.951 301.536 393.951 221.68C393.951 173.945 364.804 129.312 315.985 102.343C296.622 91.8286 281.51 81.9452 269.267 74.1646C263.683 70.6423 258.561 67.3829 253.899 64.4914C238.377 55.0286 227.056 49.7714 214.66 49.7714Z" fill="black"/>
|
||||
<path d="M250.774 260.057C248.473 269.73 243.234 278.401 235.816 284.818C230.246 290.359 223.036 293.837 215.325 294.702C207.383 293.974 199.92 290.487 194.169 284.818C186.826 278.371 181.662 269.703 179.416 260.057C179.341 259.485 179.396 258.902 179.575 258.354C179.753 257.806 180.052 257.308 180.448 256.897C180.843 256.486 181.325 256.173 181.857 255.983C182.388 255.793 182.955 255.73 183.514 255.799H246.727C247.282 255.738 247.843 255.808 248.368 256.002C248.893 256.196 249.368 256.51 249.758 256.92C250.147 257.33 250.441 257.825 250.617 258.369C250.793 258.912 250.847 259.489 250.774 260.057V260.057Z" fill="#B71422"/>
|
||||
<path d="M194.169 285.239C199.908 290.911 207.344 294.431 215.274 295.227C223.186 294.419 230.603 290.901 236.328 285.239C238.16 283.487 239.871 281.607 241.451 279.614C238.295 275.94 234.44 272.967 230.124 270.879C225.807 268.79 221.12 267.63 216.35 267.47C211.246 267.594 206.249 268.989 201.787 271.535C197.325 274.081 193.533 277.701 190.737 282.085C191.915 283.189 192.94 284.24 194.169 285.239Z" fill="#FF6164"/>
|
||||
<path d="M194.989 281.086C197.528 277.717 200.779 274.982 204.497 273.088C208.215 271.195 212.302 270.19 216.453 270.151C224.124 270.383 231.433 273.552 236.943 279.035C238.121 277.721 239.248 276.354 240.324 274.987C233.807 268.618 225.195 264.996 216.196 264.841C211.388 264.884 206.648 266.018 202.317 268.163C197.986 270.308 194.171 273.411 191.147 277.248C192.358 278.598 193.641 279.88 194.989 281.086V281.086Z" fill="black"/>
|
||||
<path d="M215.121 297.856C206.585 297.089 198.552 293.383 192.325 287.342C184.395 280.459 178.814 271.158 176.394 260.793C176.22 259.871 176.25 258.92 176.48 258.01C176.71 257.101 177.136 256.255 177.726 255.536C178.428 254.666 179.314 253.972 180.317 253.508C181.321 253.043 182.414 252.82 183.514 252.855H246.727C247.826 252.831 248.916 253.06 249.917 253.524C250.919 253.987 251.806 254.675 252.516 255.536C253.1 256.258 253.518 257.105 253.74 258.015C253.961 258.925 253.981 259.875 253.796 260.793C251.376 271.158 245.795 280.459 237.865 287.342C231.652 293.373 223.639 297.077 215.121 297.856ZM183.514 258.953C182.694 258.953 182.49 259.321 182.438 259.426C184.604 268.414 189.502 276.461 196.423 282.4C201.484 287.517 208.064 290.755 215.121 291.6C222.159 290.764 228.732 287.567 233.818 282.505C240.718 276.556 245.597 268.511 247.752 259.532C247.64 259.363 247.485 259.23 247.304 259.147C247.124 259.063 246.924 259.033 246.727 259.058L183.514 258.953Z" fill="black"/>
|
||||
<path d="M292.626 263.317C309.177 263.317 322.593 255.22 322.593 245.232C322.593 235.244 309.177 227.147 292.626 227.147C276.076 227.147 262.659 235.244 262.659 245.232C262.659 255.22 276.076 263.317 292.626 263.317Z" fill="#FEBBD0"/>
|
||||
<path d="M137.564 263.317C154.115 263.317 167.532 255.22 167.532 245.232C167.532 235.244 154.115 227.147 137.564 227.147C121.014 227.147 107.597 235.244 107.597 245.232C107.597 255.22 121.014 263.317 137.564 263.317Z" fill="#FEBBD0"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M151.651 237.977C157.236 237.988 162.698 236.298 167.347 233.121C171.995 229.944 175.621 225.424 177.765 220.132C179.909 214.84 180.476 209.014 179.392 203.391C178.309 197.769 175.625 192.603 171.679 188.546C167.734 184.49 162.705 181.726 157.228 180.604C151.751 179.482 146.074 180.053 140.913 182.243C135.753 184.434 131.341 188.147 128.238 192.912C125.134 197.676 123.477 203.279 123.477 209.01C123.477 216.684 126.444 224.044 131.726 229.474C137.008 234.905 144.174 237.963 151.651 237.977V237.977ZM278.539 237.977C284.13 238.019 289.607 236.355 294.276 233.198C298.944 230.04 302.594 225.531 304.762 220.242C306.929 214.953 307.518 209.122 306.452 203.489C305.386 197.856 302.714 192.675 298.775 188.603C294.836 184.531 289.807 181.751 284.326 180.616C278.845 179.482 273.16 180.043 267.99 182.229C262.821 184.415 258.4 188.128 255.29 192.896C252.179 197.664 250.518 203.272 250.518 209.01C250.504 216.661 253.446 224.005 258.698 229.434C263.95 234.864 271.084 237.935 278.539 237.977V237.977Z" fill="black"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M142.943 210.85C145.042 210.861 147.098 210.231 148.848 209.042C150.599 207.852 151.966 206.157 152.776 204.169C153.587 202.182 153.804 199.992 153.401 197.877C152.997 195.763 151.991 193.819 150.51 192.292C149.029 190.765 147.14 189.723 145.082 189.299C143.023 188.875 140.889 189.087 138.948 189.909C137.008 190.731 135.349 192.126 134.181 193.917C133.014 195.707 132.39 197.813 132.39 199.968C132.39 202.845 133.5 205.605 135.478 207.644C137.456 209.684 140.14 210.836 142.943 210.85ZM269.83 210.85C271.93 210.861 273.985 210.231 275.735 209.042C277.486 207.852 278.853 206.157 279.664 204.169C280.474 202.182 280.691 199.992 280.288 197.877C279.885 195.763 278.879 193.819 277.398 192.292C275.917 190.765 274.028 189.723 271.969 189.299C269.911 188.875 267.776 189.087 265.836 189.909C263.895 190.731 262.236 192.126 261.068 193.917C259.901 195.707 259.278 197.813 259.278 199.968C259.278 202.827 260.374 205.571 262.329 207.608C264.285 209.644 266.942 210.809 269.728 210.85H269.83Z" fill="white"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 8.9 KiB |
@@ -1,20 +1,33 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans",
|
||||
"Droid Sans", "Helvetica Neue", sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
|
||||
}
|
||||
|
||||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
height: 40vmin;
|
||||
height: 150px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
animation: App-logo-spin infinite 5s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.App h1 {
|
||||
font-size: 1.75rem;
|
||||
.App h3 {
|
||||
font-size: 2.75rem;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.App-article {
|
||||
@@ -30,6 +43,7 @@
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
font-size: 14pt;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
@@ -5,10 +5,7 @@
|
||||
<link rel="icon" href="favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<meta name="description" content="Web site created using create-react-app" />
|
||||
<link rel="apple-touch-icon" href="/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
@@ -25,6 +22,7 @@
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
<link rel="stylesheet" href="/index.css"></style>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
@@ -39,6 +37,6 @@
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
<script src="/src/index.jsx" async type="module"></script>
|
||||
<script src="/bundle.js" async type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
@@ -1,23 +0,0 @@
|
||||
import "./App.css";
|
||||
import logo from "./logo.svg";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App" role="main">
|
||||
<article className="App-article">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<h3>Welcome to React!</h3>
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
</article>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
17
templates/react/src/App.tsx
Normal file
17
templates/react/src/App.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
function App() {
|
||||
return (
|
||||
<div className="App" role="main">
|
||||
<article className="App-article">
|
||||
<img src={"/bunlogo.svg"} className="App-logo" alt="logo" />
|
||||
<div style={{ height: "30px" }}></div>
|
||||
<h3>Welcome to Bun!</h3>
|
||||
<div style={{ height: "10px" }}></div>
|
||||
<a className="App-link" href="https://bun.sh/docs" target="_blank" rel="noopener noreferrer">
|
||||
Read the docs →
|
||||
</a>
|
||||
</article>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -1,13 +0,0 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
16
templates/react/src/index.tsx
Normal file
16
templates/react/src/index.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as React from "react";
|
||||
import * as ReactDOM from "react-dom/client";
|
||||
import App from "./App";
|
||||
import reportWebVitals from "./reportWebVitals";
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById("root"));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />,
|
||||
</React.StrictMode>,
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
20
templates/react/tsconfig.json
Normal file
20
templates/react/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"ESNext"
|
||||
],
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": true,
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true,
|
||||
"jsx": "react-jsx",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": true,
|
||||
"types": [
|
||||
"bun-types" // add Bun global
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bun-examples/svelte-kit",
|
||||
"version": "0.0.27",
|
||||
"version": "0.0.28",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
|
||||
20
templates/tsconfig.json
Normal file
20
templates/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"ESNext"
|
||||
],
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": true,
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true,
|
||||
"jsx": "react-jsx",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": true,
|
||||
"types": [
|
||||
"bun-types" // add Bun global
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.1.10",
|
||||
"version": "0.1.11",
|
||||
"name": "@bun-examples/websi",
|
||||
"devDependencies": {
|
||||
"bun-types": "latest"
|
||||
|
||||
Reference in New Issue
Block a user