-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileUtils.js
57 lines (44 loc) · 1.26 KB
/
fileUtils.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as fs from 'fs-extra'
import * as memfs from 'mem-fs'
import * as editor from 'mem-fs-editor'
import * as shell from 'shelljs'
export const CRYPTO_CONFIG = "crypto-config.yaml"
export const TX_CONFIG = "configtx.yaml"
export const DOCKER_COMPOSE = "docker-compose.yaml"
export const write = (path, content, callback) => {
const ed = editor.create(memfs.create())
ed.write(path, content)
ed.commit([], callback)
}
export const remove = path => {
return fs.remove(path)
}
export const createFile = (path, content) => {
return new Promise((resolve, reject)=> {
try {
write(path, content, resolve)
} catch (e) {
reject(e)
}
})
}
export const enumFiles = (folderPath) => {
return new Promise((resolve, reject) => {
return fs.readdir(folderPath, (e,r) => {
if(e) {
reject(e)
}
resolve(r)
})
})
}
export const getContents = (path) => {
const edit = editor.create(memfs.create())
return edit.read(path)
}
export const exec = (contents, wd) => {
shell.exec([`cd ${wd}`, contents].join('\n'))
}
export const execFile = (path) => {
exec(getContents(path))
}