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: skip empty files per default on deploy #56

Merged
merged 3 commits 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
16 changes: 3 additions & 13 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import {type FileExtension} from 'file-type/core';
import {green, grey, red} from 'kleur';
import mime from 'mime-types';
import {minimatch} from 'minimatch';
import {lstatSync, readdirSync} from 'node:fs';
import {lstatSync} from 'node:fs';
import {readFile} from 'node:fs/promises';
import {basename, extname, join} from 'node:path';
import ora from 'ora';
import {junoConfigExist, readSatelliteConfig} from '../configs/satellite.config';
import {COLLECTION_DAPP, DAPP_COLLECTION, SOURCE, UPLOAD_BATCH_SIZE} from '../constants/constants';
import {type SatelliteConfig} from '../types/satellite.config';
import {listSourceFiles} from '../utils/deploy.utils';
import {satelliteParameters} from '../utils/satellite.utils';
import {init} from './init';

Expand Down Expand Up @@ -114,13 +115,6 @@ const assertSourceDirExists = (source: string) => {
}
};

const files = (source: string): string[] => {
return readdirSync(source).flatMap((file) => {
const path = join(source, file);
return lstatSync(path).isDirectory() ? files(path) : join(path);
});
};

const filterFilesToUpload = async ({
files,
sourceAbsolutePath,
Expand Down Expand Up @@ -190,11 +184,7 @@ const listFiles = async ({
> => {
assertSourceDirExists(sourceAbsolutePath);

const sourceFiles = files(sourceAbsolutePath);

const filteredSourceFiles = sourceFiles.filter(
(file) => ignore.find((pattern) => minimatch(file, pattern)) === undefined
);
const filteredSourceFiles = listSourceFiles({sourceAbsolutePath, ignore});

// TODO: brotli and zlib naive
const mapEncodingType = ({
Expand Down
25 changes: 25 additions & 0 deletions src/utils/deploy.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {minimatch} from 'minimatch';
import {lstatSync, readdirSync} from 'node:fs';
import {join} from 'node:path';
import type {SatelliteConfig} from '../types/satellite.config';

export const listSourceFiles = ({
sourceAbsolutePath,
ignore
}: {sourceAbsolutePath: string} & Required<Pick<SatelliteConfig, 'ignore'>>): string[] => {
const sourceFiles = files(sourceAbsolutePath);

const filteredEmptyFiles = sourceFiles.filter((file) => lstatSync(file).size > 0);

const filteredSourceFiles = filteredEmptyFiles.filter(
(file) => ignore.find((pattern) => minimatch(file, pattern)) === undefined
);

return filteredSourceFiles;
};

const files = (source: string): string[] =>
readdirSync(source).flatMap((file) => {
const path = join(source, file);
return lstatSync(path).isDirectory() ? files(path) : join(path);
});
Loading