@@ -11,6 +11,7 @@ const fs = require('fs');
1111const colors = require ( 'colors/safe' ) ;
1212const async = require ( 'async' ) ;
1313const sumanUtils = require ( 'suman-utils' ) ;
14+ const mkdirp = require ( 'mkdirp' ) ;
1415
1516//project
1617const projectRoot = global . projectRoot || sumanUtils . findProjectRoot ( process . cwd ( ) ) ;
@@ -20,23 +21,31 @@ const projectRoot = global.projectRoot || sumanUtils.findProjectRoot(process.cwd
2021module . exports = function createTestFiles ( paths ) {
2122
2223 const p = path . resolve ( __dirname , '..' , 'default-conf-files/suman.skeleton.js' ) ;
23-
2424 const strm = fs . createReadStream ( p ) ;
2525
2626 async . each ( paths , function ( p , cb ) {
2727 //TODO: difference between "finish" and "close" events on stream ??
28- strm . pipe ( fs . createWriteStream ( p , { flags : 'wx' } ) ) . once ( 'error' , cb ) . once ( 'finish' , function ( ) {
29- console . log ( ' => File was created:' , p ) ;
28+
29+ mkdirp ( path . dirname ( p ) , function ( err ) {
30+ if ( err ) {
31+ cb ( err ) ;
32+ }
33+ else {
34+ strm . pipe ( fs . createWriteStream ( p , { flags : 'wx' } ) ) . once ( 'error' , cb ) . once ( 'finish' , function ( ) {
35+ console . log ( '\n => File was created:' , p ) ;
3036 process . nextTick ( cb ) ;
31- } ) ;
37+ } ) ;
38+ }
39+ } ) ;
3240
3341 } , function ( err ) {
42+ console . log ( '\n' ) ;
3443 if ( err ) {
35- console . error ( '\n' , colors . red . bold ( ' => Suman usage error => ' ) + colors . red ( err . stack || err ) , '\n' ) ;
44+ console . error ( colors . red . bold ( ' => Suman error => ' ) + colors . red ( err . stack || err ) , '\n' ) ;
3645 process . exit ( 1 ) ;
3746 }
3847 else {
39- console . log ( '\n' , colors . green . bold ( ' => Suman message => successfully created test skeletons .' ) , '\n' ) ;
48+ console . log ( colors . blue . bold ( ' => Suman message => successfully created test skeleton(s) .' ) ) ;
4049 process . exit ( 0 ) ;
4150 }
4251 } ) ;
0 commit comments