@@ -95,8 +95,9 @@ function findBuildingBlockLogo(buildingBlockDir) {
9595
9696 files . forEach ( ( file ) => {
9797 if ( file . endsWith ( ".png" ) || file . endsWith ( ".svg" ) ) {
98+ const { id, platform } = getIdAndPlatform ( buildingBlockDir ) ;
9899 const sourcePath = path . join ( buildingBlockDir , file ) ;
99- const destinationPath = path . join ( assetsDir , path . basename ( file ) ) ;
100+ const destinationPath = path . join ( assetsDir , ` ${ id } ${ path . extname ( file ) } ` ) ;
100101
101102 fs . mkdirSync ( assetsDir , { recursive : true } ) ;
102103 fs . copyFileSync ( sourcePath , destinationPath ) ;
@@ -112,12 +113,10 @@ function findBuildingBlockLogo(buildingBlockDir) {
112113 * Parse README.md and extract relevant data
113114 */
114115function parseReadme ( filePath ) {
116+ const buildingBlockDir = path . dirname ( filePath ) ;
115117 const content = fs . readFileSync ( filePath , "utf-8" ) ;
116118 const { data, content : body } = matter ( content ) ;
117- const relativePath = filePath . replace ( process . cwd ( ) , "" ) . replace ( / \\ / g, "/" ) ;
118- const pathParts = relativePath . split ( path . sep ) . filter ( Boolean ) ;
119- const id = pathParts . slice ( 1 , pathParts . length - 2 ) . join ( "-" ) ;
120- const platform = pathParts . length > 1 ? pathParts [ 1 ] : "unknown" ;
119+ const { id, platform } = getIdAndPlatform ( buildingBlockDir ) ;
121120 const howToMatch = body . match ( / # # H o w t o U s e ( [ \s \S ] * ?) ( # # | $ ) / ) ;
122121 const resourcesMatch = body . match ( / # # R e s o u r c e s ( [ \s \S ] * ) / ) ;
123122 const inputsMatch = body . match ( / # # I n p u t s ( [ \s \S ] * ?) # # O u t p u t s / ) ;
@@ -141,7 +140,7 @@ function parseReadme(filePath) {
141140 console . log ( `🔗 GitHub remote URLs: ${ JSON . stringify ( githubUrls ) } ` ) ;
142141 console . log ( `🔗 File path: ${ filePath } ` ) ;
143142
144- const buildingBlockLogoPath = findBuildingBlockLogo ( path . dirname ( filePath ) ) ;
143+ const buildingBlockLogoPath = findBuildingBlockLogo ( buildingBlockDir ) ;
145144
146145 return {
147146 id : id ,
@@ -156,6 +155,21 @@ function parseReadme(filePath) {
156155 } ;
157156}
158157
158+ /**
159+ * This returns the id and platform type from the file path.
160+ *
161+ * @param filePath The buildingblock directory
162+ */
163+ function getIdAndPlatform ( filePath ) {
164+ const relativePath = filePath . replace ( process . cwd ( ) , "" ) . replace ( / \\ / g, "/" ) ;
165+ const pathParts = relativePath . split ( path . sep ) . filter ( Boolean ) ;
166+ // pathParts = [modules, <platform>, <module-name>, buildingblock]
167+ const id = pathParts . slice ( 1 , pathParts . length - 1 ) . join ( "-" ) ;
168+ const platform = pathParts . length > 1 ? pathParts [ 1 ] : "unknown" ;
169+
170+ return { id, platform } ;
171+ }
172+
159173const repoRoot = path . resolve ( __dirname , 'modules' ) ;
160174const platformLogos = findPlatformLogos ( ) ;
161175const readmeFiles = findReadmes ( repoRoot ) ;
0 commit comments