-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (48 loc) · 1.53 KB
/
script.js
File metadata and controls
59 lines (48 loc) · 1.53 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
import fs from 'fs'
import path from 'path'
import stripJsonComments from 'strip-json-comments'
let files = ['.eslintrc', '.vscode']
try {
let copyFile = (src, dest) => {
if (fs.existsSync(dest)) {
// Merge
let srcData = fs.readFileSync(src, 'utf8')
let destData = fs.readFileSync(dest, 'utf8')
if (destData === undefined) destData = {}
if (srcData !== undefined) srcData = stripJsonComments(srcData)
if (destData !== undefined) destData = stripJsonComments(destData)
let writeData = Object.assign(
{},
JSON.parse(destData),
JSON.parse(srcData)
)
fs.writeFileSync(dest, JSON.stringify(writeData), 'utf8')
} else {
// Copy
fs.openSync(dest, 'w')
let srcData = fs.readFileSync(src, 'utf8')
fs.writeFileSync(dest, srcData, 'utf8')
}
}
files.forEach(file => {
let __dirname = path.resolve()
let srcPath = `${__dirname}/${file}`
let destPath = path.normalize(`${__dirname}/../../${file}`)
let stat = fs.statSync(srcPath)
if (stat.isDirectory()) {
let items = fs.readdirSync(srcPath).filter(item => item !== '.DS_Store')
if (!fs.existsSync(destPath)) fs.mkdirSync(destPath)
items.forEach(item => {
let itemStat = fs.statSync(`${srcPath}/${item}`)
if (itemStat.isFile()) {
copyFile(`${srcPath}/${item}`, `${destPath}/${item}`)
}
})
}
if (stat.isFile()) {
copyFile(srcPath, destPath)
}
})
} catch (e) {
console.log('Prettier Pack Error : ', e)
}