create-disposabl-app 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Create Disposabl app
2
2
 
3
- Requires [Bun](https://bun.com) 1.4.4 or later.
3
+ Create an app with [Bun](https://bun.com):
4
4
 
5
5
  ```sh
6
6
  bun create disposabl-app@latest my-app
@@ -8,4 +8,16 @@ cd my-app
8
8
  bun run dev
9
9
  ```
10
10
 
11
- Downloads the starter from [disposabl-dev/create-disposabl-app](https://github.com/disposabl-dev/create-disposabl-app), excludes the CLI and npm publishing workflow, and installs dependencies with Bun. Existing folders are never overwritten.
11
+ Or use Node.js 22 or later:
12
+
13
+ ```sh
14
+ npx create-disposabl-app@latest my-app
15
+ npx create-disposabl-app@latest -h
16
+ npx create-disposabl-app@latest -v
17
+ ```
18
+
19
+ Options: `-h` / `--help`, `-v` / `--version`, and `--skip-install`.
20
+
21
+ The starter is bundled in the package. The CLI copies only its files, installs dependencies with Bun, and prints the next commands. Existing folders are never overwritten. Installing dependencies and running the app require Bun; help, version, and `--skip-install` work without it. The starter is an `index.ts` using `Bun.serve`.
22
+
23
+ The standard CLI uses Node.js 22 or later. In a Bun-only environment, run `bunx --bun create-disposabl-app@latest my-app`.
package/dist/index.js ADDED
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+
3
+ // cli/index.ts
4
+ import { parseArgs } from "node:util";
5
+
6
+ // cli/create-app.ts
7
+ import { spawn, spawnSync } from "node:child_process";
8
+ import {
9
+ cp,
10
+ mkdir,
11
+ readdir,
12
+ readFile,
13
+ rename,
14
+ writeFile
15
+ } from "node:fs/promises";
16
+ import { resolve } from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+ async function createApp(name, { cwd = process.cwd(), skipInstall = false } = {}) {
19
+ if (!name || !/^[a-z0-9][a-z0-9._-]*$/.test(name) || name.length > 214) {
20
+ throw new Error("Choose a folder name using lowercase letters, numbers, dots, underscores, or hyphens.");
21
+ }
22
+ if (!skipInstall && spawnSync("bun", ["--version"]).status !== 0) {
23
+ throw new Error("Install Bun from https://bun.com before creating an app.");
24
+ }
25
+ const dir = resolve(cwd, name);
26
+ await mkdir(dir);
27
+ console.log(`Creating ${name}...`);
28
+ const template = fileURLToPath(new URL("./templates/default", import.meta.url));
29
+ await Promise.all((await readdir(template)).map((file) => cp(resolve(template, file), resolve(dir, file), {
30
+ recursive: true,
31
+ force: false,
32
+ errorOnExist: true
33
+ })));
34
+ await rename(resolve(dir, "gitignore"), resolve(dir, ".gitignore"));
35
+ const manifestPath = resolve(dir, "package.json");
36
+ const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
37
+ manifest.name = name;
38
+ await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}
39
+ `);
40
+ if (!skipInstall) {
41
+ await new Promise((resolveInstall, reject) => {
42
+ const install = spawn("bun", ["install"], {
43
+ cwd: dir,
44
+ stdio: "inherit",
45
+ env: { ...process.env, NODE_ENV: "development" }
46
+ });
47
+ install.once("error", reject);
48
+ install.once("close", (code) => {
49
+ if (code === 0)
50
+ resolveInstall();
51
+ else {
52
+ reject(new Error(`Dependencies could not be installed. Run bun install inside ${name} to retry.`));
53
+ }
54
+ });
55
+ });
56
+ }
57
+ console.log(`
58
+ Your app is ready.
59
+
60
+ cd ${name}
61
+ ${skipInstall ? ` bun install
62
+ ` : ""} bun run dev
63
+ `);
64
+ return dir;
65
+ }
66
+ // cli/package.json
67
+ var version = "0.0.3";
68
+
69
+ // cli/index.ts
70
+ var help = `Usage: create-disposabl-app <appname> [options]
71
+
72
+ Create a Disposabl app from the bundled starter template.
73
+
74
+ Options:
75
+ -h, --help Show this help message
76
+ -v, --version Show the CLI version
77
+ --skip-install Copy the starter without running bun install
78
+
79
+ Examples:
80
+ bun create disposabl-app@latest my-app
81
+ npx create-disposabl-app@latest my-app
82
+ npx create-disposabl-app@latest --help
83
+
84
+ The generated app uses Bun. Install it from https://bun.com.
85
+ `;
86
+ try {
87
+ const { values, positionals } = parseArgs({
88
+ allowPositionals: true,
89
+ options: {
90
+ help: { type: "boolean", short: "h" },
91
+ version: { type: "boolean", short: "v" },
92
+ "skip-install": { type: "boolean" }
93
+ }
94
+ });
95
+ if (values.help)
96
+ console.log(help);
97
+ else if (values.version)
98
+ console.log(version);
99
+ else if (positionals.length !== 1) {
100
+ console.error(help);
101
+ process.exitCode = 1;
102
+ } else {
103
+ await createApp(positionals[0], { skipInstall: values["skip-install"] });
104
+ }
105
+ } catch (error) {
106
+ console.error(error instanceof Error ? error.message : String(error));
107
+ process.exitCode = 1;
108
+ }
@@ -0,0 +1,9 @@
1
+ # Disposabl app
2
+
3
+ Start the development server with [Bun](https://bun.com):
4
+
5
+ ```sh
6
+ bun run dev
7
+ ```
8
+
9
+ Open http://localhost:3000. Edit `index.ts` to build your app.
@@ -0,0 +1,4 @@
1
+ node_modules/
2
+ .env
3
+ .env.*
4
+ !.env.example
@@ -0,0 +1,8 @@
1
+ const server = Bun.serve({
2
+ port: process.env.PORT ?? 3000,
3
+ fetch() {
4
+ return new Response("Your Disposabl app is ready.\n");
5
+ },
6
+ });
7
+
8
+ console.log(`Your app is running at ${server.url}`);
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "disposabl-app",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "bun --hot index.ts"
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-disposabl-app",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Create a Disposabl app with Bun",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,17 +10,17 @@
10
10
  "directory": "cli"
11
11
  },
12
12
  "bin": {
13
- "create-disposabl-app": "index.js"
13
+ "create-disposabl-app": "dist/index.js"
14
14
  },
15
- "files": ["index.js", "LICENSE"],
15
+ "files": [
16
+ "dist",
17
+ "LICENSE"
18
+ ],
16
19
  "engines": {
17
- "bun": ">=1.4.4"
20
+ "node": ">=22"
18
21
  },
19
22
  "scripts": {
20
- "test": "bun test"
21
- },
22
- "dependencies": {
23
- "giget": "3.3.1"
23
+ "build": "bun build.ts"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"
package/index.js DELETED
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { mkdir, readFile, writeFile } from "node:fs/promises";
3
- import { resolve } from "node:path";
4
- import { downloadTemplate } from "giget";
5
-
6
- export async function createApp(name, source = "gh:disposabl-dev/create-disposabl-app#main") {
7
- if (!name || !/^[a-z0-9][a-z0-9._-]*$/.test(name) || name.length > 214) {
8
- throw new Error("Choose a folder name using lowercase letters, numbers, dots, underscores, or hyphens.");
9
- }
10
-
11
- const dir = resolve(name);
12
- // Claim the destination before downloading. Never overwrite an existing path.
13
- await mkdir(dir);
14
- console.log(`Creating ${name}...`);
15
- await downloadTemplate(source, {
16
- dir,
17
- force: true,
18
- ignore: (path) => path === "cli" || path.startsWith("cli/") || path === ".github/workflows/publish.yml",
19
- });
20
-
21
- const manifestPath = resolve(dir, "package.json");
22
- const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
23
- manifest.name = name;
24
- manifest.private = true;
25
- await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
26
- await writeFile(resolve(dir, "README.md"), `# ${name}\n\nStart the development server:\n\n\`\`\`sh\nbun run dev\n\`\`\`\n`);
27
-
28
- const install = Bun.spawn([process.execPath, "install"], {
29
- cwd: dir,
30
- stdin: "inherit",
31
- stdout: "inherit",
32
- stderr: "inherit",
33
- });
34
- if (await install.exited !== 0) {
35
- throw new Error(`Dependencies could not be installed. Run bun install inside ${name} to retry.`);
36
- }
37
- console.log(`\nYour app is ready.\n\n cd ${name}\n bun run dev\n`);
38
- return dir;
39
- }
40
-
41
- if (import.meta.main) {
42
- const args = process.argv.slice(2);
43
- if (args.length === 1 && ["--help", "-h"].includes(args[0])) {
44
- console.log("Usage: bun create disposabl-app@latest <appname>");
45
- } else if (args.length !== 1 || args[0].startsWith("-")) {
46
- console.error("Usage: bun create disposabl-app@latest <appname>");
47
- process.exitCode = 1;
48
- } else {
49
- try {
50
- await createApp(args[0]);
51
- } catch (error) {
52
- console.error(`Could not create app: ${error.message}`);
53
- process.exitCode = 1;
54
- }
55
- }
56
- }