Skip to content

Commit f9726a4

Browse files
authored
refactor: update exports within index files to be ordered (#8)
* chore: re-sync * refactor: sort exports of index files --------- Co-authored-by: Richard Herman <[email protected]>
1 parent c36591f commit f9726a4

File tree

15 files changed

+1415
-1335
lines changed

15 files changed

+1415
-1335
lines changed

scripts/transformers/react.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { rm } from "node:fs/promises";
44

55
import { metadata } from "../metadata/metadata.ts";
66
import type { SvgIcon, Transformer } from "../transformer.ts";
7+
import type { ExportSpecifier } from "../utils.ts";
78
import * as utils from "../utils.ts";
89

910
const svgrConfig: Config = {
@@ -40,15 +41,20 @@ export class ReactTransformer implements Transformer {
4041
public readonly name = "React components";
4142

4243
/**
43-
* Contents of the components index file.
44+
* Components exported from the index file.
4445
*/
45-
#indexContents = "";
46+
#exports: ExportSpecifier[] = [];
4647

4748
/**
4849
* @inheritdoc
4950
*/
5051
public finalize(): Promise<void> {
51-
return utils.writeGeneratedFile("src/react/icons/index.ts", this.#indexContents);
52+
const contents = this.#exports
53+
.sort((a, b) => a.identifier.localeCompare(b.identifier))
54+
.map(({ identifier, filename }) => `export { default as ${identifier} } from "./${filename}.g.js";`)
55+
.join("\n");
56+
57+
return utils.writeGeneratedFile("src/react/icons/index.ts", contents);
5258
}
5359

5460
/**
@@ -87,7 +93,10 @@ export class ReactTransformer implements Transformer {
8793
this.#formatComponent(componentName, icon.name, elementOrSwitch),
8894
);
8995

90-
this.#indexContents += `export { default as ${componentName} } from "./${filename}.g.js";\n`;
96+
this.#exports.push({
97+
identifier: componentName,
98+
filename,
99+
});
91100
}
92101

93102
/**

scripts/transformers/strings.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ export class StringsTransformer implements Transformer {
2727
* @inheritdoc
2828
*/
2929
public async finalize(): Promise<void> {
30-
for (const [size, { names, indexContents }] of this.#catalogues) {
30+
for (const [size, { names, exports }] of this.#catalogues) {
3131
// Ignore empty catalogues.
3232
if (names.length === 0) {
3333
continue;
3434
}
3535

36-
await utils.writeGeneratedFile(`${this.#pathOf(size)}/index.ts`, indexContents);
36+
const contents = exports
37+
.sort((a, b) => a.identifier.localeCompare(b.identifier))
38+
.map(({ filename, identifier }) => `export { default as ${identifier} } from "${filename}";`)
39+
.join("\n");
40+
41+
await utils.writeGeneratedFile(`${this.#pathOf(size)}/index.ts`, contents);
3742
}
3843
}
3944

@@ -63,7 +68,10 @@ export class StringsTransformer implements Transformer {
6368

6469
const catalogue = this.#catalogues.get(size)!;
6570
catalogue.names.push(icon.name);
66-
catalogue.indexContents += `export { default as ${metadata.getSvgStringMetadata(icon.name as keyof typeof metadata.icons).exportName} } from "./icons/${icon.name}.g.js";\n`;
71+
catalogue.exports.push({
72+
identifier: metadata.getSvgStringMetadata(icon.name as keyof typeof metadata.icons).exportName,
73+
filename: `./icons/${icon.name}.g.js`,
74+
});
6775
}
6876
}
6977

@@ -87,7 +95,7 @@ class Catalogue {
8795
public readonly names: string[] = [];
8896

8997
/**
90-
* String that represents the index (barrel file) of the catalogue.
98+
* Icons exported from the index file.
9199
*/
92-
public indexContents: string = "";
100+
public exports: utils.ExportSpecifier[] = [];
93101
}

scripts/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,18 @@ export function writeGeneratedFile(path: string, data: string): Promise<void> {
3838

3939
return writeFile(path, data);
4040
}
41+
42+
/**
43+
* Information for an export, for example `export { default as IconElgato } from "./logo-elgato.js"`;
44+
*/
45+
export type ExportSpecifier = {
46+
/**
47+
* The identifier of the export.
48+
*/
49+
identifier: string;
50+
51+
/**
52+
* Filename of the export.
53+
*/
54+
filename: string;
55+
};

src/metadata/icons.g.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Last synchronized: Mon, 24 Feb 2025 15:37:44 GMT
1+
// Last synchronized: Thu, 27 Feb 2025 12:11:56 GMT
22

33
/**
44
* Collection of available icons, and their associated metadata.
@@ -364,8 +364,8 @@ export const icons = {
364364
"image-check--filled": { name: "ImageCheckFilled", sizes: ["l"] },
365365
inbox: { name: "Inbox", sizes: ["l"] },
366366
"inbox--filled": { name: "InboxFilled", sizes: ["l"] },
367-
info: { name: "Info", sizes: ["m", "l"] },
368-
"info--filled": { name: "InfoFilled", sizes: ["m", "l"] },
367+
info: { name: "Info", sizes: ["s", "m", "l"] },
368+
"info--filled": { name: "InfoFilled", sizes: ["s", "m", "l"] },
369369
infobar: { name: "Infobar", sizes: ["l"] },
370370
"infobar--filled": { name: "InfobarFilled", sizes: ["l"] },
371371
"iron-low": { name: "IronLow", sizes: ["m"] },

src/metadata/providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export type ReactMetadata = {
6060
componentName: string;
6161

6262
/**
63-
* Filename of the component.
63+
* Filename of the component, with the extension omitted.
6464
*/
6565
filename: string;
6666
};

src/react/icons/Info.g.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ const IconInfo = (props: IconProps & SVGProps<SVGSVGElement>) => {
2727
/>
2828
</svg>
2929
);
30+
case "s":
31+
return (
32+
<svg
33+
xmlns="http://www.w3.org/2000/svg"
34+
fill="currentColor"
35+
viewBox="0 0 16 16"
36+
width={size}
37+
height={size}
38+
aria-label={label}
39+
role="img"
40+
{...props}
41+
>
42+
<path
43+
fillRule="evenodd"
44+
d="M8 14A6 6 0 1 0 8 2a6 6 0 0 0 0 12m0 1A7 7 0 1 0 8 1a7 7 0 0 0 0 14m0-8.5a.5.5 0 0 1 .5.5v4.502a.5.5 0 0 1-1 0V7a.5.5 0 0 1 .5-.5m0-1A.75.75 0 1 0 8 4a.75.75 0 0 0 0 1.5"
45+
clipRule="evenodd"
46+
/>
47+
</svg>
48+
);
3049
default:
3150
return (
3251
<svg

src/react/icons/InfoFilled.g.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ const IconInfoFilled = (props: IconProps & SVGProps<SVGSVGElement>) => {
2626
/>
2727
</svg>
2828
);
29+
case "s":
30+
return (
31+
<svg
32+
xmlns="http://www.w3.org/2000/svg"
33+
fill="currentColor"
34+
viewBox="0 0 16 16"
35+
width={size}
36+
height={size}
37+
aria-label={label}
38+
role="img"
39+
{...props}
40+
>
41+
<path
42+
fillRule="evenodd"
43+
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m.75-10.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0M8 6.5a.5.5 0 0 1 .5.5v4.502a.5.5 0 0 1-1 0V7a.5.5 0 0 1 .5-.5"
44+
clipRule="evenodd"
45+
/>
46+
</svg>
47+
);
2948
default:
3049
return (
3150
<svg

0 commit comments

Comments
 (0)