@@ -5,7 +5,7 @@ import * as fs from "fs";
55import { join as pathJoin } from "path" ;
66import { assert } from "tsafe/assert" ;
77import { exclude } from "tsafe/exclude" ;
8- import { writeFile , readFile , rm } from "fs/promises" ;
8+ import { writeFile , readFile , rm , access } from "fs/promises" ;
99import { crawl } from "./tools/crawl" ;
1010import { basename as pathBasename , sep as pathSep , dirname as pathDirname } from "path" ;
1111import type { Equals } from "tsafe" ;
@@ -100,7 +100,29 @@ async function main() {
100100 const dsfrDistDirPath =
101101 getProjectRoot ( ) === cwd
102102 ? pathJoin ( cwd , "dist" , "dsfr" )
103- : pathJoin ( ...[ cwd , "node_modules" , ...packageName . split ( "/" ) , "dsfr" ] ) ;
103+ : await ( async function callee ( n : number ) : Promise < string > {
104+ if ( n >= cwd . split ( pathSep ) . length ) {
105+ throw new Error ( "Need to install node modules?" ) ;
106+ }
107+
108+ const dirPath = pathJoin (
109+ ...[
110+ cwd ,
111+ ...new Array ( n ) . fill ( ".." ) ,
112+ "node_modules" ,
113+ ...packageName . split ( "/" ) ,
114+ "dsfr"
115+ ]
116+ ) ;
117+
118+ try {
119+ await access ( dirPath ) ;
120+ } catch {
121+ return callee ( n + 1 ) ;
122+ }
123+
124+ return dirPath ;
125+ } ) ( 0 ) ;
104126
105127 const icons : Icon [ ] = JSON . parse (
106128 ( await readFile ( pathJoin ( dsfrDistDirPath , pathOfIconsJson ) ) ) . toString ( "utf8" )
0 commit comments