mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 16:52:18 +00:00
Merge pull request #2454 from strapi/plugin-install-log
Review plugin install logs
This commit is contained in:
commit
568626c0a2
@ -12,8 +12,12 @@ const path = require('path');
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const shell = require('shelljs');
|
const shell = require('shelljs');
|
||||||
|
|
||||||
|
// Public
|
||||||
|
const {cyan} = require('chalk');
|
||||||
|
const ora = require('ora');
|
||||||
|
|
||||||
// Logger.
|
// Logger.
|
||||||
const { cli, logger, packageManager } = require('strapi-utils');
|
const { cli, packageManager } = require('strapi-utils');
|
||||||
|
|
||||||
// Local Strapi dependencies.
|
// Local Strapi dependencies.
|
||||||
const packageJSON = require('../package.json');
|
const packageJSON = require('../package.json');
|
||||||
@ -30,34 +34,31 @@ module.exports = function (plugin, cliArguments) {
|
|||||||
const pluginID = `${pluginPrefix}${plugin}`;
|
const pluginID = `${pluginPrefix}${plugin}`;
|
||||||
const pluginPath = `./plugins/${plugin}`;
|
const pluginPath = `./plugins/${plugin}`;
|
||||||
|
|
||||||
|
let loader = ora(`Install ${cyan(plugin)} plugin`).start();
|
||||||
|
|
||||||
// Check that we're in a valid Strapi project.
|
// Check that we're in a valid Strapi project.
|
||||||
if (!cli.isStrapiApp()) {
|
if (!cli.isStrapiApp()) {
|
||||||
return logger.error('This command can only be used inside a Strapi project.');
|
return loader.fail('This command can only be used inside a Strapi project.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the plugin is not installed yet.
|
// Check that the plugin is not installed yet.
|
||||||
if (fs.existsSync(pluginPath)) {
|
if (fs.existsSync(pluginPath)) {
|
||||||
logger.error(`It looks like this plugin is already installed. Please check in \`${pluginPath}\`.`);
|
loader.fail(`It looks like this plugin is already installed. Please check in \`${cyan(pluginPath)}\`.`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Progress message.
|
|
||||||
logger.debug('Installation in progress...');
|
|
||||||
|
|
||||||
if (cliArguments.dev) {
|
if (cliArguments.dev) {
|
||||||
try {
|
try {
|
||||||
fs.symlinkSync(path.resolve(__dirname, '..', '..', pluginID), path.resolve(process.cwd(), pluginPath), 'dir');
|
fs.symlinkSync(path.resolve(__dirname, '..', '..', pluginID), path.resolve(process.cwd(), pluginPath), 'dir');
|
||||||
|
|
||||||
logger.info('The plugin has been successfully installed.');
|
loader.succeed(`The ${cyan(plugin)} plugin has been successfully installed.`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('An error occurred during plugin installation.');
|
console.log(e);
|
||||||
|
loader.fail('An error occurred during plugin installation.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Debug message.
|
|
||||||
logger.debug('Installing the plugin from npm registry.');
|
|
||||||
|
|
||||||
// Install the plugin from the npm registry.
|
// Install the plugin from the npm registry.
|
||||||
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM();
|
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM();
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ module.exports = function (plugin, cliArguments) {
|
|||||||
const cmd = isStrapiInstalledWithNPM ? `npm install ${pluginID}@${packageJSON.version} --ignore-scripts --no-save --prefix ${pluginPath}` : `yarn --cwd ${pluginPath} add ${pluginID}@${packageJSON.version} --ignore-scripts --no-save`;
|
const cmd = isStrapiInstalledWithNPM ? `npm install ${pluginID}@${packageJSON.version} --ignore-scripts --no-save --prefix ${pluginPath}` : `yarn --cwd ${pluginPath} add ${pluginID}@${packageJSON.version} --ignore-scripts --no-save`;
|
||||||
exec(cmd, (err) => {
|
exec(cmd, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error(`An error occurred during plugin installation. \nPlease make sure this plugin is available on npm: https://www.npmjs.com/package/${pluginID}`);
|
loader.fail(`An error occurred during plugin installation. \nPlease make sure this plugin is available on npm: https://www.npmjs.com/package/${pluginID}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,12 +82,7 @@ module.exports = function (plugin, cliArguments) {
|
|||||||
shell.rm('-r', `${pluginPath}/package.json`);
|
shell.rm('-r', `${pluginPath}/package.json`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug message.
|
|
||||||
logger.debug('Plugin successfully installed from npm registry.');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Debug message.
|
|
||||||
logger.debug(`Moving the \`node_modules/${pluginID}\` folder to the \`./plugins\` folder.`);
|
|
||||||
// Move the plugin from the `node_modules` folder to the `./plugins` folder.
|
// Move the plugin from the `node_modules` folder to the `./plugins` folder.
|
||||||
fs.copySync(`${pluginPath}/node_modules/${pluginID}`, pluginPath, {
|
fs.copySync(`${pluginPath}/node_modules/${pluginID}`, pluginPath, {
|
||||||
overwrite: true,
|
overwrite: true,
|
||||||
@ -107,10 +103,10 @@ module.exports = function (plugin, cliArguments) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Success.
|
// Success.
|
||||||
logger.info('The plugin has been successfully installed.');
|
loader.succeed(`The ${cyan(plugin)} plugin has been successfully installed.`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('An error occurred during plugin installation.');
|
loader.fail('An error occurred during plugin installation.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -32,6 +32,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.1.2",
|
"async": "^2.1.2",
|
||||||
"boom": "^5.2.0",
|
"boom": "^5.2.0",
|
||||||
|
"chalk": "^2.4.1",
|
||||||
"cheerio": "^1.0.0-rc.2",
|
"cheerio": "^1.0.0-rc.2",
|
||||||
"cross-spawn": "^6.0.5",
|
"cross-spawn": "^6.0.5",
|
||||||
"delegates": "^1.0.0",
|
"delegates": "^1.0.0",
|
||||||
@ -55,6 +56,7 @@
|
|||||||
"node-fetch": "^1.7.3",
|
"node-fetch": "^1.7.3",
|
||||||
"node-schedule": "^1.2.0",
|
"node-schedule": "^1.2.0",
|
||||||
"opn": "^5.3.0",
|
"opn": "^5.3.0",
|
||||||
|
"ora": "^3.0.0",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"semver": "^5.4.1",
|
"semver": "^5.4.1",
|
||||||
"stack-trace": "0.0.10",
|
"stack-trace": "0.0.10",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user