Skip to content

Commit 1e23bf6

Browse files
committed
Organize tasks
1 parent d9d137a commit 1e23bf6

File tree

10 files changed

+140
-127
lines changed

10 files changed

+140
-127
lines changed

packages/init/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type Runtimes = Record<PackageManager, RuntimeDescription>;
4040
* whether it is installed.
4141
*/
4242
export interface RuntimeDescription {
43-
/** Human-readable name of the runtime (e.g., `"Deno"`, `"Node.js"`). */
43+
/** Human-readable name of the runtime (e.g., `"Deno"`, `"Node.js", "Bun"`). */
4444
label: string;
4545
/** Shell command to run for checking availability (e.g., `["deno", "--version"]`). */
4646
checkCommand: [string, ...string[]];
@@ -92,7 +92,7 @@ export interface WebFrameworkInitializer {
9292
/** TypeScript compiler options to include in `tsconfig.json`. */
9393
compilerOptions?: Record<string, string | boolean | number | string[] | null>;
9494
/** Task scripts keyed by task name (e.g., `"dev"`, `"prod"`, `"lint"`). */
95-
tasks?: Record<string, string>;
95+
tasks?: object;
9696
/** Instructions shown to the user after project initialization is complete. */
9797
instruction: Message;
9898
}

packages/init/src/webframeworks/astro.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import deps from "../json/deps.json" with { type: "json" };
33
import { PACKAGE_VERSION, readTemplate } from "../lib.ts";
44
import type { PackageManager, WebFrameworkDescription } from "../types.ts";
55
import { defaultDenoDependencies, defaultDevDependencies } from "./const.ts";
6-
import { getInstruction } from "./utils.ts";
6+
import { getInstruction, pmToRt } from "./utils.ts";
77

88
const astroDescription: WebFrameworkDescription = {
99
label: "Astro",
@@ -41,33 +41,11 @@ const astroDescription: WebFrameworkDescription = {
4141
`astro/astro.config.${pm === "deno" ? "deno" : "node"}.ts`,
4242
),
4343
"src/middleware.ts": await readTemplate("astro/src/middleware.ts"),
44-
...(pm !== "deno"
45-
? {
46-
"eslint.config.ts": await readTemplate("defaults/eslint.config.ts"),
47-
}
48-
: {}),
49-
},
50-
compilerOptions: undefined,
51-
tasks: {
52-
...(pm === "deno"
53-
? {
54-
dev: "deno run -A npm:astro dev",
55-
build: "deno run -A npm:astro build",
56-
preview: "deno run -A npm:astro preview",
57-
}
58-
: pm === "bun"
59-
? {
60-
dev: "bunx astro dev",
61-
build: "bunx astro build",
62-
preview: "bunx astro preview",
63-
}
64-
: {
65-
dev: "astro dev",
66-
build: "astro build",
67-
preview: "astro preview",
68-
}),
69-
...(pm !== "deno" ? { lint: "eslint ." } : {}),
44+
...(pm !== "deno" && {
45+
"eslint.config.ts": await readTemplate("defaults/eslint.config.ts"),
46+
}),
7047
},
48+
tasks: TASKS[pmToRt(pm)],
7149
instruction: getInstruction(pm, 4321),
7250
}),
7351
};
@@ -99,3 +77,23 @@ function* getAstroInitCommand(
9977

10078
const createAstroAppCommand = (pm: PackageManager): string[] =>
10179
pm === "deno" ? ["deno", "init", "-y", "--npm"] : [pm, "create"];
80+
81+
const TASKS = {
82+
"deno": {
83+
dev: "deno run -A npm:astro dev",
84+
build: "deno run -A npm:astro build",
85+
preview: "deno run -A npm:astro preview",
86+
},
87+
"bun": {
88+
dev: "bunx astro dev",
89+
build: "bunx astro build",
90+
preview: "bunx astro preview",
91+
lint: "eslint .",
92+
},
93+
"node": {
94+
dev: "dotenvx run -- astro dev",
95+
build: "dotenvx run -- astro build",
96+
preview: "dotenvx run -- astro preview",
97+
lint: "eslint .",
98+
},
99+
};

packages/init/src/webframeworks/bare-bones.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import deps from "../json/deps.json" with { type: "json" };
33
import { readTemplate } from "../lib.ts";
44
import type { WebFrameworkDescription } from "../types.ts";
55
import { defaultDenoDependencies, defaultDevDependencies } from "./const.ts";
6-
import { getInstruction, packageManagerToRuntime } from "./utils.ts";
6+
import { getInstruction, pmToRt } from "./utils.ts";
77

88
const bareBonesDescription: WebFrameworkDescription = {
99
label: "Bare-bones",
@@ -34,7 +34,7 @@ const bareBonesDescription: WebFrameworkDescription = {
3434
loggingFile: "src/logging.ts",
3535
files: {
3636
"src/main.ts": await readTemplate(
37-
`bare-bones/main/${packageManagerToRuntime(pm)}.ts`,
37+
`bare-bones/main/${pmToRt(pm)}.ts`,
3838
),
3939
...(pm !== "deno"
4040
? {
@@ -57,20 +57,24 @@ const bareBonesDescription: WebFrameworkDescription = {
5757
"noEmit": true,
5858
"strict": true,
5959
}) as Record<string, string | boolean | number | string[] | null>,
60-
tasks: {
61-
"dev": pm === "deno"
62-
? "deno run -A --watch ./src/main.ts"
63-
: pm === "bun"
64-
? "bun run --hot ./src/main.ts"
65-
: "dotenvx run -- tsx watch ./src/main.ts",
66-
"prod": pm === "deno"
67-
? "deno run -A ./src/main.ts"
68-
: pm === "bun"
69-
? "bun run ./src/main.ts"
70-
: "dotenvx run -- node --import tsx ./src/main.ts",
71-
},
60+
tasks: TASKS[pmToRt(pm)],
7261
instruction: getInstruction(pm, 8000),
7362
}),
7463
};
7564

7665
export default bareBonesDescription;
66+
67+
const TASKS = {
68+
deno: {
69+
dev: "deno run -A --watch ./src/main.ts",
70+
prod: "deno run -A ./src/main.ts",
71+
},
72+
bun: {
73+
dev: "bun run --hot ./src/main.ts",
74+
prod: "bun run ./src/main.ts",
75+
},
76+
node: {
77+
dev: "dotenvx run -- tsx watch ./src/main.ts",
78+
prod: "dotenvx run -- node --import tsx ./src/main.ts",
79+
},
80+
};

packages/init/src/webframeworks/elysia.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import deps from "../json/deps.json" with { type: "json" };
33
import { PACKAGE_VERSION, readTemplate } from "../lib.ts";
44
import type { WebFrameworkDescription } from "../types.ts";
55
import { defaultDenoDependencies, defaultDevDependencies } from "./const.ts";
6-
import { getInstruction, packageManagerToRuntime } from "./utils.ts";
6+
import { getInstruction, pmToRt } from "./utils.ts";
77

88
const elysiaDescription: WebFrameworkDescription = {
99
label: "ElysiaJS",
@@ -43,13 +43,11 @@ const elysiaDescription: WebFrameworkDescription = {
4343
loggingFile: "src/logging.ts",
4444
files: {
4545
"src/index.ts": (await readTemplate(
46-
`elysia/index/${packageManagerToRuntime(pm)}.ts`,
46+
`elysia/index/${pmToRt(pm)}.ts`,
4747
)).replace(/\/\* logger \*\//, projectName),
48-
...(pm !== "deno"
49-
? {
50-
"eslint.config.ts": await readTemplate("defaults/eslint.config.ts"),
51-
}
52-
: {}),
48+
...(pm !== "deno" && {
49+
"eslint.config.ts": await readTemplate("defaults/eslint.config.ts"),
50+
}),
5351
},
5452
compilerOptions: pm === "deno" || pm === "bun" ? undefined : {
5553
"lib": ["ESNext", "DOM"],
@@ -61,24 +59,28 @@ const elysiaDescription: WebFrameworkDescription = {
6159
"noEmit": true,
6260
"strict": true,
6361
},
64-
tasks: {
65-
"dev": pm === "deno"
66-
? "deno serve --allow-env --allow-net --watch ./src/index.ts"
67-
: pm === "bun"
68-
? "bun run --hot ./src/index.ts"
69-
: "tsx watch src/index.ts",
70-
...(pm === "deno"
71-
? { "prod": "deno serve --allow-env --allow-net ./src/index.ts" }
72-
: pm === "bun"
73-
? { "prod": "bun run ./src/index.ts" }
74-
: {
75-
"build": "tsc src/index.ts --outDir dist",
76-
"start": "NODE_ENV=production node dist/index.js",
77-
}),
78-
...(pm !== "deno" ? { "lint": "eslint ." } : {}),
79-
},
62+
tasks: TASKS[pmToRt(pm)],
8063
instruction: getInstruction(pm, 3000),
8164
}),
8265
};
8366

8467
export default elysiaDescription;
68+
69+
const TASKS = {
70+
deno: {
71+
dev:
72+
"deno serve --allow-read --allow-env --allow-net --watch ./src/index.ts",
73+
prod: "deno serve --allow-read --allow-env --allow-net ./src/index.ts",
74+
},
75+
bun: {
76+
dev: "bun run --hot ./src/index.ts",
77+
prod: "bun run ./src/index.ts",
78+
lint: "eslint .",
79+
},
80+
node: {
81+
dev: "dotenvx run -- tsx watch src/index.ts",
82+
build: "tsc src/index.ts --outDir dist",
83+
start: "NODE_ENV=production node dist/index.js",
84+
lint: "eslint .",
85+
},
86+
};

packages/init/src/webframeworks/express.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import deps from "../json/deps.json" with { type: "json" };
33
import { PACKAGE_VERSION, readTemplate } from "../lib.ts";
44
import type { WebFrameworkDescription } from "../types.ts";
55
import { defaultDenoDependencies, defaultDevDependencies } from "./const.ts";
6-
import { getInstruction } from "./utils.ts";
6+
import { getInstruction, pmToRt } from "./utils.ts";
77

88
const expressDescription: WebFrameworkDescription = {
99
label: "Express",
@@ -48,21 +48,28 @@ const expressDescription: WebFrameworkDescription = {
4848
"noEmit": true,
4949
"strict": true,
5050
},
51-
tasks: {
52-
"dev": pm === "bun"
53-
? "bun run --hot ./src/index.ts"
54-
: pm === "deno"
55-
? "deno run --allow-net --allow-env --allow-sys --watch ./src/index.ts"
56-
: "dotenvx run -- tsx watch ./src/index.ts",
57-
"prod": pm === "bun"
58-
? "bun run ./src/index.ts"
59-
: pm === "deno"
60-
? "deno run --allow-net --allow-env --allow-sys ./src/index.ts"
61-
: "dotenvx run -- node --import tsx ./src/index.ts",
62-
...(pm !== "deno" ? { "lint": "eslint ." } : {}),
63-
},
51+
tasks: TASKS[pmToRt(pm)],
6452
instruction: getInstruction(pm, 8000),
6553
}),
6654
};
6755

6856
export default expressDescription;
57+
58+
const TASKS = {
59+
deno: {
60+
dev:
61+
"deno run --allow-read --allow-net --allow-env --allow-sys --watch ./src/index.ts",
62+
prod:
63+
"deno run --allow-read --allow-net --allow-env --allow-sys ./src/index.ts",
64+
},
65+
bun: {
66+
dev: "bun run --hot ./src/index.ts",
67+
prod: "bun run ./src/index.ts",
68+
lint: "eslint .",
69+
},
70+
node: {
71+
dev: "dotenvx run -- tsx watch ./src/index.ts",
72+
prod: "dotenvx run -- node --import tsx ./src/index.ts",
73+
lint: "eslint .",
74+
},
75+
};

packages/init/src/webframeworks/hono.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PACKAGE_VERSION, readTemplate } from "../lib.ts";
55
import type { WebFrameworkDescription } from "../types.ts";
66
import { replace } from "../utils.ts";
77
import { defaultDenoDependencies, defaultDevDependencies } from "./const.ts";
8-
import { getInstruction, packageManagerToRuntime } from "./utils.ts";
8+
import { getInstruction, pmToRt } from "./utils.ts";
99

