Updated npm install to use the configuration wizard
This commit is contained in:
parent
b7442443d3
commit
3b4402fb28
102
npm/install.js
102
npm/install.js
@ -1,18 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
const ora = require('ora')({ text: 'Initializing...', spinner: 'dots12' }).start()
|
||||
const Promise = require('bluebird')
|
||||
const exec = require('child_process').exec
|
||||
const exec = require('execa')
|
||||
const fs = Promise.promisifyAll(require('fs-extra'))
|
||||
const https = require('follow-redirects').https
|
||||
const path = require('path')
|
||||
const pm2 = Promise.promisifyAll(require('pm2'))
|
||||
const tar = require('tar')
|
||||
const zlib = require('zlib')
|
||||
const inquirer = require('inquirer')
|
||||
const colors = require('colors/safe')
|
||||
const _ = require('lodash')
|
||||
|
||||
let installDir = path.resolve(__dirname, '../..')
|
||||
|
||||
console.info(colors.yellow(
|
||||
' __ __ _ _ _ _ \n' +
|
||||
'/ / /\\ \\ (_) | _(_) (_)___ \n' +
|
||||
'\\ \\/ \\/ / | |/ / | | / __| \n' +
|
||||
' \\ /\\ /| | <| |_ | \\__ \\ \n' +
|
||||
' \\/ \\/ |_|_|\\_\\_(_)/ |___/ \n' +
|
||||
' |__/\n'))
|
||||
|
||||
var ora = require('ora')({ text: 'Initializing...', spinner: 'dots12' }).start()
|
||||
|
||||
ora.text = 'Looking for running instances...'
|
||||
pm2.connectAsync().then(() => {
|
||||
return pm2.describeAsync('wiki').then(() => {
|
||||
@ -54,39 +65,20 @@ pm2.connectAsync().then(() => {
|
||||
})
|
||||
})
|
||||
}).then(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ora.text = 'Installing Wiki.js npm dependencies...'
|
||||
let npmInstallProc = exec('npm install --only=production --no-optional', {
|
||||
cwd: installDir
|
||||
})
|
||||
npmInstallProc.stdout.pipe(process.stdout)
|
||||
npmInstallProc.on('error', err => {
|
||||
reject(err)
|
||||
})
|
||||
.on('exit', () => {
|
||||
ora.text = 'Wiki.js npm dependencies installed successfully.'
|
||||
resolve(true)
|
||||
})
|
||||
ora.text = 'Installing Wiki.js npm dependencies...'
|
||||
return exec.stdout('npm', ['install', '--only=production', '--no-optional'], {
|
||||
cwd: installDir
|
||||
}).then(results => {
|
||||
ora.text = 'Wiki.js npm dependencies installed successfully.'
|
||||
return true
|
||||
})
|
||||
}).then(() => {
|
||||
fs.accessAsync(path.join(installDir, 'config.yml')).then(() => {
|
||||
/**
|
||||
* Upgrade mode
|
||||
*/
|
||||
return new Promise((resolve, reject) => {
|
||||
ora.text = 'Upgrade succeeded. Starting Wiki.js...'
|
||||
let npmInstallProc = exec('node wiki start', {
|
||||
cwd: installDir
|
||||
})
|
||||
npmInstallProc.stdout.pipe(process.stdout)
|
||||
npmInstallProc.on('error', err => {
|
||||
reject(err)
|
||||
})
|
||||
.on('exit', () => {
|
||||
ora.succeed('Wiki.js has started. Upgrade completed.')
|
||||
resolve(true)
|
||||
})
|
||||
})
|
||||
ora.succeed('Upgrade completed.')
|
||||
return false
|
||||
}).catch(err => {
|
||||
/**
|
||||
* Install mode
|
||||
@ -94,11 +86,61 @@ pm2.connectAsync().then(() => {
|
||||
if (err.code === 'ENOENT') {
|
||||
ora.text = 'First-time install, creating a new config.yml...'
|
||||
return fs.copyAsync(path.join(installDir, 'config.sample.yml'), path.join(installDir, 'config.yml')).then(() => {
|
||||
ora.succeed('Installation succeeded. You can now continue with the configuration steps. Check out https://docs.wiki.requarks.io/install for more info.')
|
||||
ora.succeed('Installation succeeded.')
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}).then((isNewInstall) => {
|
||||
if (process.stdout.isTTY) {
|
||||
inquirer.prompt([{
|
||||
type: 'list',
|
||||
name: 'action',
|
||||
message: 'Continue with configuration wizard?',
|
||||
default: 'default',
|
||||
choices: [
|
||||
{ name: 'Yes, run configuration wizard on port 3000 (recommended)', value: 'default', short: 'Yes' },
|
||||
{ name: 'Yes, run configuration wizard on a custom port...', value: 'custom', short: 'Yes' },
|
||||
{ name: 'No, I\'ll configure the config file manually', value: 'exit', short: 'No' }
|
||||
]
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'customport',
|
||||
message: 'Custom port to use:',
|
||||
default: 3000,
|
||||
validate: (val) => {
|
||||
val = _.toNumber(val)
|
||||
return (_.isNumber(val) && val > 0) ? true : 'Invalid Port!'
|
||||
},
|
||||
when: (ans) => {
|
||||
return ans.action === 'custom'
|
||||
}
|
||||
}]).then((ans) => {
|
||||
switch (ans.action) {
|
||||
case 'default':
|
||||
console.info(colors.bold.cyan('> Browse to http://your-server:3000/ to configure your wiki!'))
|
||||
ora = require('ora')({ text: 'I\'ll wait until you\'re done ;)', color: 'yellow', spinner: 'pong' }).start()
|
||||
return exec.stdout('node', ['wiki', 'configure'], {
|
||||
cwd: installDir
|
||||
})
|
||||
case 'custom':
|
||||
console.info(colors.bold.cyan('> Browse to http://your-server:' + ans.customport + '/ to configure your wiki!'))
|
||||
ora = require('ora')({ text: 'I\'ll wait until you\'re done ;)', color: 'yellow', spinner: 'pong' }).start()
|
||||
return exec.stdout('node', ['wiki', 'configure', ans.customport], {
|
||||
cwd: installDir
|
||||
})
|
||||
default:
|
||||
console.info(colors.bold.cyan('> Open config.yml in your favorite editor. Then start Wiki.js using: node wiki start'))
|
||||
process.exit(0)
|
||||
break
|
||||
}
|
||||
}).then(() => {
|
||||
ora.succeed(colors.bold.green('Wiki.js has been configured and is now running!'))
|
||||
})
|
||||
} else {
|
||||
console.info('[!] Non-interactive terminal detected. You may now manually edit config.yml and start Wiki.js by running: node wiki start')
|
||||
}
|
||||
})
|
||||
}).catch(err => {
|
||||
ora.fail(err)
|
||||
|
@ -29,12 +29,15 @@
|
||||
},
|
||||
"homepage": "https://github.com/Requarks/wiki#readme",
|
||||
"dependencies": {
|
||||
"bluebird": "^3.4.7",
|
||||
"follow-redirects": "^1.2.1",
|
||||
"fs-extra": "^2.0.0",
|
||||
"bluebird": "^3.5.0",
|
||||
"colors": "^1.1.2",
|
||||
"execa": "^0.6.3",
|
||||
"follow-redirects": "^1.2.3",
|
||||
"fs-extra": "^2.1.2",
|
||||
"inquirer": "^3.0.6",
|
||||
"lodash": "^4.17.4",
|
||||
"ora": "^1.1.0",
|
||||
"pm2": "^2.4.0",
|
||||
"ora": "^1.2.0",
|
||||
"pm2": "^2.4.3",
|
||||
"tar": "^2.2.1"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user