-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate-single-file.ts
More file actions
114 lines (105 loc) · 3.12 KB
/
Copy pathgenerate-single-file.ts
File metadata and controls
114 lines (105 loc) · 3.12 KB
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
import "auto";
export default auto({
id: "file",
title: "Generate single file",
run: async ({ project }) => {
const type = await prompt.select({
message: "Select type",
choices: [
{
value: "tsconfig",
},
],
});
if (type === "tsconfig") {
if (project.hasFile("tsconfig.json")) {
console.error("tsconfig.json already exists");
}
const base = {
$schema: "https://json.schemastore.org/tsconfig",
compilerOptions: {
strict: true,
allowJs: false,
checkJs: false,
noEmit: true,
esModuleInterop: true,
skipLibCheck: true,
},
};
const templates = {
node: {
module: "Node16",
target: "ES2022",
lib: ["ES2023"],
moduleResolution: "node16",
},
react: {
module: "ESNext",
target: "ESNext",
lib: ["DOM", "DOM.Iterable", "ESNext"],
moduleResolution: "bundler",
jsx: "react-jsx",
allowJs: false,
allowSyntheticDefaultImports: true,
esModuleInterop: false,
isolatedModules: true,
resolveJsonModule: true,
skipLibCheck: true,
useDefineForClassFields: true,
},
};
const variant = await prompt.select({
message: "Select variant",
choices: Object.keys(templates).map((key) => ({ value: key })),
});
const template = templates[variant as keyof typeof templates];
const options = await prompt.checkbox({
message: "Select options",
choices: [
new prompt.Separator("Features"),
{ value: "noEmit", checked: true },
{ value: "allowJs" },
{ value: "checkJs" },
new prompt.Separator("Rules"),
{ value: "allowUnreachableCode" },
{ value: "allowUnusedLabels" },
{ value: "exactOptionalPropertyTypes" },
{ value: "forceConsistentCasingInFileNames" },
{ value: "noFallthroughCasesInSwitch" },
{ value: "noImplicitOverride" },
{ value: "noImplicitReturns" },
{ value: "noPropertyAccessFromIndexSignature" },
{ value: "noUncheckedIndexedAccess" },
{ value: "noUnusedLocals" },
{ value: "noUnusedParameters" },
new prompt.Separator("Paths"),
{ name: "@/* -> src/*", value: "@src" },
],
});
const config = {
...base,
compilerOptions: {
...base.compilerOptions,
...template,
...options.reduce(
(acc, option) => {
if (option === "@src") {
acc.baseUrl = ".";
acc.paths = {
...acc.paths,
"@/*": ["src/*"],
};
return acc;
}
acc[option] = true;
return acc;
},
{} as Record<string, any>
),
},
};
project.writeFile("tsconfig.json", JSON.stringify(config, null, 2));
console.log("tsconfig.json created");
}
},
});