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
2 changes: 1 addition & 1 deletion src/commands/hosting.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {red} from 'kleur';
import {logHelpHostingClear} from '../help/hosting.clear.help';
import {logHelpHostingDeploy} from '../help/hosting.deploy.help';
import {logHelpHostingPrune} from '../help/hosting.prune.help';
import {logHelpHosting} from '../help/hosting.help';
import {logHelpHostingPrune} from '../help/hosting.prune.help';
import {clear} from '../services/assets/clear.services';
import {deploy} from '../services/assets/deploy.services';
import {prune} from '../services/assets/prune.services';
Expand Down
6 changes: 1 addition & 5 deletions src/help/hosting.prune.help.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {cyan, green, magenta, yellow} from 'kleur';
import {
HOSTING_PRUNE_DESCRIPTION,
OPTION_HELP,
OPTIONS_ENV
} from '../constants/help.constants';
import {HOSTING_PRUNE_DESCRIPTION, OPTION_HELP, OPTIONS_ENV} from '../constants/help.constants';
import {helpOutput} from './common.help';
import {TITLE} from './help';

Expand Down
31 changes: 21 additions & 10 deletions src/services/assets/prune.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import {
COLLECTION_DAPP,
DEPLOY_DEFAULT_IGNORE,
DEPLOY_DEFAULT_SOURCE,
files as listFiles,
hasArgs
hasArgs,
files as listFiles
} from '@junobuild/cli-tools';
import {deleteManyAssets, type Asset} from '@junobuild/core';
import {minimatch} from 'minimatch';
import {green, red, yellow} from 'kleur';
import {minimatch} from 'minimatch';
import {join} from 'node:path';
import ora from 'ora';
import {noJunoConfig} from '../../configs/juno.config';
Expand All @@ -19,23 +19,34 @@ import {listAssets} from './_deploy/deploy.list.services';
* Converts an absolute file path to its fullPath form.
* e.g. "/path/to/build/index.html" -> "/index.html"
*/
const toFullPath = (file: string, sourceAbsolutePath: string): string =>
file.replace(sourceAbsolutePath, '').replace(/\\/g, '/');
const toFullPath = ({
file,
sourceAbsolutePath
}: {
file: string;
sourceAbsolutePath: string;
}): string => file.replace(sourceAbsolutePath, '').replace(/\\/g, '/');

/**
* Returns true if the file should be excluded based on the ignore patterns.
*/
const isIgnored = (file: string, ignore: string[]): boolean =>
const isIgnored = ({file, ignore}: {file: string; ignore: string[]}): boolean =>
ignore.some((pattern) => minimatch(file, pattern, {matchBase: true}));

/**
* Scans the local source directory and returns a Set of fullPaths that are present.
* Throws if the directory cannot be read.
*/
const buildLocalPaths = (sourceAbsolutePath: string, ignore: string[]): Set<string> => {
const buildLocalPaths = ({
sourceAbsolutePath,
ignore
}: {
sourceAbsolutePath: string;
ignore: string[];
}): Set<string> => {
const allFiles = listFiles(sourceAbsolutePath);
const filteredFiles = allFiles.filter((file) => !isIgnored(file, ignore));
return new Set(filteredFiles.map((file) => toFullPath(file, sourceAbsolutePath)));
const filteredFiles = allFiles.filter((file) => !isIgnored({file, ignore}));
return new Set(filteredFiles.map((file) => toFullPath({file, sourceAbsolutePath})));
};

export const prune = async (args?: string[]) => {
Expand Down Expand Up @@ -100,7 +111,7 @@ const scanLocalFiles = ({
source: string;
}): Set<string> => {
try {
const paths = buildLocalPaths(sourceAbsolutePath, ignore);
const paths = buildLocalPaths({sourceAbsolutePath, ignore});
scanSpinner.stop();
return paths;
} catch (err: unknown) {
Expand Down
Loading