2016-07-07 05:31:53 -08:00
|
|
|
const { resolve } = require('path');
|
|
|
|
|
const { statSync, readFileSync, writeFileSync } = require('fs');
|
2016-07-07 06:09:56 -08:00
|
|
|
const file = require('./config-path');
|
2016-07-07 05:31:53 -08:00
|
|
|
|
|
|
|
|
module.exports = function initConfig () {
|
|
|
|
|
try {
|
|
|
|
|
statSync(file);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log('stat error', file, err.message);
|
2016-07-07 06:09:56 -08:00
|
|
|
const defaultConfig = readFileSync(resolve(__dirname, 'config-default.js'));
|
2016-07-07 05:31:53 -08:00
|
|
|
try {
|
|
|
|
|
console.log('attempting to write default config to', file);
|
|
|
|
|
writeFileSync(file, defaultConfig);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw new Error(`Failed to write config to ${file}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return file;
|
|
|
|
|
};
|