From 08a962cf48ce926ebfc6b1e6b6cd82fdfee8b09a Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Tue, 28 Dec 2021 23:46:48 +0100 Subject: [PATCH] feat: Enhance CLI with more logging and descriptive actions --- server/cli.js | 23 +++++++++++++++-------- server/warnings.js | 11 +++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 server/warnings.js diff --git a/server/cli.js b/server/cli.js index 57054b2..ab29885 100644 --- a/server/cli.js +++ b/server/cli.js @@ -7,6 +7,7 @@ const inquirer = require('inquirer'); const { isEmpty } = require('lodash'); const strapi = require('@strapi/strapi'); +const warnings = require('./warnings'); const packageJSON = require('../package.json'); const program = new Command(); @@ -71,7 +72,7 @@ const handleAction = async (syncType, skipConfirm, configType, partials) => { // No changes. 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); } @@ -96,7 +97,7 @@ const handleAction = async (syncType, skipConfirm, configType, partials) => { // No changes for partial diff. 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); } @@ -124,25 +125,31 @@ const handleAction = async (syncType, skipConfirm, configType, partials) => { // Preform the action. if (skipConfirm || answer.confirm) { 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 { 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); + if (warning) console.log(`${chalk.yellow.bold('[warning]')} ${warning}`); })); } 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') { - 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 { await Promise.all(Object.keys(finalDiff).map(async (name) => { await app.plugin('config-sync').service('main').exportSingleConfig(name, onSuccess); })); } 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. 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); } diff --git a/server/warnings.js b/server/warnings.js new file mode 100644 index 0000000..fef2333 --- /dev/null +++ b/server/warnings.js @@ -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.", + }, +};