oputil.js config new now preps 'menuFile' and 'promptFile'

This commit is contained in:
Bryan Ashby 2018-11-11 00:19:01 -07:00
parent c24695e998
commit f592da2645
1 changed files with 32 additions and 7 deletions

View File

@ -15,13 +15,14 @@ const getHelpFor = require('./oputil_help.js').getHelpFor;
const Errors = require('../../core/enig_error.js').Errors; const Errors = require('../../core/enig_error.js').Errors;
// deps // deps
const async = require('async'); const async = require('async');
const inq = require('inquirer'); const inq = require('inquirer');
const mkdirsSync = require('fs-extra').mkdirsSync; const mkdirsSync = require('fs-extra').mkdirsSync;
const fs = require('graceful-fs'); const fs = require('graceful-fs');
const hjson = require('hjson'); const hjson = require('hjson');
const paths = require('path'); const paths = require('path');
const _ = require('lodash'); const _ = require('lodash');
const sanatizeFilename = require('sanitize-filename');
const packageJson = require('../../package.json'); const packageJson = require('../../package.json');
@ -240,12 +241,36 @@ function writeConfig(config, path) {
} }
} }
const copyFileSyncSilent = (to, from, flags) => {
try {
fs.copyFileSync(to, from, flags);
} catch(e) {}
};
function buildNewConfig() { function buildNewConfig() {
askNewConfigQuestions( (err, configPath, config) => { askNewConfigQuestions( (err, configPath, config) => {
if(err) { if(err) {
return; return;
} }
const bn = sanatizeFilename(config.general.boardName).replace(/ /g, '_').toLowerCase();
const menuFile = `${bn}.hjson`;
copyFileSyncSilent(
paths.join(__dirname, '../../config/menu.hjson'),
paths.join(__dirname, '../../config/', menuFile),
fs.constants.COPYFILE_EXCL
);
const promptFile = `${bn}_prompt.hjson`;
copyFileSyncSilent(
paths.join(__dirname, '../../config/prompt.hjson'),
paths.join(__dirname, '../../config/', promptFile),
fs.constants.COPYFILE_EXCL
)
config.general.menuFile = menuFile;
config.general.promptFile = promptFile;
if(writeConfig(config, configPath)) { if(writeConfig(config, configPath)) {
console.info('Configuration generated'); console.info('Configuration generated');
} else { } else {