wikijs-fork/wiki.js

76 lines
1.9 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-26 23:06:20 +00:00
// ===========================================
// Wiki.js
// 1.0.0
// Licensed under AGPLv3
// ===========================================
2017-02-14 07:17:25 +00:00
const Promise = require('bluebird')
2017-02-16 17:49:56 +00:00
const fs = Promise.promisifyAll(require('fs-extra'))
const ora = require('ora')
2017-02-14 07:17:25 +00:00
const pm2 = Promise.promisifyAll(require('pm2'))
const cmdr = require('commander')
2017-02-16 17:49:56 +00:00
const path = require('path')
2017-02-14 07:17:25 +00:00
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()
2017-02-16 17:49:56 +00:00
fs.emptyDirAsync(path.join(__dirname, './logs')).then(() => {
return pm2.connectAsync().then(() => {
return pm2.startAsync({
name: 'wiki',
script: 'server.js',
cwd: __dirname,
output: path.join(__dirname, './logs/wiki-output.log'),
error: path.join(__dirname, './logs/wiki-error.log'),
minUptime: 5000,
maxRestarts: 5
}).then(() => {
spinner.succeed('Wiki.js has started successfully.')
}).finally(() => {
pm2.disconnect()
})
2017-02-14 07:17:25 +00:00
})
}).catch(err => {
2017-02-16 17:49:56 +00:00
spinner.fail(err)
2017-02-14 07:17:25 +00:00
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 => {
2017-02-16 17:49:56 +00:00
spinner.fail(err)
2017-02-14 07:17:25 +00:00
process.exit(1)
})
})
2017-02-26 23:06:20 +00:00
cmdr.command('configure [port]')
.description('Configure Wiki.js')
.action((port) => {
port = port || 3000
let spinner = ora('Initializing interactive setup...').start()
require('./configure')(port, spinner)
})
2017-02-14 07:17:25 +00:00
cmdr.parse(process.argv)
if (!process.argv.slice(2).length) {
cmdr.help()
}