You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  1. #!/usr/bin/env node
  2. 'use strict'
  3. const fs = require('fs-extra')
  4. const ora = require('ora')
  5. const Promise = require('bluebird')
  6. const pm2 = Promise.promisifyAll(require('pm2'))
  7. const cmdr = require('commander')
  8. const packageObj = fs.readJsonSync('package.json')
  9. cmdr.version(packageObj.version)
  10. cmdr.command('start')
  11. .description('Start Wiki.js process')
  12. .action(() => {
  13. let spinner = ora('Initializing...').start()
  14. pm2.connectAsync().then(() => {
  15. return pm2.startAsync({
  16. name: 'wiki',
  17. script: 'server.js',
  18. cwd: __dirname
  19. }).then(() => {
  20. spinner.succeed('Wiki.js has started successfully.')
  21. }).finally(() => {
  22. pm2.disconnect()
  23. })
  24. }).catch(err => {
  25. console.error(err)
  26. process.exit(1)
  27. })
  28. })
  29. cmdr.command('stop')
  30. .description('Stop Wiki.js process')
  31. .action(() => {
  32. let spinner = ora('Shutting down Wiki.js...').start()
  33. pm2.connectAsync().then(() => {
  34. return pm2.stopAsync('wiki').then(() => {
  35. spinner.succeed('Wiki.js has stopped successfully.')
  36. }).finally(() => {
  37. pm2.disconnect()
  38. })
  39. }).catch(err => {
  40. console.error(err)
  41. process.exit(1)
  42. })
  43. })
  44. cmdr.parse(process.argv)
  45. if (!process.argv.slice(2).length) {
  46. cmdr.help()
  47. }