diff --git a/src/help/hosting.deploy.help.ts b/src/help/hosting.deploy.help.ts index 98b7599..0ce4e1b 100644 --- a/src/help/hosting.deploy.help.ts +++ b/src/help/hosting.deploy.help.ts @@ -18,6 +18,7 @@ Options: ${yellow('--no-apply')} Submit the deployment as a change but do not apply it yet. ${OPTION_KEEP_STAGED} ${yellow('-i, --immediate')} Deploy files instantly (bypasses the change workflow). + ${yellow('--prune')} Prune stale app files after successful deployment. ${OPTIONS_ENV} ${OPTION_HELP} diff --git a/src/services/assets/deploy.services.ts b/src/services/assets/deploy.services.ts index 12104e6..ce1be5b 100644 --- a/src/services/assets/deploy.services.ts +++ b/src/services/assets/deploy.services.ts @@ -11,13 +11,21 @@ import {getSatelliteVersion} from '../version.services'; import {parseBatchSize} from './_args.services'; import {deployImmediate} from './_deploy/deploy.individual.services'; import {deployWithProposal as executeDeployWithProposal} from './_deploy/deploy.with-proposal.services'; +import {executePrune} from './prune.services'; export const deploy = async (args?: string[]) => { if (await noJunoConfig()) { await init(); } - await executeDeploy(args); + const {value: uploadBatchSize} = parseBatchSize(args); + + await executeDeploy({args, batchSize: uploadBatchSize}); + + const pruneOption = hasArgs({args, options: ['--prune']}); + if (pruneOption) { + await executePrune({batchSize: uploadBatchSize}); + } const configOption = hasArgs({args, options: ['--config']}); if (configOption) { @@ -28,7 +36,13 @@ export const deploy = async (args?: string[]) => { await links(); }; -const executeDeploy = async (args?: string[]) => { +const executeDeploy = async ({ + args, + batchSize: uploadBatchSize +}: { + args?: string[]; + batchSize?: number; +}) => { // TODO: Remove fetching the version. We use it for backwards compatibility reasons. const result = await getSatelliteVersion(); @@ -42,8 +56,6 @@ const executeDeploy = async (args?: string[]) => { // wouldn't harm usage, it might prevent crawlers from properly fetching content. const deprecatedGzip = compare(result.version, '0.1.1') < 0 ? '**/*.+(css|js|mjs)' : undefined; - const {value: uploadBatchSize} = parseBatchSize(args); - const clearOption = hasArgs({args, options: ['--clear']}); const immediate = hasArgs({args, options: ['-i', '--immediate']}); diff --git a/src/services/assets/prune.services.ts b/src/services/assets/prune.services.ts index fb42879..3938703 100644 --- a/src/services/assets/prune.services.ts +++ b/src/services/assets/prune.services.ts @@ -21,14 +21,13 @@ export const prune = async (args?: string[]) => { return; } - await executePrune(args); -}; - -const executePrune = async (args?: string[]) => { const dryRun = hasArgs({args, options: ['--dry-run']}); - const {value: pruneBatchSize} = parseBatchSize(args); + await executePrune({dryRun, batchSize: pruneBatchSize}); +}; + +export const executePrune = async (params: {dryRun?: boolean; batchSize?: number}) => { const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(); const listExistingAssets = async ({startAfter}: {startAfter?: string}): Promise => @@ -46,8 +45,7 @@ const executePrune = async (args?: string[]) => { config: satelliteConfig, listAssets: listExistingAssets, assertSourceDirExists, - dryRun, - batchSize: pruneBatchSize + ...params }, pruneFn });