feat: Enhance CLI with more logging and descriptive actions
parent
d8185bde99
commit
08a962cf48
|
@ -7,6 +7,7 @@ const inquirer = require('inquirer');
|
||||||
const { isEmpty } = require('lodash');
|
const { isEmpty } = require('lodash');
|
||||||
const strapi = require('@strapi/strapi');
|
const strapi = require('@strapi/strapi');
|
||||||
|
|
||||||
|
const warnings = require('./warnings');
|
||||||
const packageJSON = require('../package.json');
|
const packageJSON = require('../package.json');
|
||||||
|
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
|
@ -71,7 +72,7 @@ const handleAction = async (syncType, skipConfirm, configType, partials) => {
|
||||||
|
|
||||||
// No changes.
|
// No changes.
|
||||||
if (isEmpty(diff.diff)) {
|
if (isEmpty(diff.diff)) {
|
||||||
console.log(`${chalk.bgCyan.bold('[notice]')} There are no changes to ${syncType}.`);
|
console.log(`${chalk.blue.bold('[notice]')} There are no changes to ${syncType}.`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ const handleAction = async (syncType, skipConfirm, configType, partials) => {
|
||||||
|
|
||||||
// No changes for partial diff.
|
// No changes for partial diff.
|
||||||
if ((partials || configType) && isEmpty(partialDiff)) {
|
if ((partials || configType) && isEmpty(partialDiff)) {
|
||||||
console.log(`${chalk.bgCyan.bold('[notice]')} There are no changes for the specified config.`);
|
console.log(`${chalk.blue.bold('[notice]')} There are no changes for the specified config.`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,25 +125,31 @@ const handleAction = async (syncType, skipConfirm, configType, partials) => {
|
||||||
// Preform the action.
|
// Preform the action.
|
||||||
if (skipConfirm || answer.confirm) {
|
if (skipConfirm || answer.confirm) {
|
||||||
if (syncType === 'import') {
|
if (syncType === 'import') {
|
||||||
const onSuccess = (name) => console.log(`${chalk.bgGreen.bold('[success]')} Imported ${name}`);
|
const onSuccess = (name) => console.log(`${chalk.green.bold('[success]')} Imported ${name} (${getConfigState(diff, name, syncType)})`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all(Object.keys(finalDiff).map(async (name) => {
|
await Promise.all(Object.keys(finalDiff).map(async (name) => {
|
||||||
|
let warning;
|
||||||
|
if (
|
||||||
|
getConfigState(diff, name, syncType) === chalk.red('Delete')
|
||||||
|
&& warnings.delete[name]
|
||||||
|
) warning = warnings.delete[name];
|
||||||
|
|
||||||
await app.plugin('config-sync').service('main').importSingleConfig(name, onSuccess);
|
await app.plugin('config-sync').service('main').importSingleConfig(name, onSuccess);
|
||||||
|
if (warning) console.log(`${chalk.yellow.bold('[warning]')} ${warning}`);
|
||||||
}));
|
}));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`${chalk.bgRed.bold('[error]')} Something went wrong during the import. ${e}`);
|
console.log(`${chalk.red.bold('[error]')} Something went wrong during the import. ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (syncType === 'export') {
|
if (syncType === 'export') {
|
||||||
const onSuccess = (name) => console.log(`${chalk.bgGreen.bold('[success]')} Exported ${name}`);
|
const onSuccess = (name) => console.log(`${chalk.green.bold('[success]')} Exported ${name} (${getConfigState(diff, name, syncType)})`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all(Object.keys(finalDiff).map(async (name) => {
|
await Promise.all(Object.keys(finalDiff).map(async (name) => {
|
||||||
await app.plugin('config-sync').service('main').exportSingleConfig(name, onSuccess);
|
await app.plugin('config-sync').service('main').exportSingleConfig(name, onSuccess);
|
||||||
}));
|
}));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`${chalk.bgRed.bold('[error]')} Something went wrong during the export. ${e}`);
|
console.log(`${chalk.red.bold('[error]')} Something went wrong during the export. ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,7 +209,7 @@ program
|
||||||
|
|
||||||
// No changes.
|
// No changes.
|
||||||
if (isEmpty(diff.diff)) {
|
if (isEmpty(diff.diff)) {
|
||||||
console.log(`${chalk.bgCyan.bold('[notice]')} No differences between DB and sync directory.`);
|
console.log(`${chalk.blue.bold('[notice]')} No differences between DB and sync directory.`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
delete: {
|
||||||
|
'user-role.public': "You've just deleted a default role from the users-permissions plugin.",
|
||||||
|
'user-role.authenticated': "You've just deleted a default role from the users-permissions plugin.",
|
||||||
|
'admin-role.strapi-super-admin': "You've just deleted one of the default admin roles from Strapi.",
|
||||||
|
'admin-role.strapi-author': "You've just deleted one of the default admin roles from Strapi.",
|
||||||
|
'admin-role.strapi-editor': "You've just deleted one of the default admin roles from Strapi.",
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue