mirror of https://github.com/requarks/wiki
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.
92 lines
2.8 KiB
92 lines
2.8 KiB
8 years ago
|
#!/usr/bin/env node
|
||
8 years ago
|
|
||
8 years ago
|
// ===========================================
|
||
6 years ago
|
// Wiki.js DEV UTILITY
|
||
8 years ago
|
// Licensed under AGPLv3
|
||
|
// ===========================================
|
||
|
|
||
7 years ago
|
const Promise = require('bluebird')
|
||
7 years ago
|
const _ = require('lodash')
|
||
|
const chalk = require('chalk')
|
||
7 years ago
|
|
||
|
const init = {
|
||
7 years ago
|
dev() {
|
||
6 years ago
|
const webpack = require('webpack')
|
||
|
const chokidar = require('chokidar')
|
||
7 years ago
|
|
||
6 years ago
|
global.DEV = true
|
||
6 years ago
|
global.WP_CONFIG = require('./webpack/webpack.dev.js')
|
||
6 years ago
|
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...'))
|
||
6 years ago
|
require('../server')
|
||
7 years ago
|
|
||
6 years ago
|
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()
|
||
|
}
|
||
|
})
|
||
7 years ago
|
|
||
6 years ago
|
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()
|
||
7 years ago
|
})
|
||
7 years ago
|
})
|
||
6 years ago
|
})
|
||
7 years ago
|
},
|
||
|
async reload() {
|
||
6 years ago
|
console.warn(chalk.yellow('--- Stopping scheduled jobs...'))
|
||
|
if (global.WIKI.scheduler) {
|
||
|
global.WIKI.scheduler.stop()
|
||
|
}
|
||
7 years ago
|
console.warn(chalk.yellow('--- Closing DB connections...'))
|
||
7 years ago
|
await global.WIKI.models.knex.destroy()
|
||
7 years ago
|
console.warn(chalk.yellow('--- Closing Server connections...'))
|
||
6 years ago
|
if (global.WIKI.server) {
|
||
|
await new Promise((resolve, reject) => global.WIKI.server.destroy(resolve))
|
||
|
}
|
||
|
console.warn(chalk.yellow('--- Purging node modules cache...'))
|
||
6 years ago
|
|
||
6 years ago
|
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]
|
||
|
}
|
||
|
})
|
||
6 years ago
|
|
||
6 years ago
|
console.warn(chalk.yellow('--- Unregistering process listeners...'))
|
||
6 years ago
|
|
||
6 years ago
|
process.removeAllListeners('unhandledRejection')
|
||
|
process.removeAllListeners('uncaughtException')
|
||
6 years ago
|
|
||
6 years ago
|
require('../server')
|
||
7 years ago
|
}
|
||
|
}
|
||
8 years ago
|
|
||
6 years ago
|
init.dev()
|