From 8b89c2bba76b4a0118f31620bc9297e55803696e Mon Sep 17 00:00:00 2001 From: NGPixel Date: Mon, 15 May 2017 00:09:44 -0400 Subject: [PATCH] fix: config env vars parser + heroku config file --- npm/configs/config.heroku.yml | 24 ++++++++++++------------ npm/install.js | 16 ++++++++-------- server/configure.js | 4 ++-- server/helpers/config.js | 2 +- server/init.js | 17 ++--------------- 5 files changed, 25 insertions(+), 38 deletions(-) diff --git a/npm/configs/config.heroku.yml b/npm/configs/config.heroku.yml index 32caa049..215a259c 100644 --- a/npm/configs/config.heroku.yml +++ b/npm/configs/config.heroku.yml @@ -8,13 +8,13 @@ # Title of this site # --------------------------------------------------------------------- -title: Wiki +title: $(WIKI_TITLE) # --------------------------------------------------------------------- # Full public path to the site, without the trailing slash # --------------------------------------------------------------------- -host: https://YOURAPP.herokuapp.com/ +host: $(WIKI_HOST) # --------------------------------------------------------------------- # Port the main server should listen to (80 by default) @@ -44,13 +44,13 @@ uploads: # --------------------------------------------------------------------- # Possible values: en, de, es, fr, ko, pt or ru -lang: en +lang: $(WIKI_LANG) # --------------------------------------------------------------------- # Site Authentication # --------------------------------------------------------------------- -public: false +public: $(WIKI_PUBLIC) auth: defaultReadAccess: false @@ -97,7 +97,7 @@ auth: # --------------------------------------------------------------------- # Use a long and unique random string (256-bit keys are perfect!) -sessionSecret: 1234567890abcdefghijklmnopqrstuvxyz +sessionSecret: $(WIKI_SESSION_KEY) # --------------------------------------------------------------------- # Database Connection String @@ -110,16 +110,16 @@ db: $(MONGODB_URI) # --------------------------------------------------------------------- git: - url: https://github.com/Organization/Repo - branch: master + url: $(WIKI_GIT_URL) + branch: $(WIKI_GIT_BRANCH) auth: # Type: basic or ssh - type: ssh + type: basic # Only for Basic authentication: - username: marty - password: MartyMcFly88 + username: $(WIKI_GIT_USERNAME) + password: $(WIKI_GIT_PASSWORD) # Only for SSH authentication: privateKey: /etc/wiki/keys/git.pem @@ -127,10 +127,10 @@ git: sslVerify: true # Default email to use as commit author - serverEmail: marty@example.com + serverEmail: $(WIKI_SERVER_EMAIL) # Whether to use user email as author in commits - showUserEmail: true + showUserEmail: $(WIKI_SHOW_USER_EMAIL) # --------------------------------------------------------------------- # Features diff --git a/npm/install.js b/npm/install.js index 791e8647..2cfbf4bc 100644 --- a/npm/install.js +++ b/npm/install.js @@ -137,7 +137,7 @@ const tasks = { if (err.code === 'ENOENT') { ora.text = 'First-time install, creating a new config.yml...' let sourceConfigFile = path.join(installDir, 'config.sample.yml') - if (process.env.IS_HEROKU) { + if (process.env.WIKI_JS_HEROKU) { sourceConfigFile = path.join(__dirname, 'configs/config.heroku.yml') } else if (process.env.WIKI_JS_DOCKER) { sourceConfigFile = path.join(__dirname, 'configs/config.docker.yml') @@ -152,7 +152,11 @@ const tasks = { }) }, startConfigurationWizard () { - if (process.stdout.isTTY && !process.env.WIKI_JS_DOCKER) { + if (process.env.WIKI_JS_HEROKU) { + console.info('Wiki.js has been installed and is configured to use Heroku configuration.') + } else if (process.env.WIKI_JS_DOCKER) { + console.info('Docker environment detected. Skipping setup wizard auto-start.') + } else if (process.stdout.isTTY) { inquirer.prompt([{ type: 'list', name: 'action', @@ -202,11 +206,7 @@ const tasks = { }) }) } else { - if (!process.env.IS_HEROKU && !process.env.WIKI_JS_DOCKER) { - console.info(colors.cyan('[WARNING] Non-interactive terminal detected. You must manually start the configuration wizard using the command: node wiki configure')) - } else { - console.info('Container environment detected. Skipping setup wizard auto-start. OK.') - } + console.info(colors.cyan('[WARNING] Non-interactive terminal detected. You must manually start the configuration wizard using the command: node wiki configure')) } } } @@ -224,7 +224,7 @@ if (!process.env.IS_HEROKU && !process.env.WIKI_JS_DOCKER) { ' \\/ \\/ |_|_|\\_\\_(_)/ |___/ \n' + ' |__/\n')) } else { - console.info('=-=-= WIKI.JS =-=-=') + console.info('> WIKI.JS [Installing...]') } let ora = require('ora')({ text: 'Initializing...', spinner: 'dots12' }).start() diff --git a/server/configure.js b/server/configure.js index a49fdb83..91ecaf95 100644 --- a/server/configure.js +++ b/server/configure.js @@ -67,8 +67,8 @@ module.exports = (port, spinner) => { langs, conf, runmode: { - staticPort: (process.env.IS_HEROKU || process.env.WIKI_JS_DOCKER), - staticMongo: (!_.isNil(process.env.IS_HEROKU)) + staticPort: (process.env.WIKI_JS_HEROKU || process.env.WIKI_JS_DOCKER), + staticMongo: (!_.isNil(process.env.WIKI_JS_HEROKU)) } }) }) diff --git a/server/helpers/config.js b/server/helpers/config.js index 8c1eddf4..41b66167 100644 --- a/server/helpers/config.js +++ b/server/helpers/config.js @@ -13,7 +13,7 @@ module.exports = { return _.replace( cfg, (/\$\(([A-Z0-9_]+)\)/g, - (m) => { return process.env[m] }) + (fm, m) => { return process.env[m] }) ) } } diff --git a/server/init.js b/server/init.js index fb6b8642..050720d5 100644 --- a/server/init.js +++ b/server/init.js @@ -13,7 +13,7 @@ module.exports = { * Detect the most appropriate start mode */ startDetect: function () { - if (process.env.IS_HEROKU) { + if (process.env.WIKI_JS_HEROKU) { return this.startInHerokuMode() } else { return this.startInBackgroundMode() @@ -49,21 +49,8 @@ module.exports = { * Start in Heroku mode */ startInHerokuMode: function () { - let self = this - console.info('Initializing Wiki.js for Heroku...') - let herokuStatePath = path.join(__dirname, './app/heroku.json') - return fs.accessAsync(herokuStatePath).then(() => { - require('./server.js') - }).catch(err => { - if (err.code === 'ENOENT') { - console.info('Wiki.js is not configured yet. Launching configuration wizard...') - self.configure(process.env.PORT) - } else { - console.error(err) - process.exit(1) - } - }) + require('./server.js') }, /** * Stop Wiki.js process(es)