mirror of
https://github.com/strapi/strapi.git
synced 2025-12-04 02:51:26 +00:00
Use spawn instead of exec to auto-install adapters
This commit is contained in:
parent
b117e1d3ee
commit
b7f674b86a
@ -308,21 +308,6 @@ module.exports = function (strapi) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Subaction for config
|
|
||||||
*
|
|
||||||
* @param {Object} data
|
|
||||||
*
|
|
||||||
* @return {Function} cb
|
|
||||||
*/
|
|
||||||
|
|
||||||
handleConfig: function (data, cb) {
|
|
||||||
strapi.log.warn('We need to flush server.');
|
|
||||||
strapi.log.warn('Install dependencies if we have to.');
|
|
||||||
|
|
||||||
cb(null, true);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pull global strapi variable from local server
|
* Pull global strapi variable from local server
|
||||||
*
|
*
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
// Node.js core.
|
// Node.js core.
|
||||||
const cluster = require('cluster');
|
const cluster = require('cluster');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const exec = require('child_process').exec;
|
const spawn = require('child_process').spawn;
|
||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
@ -75,14 +75,8 @@ module.exports = function (strapi) {
|
|||||||
try {
|
try {
|
||||||
strapi.adapters[name] = require(path.resolve(strapi.config.appPath, 'node_modules', adapter));
|
strapi.adapters[name] = require(path.resolve(strapi.config.appPath, 'node_modules', adapter));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (strapi.config.environment === 'development') {
|
strapi.log.error('The adapter `' + adapter + '` is not installed.');
|
||||||
strapi.log.warn('Installing the `' + adapter + '` adapter, please wait...');
|
process.exit(1);
|
||||||
spawn('npm', ['install', adapter, '--save']);
|
|
||||||
} else {
|
|
||||||
strapi.log.error('The adapter `' + adapter + '` is not installed.');
|
|
||||||
strapi.log.error('Execute `$ npm install ' + adapter + ' --save` to install it.');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -266,22 +260,28 @@ module.exports = function (strapi) {
|
|||||||
strapi.emit('hook:waterline:installed');
|
strapi.emit('hook:waterline:installed');
|
||||||
});
|
});
|
||||||
|
|
||||||
_.forEach(strapi.config.orm.adapters, function (adapter, name) {
|
_.forEach(strapi.config.orm.adapters, function (adapter) {
|
||||||
try {
|
try {
|
||||||
const isReady = require(path.resolve(strapi.config.appPath, 'node_modules', adapter));
|
require(path.resolve(strapi.config.appPath, 'node_modules', adapter));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (strapi.config.environment === 'development') {
|
if (strapi.config.environment === 'development') {
|
||||||
const command = 'npm install ' + adapter + ' --save';
|
|
||||||
|
|
||||||
strapi.log.warn('Installing the `' + adapter + '` adapter, please wait...');
|
strapi.log.warn('Installing the `' + adapter + '` adapter, please wait...');
|
||||||
|
console.log();
|
||||||
|
|
||||||
// Run command
|
const process = spawn('npm', ['install', adapter, '--save']);
|
||||||
exec(command, function(error, stdout, stderr) {
|
|
||||||
if (error) {
|
process.on('error', function (error) {
|
||||||
|
strapi.log.error('The adapter `' + adapter + '` has not been installed.');
|
||||||
|
strapi.log.error(error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('close', function (code) {
|
||||||
|
if (code !== 0) {
|
||||||
strapi.log.error('The adapter `' + adapter + '` has not been installed.');
|
strapi.log.error('The adapter `' + adapter + '` has not been installed.');
|
||||||
strapi.log.error(error);
|
strapi.log.error('Code: ' + code);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user