-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathblockTSup.ts
123 lines (116 loc) · 2.82 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { z } from "zod";
import { base } from "../base.js";
import { getPackageDependencies } from "../data/packageData.js";
import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
import { blockESLint } from "./blockESLint.js";
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
import { blockPackageJson } from "./blockPackageJson.js";
import { blockReleaseIt } from "./blockReleaseIt.js";
import { blockRemoveDependencies } from "./blockRemoveDependencies.js";
import { blockRemoveFiles } from "./blockRemoveFiles.js";
import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js";
import { CommandPhase } from "./phases.js";
export const blockTSup = base.createBlock({
about: {
name: "TSup",
},
addons: {
entry: z.array(z.string()).default([]),
properties: z.record(z.unknown()).default({}),
runInCI: z.array(z.string()).default([]),
},
produce({ addons, options }) {
const { entry, properties, runInCI } = 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" },
...runInCI.map((run) => ({ run })),
],
},
],
}),
blockPackageJson({
properties: {
devDependencies: getPackageDependencies("tsup"),
scripts: {
build: "tsup",
},
},
}),
blockReleaseIt({
builders: [
{
order: 0,
run: "pnpm build",
},
],
}),
],
files: {
"tsup.config.ts": `import { defineConfig } from "tsup";
export default defineConfig(${JSON.stringify({
bundle: false,
clean: true,
dts: true,
entry: ["src/**/*.ts", ...entry],
format: "esm",
outDir: "lib",
...properties,
})});
`,
},
scripts: options.bin
? [
{
commands: ["pnpm build"],
phase: CommandPhase.Build,
},
]
: undefined,
};
},
transition() {
return {
addons: [
blockRemoveDependencies({
dependencies: [
"@babel/cli",
"@babel/core",
"@babel/preset-typescript",
"babel",
],
}),
blockRemoveFiles({
files: [".babelrc*", "babel.config.*", "dist", "lib"],
}),
blockRemoveWorkflows({
workflows: ["build", "tsup"],
}),
],
};
},
});