Skip to content

Commit 4868875

Browse files
committed
Fix the dependency on css for good this time (hopefully)
1 parent 84a271b commit 4868875

File tree

6 files changed

+76
-87
lines changed

6 files changed

+76
-87
lines changed

src/bin/css_to_ts/css_to_ts.ts

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@ import { getProjectRoot } from "../tools/getProjectRoot";
55
import { generateTypographyTsCode } from "./typography";
66
import { generateSpacingTsCode } from "./spacing";
77
import { generateClassNamesTsCode } from "./classNames";
8+
import { collectIcons } from "./icons";
89
import * as fs from "fs";
9-
import { readFile } from "fs/promises";
10-
import {
11-
join as pathJoin,
12-
basename as pathBasename,
13-
relative as pathRelative,
14-
dirname as pathDirname
15-
} from "path";
16-
import { crawl } from "../tools/crawl";
17-
import { id } from "tsafe/id";
10+
import { join as pathJoin, basename as pathBasename, relative as pathRelative } from "path";
1811

19-
export async function main() {
12+
(async () => {
2013
const projectRoot = getProjectRoot();
2114

2215
const dsfrDistDirPath = pathJoin(projectRoot, "dsfr");
@@ -124,71 +117,4 @@ export async function main() {
124117
"utf8"
125118
)
126119
);
127-
}
128-
129-
export type Icon = Icon.Dsfr | Icon.Remixicon;
130-
131-
export namespace Icon {
132-
export type Common = {
133-
iconId: string;
134-
};
135-
136-
export type Dsfr = Common & {
137-
prefix: "fr-icon-";
138-
category: string;
139-
};
140-
141-
export type Remixicon = Common & {
142-
prefix: "ri-";
143-
rawSvgCode: string;
144-
};
145-
}
146-
147-
export async function collectIcons(params: {
148-
dsfrDistDirPath: string;
149-
remixiconDirPath: string;
150-
}): Promise<Icon[]> {
151-
const { dsfrDistDirPath, remixiconDirPath } = params;
152-
153-
return (
154-
await Promise.all([
155-
(async () => {
156-
const iconDirPath = pathJoin(remixiconDirPath, "icons");
157-
158-
return Promise.all(
159-
(await crawl({ "dirPath": iconDirPath }))
160-
.filter(filePath => filePath.endsWith(".svg"))
161-
.map(async svgFilePath =>
162-
id<Icon.Remixicon>({
163-
"prefix": "ri-",
164-
"iconId": pathBasename(svgFilePath).replace(/\.svg$/, ""),
165-
"rawSvgCode": (
166-
await readFile(pathJoin(iconDirPath, svgFilePath))
167-
).toString("utf8")
168-
})
169-
)
170-
);
171-
})(),
172-
(async () =>
173-
(
174-
await crawl({
175-
"dirPath": pathJoin(dsfrDistDirPath, "icons"),
176-
"getDoCrawlInDir": ({ relativeDirPath }) =>
177-
pathBasename(relativeDirPath) !== "remixicon"
178-
})
179-
)
180-
.filter(filePath => filePath.endsWith(".svg"))
181-
.map(svgFilePath =>
182-
id<Icon.Dsfr>({
183-
"prefix": "fr-icon-",
184-
"category": pathBasename(pathDirname(svgFilePath)),
185-
"iconId": pathBasename(svgFilePath).replace(/\.svg$/, "")
186-
})
187-
))()
188-
])
189-
).flat();
190-
}
191-
192-
if (require.main === module) {
193-
main();
194-
}
120+
})();
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { readFile } from "fs/promises";
2+
import { join as pathJoin, basename as pathBasename, dirname as pathDirname } from "path";
3+
import { id } from "tsafe/id";
4+
import { crawl } from "../../tools/crawl";
5+
6+
export type Icon = Icon.Dsfr | Icon.Remixicon;
7+
8+
export namespace Icon {
9+
export type Common = {
10+
iconId: string;
11+
};
12+
13+
export type Dsfr = Common & {
14+
prefix: "fr-icon-";
15+
category: string;
16+
};
17+
18+
export type Remixicon = Common & {
19+
prefix: "ri-";
20+
rawSvgCode: string;
21+
};
22+
}
23+
24+
export async function collectIcons(params: {
25+
dsfrDistDirPath: string;
26+
remixiconDirPath: string;
27+
}): Promise<Icon[]> {
28+
const { dsfrDistDirPath, remixiconDirPath } = params;
29+
30+
return (
31+
await Promise.all([
32+
(async () => {
33+
const iconDirPath = pathJoin(remixiconDirPath, "icons");
34+
35+
return Promise.all(
36+
(await crawl({ "dirPath": iconDirPath }))
37+
.filter(filePath => filePath.endsWith(".svg"))
38+
.map(async svgFilePath =>
39+
id<Icon.Remixicon>({
40+
"prefix": "ri-",
41+
"iconId": pathBasename(svgFilePath).replace(/\.svg$/, ""),
42+
"rawSvgCode": (
43+
await readFile(pathJoin(iconDirPath, svgFilePath))
44+
).toString("utf8")
45+
})
46+
)
47+
);
48+
})(),
49+
(async () =>
50+
(
51+
await crawl({
52+
"dirPath": pathJoin(dsfrDistDirPath, "icons"),
53+
"getDoCrawlInDir": ({ relativeDirPath }) =>
54+
pathBasename(relativeDirPath) !== "remixicon"
55+
})
56+
)
57+
.filter(filePath => filePath.endsWith(".svg"))
58+
.map(svgFilePath =>
59+
id<Icon.Dsfr>({
60+
"prefix": "fr-icon-",
61+
"category": pathBasename(pathDirname(svgFilePath)),
62+
"iconId": pathBasename(svgFilePath).replace(/\.svg$/, "")
63+
})
64+
))()
65+
])
66+
).flat();
67+
}

src/bin/css_to_ts/icons/generateIconsRawCssCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Icon } from "../css_to_ts";
1+
import type { Icon } from "../icons";
22

33
type IconLike = Icon.Dsfr | Omit<Icon.Remixicon, "rawSvgCode">;
44

src/bin/css_to_ts/icons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./generateIconsRawCssCode";
22
export * from "./getPatchedRawCssCodeForCompatWithRemixIcon";
3+
export * from "./collectIcons";

src/bin/css_to_ts/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
export * from "./css_to_ts";
2-
import { main } from "./css_to_ts";
3-
4-
if (require.main === module) {
5-
main();
6-
}
1+
import "./css_to_ts";

src/bin/only_include_used_icons.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
2-
import { collectIcons } from "./css_to_ts";
2+
import { collectIcons } from "./css_to_ts/icons/collectIcons";
3+
import type { Icon } from "./css_to_ts/icons/collectIcons";
34
import { generateIconsRawCssCode } from "./css_to_ts/icons/generateIconsRawCssCode";
45
import { pathOfPatchedRawCssCodeForCompatWithRemixIconRelativeToDsfrDist } from "./css_to_ts/icons/getPatchedRawCssCodeForCompatWithRemixIcon/pathOfPatchedRawCssCodeForCompatWithRemixIconRelativeToDsfrDist";
56
import { getProjectRoot } from "./tools/getProjectRoot";
@@ -10,7 +11,6 @@ import { exclude } from "tsafe/exclude";
1011
import { writeFile, readFile } from "fs/promises";
1112
import { crawl } from "./tools/crawl";
1213
import { basename as pathBasename } from "path";
13-
import type { Icon } from "./css_to_ts";
1414
import type { Equals } from "tsafe";
1515

1616
(async () => {

0 commit comments

Comments
 (0)