@@ -20,9 +20,6 @@ var Loader = function (data) {
2020 options [ key ] = _ . has ( options , key ) ? options [ key ] : defaults [ key ] ;
2121 } ) ;
2222
23- staticFullPaths = _ . map ( options . directories , function ( dir ) {
24- return path . resolve ( options . path , dir . directory )
25- } ) ;
2623 logger = new Logger ( options . log ) ;
2724
2825 function makeRequest ( url ) {
@@ -283,9 +280,14 @@ var Loader = function (data) {
283280 . then ( function ( html ) { // Prepare for further loading
284281 return prepare ( html )
285282 } )
286- . then ( function ( html ) { // Load css sources in index page
283+ . then ( function ( html ) {
287284 fs . ensureDirSync ( options . path ) ;
288285 setLoadedFilename ( options . url , options . path ) ;
286+
287+ staticFullPaths = _ . map ( options . directories , function ( dir ) {
288+ return path . resolve ( options . path , dir . directory )
289+ } ) ;
290+
289291 return loadCssSources ( html , options . url ) ;
290292 } )
291293 }
@@ -315,22 +317,27 @@ var Loader = function (data) {
315317 return fs . removeAsync ( options . path ) ;
316318 }
317319
320+ function noop ( ) { }
321+
318322 return {
319323 scrape : function ( callback ) {
324+ callback = typeof callback === 'function' ? callback : noop ;
325+
326+ if ( ! options . path ) {
327+ return callback ( new Error ( 'Path is not defined' ) ) ;
328+ }
320329 if ( fs . existsSync ( options . path ) ) {
321- return callback ( new Error ( 'Path ' + options . path + ' exists!' ) , null ) ;
330+ return callback ( new Error ( 'Path ' + options . path + ' exists' ) ) ;
322331 }
323332
324333 process ( )
325- . then ( function ( res ) {
326- return callback ( null , res )
327- } )
328- . catch ( function ( e ) {
329- return errorCleanup ( )
330- . then ( function ( ) {
331- return callback ( e , null )
332- } ) ;
333- } )
334+ . then ( function ( res , e ) {
335+ if ( e ) {
336+ errorCleanup ( ) ;
337+ res = null ;
338+ }
339+ return callback ( e , res ) ;
340+ } ) ;
334341 }
335342 }
336343} ;
0 commit comments