Skip to content

Commit

Permalink
feat: skip empty files per default on deploy (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker authored Nov 10, 2023
1 parent 569db4d commit a2412db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
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);
});

0 comments on commit a2412db

Please sign in to comment.