Browse Source

make intermediate dirs in writeFile helper

better-aggressive
Rich Harris 9 years ago
parent
commit
e8fe0d1080
  1. 16
      src/utils/fs.js

16
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 {

Loading…
Cancel
Save