forked from SUI-Components/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.js
40 lines (37 loc) · 955 Bytes
/
file.js
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
const fse = require('fs-extra')
const colors = require('colors')
const {showError} = require('./cli')
/**
* Write a file with given content
* @param {String} path Path of file to write
* @param {String} content Content to write
* @return {Promise}
*/
const writeFile = (path, content) => {
return fse
.outputFile(path, content)
.then(() => {
console.log(colors.gray(`Created ${path}`)) // eslint-disable-line no-console
})
.catch(err => {
showError(`Failed creating ${path}`)
throw new Error(err)
})
}
/**
* Remove a file
* @param {String} path Path of file to remove
* @return {Promise}
*/
const removeFile = path => {
return fse
.remove(path)
.then(() => {
console.log(colors.gray(`Removed ${path}`)) // eslint-disable-line no-console
})
.catch(err => {
showError(`Failed removing ${path}`)
throw new Error(err)
})
}
module.exports = {writeFile, removeFile}