chore: fix size update github action date format

PiperOrigin-RevId: 601557983
This commit is contained in:
Elizabeth Mitchell 2024-01-25 13:58:40 -08:00 committed by Copybara-Service
parent e056d1dd2f
commit c9e72ce194

View File

@ -6,9 +6,9 @@
import * as fs from 'fs/promises';
import { MarkdownTable } from '../analyzer/markdown-tree-builder.js';
import { COMPONENT_CUSTOM_ELEMENTS } from '../component-custom-elements.js';
import { Bundle, Size, getBundleSize } from './bundle-size.js';
import {MarkdownTable} from '../analyzer/markdown-tree-builder.js';
import {COMPONENT_CUSTOM_ELEMENTS} from '../component-custom-elements.js';
import {Bundle, Size, getBundleSize} from './bundle-size.js';
// The bundles to track sizes for.
@ -28,7 +28,7 @@ const bundles: Bundle[] = [
).map((component) => {
const tsCustomElementPaths = COMPONENT_CUSTOM_ELEMENTS[component];
const jsCustomElementPaths = tsCustomElementPaths.map((tsPath) =>
tsPath.replace(/\.ts$/, '.js')
tsPath.replace(/\.ts$/, '.js'),
);
return {
@ -41,14 +41,14 @@ const bundles: Bundle[] = [
// Compute bundle sizes.
const bundleSizes = await Promise.all(
bundles.map((bundle) => getBundleSize(bundle))
bundles.map((bundle) => getBundleSize(bundle)),
);
// Create a markdown table with size data.
const columns = ['Component', 'gzip', 'minified', '*% CSS*', 'Import'];
const rows: string[][] = [];
for (const { name, size, inputs } of bundleSizes) {
for (const {name, size, inputs} of bundleSizes) {
rows.push([
`**${camelToSentenceCase(name)}**`,
`**${bytesToString(size.gzip)}**`,
@ -67,7 +67,7 @@ for (const { name, size, inputs } of bundleSizes) {
getCssPercent(input.size),
getImport(input.input),
];
})
}),
);
}
}
@ -79,12 +79,12 @@ for (const row of rows) {
// Update markdown file.
const markdownContent = await fs.readFile('docs/size.md', { encoding: 'utf8' });
const markdownContent = await fs.readFile('docs/size.md', {encoding: 'utf8'});
const updateTrackingStart = '<!-- MWC_UPDATE_TRACKING_START -->';
const updateTrackingEnd = '<!-- MWC_UPDATE_TRACKING_END -->';
const now = new Date();
const nowString = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
const nowString = now.toISOString().split('T')[0];
const newMarkdownContent = [
markdownContent.substring(0, markdownContent.indexOf(updateTrackingStart)),