mirror of https://github.com/lukechilds/rollup.git
Rich Harris
9 years ago
13 changed files with 69 additions and 50 deletions
@ -0,0 +1,5 @@ |
|||
const nope = method => `Cannot use fs.${method} inside browser`; |
|||
|
|||
export const readdirSync = nope( 'readdirSync' ); |
|||
export const readFileSync = nope( 'readFileSync' ); |
|||
export const writeFile = nope( 'writeFile' ); |
@ -0,0 +1 @@ |
|||
export default window.Promise; |
@ -1,17 +0,0 @@ |
|||
export function readdirSync () { |
|||
throw new Error( 'Cannot use sander.readdirSync inside browser' ); |
|||
} |
|||
|
|||
export function readFile () { |
|||
throw new Error( 'Cannot use sander.readFile inside browser' ); |
|||
} |
|||
|
|||
export function readFileSync () { |
|||
throw new Error( 'Cannot use sander.readFileSync inside browser' ); |
|||
} |
|||
|
|||
export function writeFile () { |
|||
throw new Error( 'Cannot use sander.writeFile inside browser' ); |
|||
} |
|||
|
|||
export const Promise = window.Promise; |
@ -0,0 +1,30 @@ |
|||
import Promise from 'es6-promise/lib/es6-promise/promise'; |
|||
import * as fs from 'fs'; |
|||
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 ) => { |
|||
mkdirpath( dest ); |
|||
|
|||
fs.writeFile( dest, data, err => { |
|||
if ( err ) { |
|||
reject( err ); |
|||
} else { |
|||
fulfil(); |
|||
} |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
export const readdirSync = fs.readdirSync; |
|||
export const readFileSync = fs.readFileSync; |
Loading…
Reference in new issue