mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
47 lines
1.0 KiB
JavaScript
Executable File
47 lines
1.0 KiB
JavaScript
Executable File
/**
|
|
* @module @jsdoc/util/lib/fs
|
|
*/
|
|
|
|
const _ = require('lodash');
|
|
const fs = require('fs');
|
|
const klaw = require('klaw-sync');
|
|
const path = require('path');
|
|
|
|
const walkSync = exports.walkSync = (filepaths, opts = {}) => {
|
|
const depth = _.has(opts, 'depth') ? opts.depth : -1;
|
|
let filter;
|
|
let found = [];
|
|
|
|
if (typeof filepaths === 'string') {
|
|
filepaths = [filepaths];
|
|
}
|
|
|
|
if (typeof opts.filter === 'function') {
|
|
filter = f => opts.filter.call(null, f.path);
|
|
}
|
|
|
|
filepaths.forEach(f => {
|
|
f = path.resolve(f);
|
|
|
|
if (fs.statSync(f).isFile()) {
|
|
found.push({ path: f });
|
|
} else {
|
|
found = found.concat(
|
|
klaw(f, {
|
|
depthLimit: depth,
|
|
filter: filter,
|
|
nodir: true
|
|
})
|
|
);
|
|
}
|
|
});
|
|
|
|
return found.map(f => f.path);
|
|
};
|
|
|
|
exports.lsSync = (dir, opts = {}) => walkSync(dir, {
|
|
depth: opts.depth,
|
|
filter: (f => !path.basename(f).startsWith('.')),
|
|
nodir: true
|
|
});
|