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')
|
2018-06-24 04:20:35 +00:00
|
|
|
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
|
2019-06-02 01:38:21 +00:00
|
|
|
global.WP_CONFIG = require('./webpack/webpack.dev.js')
|
2019-05-26 01:52:42 +00:00
|
|
|
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...'))
|
2019-06-02 01:38:21 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
})
|
2018-06-24 04:20:35 +00:00
|
|
|
|
2019-05-26 01:52:42 +00:00
|
|
|
const devWatcher = chokidar.watch([
|
|
|
|
'./server',
|
|
|
|
'!./server/views/master.pug'
|
|
|
|
], {
|
2019-06-23 03:32:48 +00:00
|
|
|
cwd: process.cwd(),
|
2019-05-26 01:52:42 +00:00
|
|
|
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
|
|
|
})
|
2018-06-24 04:20:35 +00:00
|
|
|
},
|
|
|
|
async reload() {
|
2019-02-13 22:20:46 +00:00
|
|
|
console.warn(chalk.yellow('--- Stopping scheduled jobs...'))
|
|
|
|
if (global.WIKI.scheduler) {
|
|
|
|
global.WIKI.scheduler.stop()
|
|
|
|
}
|
2018-06-24 04:20:35 +00:00
|
|
|
console.warn(chalk.yellow('--- Closing DB connections...'))
|
2018-07-30 02:23:33 +00:00
|
|
|
await global.WIKI.models.knex.destroy()
|
2018-06-24 04:20:35 +00:00
|
|
|
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-06-02 01:38:21 +00:00
|
|
|
require('../server')
|
2017-10-08 02:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 00:23:42 +00:00
|
|
|
|
2019-06-02 01:38:21 +00:00
|
|
|
init.dev()
|