File tree Expand file tree Collapse file tree 5 files changed +31
-1
lines changed Expand file tree Collapse file tree 5 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -15,4 +15,22 @@ describe('ls', () => {
1515
1616 expect ( result . sort ( ) ) . toEqual ( expected . sort ( ) )
1717 } )
18+
19+ describe ( 'dirs' , ( ) => {
20+ test ( 'without prefix' , ( ) => {
21+ const result = ls . dirs ( `${ fixtures } /ls/dirs` )
22+
23+ const expected = [ '.baz' , 'bar' , 'foo' ]
24+
25+ expect ( result . sort ( ) ) . toEqual ( expected . sort ( ) )
26+ } )
27+
28+ test ( 'with prefix' , ( ) => {
29+ const result = ls . dirs ( `${ fixtures } /ls/dirs` , 'prefix' )
30+
31+ const expected = [ 'prefix/.baz' , 'prefix/bar' , 'prefix/foo' ]
32+
33+ expect ( result . sort ( ) ) . toEqual ( expected . sort ( ) )
34+ } )
35+ } )
1836} )
Original file line number Diff line number Diff line change @@ -44,6 +44,18 @@ const configs = path =>
4444 ) } `,
4545 )
4646
47- const ls = { configs}
47+ /**
48+ * Enumerate one level of directories
49+ *
50+ * @param {string } path - directory to enumerate
51+ * @param {string } [prefix] - prefix for each scope entry (e.g: `prefix/entry`)
52+ */
53+ const dirs = ( path , prefix ) =>
54+ readdirSync ( path )
55+ . filter ( f => statSync ( join ( path , f ) ) . isDirectory ( ) )
56+ . map ( item => ( prefix ? `${ prefix } /${ item } ` : item ) )
57+ . map ( item => item . toLowerCase ( ) )
58+
59+ const ls = { configs, dirs}
4860
4961module . exports = { ls, scopes}
You can’t perform that action at this time.
0 commit comments