wikijs-fork/wiki.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-02-14 20:27:08 +00:00
#!/usr/bin/env node
2017-02-14 07:17:25 +00:00
'use strict'
2017-02-14 20:27:08 +00:00
const fs = require('fs-extra')
2017-02-14 07:17:25 +00:00
const ora = require('ora')
const Promise = require('bluebird')
const pm2 = Promise.promisifyAll(require('pm2'))
const cmdr = require('commander')
2017-02-14 20:27:08 +00:00
const packageObj = fs.readJsonSync('package.json')
cmdr.version(packageObj.version)
2017-02-14 07:17:25 +00:00
cmdr.command('start')
.description('Start Wiki.js process')
.action(() => {
let spinner = ora('Initializing...').start()
pm2.connectAsync().then(() => {
return pm2.startAsync({
name: 'wiki',
script: 'server.js',
cwd: __dirname
}).then(() => {
spinner.succeed('Wiki.js has started successfully.')
}).finally(() => {
pm2.disconnect()
})
}).catch(err => {
console.error(err)
process.exit(1)
})
})
cmdr.command('stop')
.description('Stop Wiki.js process')
.action(() => {
let spinner = ora('Shutting down Wiki.js...').start()
pm2.connectAsync().then(() => {
return pm2.stopAsync('wiki').then(() => {
spinner.succeed('Wiki.js has stopped successfully.')
}).finally(() => {
pm2.disconnect()
})
}).catch(err => {
console.error(err)
process.exit(1)
})
})
cmdr.parse(process.argv)
if (!process.argv.slice(2).length) {
cmdr.help()
}