@@ -95,8 +95,9 @@ function findBuildingBlockLogo(buildingBlockDir) {
95
95
96
96
files . forEach ( ( file ) => {
97
97
if ( file . endsWith ( ".png" ) || file . endsWith ( ".svg" ) ) {
98
+ const { id, platform } = getIdAndPlatform ( buildingBlockDir ) ;
98
99
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 ) } ` ) ;
100
101
101
102
fs . mkdirSync ( assetsDir , { recursive : true } ) ;
102
103
fs . copyFileSync ( sourcePath , destinationPath ) ;
@@ -112,12 +113,10 @@ function findBuildingBlockLogo(buildingBlockDir) {
112
113
* Parse README.md and extract relevant data
113
114
*/
114
115
function parseReadme ( filePath ) {
116
+ const buildingBlockDir = path . dirname ( filePath ) ;
115
117
const content = fs . readFileSync ( filePath , "utf-8" ) ;
116
118
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 ) ;
121
120
const howToMatch = body . match ( / # # H o w t o U s e ( [ \s \S ] * ?) ( # # | $ ) / ) ;
122
121
const resourcesMatch = body . match ( / # # R e s o u r c e s ( [ \s \S ] * ) / ) ;
123
122
const inputsMatch = body . match ( / # # I n p u t s ( [ \s \S ] * ?) # # O u t p u t s / ) ;
@@ -140,8 +139,9 @@ function parseReadme(filePath) {
140
139
const githubUrls = getGithubRemoteUrls ( filePath ) ;
141
140
console . log ( `🔗 GitHub remote URLs: ${ JSON . stringify ( githubUrls ) } ` ) ;
142
141
console . log ( `🔗 File path: ${ filePath } ` ) ;
142
+ console . log ( 'ID=' + id ) ;
143
143
144
- const buildingBlockLogoPath = findBuildingBlockLogo ( path . dirname ( filePath ) ) ;
144
+ const buildingBlockLogoPath = findBuildingBlockLogo ( buildingBlockDir ) ;
145
145
146
146
return {
147
147
id : id ,
@@ -156,6 +156,21 @@ function parseReadme(filePath) {
156
156
} ;
157
157
}
158
158
159
+ /**
160
+ * This returns the id and platform type from the file path.
161
+ *
162
+ * @param filePath The buildingblock directory
163
+ */
164
+ function getIdAndPlatform ( filePath ) {
165
+ const relativePath = filePath . replace ( process . cwd ( ) , "" ) . replace ( / \\ / g, "/" ) ;
166
+ const pathParts = relativePath . split ( path . sep ) . filter ( Boolean ) ;
167
+ // pathParts = [modules, <platform>, <module-name>, buildingblock]
168
+ const id = pathParts . slice ( 1 , pathParts . length - 1 ) . join ( "-" ) ;
169
+ const platform = pathParts . length > 1 ? pathParts [ 1 ] : "unknown" ;
170
+
171
+ return { id, platform } ;
172
+ }
173
+
159
174
const repoRoot = path . resolve ( __dirname , 'modules' ) ;
160
175
const platformLogos = findPlatformLogos ( ) ;
161
176
const readmeFiles = findReadmes ( repoRoot ) ;
0 commit comments