diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index d59be8af..ac9728ae 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -1,7 +1,12 @@ -import {hasArgs} from '@junobuild/cli-tools'; +import { + deploy as cliDeploy, + deployWithProposal as cliDeployWithProposal, + type DeployResult, + hasArgs +} from '@junobuild/cli-tools'; import {junoConfigExist} from '../configs/juno.config'; import {clear} from '../services/clear.services'; -import {executeDeploy} from '../services/deploy/deploy.execute.services'; +import {type DeployFnParams, executeDeploy} from '../services/deploy/deploy.execute.services'; import {links} from '../services/links.services'; import {init} from './init'; @@ -10,11 +15,52 @@ export const deploy = async (args?: string[]) => { await init(); } - if (hasArgs({args, options: ['-c', '--clear']})) { + const clearOption = hasArgs({args, options: ['-c', '--clear']}); + const immediate = hasArgs({args, options: ['-i', '--immediate']}); + + if (immediate) { + await deployImmediate({args, clearOption}); + return; + } + + await deployWithProposal({args, clearOption}); +}; + +const deployWithProposal = async ({args, clearOption}: {args?: string[]; clearOption: boolean}) => { + const noCommit = hasArgs({args, options: ['-n', '--no-commit']}); + + const deployFn = async ({deploy, satellite}: DeployFnParams): Promise => + await cliDeployWithProposal({ + deploy, + proposal: { + clearAssets: clearOption, + autoCommit: !noCommit, + cdn: { + satellite + } + } + }); + + await executeDeploy({ + args, + deployFn + }); + + await links(args); +}; + +const deployImmediate = async ({args, clearOption}: {args?: string[]; clearOption: boolean}) => { + if (clearOption) { await clear(args); } - await executeDeploy(args); + const deployFn = async ({deploy}: DeployFnParams): Promise => + await cliDeploy(deploy); + + await executeDeploy({ + args, + deployFn + }); await links(args); }; diff --git a/src/help/deploy.help.ts b/src/help/deploy.help.ts index 1be071d3..c66ef431 100644 --- a/src/help/deploy.help.ts +++ b/src/help/deploy.help.ts @@ -7,6 +7,8 @@ const usage = `Usage: ${green('juno')} ${cyan('deploy')} ${yellow('[options]')} Options: ${yellow('-c, --clear')} Clear existing app files before proceeding with deployment. + ${yellow('-n, --no-commit')} Submit the deployment as a change but do not apply it yet. + ${yellow('-i, --immediate')} Deploy files instantly (bypasses the change workflow). ${helpMode} ${yellow('-h, --help')} Output usage information.`; diff --git a/src/services/deploy/deploy.execute.services.ts b/src/services/deploy/deploy.execute.services.ts index 1e29b67b..5bad6ef9 100644 --- a/src/services/deploy/deploy.execute.services.ts +++ b/src/services/deploy/deploy.execute.services.ts @@ -1,19 +1,27 @@ -import type {UploadFileStorage} from '@junobuild/cli-tools'; -import { - deploy as cliDeploy, - postDeploy as cliPostDeploy, - preDeploy as cliPreDeploy -} from '@junobuild/cli-tools'; +import type {DeployParams, DeployResult, UploadFileStorage} from '@junobuild/cli-tools'; +import {postDeploy as cliPostDeploy, preDeploy as cliPreDeploy} from '@junobuild/cli-tools'; import {type Asset, uploadBlob} from '@junobuild/core'; import {red} from 'kleur'; import {lstatSync} from 'node:fs'; import {readJunoConfig} from '../../configs/juno.config'; +import {type SatelliteParametersWithId} from '../../types/satellite'; import {configEnv} from '../../utils/config.utils'; import {satelliteParameters} from '../../utils/satellite.utils'; import {assertSatelliteMemorySize} from './deploy.assert.services'; import {listAssets} from './deploy.assets.services'; -export const executeDeploy = async (args?: string[]) => { +export interface DeployFnParams { + deploy: DeployParams; + satellite: SatelliteParametersWithId; +} + +export const executeDeploy = async ({ + args, + deployFn +}: { + args?: string[]; + deployFn: (params: DeployFnParams) => Promise; +}) => { const env = configEnv(args); const {satellite: satelliteConfig} = await readJunoConfig(env); @@ -54,12 +62,15 @@ export const executeDeploy = async (args?: string[]) => { await cliPreDeploy({config: satelliteConfig}); - const {result} = await cliDeploy({ - config: satelliteConfig, - listAssets: listExistingAssets, - assertSourceDirExists, - assertMemory, - uploadFile + const {result} = await deployFn({ + deploy: { + config: satelliteConfig, + listAssets: listExistingAssets, + assertSourceDirExists, + assertMemory, + uploadFile + }, + satellite }); if (result === 'skipped') {