Skip to content

Commit

Permalink
Better reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Oct 12, 2023
1 parent 05be5c1 commit 4025d0b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
10 changes: 8 additions & 2 deletions node-src/lib/uploadMetadataFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CHROMATIC_LOG_FILE } from './log';
import { uploadAsIndividualFiles } from './upload';
import { CHROMATIC_DIAGNOSTICS_FILE } from './writeChromaticDiagnostics';
import uploadingMetadata from '../ui/messages/info/uploadingMetadata';
import { baseStorybookUrl } from './utils';

const fileSize = (path: string): Promise<number> =>
new Promise((resolve) => stat(path, (err, stats) => resolve(err ? 0 : stats.size)));
Expand All @@ -35,7 +36,11 @@ export async function uploadMetadataFiles(ctx: Context) {
const contentLength = await fileSize(localPath);
return contentLength && { localPath, targetPath, contentLength };
})
).then((files) => files.filter(Boolean));
).then((files) =>
files
.filter(Boolean)
.sort((a, b) => a.targetPath.localeCompare(b.targetPath, 'en', { numeric: true }))
);

if (!files.length) {
ctx.log.warn('No metadata files found, skipping metadata upload.');
Expand All @@ -51,7 +56,8 @@ export async function uploadMetadataFiles(ctx: Context) {
contentLength: html.length,
});

ctx.log.info(uploadingMetadata(files));
const directoryUrl = `${baseStorybookUrl(ctx.isolatorUrl)}/.chromatic/`;
ctx.log.info(uploadingMetadata(directoryUrl, files));

await uploadAsIndividualFiles(ctx, files);
});
Expand Down
39 changes: 36 additions & 3 deletions node-src/ui/content/metadata.html.stories.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
import { files } from '../messages/info/uploadingMetadata.stories';
import metadataHtml from './metadata.html';

export default {
title: 'HTML/Metadata index',
includeStories: /^[A-Z]/,
};

const announced: any = { announcedBuild: { number: 7801 } };
export const files = [
{
contentLength: 833,
localPath: 'build-storybook.log',
targetPath: '.chromatic/build-storybook.log',
},
{
contentLength: 674,
localPath: 'chromatic.log',
targetPath: '.chromatic/chromatic.log',
},
{
contentLength: 3645,
localPath: 'chromatic-diagnostics.json',
targetPath: '.chromatic/chromatic-diagnostics.json',
},
{
contentLength: 423,
localPath: 'main.ts',
targetPath: '.chromatic/main.ts',
},
{
contentLength: 5635,
localPath: 'preview.tsx',
targetPath: '.chromatic/preview.tsx',
},
{
contentLength: 5635,
localPath: 'preview-stats.json',
targetPath: '.chromatic/preview-stats.json',
},
];

const announced: any = { announcedBuild: { number: 7805 } };

const build: any = {
...announced,
build: { webUrl: 'https://www.chromatic.com/build?appId=5d67dc0374b2e300209c41e7&number=7801' },
build: { webUrl: 'https://www.chromatic.com/build?appId=5d67dc0374b2e300209c41e7&number=7805' },
};

export const Default = () => metadataHtml(announced, files);
Expand Down
1 change: 0 additions & 1 deletion node-src/ui/content/metadata.html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export default ({ announcedBuild, build }: Context, files: FileDesc[]) => `<!DOC
<span>Metadata files</span>
<ul>
${files
.sort((a, b) => a.targetPath.localeCompare(b.targetPath, 'en', { numeric: true }))
.map(({ targetPath, contentLength }) => {
const path = targetPath.replace(/^\.chromatic\//, '');
const size = filesize(contentLength);
Expand Down
10 changes: 10 additions & 0 deletions node-src/ui/messages/info/uploadingMetadata.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { files } from '../../content/metadata.html.stories';
import uploadingMetadata from './uploadingMetadata';

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

const directoryUrl = 'https://5d67dc0374b2e300209c41e7-dlmmxasauj.chromatic.com/.chromatic/';

export const UploadingMetadata = () => uploadingMetadata(directoryUrl, files);
12 changes: 12 additions & 0 deletions node-src/ui/messages/info/uploadingMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import chalk from 'chalk';
import pluralize from 'pluralize';

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

export default (directoryUrl: string, files: FileDesc[]) => {
const count = pluralize('metadata file', files.length, true);
const list = `- ${files.map((f) => f.targetPath.replace(/^\.chromatic\//, '')).join('\n- ')}`;
return chalk`${info} Uploading {bold ${count}} to ${link(directoryUrl)}\n${list}`;
};

0 comments on commit 4025d0b

Please sign in to comment.