nl_tokens: check if folder or file exists if not create it
pl_tokens: function existsOrCreate ( filePath , opts , cb ) { if ( arguments . length === 2 ) { cb = arguments [ 1 ] ; opts = { } ; } opts . encoding = opts . encoding || 'utf8' ; opts . data = opts . data || opts . content || '' ; opts . mode = opts . mode || '0777' ; opts . replace = opts . replace ? true : false ; var fp = resolve ( filePath ) ; var isFile = opts . hasOwnProperty ( 'isFile' ) ? opts . isFile : ! ! fp . extName ; fs . exists ( fp . fullPath , function ( exists ) { if ( exists && ! opts . replace ) cb ( null , exists ) ; else { // file doesn't exists, create folder first mkdirp ( ( isFile ? fp . dirName : fp . fullPath ) , opts . mode , function ( err ) { if ( err ) cb ( new Error ( 'fsExt.existsOrCreate: creating folders failed' ) . cause ( err ) ) ; else if ( isFile || opts . replace ) { // folders are created, so create file fs . writeFile ( fp . fullPath , opts . data , opts . encoding , function ( <mask> ) { if ( err ) cb ( new Error ( 'fsExt.existsOrCreate: creating file failed' ) . cause ( err ) ) ; else cb ( null , exists ) ; } ) ; } else cb ( null , exists ) ; } ) ; } } ) ; }