diff --git a/.gitignore b/.gitignore index 77fb9913..bb979fc4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,7 @@ client_custom/src/pages devConfig/sequelizeCliConfig.js devConfig/testingConfig.js -config/mysqlConfig.json -config/siteConfig.json +config/ public/bundle/bundle.js public/bundle/bundle.js.map diff --git a/cli/configure.js b/cli/configure.js index 195cf69b..0d59cbbd 100644 --- a/cli/configure.js +++ b/cli/configure.js @@ -12,6 +12,14 @@ let thumbnailChannelDefault = '@thumbnails'; let thumbnailChannel = ''; let thumbnailChannelId = ''; +const createConfigFile = (fileName, configObject) => { // siteConfig.json , siteConfig + const fileLocation = Path.resolve(__dirname, `../config/${fileName}`); + const fileContents = JSON.stringify(configObject, null, 2); + fs.writeFileSync(fileLocation, fileContents, 'utf-8'); + console.log(`Successfully created /config/${fileName}\n`); +}; + +// import existing configs or import the defaults let mysqlConfig; try { mysqlConfig = require('../config/mysqlConfig.json'); @@ -37,14 +45,33 @@ const { }, } = siteConfig; +let lbryConfig; +try { + lbryConfig = require('../config/lbryConfig.json'); +} catch (error) { + lbryConfig = require('./defaults/lbryConfig.json'); +} + +let loggerConfig; +try { + loggerConfig = require('../config/loggerConfig.json'); +} catch (error) { + loggerConfig = require('./defaults/loggerConfig.json'); +} + +let slackConfig; +try { + slackConfig = require('../config/slackConfig.json'); +} catch (error) { + slackConfig = require('./defaults/slackConfig.json'); +} + +// ask user questions and create config files inquirer .prompt(mysqlQuestions(mysqlDatabase, mysqlUsername, mysqlPassword)) .then(results => { console.log('\nCreating mysql config file...'); - const fileLocation = Path.resolve(__dirname, '../config/mysqlConfig.json'); - const fileContents = JSON.stringify(results, null, 2); - fs.writeFileSync(fileLocation, fileContents, 'utf-8'); - console.log('Successfully created /config/mysqlConfig.json!\n'); + createConfigFile('mysqlConfig.json', results); }) .then(() => { // check for lbrynet connection & retrieve a default address @@ -163,11 +190,11 @@ inquirer siteConfig['publishing']['uploadDirectory'] = results.uploadDirectory; }) .then(() => { - // create the siteConfig.json file - const fileLocation = Path.resolve(__dirname, '../config/siteConfig.json'); - const fileContents = JSON.stringify(siteConfig, null, 2); - fs.writeFileSync(fileLocation, fileContents, 'utf-8'); - console.log('Successfully created /config/siteConfig.json\n'); + // create the config files + createConfigFile('siteConfig.json', siteConfig); + createConfigFile('lbryConfig.json', lbryConfig); + createConfigFile('loggerConfig.json', loggerConfig); + createConfigFile('slackConfig.json', slackConfig); }) .then(() => { console.log('\nYou\'re all done!'); diff --git a/cli/defaults/lbryConfig.json b/cli/defaults/lbryConfig.json new file mode 100644 index 00000000..07ec92c4 --- /dev/null +++ b/cli/defaults/lbryConfig.json @@ -0,0 +1,5 @@ +{ + "apiHost": "localhost", + "apiPort": "5279", + "getTimeout": 30 +} diff --git a/cli/defaults/loggerConfig.json b/cli/defaults/loggerConfig.json new file mode 100644 index 00000000..662d124f --- /dev/null +++ b/cli/defaults/loggerConfig.json @@ -0,0 +1,3 @@ +{ + "logLevel": "verbose" +} diff --git a/cli/defaults/slackConfig.json b/cli/defaults/slackConfig.json new file mode 100644 index 00000000..5bbf8072 --- /dev/null +++ b/cli/defaults/slackConfig.json @@ -0,0 +1,5 @@ +{ + "slackWebHook": false, + "slackErrorChannel": false, + "slackInfoChannel": false +} \ No newline at end of file