forked from jsdoc/jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jsdoc-core): add
@jsdoc/core.util.fs.lsSync
- Loading branch information
Showing
6 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @module @jsdoc/util/lib/fs | ||
*/ | ||
|
||
const _ = require('lodash'); | ||
const klawSync = require('klaw-sync'); | ||
const path = require('path'); | ||
|
||
exports.lsSync = ((dir, opts = {}) => { | ||
const depth = _.has(opts, 'depth') ? opts.depth : -1; | ||
|
||
const files = klawSync(dir, { | ||
depthLimit: depth, | ||
filter: (f => !path.basename(f.path).startsWith('.')), | ||
nodir: true | ||
}); | ||
|
||
return files.map(f => f.path); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const cast = require('./cast'); | ||
const fs = require('./fs'); | ||
|
||
module.exports = { | ||
cast | ||
cast, | ||
fs | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
describe('@jsdoc/util/lib/fs', () => { | ||
const mockFs = require('mock-fs'); | ||
const fsUtil = require('../../../../lib/util/fs'); | ||
const path = require('path'); | ||
|
||
afterEach(() => mockFs.restore()); | ||
|
||
it('has an lsSync method', () => { | ||
expect(fsUtil.lsSync).toBeFunction(); | ||
}); | ||
|
||
describe('lsSync', () => { | ||
beforeEach(() => { | ||
mockFs({ | ||
head: { | ||
eyes: '', | ||
ears: '', | ||
mouth: '', | ||
nose: '', | ||
shoulders: { | ||
knees: { | ||
meniscus: '', | ||
toes: { | ||
phalanx: '', | ||
'.big-toe-phalanx': '' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
const cwd = process.cwd(); | ||
|
||
function resolvePaths(files) { | ||
return files.map(f => path.join(cwd, f)).sort(); | ||
} | ||
|
||
const allFiles = resolvePaths([ | ||
'head/eyes', | ||
'head/ears', | ||
'head/mouth', | ||
'head/nose', | ||
'head/shoulders/knees/meniscus', | ||
'head/shoulders/knees/toes/phalanx' | ||
]); | ||
|
||
it('gets all non-hidden files from all levels by default', () => { | ||
const files = fsUtil.lsSync(cwd).sort(); | ||
|
||
expect(files).toEqual(allFiles); | ||
}); | ||
|
||
it('limits recursion depth when asked', () => { | ||
const files = fsUtil.lsSync(cwd, { depth: 1 }).sort(); | ||
|
||
expect(files).toEqual(resolvePaths([ | ||
'head/eyes', | ||
'head/ears', | ||
'head/mouth', | ||
'head/nose' | ||
])); | ||
}); | ||
|
||
it('treats a depth of -1 as infinite', () => { | ||
const files = fsUtil.lsSync('head', { depth: -1 }).sort(); | ||
|
||
expect(files).toEqual(allFiles); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters