-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathfs-utils.mjs
More file actions
35 lines (31 loc) · 953 Bytes
/
Copy pathfs-utils.mjs
File metadata and controls
35 lines (31 loc) · 953 Bytes
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
import fs from 'fs-extra'
export async function copyTemplateDir (templatePath, targetPath) {
return new Promise((resolve, reject) => {
fs.copy(templatePath, targetPath, (error) => {
if (error) { return reject(error) }
resolve()
})
})
}
export 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()
})
})
})
}
export function readFile (filePath, options = 'utf-8') {
return fs.readFileSync(filePath, options)
}
export function writeFile (filePath, fileSource, options = 'utf-8') {
fs.writeFileSync(filePath, fileSource, options)
}