@@ -3,7 +3,7 @@ const fse = require('fs-extra');
3
3
const path = require ( 'path' ) ;
4
4
const _ = require ( 'lodash' ) ;
5
5
const { loadConfig } = require ( '@stackbit/sdk' ) ;
6
- const { parseFile, mapPromise, readDirRecursively } = require ( '@stackbit/utils' ) ;
6
+ const { parseFile, mapPromise, reducePromise , readDirRecursively } = require ( '@stackbit/utils' ) ;
7
7
const { matchObjectsToModels } = require ( './models-matcher' ) ;
8
8
9
9
@@ -24,6 +24,10 @@ function log(message) {
24
24
console . log ( `[${ SOURCE } ] ${ message } ` ) ;
25
25
}
26
26
27
+ function logError ( message ) {
28
+ console . error ( `[${ SOURCE } ] ${ message } ` ) ;
29
+ }
30
+
27
31
module . exports . bootstrap = async ( { setPluginContext, options, refresh } ) => {
28
32
let { watch, sources = [ ] } = options ;
29
33
@@ -137,22 +141,27 @@ async function readFiles(sources) {
137
141
const ext = path . extname ( filePath ) . substring ( 1 ) ;
138
142
return [ 'yml' , 'yaml' , 'json' , 'toml' , 'md' ] . includes ( ext ) ;
139
143
} ) . sort ( ) ;
140
- return mapPromise ( filePaths , async filePath => {
144
+ return reducePromise ( filePaths , async ( result , filePath ) => {
141
145
const absFilePath = path . join ( absSourcePath , filePath ) ;
142
- const data = await parseFile ( absFilePath ) ;
143
146
const relProjectPath = path . relative ( absProjectPath , absFilePath ) ;
144
147
const relSourcePath = path . relative ( absSourcePath , absFilePath ) ;
145
- return _ . assign ( {
146
- __metadata : {
147
- id : `${ relProjectPath } ` ,
148
- source : SOURCE ,
149
- sourceName : name ,
150
- sourcePath : sourcePath ,
151
- relSourcePath : relSourcePath ,
152
- relProjectPath : relProjectPath
153
- }
154
- } , data ) ;
155
- } ) ;
148
+ try {
149
+ const data = await parseFile ( absFilePath ) ;
150
+ result . push ( _ . assign ( {
151
+ __metadata : {
152
+ id : `${ relProjectPath } ` ,
153
+ source : SOURCE ,
154
+ sourceName : name ,
155
+ sourcePath : sourcePath ,
156
+ relSourcePath : relSourcePath ,
157
+ relProjectPath : relProjectPath
158
+ }
159
+ } , data ) ) ;
160
+ } catch ( error ) {
161
+ logError ( `failed to parse file: ${ relProjectPath } ` ) ;
162
+ }
163
+ return result ;
164
+ } , [ ] ) ;
156
165
} ) ;
157
166
return _ . chain ( result ) . flatten ( ) . value ( ) ;
158
167
}
0 commit comments