Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Commit

Permalink
Fix configuration script.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaneEveritt committed Feb 16, 2017
1 parent 54e8092 commit fc3c29e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions scripts/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
*/

/* eslint no-console: 0 */
const rfr = require('rfr');
const _ = require('lodash');
const Inquirer = require('inquirer');
const Request = require('request');
const Fs = require('fs');
const Fs = require('fs-extra');
const Path = require('path');

const configFilePath = rfr.resolve('/config/core.json');
const CONFIG_PATH = Path.resolve('config/core.json');
const CONFIG_EXISTS = Fs.existsSync(CONFIG_PATH);

const regex = {
fqdn: new RegExp(/^https?:\/\/(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,64}\/?$/),
Expand Down Expand Up @@ -113,8 +114,7 @@ _.forEach(params, (param, key) => {
});

// Check if the configuration file exists already
const configExists = Fs.existsSync(configFilePath);
if (configExists) console.log('Configuration file (core.json) exists.');
if (CONFIG_EXISTS) console.log('Configuration file (core.json) exists.');

// Interactive questioning of missing parameters
Inquirer.prompt([
Expand All @@ -136,7 +136,7 @@ Inquirer.prompt([
type: 'confirm',
default: false,
message: 'Overwrite existing configuration?',
when: () => !params.overwrite.value && configExists,
when: () => !params.overwrite.value && CONFIG_EXISTS,
},
]).then(answers => {
// Overwrite the values in the overly complicated params object
Expand All @@ -145,7 +145,7 @@ Inquirer.prompt([
});

// If file exists and no overwrite wanted error and exit.
if (!params.overwrite.value && configExists) {
if (!params.overwrite.value && CONFIG_EXISTS) {
console.error('Configuration file already exists, no overwrite requested. Aborting.');
process.exit();
}
Expand All @@ -160,7 +160,7 @@ Inquirer.prompt([
if (response.statusCode === 200) {
console.log('Writing configuration to file.');

Fs.writeFile(configFilePath, JSON.stringify(jsonBody, null, 4), err => {
Fs.writeFile(CONFIG_PATH, JSON.stringify(jsonBody, null, 4), err => {
if (err) {
console.error('Failed to write configuration file.');
} else {
Expand Down

0 comments on commit fc3c29e

Please sign in to comment.