wikijs-fork/wiki.js

106 lines
3.2 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
2017-02-26 23:06:20 +00:00
// ===========================================
2019-05-26 01:52:42 +00:00
// Wiki.js DEV UTILITY
2017-02-26 23:06:20 +00:00
// Licensed under AGPLv3
// ===========================================
2017-10-08 02:44:35 +00:00
const Promise = require('bluebird')
const _ = require('lodash')
const chalk = require('chalk')
2017-10-08 02:44:35 +00:00
const init = {
2018-01-27 05:20:49 +00:00
dev() {
2019-05-26 01:52:42 +00:00
const webpack = require('webpack')
const chokidar = require('chokidar')
2018-01-27 05:20:49 +00:00
2019-05-26 01:52:42 +00:00
global.DEV = true
global.WP_CONFIG = require('./dev/webpack/webpack.dev.js')
global.WP = webpack(global.WP_CONFIG)
global.WP_DEV = {
devMiddleware: require('webpack-dev-middleware')(global.WP, {
publicPath: global.WP_CONFIG.output.publicPath
}),
hotMiddleware: require('webpack-hot-middleware')(global.WP)
}
global.WP_DEV.devMiddleware.waitUntilValid(() => {
console.info(chalk.yellow.bold('>>> Starting Wiki.js in DEVELOPER mode...'))
require('./server')
2018-01-27 05:20:49 +00:00
2019-05-26 01:52:42 +00:00
process.stdin.setEncoding('utf8')
process.stdin.on('data', data => {
if (_.trim(data) === 'rs') {
console.warn(chalk.yellow.bold('--- >>>>>>>>>>>>>>>>>>>>>>>> ---'))
console.warn(chalk.yellow.bold('--- Manual restart requested ---'))
console.warn(chalk.yellow.bold('--- <<<<<<<<<<<<<<<<<<<<<<<< ---'))
this.reload()
}
})
2019-05-26 01:52:42 +00:00
const devWatcher = chokidar.watch([
'./server',
'!./server/views/master.pug'
], {
ignoreInitial: true,
atomic: 400
})
devWatcher.on('ready', () => {
devWatcher.on('all', () => {
console.warn(chalk.yellow.bold('--- >>>>>>>>>>>>>>>>>>>>>>>>>>>> ---'))
console.warn(chalk.yellow.bold('--- Changes detected: Restarting ---'))
console.warn(chalk.yellow.bold('--- <<<<<<<<<<<<<<<<<<<<<<<<<<<< ---'))
this.reload()
2018-01-27 22:39:55 +00:00
})
2018-01-27 05:20:49 +00:00
})
2019-05-26 01:52:42 +00:00
})
},
async reload() {
console.warn(chalk.yellow('--- Stopping scheduled jobs...'))
if (global.WIKI.scheduler) {
global.WIKI.scheduler.stop()
}
console.warn(chalk.yellow('--- Closing DB connections...'))
await global.WIKI.models.knex.destroy()
console.warn(chalk.yellow('--- Closing Server connections...'))
2019-02-22 22:05:18 +00:00
if (global.WIKI.server) {
await new Promise((resolve, reject) => global.WIKI.server.destroy(resolve))
}
console.warn(chalk.yellow('--- Purging node modules cache...'))
2018-12-02 04:03:14 +00:00
2019-02-22 22:05:18 +00:00
global.WIKI = {}
Object.keys(require.cache).forEach(id => {
if (/[/\\]server[/\\]/.test(id)) {
delete require.cache[id]
}
})
Object.keys(module.constructor._pathCache).forEach(cacheKey => {
if (/[/\\]server[/\\]/.test(cacheKey)) {
delete module.constructor._pathCache[cacheKey]
}
})
2018-12-02 04:03:14 +00:00
2019-02-22 22:05:18 +00:00
console.warn(chalk.yellow('--- Unregistering process listeners...'))
2018-12-02 04:03:14 +00:00
2019-02-22 22:05:18 +00:00
process.removeAllListeners('unhandledRejection')
process.removeAllListeners('uncaughtException')
2018-12-02 04:03:14 +00:00
2019-02-22 22:05:18 +00:00
require('./server')
2017-10-08 02:44:35 +00:00
}
}
require('yargs') // eslint-disable-line no-unused-expressions
.usage('Usage: node $0 <cmd> [args]')
2018-01-27 05:20:49 +00:00
.command({
command: 'dev',
desc: 'Start in Developer Mode',
handler: argv => {
init.dev()
}
})
.recommendCommands()
.demandCommand(1, 'You must provide one of the accepted commands above.')
.help()
.version()
2019-05-26 01:52:42 +00:00
.epilogue('Read the docs at https://docs-beta.requarks.io/dev')
.argv