diff --git a/CHANGELOG.md b/CHANGELOG.md index 74b972a4..fd4140de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added +- Automated Upgrade / Re-install feature +- Automated process manager ## [v1.0-beta.5] - 2017-02-12 ### Added diff --git a/libs/local.js b/libs/local.js index f243e5f3..31c7e32c 100644 --- a/libs/local.js +++ b/libs/local.js @@ -102,8 +102,8 @@ module.exports = { try { fs.ensureDirSync(path.resolve(ROOTPATH, appconfig.paths.data)) + fs.emptyDirSync(path.resolve(ROOTPATH, appconfig.paths.data)) fs.ensureDirSync(path.resolve(ROOTPATH, appconfig.paths.data, './cache')) - fs.emptyDirSync(path.resolve(ROOTPATH, appconfig.paths.data, './cache')) fs.ensureDirSync(path.resolve(ROOTPATH, appconfig.paths.data, './thumbs')) fs.ensureDirSync(path.resolve(ROOTPATH, appconfig.paths.data, './temp-upload')) diff --git a/package.json b/package.json index 562447b9..d71aa8dc 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A modern, lightweight and powerful wiki app built on NodeJS, Git and Markdown", "main": "server.js", "scripts": { - "start": "node server", + "start": "node wiki start", "dev": "gulp dev", "test": "snyk test && standard && pug-lint ./views", "snyk-protect": "snyk protect", @@ -40,6 +40,7 @@ "cheerio": "^0.22.0", "child-process-promise": "^2.2.0", "chokidar": "^1.6.0", + "commander": "^2.9.0", "compression": "^1.6.2", "connect-flash": "^0.1.1", "connect-mongo": "^1.3.2", @@ -76,6 +77,7 @@ "moment-timezone": "^0.5.11", "mongoose": "^4.8.1", "multer": "^1.2.1", + "ora": "^1.1.0", "passport": "^0.3.2", "passport-facebook": "^2.1.1", "passport-google-oauth20": "^1.0.0", diff --git a/wiki.js b/wiki.js new file mode 100644 index 00000000..00176367 --- /dev/null +++ b/wiki.js @@ -0,0 +1,50 @@ +'use strict' + +const ora = require('ora') +const Promise = require('bluebird') +const pm2 = Promise.promisifyAll(require('pm2')) +const cmdr = require('commander') + +cmdr.version('1.0.0') + +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() +}