Skip to content

Commit

Permalink
Skip empty files when uploading individual files
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jan 15, 2024
1 parent a373f1f commit a36bcdb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
9 changes: 8 additions & 1 deletion node-src/lib/uploadFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createReadStream } from 'fs';
import pLimit from 'p-limit';
import progress from 'progress-stream';
import { Context, FileDesc, TargetInfo } from '../types';
import skippingEmptyFiles from '../ui/messages/warnings/skippingEmptyFiles';

export async function uploadFiles(
ctx: Context,
Expand All @@ -15,8 +16,14 @@ export async function uploadFiles(
const limitConcurrency = pLimit(10);
let totalProgress = 0;

const nonEmptyTargets = targets.filter(({ contentLength }) => contentLength > 0);
if (nonEmptyTargets.length !== targets.length) {
const emptyFiles = targets.filter(({ contentLength }) => contentLength === 0);
ctx.log.warn(skippingEmptyFiles({ emptyFiles }));
}

await Promise.all(
targets.map(({ contentLength, filePath, formAction, formFields, localPath }) => {
nonEmptyTargets.map(({ contentLength, filePath, formAction, formFields, localPath }) => {
let fileProgress = 0; // The bytes uploaded for this this particular file

ctx.log.debug(`Uploading ${filePath} (${filesize(contentLength)})`);
Expand Down
14 changes: 14 additions & 0 deletions node-src/ui/messages/warnings/skippingEmptyFiles.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import skippingEmptyFiles from './skippingEmptyFiles';

export default {
title: 'CLI/Messages/Warnings',
};

export const SkippingEmptyFiles = () =>
skippingEmptyFiles({
emptyFiles: Array.from({ length: 3 }, (_, i) => ({
contentLength: 0,
localPath: `file${i}.js`,
targetPath: `file${i}.js`,
})),
});
17 changes: 17 additions & 0 deletions node-src/ui/messages/warnings/skippingEmptyFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import chalk from 'chalk';
import pluralize from 'pluralize';
import { dedent } from 'ts-dedent';

import { warning } from '../../components/icons';
import { FileDesc } from '../../../types';

export default ({ emptyFiles }: { emptyFiles: FileDesc[] }) => {
const listing = chalk`\n{dim →} ${emptyFiles.map((f) => f.targetPath).join(chalk`\n{dim →} `)}`;
return dedent(chalk`
${warning} {bold Not uploading empty files}
Found ${pluralize('empty files', emptyFiles.length, true)} in your built Storybook:${listing}
Uploading empty files is not supported except when using a zip file.
You can ignore this warning if your Storybook doesn't need these files.
Otherwise, configure Chromatic with the {bold zip} option.
`);
};

0 comments on commit a36bcdb

Please sign in to comment.