-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathblockTypeScript.ts
145 lines (137 loc) · 3.46 KB
/
blockTypeScript.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { base } from "../base.js";
import { getPackageDependencies } from "../data/packageData.js";
import { getPrimaryBin } from "./bin/getPrimaryBin.js";
import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
import { blockExampleFiles } from "./blockExampleFiles.js";
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
import { blockGitignore } from "./blockGitignore.js";
import { blockMarkdownlint } from "./blockMarkdownlint.js";
import { blockPackageJson } from "./blockPackageJson.js";
import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js";
import { blockVitest } from "./blockVitest.js";
import { blockVSCode } from "./blockVSCode.js";
export const blockTypeScript = base.createBlock({
about: {
name: "TypeScript",
},
produce({ options }) {
const primaryBin = getPrimaryBin(options.bin, options.repository);
return {
addons: [
blockDevelopmentDocs({
sections: {
"Type Checking": {
contents: `
You should be able to see suggestions from [TypeScript](https://typescriptlang.org) in your editor for all open files.
However, it can be useful to run the TypeScript command-line (\`tsc\`) to type check all files in \`src/\`:
\`\`\`shell
pnpm tsc
\`\`\`
Add \`--watch\` to keep the type checker running in a watch mode that updates the display as you save files:
\`\`\`shell
pnpm tsc --watch
\`\`\`
`,
},
},
}),
blockExampleFiles({
files: {
"greet.ts": `import { GreetOptions } from "./types.js";
export function greet(options: GreetOptions | string) {
const {
logger = console.log.bind(console),
message,
times = 1,
} = typeof options === "string" ? { message: options } : options;
for (let i = 0; i < times; i += 1) {
logger(message);
}
}
`,
"index.ts": `export * from "./greet.js";
export * from "./types.js";
`,
"types.ts": `export interface GreetOptions {
logger?: (message: string) => void;
message: string;
times?: number;
}
`,
},
}),
blockGitignore({
ignores: ["/lib"],
}),
blockGitHubActionsCI({
jobs: [{ name: "Type Check", steps: [{ run: "pnpm tsc" }] }],
}),
blockMarkdownlint({
ignores: ["lib/"],
}),
blockPackageJson({
properties: {
devDependencies: getPackageDependencies("typescript"),
files: ["lib/"],
main: "lib/index.js",
scripts: {
tsc: "tsc",
},
},
}),
blockVitest({ coverage: { include: ["src"] }, exclude: ["lib"] }),
blockVSCode({
debuggers: primaryBin
? [
{
name: "Debug Program",
preLaunchTask: "build",
program: primaryBin,
request: "launch",
skipFiles: ["<node_internals>/**"],
type: "node",
},
]
: [],
settings: {
"typescript.tsdk": "node_modules/typescript/lib",
},
tasks: [
{
detail: "Build the project",
label: "build",
script: "build",
type: "npm",
},
],
}),
],
files: {
"tsconfig.json": JSON.stringify({
compilerOptions: {
declaration: true,
declarationMap: true,
esModuleInterop: true,
module: "NodeNext",
moduleResolution: "NodeNext",
noEmit: true,
resolveJsonModule: true,
skipLibCheck: true,
strict: true,
target: "ES2022",
},
include: ["src"],
}),
},
};
},
transition() {
return {
addons: [
blockRemoveWorkflows({
workflows: ["tsc"],
}),
],
};
},
});