Skip to content

Commit dc31fd9

Browse files
committed
test
1 parent 58506bf commit dc31fd9

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

scripts/picto-builder.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export default createIcon(
9696

9797
async function generateIndex(outputDir: string): Promise<string> {
9898
const files = await glob(`${outputDir}/*.tsx`);
99+
const filePath = path.join(outputDir, "index.ts");
99100

100101
const exports = files
101102
.map(f => {
@@ -104,21 +105,22 @@ async function generateIndex(outputDir: string): Promise<string> {
104105
})
105106
.join("\n");
106107

107-
await fs.writeFile(path.join(outputDir, "index.ts"), exports);
108-
return path.join(outputDir, "index.ts");
108+
await fs.writeFile(filePath, exports);
109+
return filePath;
109110
}
110111

111112
async function generateTypes(outputDir: string): Promise<string> {
112113
const files = await glob(`${outputDir}/*.tsx`);
113114
const iconNames = files.map(f => pascalCaseName(path.basename(f, ".tsx")));
115+
const filePath = path.join(outputDir, "index.d.ts");
114116

115117
const header = `import { IconWrapper } from './utils/IconWrapper';\n\ntype SvgIconComponent = typeof IconWrapper;\n\n`;
116118
const lines = iconNames.map(name => `export const ${name}: SvgIconComponent;`);
117119

118120
const content = `${header}${lines.join("\n")}\n`;
119121

120-
await fs.writeFile(path.join(outputDir, "index.d.ts"), content, "utf8");
121-
return path.join(outputDir, "index.d.ts");
122+
await fs.writeFile(filePath, content, "utf8");
123+
return filePath;
122124
}
123125

124126
export async function build(srcDir: string, outDir: string): Promise<string[]> {

test/integration/cra/src/Picto.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { fr } from "@codegouvfr/react-dsfr";
2+
3+
import * as Pictogrammes from '@codegouvfr/react-dsfr/picto';
4+
5+
export function Picto() {
6+
return (
7+
<div className={fr.cx("fr-my-4w")}>
8+
{
9+
Object.entries(Pictogrammes).map(([name, Component]) => (
10+
<Component
11+
key={name}
12+
fontSize="10em"
13+
/>
14+
))
15+
}
16+
</div>
17+
)
18+
}

test/integration/cra/src/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRoot } from "react-dom/client";
33
import { startReactDsfr } from "@codegouvfr/react-dsfr/spa";
44
import { Home } from "./Home";
55
import { Mui } from "./Mui";
6+
import { Picto } from "./Picto";
67
import { useRoute, RouteProvider } from "./router";
78
import { Header } from "@codegouvfr/react-dsfr/Header";
89
import { fr } from "@codegouvfr/react-dsfr";
@@ -57,6 +58,11 @@ function Root() {
5758
"text": "Mui playground",
5859
"linkProps": routes.mui().link,
5960
"isActive": route.name === "mui"
61+
},
62+
{
63+
"text": "Picto playground",
64+
"linkProps": routes.picto().link,
65+
"isActive": location.pathname === "picto"
6066
}
6167
]}
6268
/>
@@ -70,6 +76,7 @@ function Root() {
7076
switch (route.name) {
7177
case "mui": return <Mui />;
7278
case "home": return <Home />;
79+
case "picto": return <Picto />;
7380
case false: return <h1>404</h1>
7481
}
7582
})()}

test/integration/cra/src/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRouter, defineRoute } from "type-route";
33
const routeDefs = {
44
"home": defineRoute("/"),
55
"mui": defineRoute("/mui"),
6+
"picto": defineRoute("/picto"),
67
};
78

89
export const { RouteProvider, useRoute, routes } = createRouter(routeDefs);

0 commit comments

Comments
 (0)