Skip to content

Commit 0c7e34d

Browse files
committed
[Issue #6] - Config creator should be able to append to existing config
1 parent 654d1fd commit 0c7e34d

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Additions
66

7+
- [Issue #6] - Config creator should be able to append to existing config
78

89
### Fixes
910

lib/config.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ module.exports = function() {
2121
shell.execSync("mkdir " + dir);
2222
}
2323

24+
// Pull default config
25+
let defaultConfig = require("../config.json");
26+
2427
// Check for environment config file
2528
if (!fs.existsSync(file)) {
26-
let defaultConfig = require("../config.json");
2729

2830
try {
2931
// Create file
@@ -34,14 +36,34 @@ module.exports = function() {
3436
'\t'
3537
)
3638
);
39+
40+
console.log("Config file created successfully.");
3741
}
3842
catch (ex) {
3943
throw "Could not create configuration file.";
4044
}
4145

4246
}
4347
else {
44-
console.log("Configuration file exists. Will not overwrite.");
48+
// Append the config to existing
49+
let existingConfig = fs.readFileSync(file);
50+
if (existingConfig) {
51+
existingConfig = JSON.parse(existingConfig);
52+
existingConfig.baker = defaultConfig.baker;
53+
54+
// Rewrite the file
55+
try {
56+
fs.writeFileSync(file, JSON.stringify(existingConfig, null, '\t'));
57+
}
58+
catch (ex) {
59+
throw "Could not append configuration file.";
60+
}
61+
62+
console.log("Config file appended successfully.");
63+
}
64+
else {
65+
throw "Could not append configuration file."
66+
}
4567
}
4668

4769
}

0 commit comments

Comments
 (0)