A small collection of sync & async filesystem functions for Node Js.
npm install --save-dev njfs
- unix(path): Synchronous. Returns path with unix-like directory separators.
- root(path): Synchronous. Returns the root directory of the package.
- list(path, opts): Asynchronous. Returns the list of files and folders of the given path.
- move(path, dest): Asynchronous. Moves files or folders.
- copy(path, dest): Asynchronous. Copies files or folders.
- isFile(path): Synchronous. Checks whether the specified path is an existing file or not.
- isDir(path): Synchronous. Checks whether the specified path is an existing directory or not.
const {move, copy, root, list, isDir} = require('njfs');
gulp.task('example', async () =>
await gulp.watch(['./src/*.*'], gulp.series('build', async () => {
const dist = root() + 'src';
const dest = root() + 'dist/js';
try {
const files = await list(dist, {extensions:'js, jsx'});
await Promise.all(files.map(async (file) => {
const path = `${dist}/${file}`;
if (!isDir(path)) {
await copy(path, dest);
console.log(`${file} transfered to ${dest}`);
}
}));
} catch (e) {
console.log(e);
}
})
));
When you encounter a problem, please open an issue. I would be glad to help you to find a solution if possible.
Github: @orcunsaltik
See the LICENSE file for license rights and limitations (MIT).