Skip to content

Commit b491848

Browse files
committed
1 parent e73ef4b commit b491848

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

src/bin/copy-dsfr-to-public.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/usr/bin/env node
22
/* eslint-disable @typescript-eslint/no-unused-vars */
33

4-
import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
4+
import {
5+
join as pathJoin,
6+
relative as pathRelative,
7+
sep as pathSep,
8+
resolve as pathResolve
9+
} from "path";
510
import * as fs from "fs";
611
import { getProjectRoot } from "./tools/getProjectRoot";
712
import { assert } from "tsafe/assert";
@@ -130,13 +135,35 @@ import type { Equals } from "tsafe";
130135
fs.rmSync(dsfrDirPath, { "recursive": true, "force": true });
131136
}
132137

133-
fs.cpSync(
134-
pathJoin(projectDirPath, "node_modules", "@codegouvfr", "react-dsfr", "dsfr"),
135-
dsfrDirPath,
136-
{
137-
"recursive": true
138+
(function callee(depth: number) {
139+
const parentProjectDirPath = pathResolve(
140+
pathJoin(...[projectDirPath, ...new Array(depth).fill("..")])
141+
);
142+
143+
const dsfrDirPathInNodeModules = pathJoin(
144+
...[parentProjectDirPath, "node_modules", "@codegouvfr", "react-dsfr", "dsfr"]
145+
);
146+
147+
if (!fs.existsSync(dsfrDirPathInNodeModules)) {
148+
if (parentProjectDirPath === "/") {
149+
console.error(
150+
[
151+
"Can't find dsfr directory",
152+
`please submit an issue about it here ${getRepoIssueUrl()}`
153+
].join(" ")
154+
);
155+
process.exit(-1);
156+
}
157+
158+
callee(depth + 1);
159+
160+
return;
138161
}
139-
);
162+
163+
fs.cpSync(dsfrDirPathInNodeModules, dsfrDirPath, {
164+
"recursive": true
165+
});
166+
})(0);
140167
})();
141168

142169
function getRepoIssueUrl() {

0 commit comments

Comments
 (0)