Skip to content

Commit 81c4f33

Browse files
feat: ignore .DS_Store on Mac or Thumbs.db on Windows for deploy (#58)
1 parent a5e2487 commit 81c4f33

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/constants/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export const CONSOLE_URL = 'https://console.juno.build';
1414
export const CONSOLE_SATELLITE_URL = `${CONSOLE_URL}/satellite/?s=`;
1515
export const JUNO_CDN_URL = 'https://fmkjf-bqaaa-aaaal-acpza-cai.raw.icp0.io';
1616
export const GITHUB_API_CLI_URL = 'https://api.github.com/repos/junobuild/cli';
17+
export const IGNORE_OS_FILES = ['.ds_store', 'thumbs.db'];

src/utils/deploy.utils.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {minimatch} from 'minimatch';
22
import {lstatSync, readdirSync} from 'node:fs';
3-
import {join} from 'node:path';
3+
import {basename, join} from 'node:path';
4+
import {IGNORE_OS_FILES} from '../constants/constants';
45
import type {SatelliteConfig} from '../types/satellite.config';
56

67
export const listSourceFiles = ({
@@ -9,13 +10,24 @@ export const listSourceFiles = ({
910
}: {sourceAbsolutePath: string} & Required<Pick<SatelliteConfig, 'ignore'>>): string[] => {
1011
const sourceFiles = files(sourceAbsolutePath);
1112

12-
const filteredEmptyFiles = sourceFiles.filter((file) => lstatSync(file).size > 0);
13+
return sourceFiles.filter((file) => filterFile({file, ignore}));
14+
};
15+
16+
const filterFile = ({
17+
file,
18+
ignore
19+
}: {file: string} & Required<Pick<SatelliteConfig, 'ignore'>>): boolean => {
20+
// File must not be empty >= 0kb
21+
if (lstatSync(file).size <= 0) {
22+
return false;
23+
}
1324

14-
const filteredSourceFiles = filteredEmptyFiles.filter(
15-
(file) => ignore.find((pattern) => minimatch(file, pattern)) === undefined
16-
);
25+
// Ignore .DS_Store on Mac or Thumbs.db on Windows
26+
if (IGNORE_OS_FILES.includes(basename(file).toLowerCase())) {
27+
return false;
28+
}
1729

18-
return filteredSourceFiles;
30+
return ignore.find((pattern) => minimatch(file, pattern)) === undefined;
1931
};
2032

2133
const files = (source: string): string[] =>

0 commit comments

Comments
 (0)