-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathfs-utils.js
More file actions
43 lines (35 loc) · 1.04 KB
/
fs-utils.js
File metadata and controls
43 lines (35 loc) · 1.04 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
module.exports.copyTemplateDir = copyTemplateDir
module.exports.processFile = processFile
module.exports.readFile = readFile
module.exports.writeFile = writeFile
const fs = require('fs-extra')
async function copyTemplateDir (templatePath, targetPath) {
return new Promise((resolve, reject) => {
fs.copy(templatePath, targetPath, (error) => {
if (error) { return reject(error) }
resolve()
})
})
}
async function processFile (filePath, manipulateSourceFn) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf8', (error, rawSource) => {
if (error) {
return reject(error)
}
const output = manipulateSourceFn(rawSource)
fs.writeFile(filePath, output, (error) => {
if (error) {
return reject(error)
}
resolve()
})
})
})
}
function readFile (filePath, options = 'utf-8') {
return fs.readFileSync(filePath, options)
}
function writeFile (filePath, fileSource, options = 'utf-8') {
fs.writeFileSync(filePath, fileSource, options)
}