From d568edb87663c825aad5594d7f9a241c03caafa4 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 8 May 2020 13:02:29 +0200 Subject: [PATCH] packages/cli: make plugin:diff --check output all errors --- .../cli/src/commands/plugin/diff/index.ts | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/commands/plugin/diff/index.ts b/packages/cli/src/commands/plugin/diff/index.ts index 116ba9e633..5338594a3b 100644 --- a/packages/cli/src/commands/plugin/diff/index.ts +++ b/packages/cli/src/commands/plugin/diff/index.ts @@ -41,7 +41,7 @@ const fileHandlers = [ }, ]; -const inquirerPromptFunc: PromptFunc = async msg => { +const inquirerPromptFunc: PromptFunc = async (msg) => { const { result } = await inquirer.prompt({ type: 'confirm', name: 'result', @@ -50,23 +50,42 @@ const inquirerPromptFunc: PromptFunc = async msg => { return result; }; -const checkPromptFunc: PromptFunc = async msg => { - throw new Error(`Check failed, the following change was needed: ${msg}`); +const makeCheck = () => { + let failed = false; + + const promptFunc: PromptFunc = async (msg) => { + failed = true; + console.log(chalk.red(`[Check Failed] ${msg}`)); + return false; + }; + + const finalize = () => { + if (failed) { + throw new Error( + 'Check failed, the plugin is not in sync with the latest template', + ); + } + }; + + return [promptFunc, finalize] as const; }; -const yesPromptFunc: PromptFunc = async msg => { + +const yesPromptFunc: PromptFunc = async (msg) => { console.log(`Accepting: "${msg}"`); return true; }; export default async (cmd: Command) => { let promptFunc = inquirerPromptFunc; + let finalize = () => {}; if (cmd.check) { - promptFunc = checkPromptFunc; + [promptFunc, finalize] = makeCheck(); } else if (cmd.yes) { promptFunc = yesPromptFunc; } const templateFiles = await readTemplateFiles('default-plugin'); await handleAllFiles(fileHandlers, templateFiles, promptFunc); + await finalize(); };