diff --git a/src/utils/fs.js b/src/utils/fs.js index 59c51fd..fc3ee77 100644 --- a/src/utils/fs.js +++ b/src/utils/fs.js @@ -1,10 +1,22 @@ import Promise from 'es6-promise/lib/es6-promise/promise'; import * as fs from 'fs'; -import { resolve } from './path'; +import { dirname } from './path'; + +function mkdirpath ( path ) { + const dir = dirname( path ); + try { + fs.readdirSync( dir ); + } catch ( err ) { + mkdirpath( dir ); + fs.mkdirSync( dir ); + } +} export function writeFile ( dest, data ) { return new Promise( ( fulfil, reject ) => { - fs.writeFile( resolve( process.cwd(), dest ), data, err => { + mkdirpath( dest ); + + fs.writeFile( dest, data, err => { if ( err ) { reject( err ); } else {