2017-02-14 15:27:08 -05:00
|
|
|
#!/usr/bin/env node
|
2017-02-14 02:17:25 -05:00
|
|
|
|
2017-02-26 18:06:20 -05:00
|
|
|
// ===========================================
|
2019-05-25 21:52:42 -04:00
|
|
|
// Wiki.js DEV UTILITY
|
2017-02-26 18:06:20 -05:00
|
|
|
// Licensed under AGPLv3
|
|
|
|
// ===========================================
|
|
|
|
|
2017-10-07 22:44:35 -04:00
|
|
|
const Promise = require('bluebird')
|
2018-06-24 00:20:35 -04:00
|
|
|
const _ = require('lodash')
|
|
|
|
const chalk = require('chalk')
|
2017-10-07 22:44:35 -04:00
|
|
|
|
|
|
|
const init = {
|
2018-01-27 00:20:49 -05:00
|
|
|
dev() {
|
2019-05-25 21:52:42 -04:00
|
|
|
const webpack = require('webpack')
|
|
|
|
const chokidar = require('chokidar')
|
2018-01-27 00:20:49 -05:00
|
|
|
|
2019-08-03 04:48:55 +00:00
|
|
|
console.info(chalk.yellow.bold('--- ====================== ---'))
|
|
|
|
console.info(chalk.yellow.bold('--- Wiki.js DEVELOPER MODE ---'))
|
|
|
|
console.info(chalk.yellow.bold('--- ====================== ---'))
|
|
|
|
|
2019-05-25 21:52:42 -04:00
|
|
|
global.DEV = true
|
2019-06-01 21:38:21 -04:00
|
|
|
global.WP_CONFIG = require('./webpack/webpack.dev.js')
|
2019-05-25 21:52:42 -04: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-01 21:38:21 -04:00
|
|
|
require('../server')
|
2018-01-27 00:20:49 -05:00
|
|
|
|
2019-05-25 21:52:42 -04: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 00:20:35 -04:00
|
|
|
|
2019-05-25 21:52:42 -04:00
|
|
|
const devWatcher = chokidar.watch([
|
|
|
|
'./server',
|
|
|
|
'!./server/views/master.pug'
|
|
|
|
], {
|
2019-06-22 23:32:48 -04:00
|
|
|
cwd: process.cwd(),
|
2019-05-25 21:52:42 -04:00
|
|
|
ignoreInitial: true,
|
|
|
|
atomic: 400
|
|
|
|
})
|
|
|
|
devWatcher.on('ready', () => {
|
2019-06-30 15:18:26 -04:00
|
|
|
devWatcher.on('all', _.debounce(() => {
|
2019-05-25 21:52:42 -04:00
|
|
|
console.warn(chalk.yellow.bold('--- >>>>>>>>>>>>>>>>>>>>>>>>>>>> ---'))
|
|
|
|
console.warn(chalk.yellow.bold('--- Changes detected: Restarting ---'))
|
|
|
|
console.warn(chalk.yellow.bold('--- <<<<<<<<<<<<<<<<<<<<<<<<<<<< ---'))
|
|
|
|
this.reload()
|
2019-06-30 15:18:26 -04:00
|
|
|
}, 500))
|
2018-01-27 00:20:49 -05:00
|
|
|
})
|
2019-05-25 21:52:42 -04:00
|
|
|
})
|
2018-06-24 00:20:35 -04:00
|
|
|
},
|
|
|
|
async reload() {
|
2019-02-13 17:20:46 -05:00
|
|
|
console.warn(chalk.yellow('--- Stopping scheduled jobs...'))
|
|
|
|
if (global.WIKI.scheduler) {
|
|
|
|
global.WIKI.scheduler.stop()
|
|
|
|
}
|
2018-06-24 00:20:35 -04:00
|
|
|
console.warn(chalk.yellow('--- Closing DB connections...'))
|
2018-07-29 22:23:33 -04:00
|
|
|
await global.WIKI.models.knex.destroy()
|
2018-06-24 00:20:35 -04:00
|
|
|
console.warn(chalk.yellow('--- Closing Server connections...'))
|
2020-01-11 22:33:19 -05:00
|
|
|
if (global.WIKI.servers) {
|
|
|
|
await global.WIKI.servers.stopServers()
|
2019-02-22 17:05:18 -05:00
|
|
|
}
|
|
|
|
console.warn(chalk.yellow('--- Purging node modules cache...'))
|
2018-12-01 23:03:14 -05:00
|
|
|
|
2019-02-22 17:05:18 -05: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-01 23:03:14 -05:00
|
|
|
|
2019-02-22 17:05:18 -05:00
|
|
|
console.warn(chalk.yellow('--- Unregistering process listeners...'))
|
2018-12-01 23:03:14 -05:00
|
|
|
|
2019-02-22 17:05:18 -05:00
|
|
|
process.removeAllListeners('unhandledRejection')
|
|
|
|
process.removeAllListeners('uncaughtException')
|
2018-12-01 23:03:14 -05:00
|
|
|
|
2019-06-01 21:38:21 -04:00
|
|
|
require('../server')
|
2017-10-07 22:44:35 -04:00
|
|
|
}
|
|
|
|
}
|
2017-04-18 20:23:42 -04:00
|
|
|
|
2019-06-01 21:38:21 -04:00
|
|
|
init.dev()
|