You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
586 B
28 lines
586 B
9 years ago
|
import path from 'path';
|
||
|
import fs from 'fs-promise';
|
||
|
import { homedir } from 'os';
|
||
|
|
||
|
const file = path.resolve(homedir(), '.now.json');
|
||
|
|
||
|
export function read () {
|
||
|
let existing = null;
|
||
|
try {
|
||
|
existing = fs.readFileSync(file, 'utf8');
|
||
|
existing = JSON.parse(existing);
|
||
|
} catch (err) {}
|
||
|
return existing || {};
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Merges the `data` object onto the
|
||
|
* JSON config stored in `.now.json`.
|
||
|
*
|
||
|
* (atomic)
|
||
|
* @param {Object} data
|
||
|
*/
|
||
|
|
||
|
export function merge (data) {
|
||
|
const cfg = Object.assign({}, read(), data);
|
||
|
return fs.writeFile(file, JSON.stringify(cfg, null, 2));
|
||
|
}
|