Skip to content

Commit d73256f

Browse files
feat: fmt and lint prune service (#477)
Signed-off-by: David Dal Busco <[email protected]>
1 parent 7ac2934 commit d73256f

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/commands/hosting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {red} from 'kleur';
22
import {logHelpHostingClear} from '../help/hosting.clear.help';
33
import {logHelpHostingDeploy} from '../help/hosting.deploy.help';
4-
import {logHelpHostingPrune} from '../help/hosting.prune.help';
54
import {logHelpHosting} from '../help/hosting.help';
5+
import {logHelpHostingPrune} from '../help/hosting.prune.help';
66
import {clear} from '../services/assets/clear.services';
77
import {deploy} from '../services/assets/deploy.services';
88
import {prune} from '../services/assets/prune.services';

src/help/hosting.prune.help.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import {cyan, green, magenta, yellow} from 'kleur';
2-
import {
3-
HOSTING_PRUNE_DESCRIPTION,
4-
OPTION_HELP,
5-
OPTIONS_ENV
6-
} from '../constants/help.constants';
2+
import {HOSTING_PRUNE_DESCRIPTION, OPTION_HELP, OPTIONS_ENV} from '../constants/help.constants';
73
import {helpOutput} from './common.help';
84
import {TITLE} from './help';
95

src/services/assets/prune.services.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {
22
COLLECTION_DAPP,
33
DEPLOY_DEFAULT_IGNORE,
44
DEPLOY_DEFAULT_SOURCE,
5-
files as listFiles,
6-
hasArgs
5+
hasArgs,
6+
files as listFiles
77
} from '@junobuild/cli-tools';
88
import {deleteManyAssets, type Asset} from '@junobuild/core';
9-
import {minimatch} from 'minimatch';
109
import {green, red, yellow} from 'kleur';
10+
import {minimatch} from 'minimatch';
1111
import {join} from 'node:path';
1212
import ora from 'ora';
1313
import {noJunoConfig} from '../../configs/juno.config';
@@ -19,23 +19,34 @@ import {listAssets} from './_deploy/deploy.list.services';
1919
* Converts an absolute file path to its fullPath form.
2020
* e.g. "/path/to/build/index.html" -> "/index.html"
2121
*/
22-
const toFullPath = (file: string, sourceAbsolutePath: string): string =>
23-
file.replace(sourceAbsolutePath, '').replace(/\\/g, '/');
22+
const toFullPath = ({
23+
file,
24+
sourceAbsolutePath
25+
}: {
26+
file: string;
27+
sourceAbsolutePath: string;
28+
}): string => file.replace(sourceAbsolutePath, '').replace(/\\/g, '/');
2429

2530
/**
2631
* Returns true if the file should be excluded based on the ignore patterns.
2732
*/
28-
const isIgnored = (file: string, ignore: string[]): boolean =>
33+
const isIgnored = ({file, ignore}: {file: string; ignore: string[]}): boolean =>
2934
ignore.some((pattern) => minimatch(file, pattern, {matchBase: true}));
3035

3136
/**
3237
* Scans the local source directory and returns a Set of fullPaths that are present.
3338
* Throws if the directory cannot be read.
3439
*/
35-
const buildLocalPaths = (sourceAbsolutePath: string, ignore: string[]): Set<string> => {
40+
const buildLocalPaths = ({
41+
sourceAbsolutePath,
42+
ignore
43+
}: {
44+
sourceAbsolutePath: string;
45+
ignore: string[];
46+
}): Set<string> => {
3647
const allFiles = listFiles(sourceAbsolutePath);
37-
const filteredFiles = allFiles.filter((file) => !isIgnored(file, ignore));
38-
return new Set(filteredFiles.map((file) => toFullPath(file, sourceAbsolutePath)));
48+
const filteredFiles = allFiles.filter((file) => !isIgnored({file, ignore}));
49+
return new Set(filteredFiles.map((file) => toFullPath({file, sourceAbsolutePath})));
3950
};
4051

4152
export const prune = async (args?: string[]) => {
@@ -100,7 +111,7 @@ const scanLocalFiles = ({
100111
source: string;
101112
}): Set<string> => {
102113
try {
103-
const paths = buildLocalPaths(sourceAbsolutePath, ignore);
114+
const paths = buildLocalPaths({sourceAbsolutePath, ignore});
104115
scanSpinner.stop();
105116
return paths;
106117
} catch (err: unknown) {

0 commit comments

Comments
 (0)