-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathblockTSup.ts
102 lines (95 loc) · 2.22 KB
/
blockTSup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { z } from "zod";
import { base } from "../base.js";
import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
import { blockESLint } from "./blockESLint.js";
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
import { blockPackageJson } from "./blockPackageJson.js";
import { getPackageDependencies } from "./packageData.js";
import { CommandPhase } from "./phases.js";
export const blockTSup = base.createBlock({
about: {
name: "tsup",
},
addons: {
entry: z.array(z.string()).default([]),
runArgs: z.array(z.string()).default([]),
},
migrate() {
return {
scripts: [
{
commands: ["rm -rf .babelrc* babel.config.* dist lib"],
phase: CommandPhase.Migrations,
},
],
};
},
produce({ addons, options }) {
const { entry } = addons;
return {
addons: [
blockDevelopmentDocs({
sections: {
Building: {
contents: `
Run [**tsup**](https://tsup.egoist.dev) locally to build source files from \`src/\` into output files in \`lib/\`:
\`\`\`shell
pnpm build
\`\`\`
Add \`--watch\` to run the builder in a watch mode that continuously cleans and recreates \`lib/\` as you save files:
\`\`\`shell
pnpm build --watch
\`\`\`
`,
},
},
}),
blockESLint({
beforeLint: `Note that you'll need to run \`pnpm build\` before \`pnpm lint\` so that lint rules which check the file system can pick up on any built files.`,
}),
blockGitHubActionsCI({
jobs: [
{
name: "Build",
steps: [
{ run: "pnpm build" },
{
run: `node lib/index.js${addons.runArgs.map((arg) => ` ${arg}`).join("")}`,
},
],
},
],
}),
blockPackageJson({
properties: {
devDependencies: getPackageDependencies("tsup"),
scripts: {
build: "tsup",
},
},
}),
],
files: {
"tsup.config.ts": `import { defineConfig } from "tsup";
export default defineConfig({
bundle: false,
clean: true,
dts: true,
entry: ${JSON.stringify(["src/**/*.ts", ...entry])},
format: "esm",
outDir: "lib",
sourcemap: true,
});
`,
},
scripts: options.bin
? [
{
commands: ["pnpm build"],
phase: CommandPhase.Build,
},
]
: undefined,
};
},
});