|
1 | 1 | #!/usr/bin/env node |
2 | 2 | /* eslint-disable @typescript-eslint/no-unused-vars */ |
3 | 3 |
|
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"; |
5 | 10 | import * as fs from "fs"; |
6 | 11 | import { getProjectRoot } from "./tools/getProjectRoot"; |
7 | 12 | import { assert } from "tsafe/assert"; |
@@ -130,13 +135,35 @@ import type { Equals } from "tsafe"; |
130 | 135 | fs.rmSync(dsfrDirPath, { "recursive": true, "force": true }); |
131 | 136 | } |
132 | 137 |
|
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; |
138 | 161 | } |
139 | | - ); |
| 162 | + |
| 163 | + fs.cpSync(dsfrDirPathInNodeModules, dsfrDirPath, { |
| 164 | + "recursive": true |
| 165 | + }); |
| 166 | + })(0); |
140 | 167 | })(); |
141 | 168 |
|
142 | 169 | function getRepoIssueUrl() { |
|
0 commit comments