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
54 changes: 50 additions & 4 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<DeployResult> =>
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<DeployResult> =>
await cliDeploy(deploy);

await executeDeploy({
args,
deployFn
});

await links(args);
};
2 changes: 2 additions & 0 deletions src/help/deploy.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`;

Expand Down
37 changes: 24 additions & 13 deletions src/services/deploy/deploy.execute.services.ts
Original file line number Diff line number Diff line change
@@ -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<DeployResult>;
}) => {
const env = configEnv(args);
const {satellite: satelliteConfig} = await readJunoConfig(env);

Expand Down Expand Up @@ -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') {
Expand Down