Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/help/config.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const run = async () => {
await deploy(args);
break;
case 'config':
await config();
await config(args);
break;
case 'clear':
await clear();
Expand Down
27 changes: 23 additions & 4 deletions src/services/config/config.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
setRule,
setStorageConfig
} from '@junobuild/admin';
import {hasArgs} from '@junobuild/cli-tools';
import type {
AuthenticationConfig,
DatastoreCollection,
Expand All @@ -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 {
Expand All @@ -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';
Expand All @@ -56,7 +58,7 @@ type SetConfigResults = [

type EditConfig = Omit<SatelliteConfig, 'assertions'>;

export const config = async () => {
export const config = async (args?: string[]) => {
const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext();
const {satelliteId} = satellite;

Expand All @@ -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) {
Expand Down Expand Up @@ -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<EditConfig> => {
const {
storage: currentStorage,
Expand Down Expand Up @@ -536,6 +544,17 @@ const prepareConfig = async ({
};

const confirmAndExtendWithVersions = async (): Promise<EditConfig> => {
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?'
);
Expand Down