1010
const honoDescription: WebFrameworkDescription = {
1111
label: "Hono",
@@ -46,7 +46,7 @@ const honoDescription: WebFrameworkDescription = {
4646
replace(/\/\* logger \*\//, projectName),
4747
),
4848
"src/index.ts": await readTemplate(
49-
`hono/index/${packageManagerToRuntime(pm)}.ts`,
49+
`hono/index/${pmToRt(pm)}.ts`,
5050
),
5151
...(pm !== "deno"
5252
? {
@@ -66,21 +66,26 @@ const honoDescription: WebFrameworkDescription = {
6666
"jsx": "react-jsx",
6767
"jsxImportSource": "hono/jsx",
6868
},
69-
tasks: {
70-
"dev": pm === "deno"
71-
? "deno run -A --watch ./src/index.ts"
72-
: pm === "bun"
73-
? "bun run --hot ./src/index.ts"
74-
: "dotenvx run -- tsx watch ./src/index.ts",
75-
"prod": pm === "deno"
76-
? "deno run -A ./src/index.ts"
77-
: pm === "bun"
78-
? "bun run ./src/index.ts"
79-
: "dotenvx run -- node --import tsx ./src/index.ts",
80-
...(pm !== "deno" ? { "lint": "eslint ." } : {}),
81-
},
69+
tasks: TASKS[pmToRt(pm)],
8270
instruction: getInstruction(pm, 8000),
8371
}),
8472
};
8573

8674
export default honoDescription;
75+
76+
const TASKS = {
77+
deno: {
78+
dev: "deno run -A --watch ./src/index.ts",
79+
prod: "deno run -A ./src/index.ts",
80+
},
81+
bun: {
82+
dev: "bun run --hot ./src/index.ts",
83+
prod: "bun run ./src/index.ts",
84+
lint: "eslint .",
85+
},
86+
node: {
87+
dev: "dotenvx run -- tsx watch ./src/index.ts",
88+
prod: "dotenvx run -- node --import tsx ./src/index.ts",
89+
lint: "eslint .",
90+
},
91+
};

packages/init/src/webframeworks/next.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ const nextDescription: WebFrameworkDescription = {
2929
}
3030
: {}),
3131
},
32-
tasks: {
33-
...(pm !== "deno" ? { "lint": "eslint ." } : {}),
34-
},
32+
tasks: pm !== "deno" ? { "lint": "eslint ." } : {},
3533
instruction: getInstruction(pm, 3000),
3634
}),
3735
};

packages/init/src/webframeworks/nitro.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const nitroDescription: WebFrameworkDescription = {
1212
command: getNitroInitCommand(pm),
1313
dependencies: {
1414
"@fedify/h3": PACKAGE_VERSION,
15-
...(pm === "deno" ? defaultDenoDependencies : {}),
15+
...(pm === "deno" && defaultDenoDependencies),
1616
},
1717
devDependencies: defaultDevDependencies,
1818
federationFile: "server/federation.ts",
@@ -24,11 +24,9 @@ const nitroDescription: WebFrameworkDescription = {
2424
),
2525
"server/error.ts": await readTemplate("nitro/server/error.ts"),
2626
"nitro.config.ts": await readTemplate("nitro/nitro.config.ts"),
27-
...(pm !== "deno"
28-
? {
29-
"eslint.config.ts": await readTemplate("defaults/eslint.config.ts"),
30-
}
31-
: {}),
27+
...(pm !== "deno" && {
28+
"eslint.config.ts": await readTemplate("defaults/eslint.config.ts"),
29+
}),
3230
},
3331
tasks: pm !== "deno" ? { "lint": "eslint ." } : {} as { lint?: string },
3432
instruction: getInstruction(pm, 3000),

0 commit comments

Comments
 (0)