-
Notifications
You must be signed in to change notification settings - Fork 3
/
postinstall.ts
63 lines (49 loc) · 1.7 KB
/
postinstall.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
// @ts-ignore
const fs = require('fs')
const nodeVersion = 'node 10.11'
const exceptionList = [
'./node_modules/core-js',
'./node_modules/core-js-compat',
]
const collect = (staticPath, subPath = '/') => {
let files = fs.readdirSync(staticPath)
let folders = [{subPath,staticPath}]
for(let file of files){
let checkPath = staticPath + '/' + file
let stats = fs.statSync(checkPath)
if(! stats.isDirectory()) continue
if(exceptionList.indexOf(checkPath) != -1) continue
let collectedDatas = collect(checkPath, subPath + file + '/')
for(let collectedData of collectedDatas)
folders.push(collectedData)
}
return folders
}
const find = staticPath => {
let folders = []
for(let folder of collect(staticPath))
if(fs.existsSync(folder.staticPath + `/package.json`))
folders.push(folder.staticPath)
return folders
}
const patch = staticPath => {
let folders = find(staticPath)
for (let folderName of folders) {
let stats = fs.statSync(folderName)
if (!stats.isDirectory()) continue
try {
let packageFilePath = `${folderName}/package.json`
let browserListFilePath = `${folderName}/.browserslistrc`
let packageFileData = JSON.parse(fs.readFileSync(packageFilePath))
delete packageFileData['browserslist']
fs.writeFileSync(browserListFilePath, nodeVersion)
fs.writeFileSync(
packageFilePath,
JSON.stringify(packageFileData, null, 2)
)
// console.log(`Fixed browserlist in ${packageFilePath}`)
} catch (e) {}
}
}
patch('./node_modules')
console.log(`All browserlist has been updated.`)