mirror of
https://github.com/strapi/strapi.git
synced 2025-09-14 11:08:35 +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 _ = require('lodash');
|
||||||
const forever = require('forever-monitor');
|
const forever = require('forever-monitor');
|
||||||
|
|
||||||
|
// Local Strapi dependencies.
|
||||||
|
const isLocalStrapiValid = require('../lib/private/isLocalStrapiValid');
|
||||||
|
|
||||||
// Logger.
|
// Logger.
|
||||||
const logger = require('strapi-utils').logger;
|
const logger = require('strapi-utils').logger;
|
||||||
|
|
||||||
@ -25,28 +28,23 @@ const logger = require('strapi-utils').logger;
|
|||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
try {
|
try {
|
||||||
// Require server configurations
|
|
||||||
const server = require(path.resolve(process.cwd(), 'config', 'environments', 'development', 'server.json'));
|
|
||||||
const options = {};
|
|
||||||
|
|
||||||
// Set NODE_ENV
|
// Set NODE_ENV
|
||||||
if (_.isEmpty(process.env.NODE_ENV)) {
|
if (_.isEmpty(process.env.NODE_ENV)) {
|
||||||
process.env.NODE_ENV = 'development';
|
process.env.NODE_ENV = 'development';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.reload === true && process.env.NODE_ENV === 'development') {
|
// Require server configurations
|
||||||
_.assign(options, {
|
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,
|
silent: false,
|
||||||
watch: true,
|
watch: true,
|
||||||
watchDirectory: process.cwd(),
|
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);
|
const child = new (forever.Monitor)('server.js', options);
|
||||||
|
|
||||||
@ -54,13 +52,33 @@ module.exports = function () {
|
|||||||
child.on('restart', function() {
|
child.on('restart', function() {
|
||||||
console.log();
|
console.log();
|
||||||
logger.info('Restarting due to changes...');
|
logger.info('Restarting due to changes...');
|
||||||
console.log();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start child process
|
// Start child process
|
||||||
child.start();
|
return child.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the app's local `strapi` in `node_modules` if it's existant and valid.
|
||||||
|
const localStrapiPath = path.resolve(process.cwd(), 'node_modules', 'strapi');
|
||||||
|
|
||||||
|
if (isLocalStrapiValid(localStrapiPath, process.cwd())) {
|
||||||
|
return require(localStrapiPath).start(afterwards);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
} catch (e) {
|
||||||
console.error(e);
|
logger.error(e);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user