-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenable-ts.mjs
52 lines (48 loc) · 1.41 KB
/
enable-ts.mjs
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
import {join} from 'node:path'
import {writeFileSync} from 'node:fs'
import {execSync} from 'node:child_process'
// -------------------------------------------------------------
// Config.
// -------------------------------------------------------------
const config = `{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}`
// -------------------------------------------------------------
// Script.
// -------------------------------------------------------------
try {
console.info('Enabling TypeScript…')
writeFileSync(join(process.cwd(), 'tsconfig.json'), config)
execSync(
'npm add --save-dev @types/node @types/react @types/react-dom @types/styled-components typescript'
)
console.info('TypeScript successfully configured for this project!')
} catch (e) {
console.error('TypeScript configuration failed.')
console.error(e)
}