Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ignore .DS_Store on Mac or Thumbs.db on Windows for deploy #58

Merged
merged 1 commit into from
Nov 10, 2023
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/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export const CONSOLE_URL = 'https://console.juno.build';
export const CONSOLE_SATELLITE_URL = `${CONSOLE_URL}/satellite/?s=`;
export const JUNO_CDN_URL = 'https://fmkjf-bqaaa-aaaal-acpza-cai.raw.icp0.io';
export const GITHUB_API_CLI_URL = 'https://api.github.com/repos/junobuild/cli';
export const IGNORE_OS_FILES = ['.ds_store', 'thumbs.db'];
24 changes: 18 additions & 6 deletions src/utils/deploy.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {minimatch} from 'minimatch';
import {lstatSync, readdirSync} from 'node:fs';
import {join} from 'node:path';
import {basename, join} from 'node:path';
import {IGNORE_OS_FILES} from '../constants/constants';
import type {SatelliteConfig} from '../types/satellite.config';

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

const filteredEmptyFiles = sourceFiles.filter((file) => lstatSync(file).size > 0);
return sourceFiles.filter((file) => filterFile({file, ignore}));
};

const filterFile = ({
file,
ignore
}: {file: string} & Required<Pick<SatelliteConfig, 'ignore'>>): boolean => {
// File must not be empty >= 0kb
if (lstatSync(file).size <= 0) {
return false;
}

const filteredSourceFiles = filteredEmptyFiles.filter(
(file) => ignore.find((pattern) => minimatch(file, pattern)) === undefined
);
// Ignore .DS_Store on Mac or Thumbs.db on Windows
if (IGNORE_OS_FILES.includes(basename(file).toLowerCase())) {
return false;
}

return filteredSourceFiles;
return ignore.find((pattern) => minimatch(file, pattern)) === undefined;
};

const files = (source: string): string[] =>
Expand Down