-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin.js
More file actions
52 lines (45 loc) · 1.38 KB
/
bin.js
File metadata and controls
52 lines (45 loc) · 1.38 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
#! /usr/bin/env node
import { existsSync, writeFileSync, readFileSync } from 'node:fs'
import { spawnSync } from 'node:child_process'
import { resolve } from 'node:path'
import { pathToFileURL } from 'node:url'
const myArgs = process.argv.slice(2)
if (myArgs[0] === '--init') {
if (myArgs.length !== 1) {
console.error("Error: unknown command")
process.exit(1)
}
const packageJSON = resolve(process.cwd(), 'package.json')
const tsconfigJSON = resolve(process.cwd(), 'tsconfig.json')
if (!existsSync(packageJSON)) {
writeFileSync(packageJSON,
`{
"type": "module"
}`
)
} else {
writeFileSync(packageJSON, JSON.stringify({
type: 'module',
...JSON.parse(readFileSync(packageJSON).toString())
}, null, 2))
}
if (!existsSync(tsconfigJSON)) {
writeFileSync(tsconfigJSON,
`{
"compilerOptions": {
"noEmit": true,
"target": "esnext",
"module": "nodenext",
"rewriteRelativeImportExtensions": true,
"erasableSyntaxOnly": true,
"verbatimModuleSyntax": true,
"types": ["node"],
"noUncheckedIndexedAccess": true,
}
}`
)
}
process.exit()
}
myArgs.unshift('--import', pathToFileURL(resolve(import.meta.dirname, 'loader.js')).href)
process.exit(spawnSync('node', myArgs, {stdio: 'inherit'}).status)