@@ -7,7 +7,7 @@ import { assert } from "tsafe/assert";
77import { exclude } from "tsafe/exclude" ;
88import { writeFile , readFile , rm } from "fs/promises" ;
99import { crawl } from "./tools/crawl" ;
10- import { basename as pathBasename , sep as pathSep } from "path" ;
10+ import { basename as pathBasename , sep as pathSep , dirname as pathDirname } from "path" ;
1111import type { Equals } from "tsafe" ;
1212
1313export const pathOfIconsJson = pathJoin ( "utility" , "icons" , "icons.json" ) ;
@@ -97,9 +97,10 @@ async function main() {
9797
9898 const cwd = process . cwd ( ) ;
9999
100- const nodeModulesDirPath = pathJoin ( cwd , "node_modules" ) ;
101-
102- const dsfrDistDirPath = pathJoin ( ...[ nodeModulesDirPath , ...packageName . split ( "/" ) , "dsfr" ] ) ;
100+ const dsfrDistDirPath =
101+ getProjectRoot ( ) === cwd
102+ ? pathJoin ( cwd , "dist" , "dsfr" )
103+ : pathJoin ( ...[ cwd , "node_modules" , ...packageName . split ( "/" ) , "dsfr" ] ) ;
103104
104105 const icons : Icon [ ] = JSON . parse (
105106 ( await readFile ( pathJoin ( dsfrDistDirPath , pathOfIconsJson ) ) ) . toString ( "utf8" )
@@ -158,6 +159,12 @@ async function main() {
158159 return false ;
159160 }
160161
162+ if (
163+ pathDirname ( relativeDirPath ) . endsWith ( pathJoin ( ...packageName . split ( "/" ) ) )
164+ ) {
165+ return pathBasename ( relativeDirPath ) === "src" ;
166+ }
167+
161168 if ( pathBasename ( relativeDirPath ) === "node_modules" ) {
162169 return false ;
163170 }
@@ -230,6 +237,8 @@ async function main() {
230237 return { usedIconClassNames } ;
231238 } ) ( ) ;
232239
240+ console . log ( "Detected usage of the following icons: " , usedIconClassNames ) ;
241+
233242 const usedIcons = usedIconClassNames . map ( className => {
234243 const icon = icons . find ( ( { prefix, iconId } ) => `${ prefix } ${ iconId } ` === className ) ;
235244
@@ -263,14 +272,15 @@ async function main() {
263272 rm ( nextCacheDir , { "recursive" : true , "force" : true } ) ;
264273 } ;
265274
266- [
267- dsfrDistDirPath ,
268- ...( ( ) => {
269- const dsfrDistInPublic = pathJoin ( cwd , "public" , "dsfr" ) ;
275+ [ dsfrDistDirPath , pathJoin ( cwd , "public" , "dsfr" ) ] . forEach ( async dsfrDistDirPath => {
276+ const cssFilePaths = [ "icons.css" , "icons.min.css" ] . map ( cssFileBasename =>
277+ pathJoin ( dsfrDistDirPath , "utility" , "icons" , cssFileBasename )
278+ ) ;
279+
280+ if ( cssFilePaths . some ( cssFilePath => ! fs . existsSync ( cssFilePath ) ) ) {
281+ return ;
282+ }
270283
271- return fs . existsSync ( dsfrDistInPublic ) ? [ dsfrDistInPublic ] : [ ] ;
272- } ) ( )
273- ] . forEach ( async dsfrDistDirPath => {
274284 const remixiconDirPath = pathJoin ( dsfrDistDirPath , "icons" , "remixicon" ) ;
275285
276286 if ( ! fs . existsSync ( remixiconDirPath ) ) {
@@ -287,9 +297,7 @@ async function main() {
287297 )
288298 ) ;
289299
290- [ "icons.css" , "icons.min.css" ] . forEach ( async cssFileBasename => {
291- const filePath = pathJoin ( dsfrDistDirPath , "utility" , "icons" , cssFileBasename ) ;
292-
300+ cssFilePaths . forEach ( async filePath => {
293301 const currentCode = await readFile ( filePath ) ;
294302
295303 if ( Buffer . compare ( rawIconCssCodeBuffer , currentCode ) === 0 ) {
0 commit comments