-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.ts
38 lines (31 loc) · 971 Bytes
/
script.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
import packageJson from './playground/package.json'
import { writeFile } from 'fs/promises'
import { resolve } from 'node:path'
import { format } from 'prettier'
type PackageProperties = keyof typeof packageJson
// add the path of the `package.json` you want to clear here
const packagePath = resolve(__dirname, 'playground', 'package.json')
// add the keys you want to remove
const unwantedProperties: PackageProperties[] = [
'keywords',
'files',
'scripts',
'devDependencies',
]
init()
function init() {
deleteProperties()
rewritePackageJson()
}
function deleteProperties() {
unwantedProperties.forEach((key) => delete packageJson[key])
}
async function rewritePackageJson() {
try {
const content = JSON.stringify(packageJson)
const prettifiedContent = format(content, { parser: 'json-stringify' })
await writeFile(packagePath, prettifiedContent)
} catch {
console.error('Failed to rewrite the cleaned package.json file.')
}
}