From a016a0c266bed96cc9d06c35d62af1794a326774 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Thu, 3 Apr 2025 13:05:15 +0200 Subject: [PATCH 1/2] feat: print success or errors of config cmd --- src/commands/config.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/commands/config.ts b/src/commands/config.ts index 8384728e..d3146e03 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -8,6 +8,7 @@ import { setStorageConfig } from '@junobuild/admin'; import type {ModuleSettings} from '@junobuild/config'; +import {red} from 'kleur'; import ora from 'ora'; import {initAgent} from '../api/agent.api'; import {junoConfigExist, readJunoConfig} from '../configs/juno.config'; @@ -28,8 +29,10 @@ export const config = async (args?: string[]) => { const spinner = ora(`Configuring...`).start(); + let results: PromiseSettledResult[]; + try { - await Promise.allSettled([ + results = await Promise.allSettled([ setStorageConfig({ config: { headers: storage?.headers ?? [], @@ -62,6 +65,25 @@ export const config = async (args?: string[]) => { } finally { spinner.stop(); } + + printResults(results); +}; + +const printResults = (results: PromiseSettledResult[]) => { + const errors = results.filter((result) => result.status === 'rejected'); + + if (errors.length === 0) { + console.log('✅ Configuration applied.'); + return; + } + + console.log( + red(`The configuration failed with ${errors.length} error${errors.length > 1 ? 's' : ''} 😢.`) + ); + + errors.forEach((error, index) => { + console.log(`${index}:`, error.reason); + }); }; const setSettings = async ({ From b4be8ae7261b6dc85d0969c32361ec82890bdc9a Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Thu, 3 Apr 2025 13:19:03 +0200 Subject: [PATCH 2/2] chore: lint --- src/commands/config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/config.ts b/src/commands/config.ts index d3146e03..c5152574 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -29,7 +29,7 @@ export const config = async (args?: string[]) => { const spinner = ora(`Configuring...`).start(); - let results: PromiseSettledResult[]; + let results: Array> = []; try { results = await Promise.allSettled([ @@ -69,7 +69,7 @@ export const config = async (args?: string[]) => { printResults(results); }; -const printResults = (results: PromiseSettledResult[]) => { +const printResults = (results: Array>) => { const errors = results.filter((result) => result.status === 'rejected'); if (errors.length === 0) {