-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblankJson.js
49 lines (42 loc) · 1.11 KB
/
blankJson.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
const fs = require("fs");
const path = require("path");
const defaultSettings = {
lib: {
path: ["./lib"],
},
assets: {
path: ["./assets"],
},
tests: {
path: ["./tests"],
mochaOptions: {},
},
conf: {
watch: [],
},
};
const read = (_path, settings) => {
const rc = settings || JSON.parse(JSON.stringify(defaultSettings));
const fPath = path.normalize(_path + path.sep + "blank.json");
try {
const rcData = JSON.parse(fs.readFileSync(fPath, "UTF8"));
Object.assign(rc, rcData);
} catch (err) {
console.info("Can't load required blank.json");
process.exit(1);
}
return rc;
};
const write = (_path, appName) => {
const fPath = path.normalize(_path + path.sep + "blank.json");
const data = Object.assign({ name: appName }, defaultSettings);
try {
fs.writeFileSync(fPath, JSON.stringify(data, null, 4), "UTF8");
} catch (err) {
throw new Error(`unable to write default settings file in '${fPath}'. Inner error: ${err.message}`);
}
};
module.exports = {
read,
write,
};