diff --git a/src/commands/config.ts b/src/commands/config.ts index bb7e64f8..41691692 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -1,5 +1,5 @@ import {config as configServices} from '../services/config/config.services'; -export const config = async () => { - await configServices(); +export const config = async (args?: string[]) => { + await configServices(args); }; diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index 6fc60744..cb65f649 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -15,7 +15,7 @@ export const deploy = async (args?: string[]) => { const configOption = hasArgs({args, options: ['--config']}); if (configOption) { console.log(''); - await config(); + await config(args); } await links(); diff --git a/src/help/config.help.ts b/src/help/config.help.ts index ea1cd0da..fe770f49 100644 --- a/src/help/config.help.ts +++ b/src/help/config.help.ts @@ -6,6 +6,7 @@ import {TITLE} from './help'; const usage = `Usage: ${green('juno')} ${cyan('config')} ${yellow('[options]')} Options: + ${yellow('--force')} Overwrite configuration without checks. ${OPTIONS_ENV} ${OPTION_HELP}`; diff --git a/src/index.ts b/src/index.ts index af37a585..b0934480 100644 --- a/src/index.ts +++ b/src/index.ts @@ -133,7 +133,7 @@ export const run = async () => { await deploy(args); break; case 'config': - await config(); + await config(args); break; case 'clear': await clear(); diff --git a/src/services/config/config.services.ts b/src/services/config/config.services.ts index ee8ea8a0..f17da245 100644 --- a/src/services/config/config.services.ts +++ b/src/services/config/config.services.ts @@ -10,6 +10,7 @@ import { setRule, setStorageConfig } from '@junobuild/admin'; +import {hasArgs} from '@junobuild/cli-tools'; import type { AuthenticationConfig, DatastoreCollection, @@ -21,7 +22,7 @@ import type { StorageCollection, StorageConfig } from '@junobuild/config'; -import {red} from 'kleur'; +import {red, yellow} from 'kleur'; import ora from 'ora'; import {getLatestAppliedConfig, saveLastAppliedConfig} from '../../configs/cli.state.config'; import { @@ -41,6 +42,7 @@ import { } from '../../types/cli.state'; import type {SatelliteParametersWithId} from '../../types/satellite'; import {objHash} from '../../utils/obj.utils'; +import {isHeadless} from '../../utils/process.utils'; import {confirmAndExit} from '../../utils/prompt.utils'; import {assertConfigAndLoadSatelliteContext} from '../../utils/satellite.utils'; import {getSettings, setSettings} from './settings.services'; @@ -56,7 +58,7 @@ type SetConfigResults = [ type EditConfig = Omit; -export const config = async () => { +export const config = async (args?: string[]) => { const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(); const {satelliteId} = satellite; @@ -66,13 +68,17 @@ export const config = async () => { // Get the hashes from the CLI state const lastAppliedConfig = getLatestAppliedConfig({satelliteId}); + // Apply configuration regardless of whether differences are noticed + const force = hasArgs({args, options: ['--force']}); + // Compare last hashes with current configuration of the Satellite // Prompt the user if there will be an overwrite // Extends the configuration provided by the dev with the version fields (unless they specified the field themselves) const editConfig = await prepareConfig({ currentConfig, lastAppliedConfig, - satelliteConfig + satelliteConfig, + force }); if (Object.values(editConfig).filter(nonNullish).length === 0) { @@ -333,11 +339,13 @@ const setConfigs = async ({ const prepareConfig = async ({ currentConfig, lastAppliedConfig, - satelliteConfig + satelliteConfig, + force }: { currentConfig: CurrentConfig; lastAppliedConfig: CliStateSatelliteAppliedConfigHashes | undefined; satelliteConfig: EditConfig; + force: boolean; }): Promise => { const { storage: currentStorage, @@ -536,6 +544,17 @@ const prepareConfig = async ({ }; const confirmAndExtendWithVersions = async (): Promise => { + if (force) { + return filterIdenticalConfig(extendWithVersions()); + } + + if (isHeadless()) { + console.log( + yellow('Non-interactive mode detected. Re-run with --force to overwrite without checks.') + ); + process.exit(1); + } + await confirmAndExit( 'This action will overwrite the current configuration of the Satellite. Are you sure you want to continue?' );