0.3.1 • Published 8 years ago
panto-file-utils v0.3.1
panto-file-utils
File utils for panto.
You can locate/read file(s) ONLY in src directory, but mkdir/write/remove ONLY in output directory.
const PantoOptions = require('panto-options');
const FileUtils = require('panto-file-utils');
const fu = new FileUtils(new PantoOptions({cwd: '.', src: 'src', output: 'out'}));
fu.isBinary('foo/bar/a.png')// true
fu.isBinary('a.js')// false
// locate only in SRC
fu.locate('foo/a.js')// ./src/foo/a.js
// touch only in OUTPUT
fu.touch('foo/a.js')// ./out/foo/a.js
// read from only SRC
fu.read('foo/a.js').then(...)// ./src/foo/a.js
// write to only OUTPUT
fu.write('foo/b.js', 'hello').then(...) // ./out/foo/b.js
// remove from only OUTPUT,alias unlink/remove
fu.rimraf('foo/b.js', 'hello').then(...) // ./out/foo/b.js
// mkdir only in OUTPUT
fu.safeDirp('bar').then(...)// ./out/bar/
fu.copy('foo', 'bar').then(...)// ./out/bar/
// Alias for multimatch
fu.match(...)
apis
- isBinary(filename): Boolean, if it's a binary file type.
- locate(filename): Promise, return a file path under ${cwd}/${src}.
- touch(filename): Promise, return a file path under ${cwd}/${output}.
- safeDirp(filename): Promise, make sure file's directories exist.
- read(filename): Promise, read a file under ${cwd}/${src}.
- write(filename, content): Promise, write a file under ${cwd}/${output}.
- match(filename, pattern): Promise, alias as multimatch.
- remove(filename): Promise, remove a file or directory under ${cwd}/${output}.
- unlink: Alias for remove.
- rimraf: Alias for remove.
- copy: Promise, copy from ${cwd}/${src} to ${cwd}/${output}.