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
1 change: 1 addition & 0 deletions src/help/hosting.prune.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('hosting')} ${magenta('prune')} ${yellow('[options]')}

Options:
${yellow('--batch')} Number of files to prune in parallel per batch (default: 100).
${yellow('--dry-run')} List stale files that would be deleted without actually deleting them.
${OPTIONS_ENV}
${OPTION_HELP}`;
Expand Down
22 changes: 22 additions & 0 deletions src/services/assets/_args.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {isEmptyString} from '@dfinity/utils';
import {nextArg} from '@junobuild/cli-tools';

export const parseBatchSize = (args?: string[]): {valid: boolean; value?: number} => {
const batchArg = nextArg({args, option: '--batch'});

if (isEmptyString(batchArg)) {
return {valid: true};
}

const batch = parseInt(batchArg);

if (isNaN(batch)) {
return {valid: false};
}

if (batch <= 0) {
return {valid: false};
}

return {valid: true, value: batch};
};
26 changes: 3 additions & 23 deletions src/services/assets/deploy.services.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {isEmptyString} from '@dfinity/utils';
import {hasArgs, nextArg} from '@junobuild/cli-tools';
import {hasArgs} from '@junobuild/cli-tools';
import {yellow} from 'kleur';
import {compare} from 'semver';
import {noJunoConfig} from '../../configs/juno.config';
Expand All @@ -9,6 +8,7 @@ import {applyConfig} from '../config/apply.services';
import {init} from '../config/init.services';
import {links} from '../links.services';
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';

Expand Down Expand Up @@ -42,7 +42,7 @@ 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} = parseUploadBatchSize(args);
const {value: uploadBatchSize} = parseBatchSize(args);

const clearOption = hasArgs({args, options: ['--clear']});
const immediate = hasArgs({args, options: ['-i', '--immediate']});
Expand Down Expand Up @@ -96,23 +96,3 @@ const deployWithProposal = async ({
proposalId
});
};

const parseUploadBatchSize = (args?: string[]): {valid: boolean; value?: number} => {
const batchArg = nextArg({args, option: '--batch'});

if (isEmptyString(batchArg)) {
return {valid: true};
}

const batch = parseInt(batchArg);

if (isNaN(batch)) {
return {valid: false};
}

if (batch <= 0) {
return {valid: false};
}

return {valid: true, value: batch};
};
6 changes: 5 additions & 1 deletion src/services/assets/prune.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {noJunoConfig} from '../../configs/juno.config';
import type {SatelliteParametersWithId} from '../../types/satellite';
import {assertConfigAndLoadSatelliteContext} from '../../utils/juno.config.utils';
import {consoleNoConfigFound} from '../../utils/msg.utils';
import {parseBatchSize} from './_args.services';
import {listAssets} from './_assets.list.services';

export const prune = async (args?: string[]) => {
Expand All @@ -26,6 +27,8 @@ export const prune = async (args?: string[]) => {
const executePrune = async (args?: string[]) => {
const dryRun = hasArgs({args, options: ['--dry-run']});

const {value: pruneBatchSize} = parseBatchSize(args);

const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext();

const listExistingAssets = async ({startAfter}: {startAfter?: string}): Promise<Asset[]> =>
Expand All @@ -43,7 +46,8 @@ const executePrune = async (args?: string[]) => {
config: satelliteConfig,
listAssets: listExistingAssets,
assertSourceDirExists,
dryRun
dryRun,
batchSize: pruneBatchSize
},
pruneFn
});
Expand Down
Loading