mirror of
https://github.com/strapi/strapi.git
synced 2025-09-14 02:57:52 +00:00
Use forever-monitor in development only
This commit is contained in:
parent
012abadc41
commit
0974eb1e02
@ -13,6 +13,9 @@ const path = require('path');
|
||||
const _ = require('lodash');
|
||||
const forever = require('forever-monitor');
|
||||
|
||||
// Local Strapi dependencies.
|
||||
const isLocalStrapiValid = require('../lib/private/isLocalStrapiValid');
|
||||
|
||||
// Logger.
|
||||
const logger = require('strapi-utils').logger;
|
||||
|
||||
@ -25,42 +28,57 @@ const logger = require('strapi-utils').logger;
|
||||
|
||||
module.exports = function () {
|
||||
try {
|
||||
// Require server configurations
|
||||
const server = require(path.resolve(process.cwd(), 'config', 'environments', 'development', 'server.json'));
|
||||
const options = {};
|
||||
|
||||
// Set NODE_ENV
|
||||
if (_.isEmpty(process.env.NODE_ENV)) {
|
||||
process.env.NODE_ENV = 'development';
|
||||
}
|
||||
|
||||
if (server.reload === true && process.env.NODE_ENV === 'development') {
|
||||
_.assign(options, {
|
||||
// Require server configurations
|
||||
const server = require(path.resolve(process.cwd(), 'config', 'environments', 'development', 'server.json'));
|
||||
|
||||
if (process.env.NODE_ENV === 'development' && server.reload === true) {
|
||||
|
||||
const options = _.assign({}, {
|
||||
silent: false,
|
||||
watch: true,
|
||||
watchDirectory: process.cwd(),
|
||||
killTree: true // Kills the entire child process tree on `exit`
|
||||
killTree: true, // Kills the entire child process tree on `exit`,
|
||||
spinSleepTime: 0
|
||||
});
|
||||
} else {
|
||||
_.assign(options, {
|
||||
silent: process.env.NODE_ENV === 'production',
|
||||
watch: false
|
||||
|
||||
const child = new (forever.Monitor)('server.js', options);
|
||||
|
||||
// Run listeners
|
||||
child.on('restart', function() {
|
||||
console.log();
|
||||
logger.info('Restarting due to changes...');
|
||||
});
|
||||
|
||||
// Start child process
|
||||
return child.start();
|
||||
}
|
||||
|
||||
const child = new (forever.Monitor)('server.js', options);
|
||||
// Use the app's local `strapi` in `node_modules` if it's existant and valid.
|
||||
const localStrapiPath = path.resolve(process.cwd(), 'node_modules', 'strapi');
|
||||
|
||||
// Run listeners
|
||||
child.on('restart', function() {
|
||||
console.log();
|
||||
logger.info('Restarting due to changes...');
|
||||
console.log();
|
||||
});
|
||||
if (isLocalStrapiValid(localStrapiPath, process.cwd())) {
|
||||
return require(localStrapiPath).start(afterwards);
|
||||
}
|
||||
|
||||
// Start child process
|
||||
child.start();
|
||||
// Otherwise, if no workable local `strapi` module exists,
|
||||
// run the application using the currently running version
|
||||
// of `strapi`. This is probably always the global install.
|
||||
return require('../lib/')().start(afterwards);
|
||||
|
||||
function afterwards(err, strapi) {
|
||||
if (err) {
|
||||
logger.error(err.stack ? err.stack : err);
|
||||
|
||||
strapi ? strapi.stop() : process.exit(1);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
logger.error(e);
|
||||
process.exit(0);
|
||||
}
|
||||
};
|
||||
|
@ -84,7 +84,7 @@ module.exports = function (strapi) {
|
||||
strapi.emit('hook:' + id + ':error');
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
|
||||
strapi.emit('hook:' + id + ':loaded');
|
||||
|
||||
// Defer to next tick to allow other stuff to happen.
|
||||
|
Loading…
x
Reference in New Issue
Block a user