1
1
import fs from 'fs' ;
2
2
import { join , resolve , dirname , basename } from 'path' ;
3
3
4
- export interface Options {
4
+ export interface DirectoryToAstOptions {
5
5
relativePath ?: string ;
6
6
extensions ?: string [ ] ;
7
7
include ?: RegExp | ( ( path : string , kind : 'dir' | 'file' , filename : string ) => boolean ) ;
8
8
exclude ?: RegExp | ( ( path : string , kind : 'dir' | 'file' , filename : string ) => boolean ) ;
9
9
}
10
10
11
- type AstNodeKinds = 'rootType' | 'dir' | 'file' ;
11
+ export type AstNodeKinds = 'rootType' | 'dir' | 'file' ;
12
12
13
- interface AstBaseNode {
13
+ export interface AstBaseNode {
14
14
kind : AstNodeKinds ;
15
15
name : string ;
16
16
absPath : string ;
@@ -45,11 +45,14 @@ export interface AstResult {
45
45
subscription ?: AstRootTypeNode ;
46
46
}
47
47
48
- export const defaultOptions : Options = {
48
+ export const defaultOptions : DirectoryToAstOptions = {
49
49
extensions : [ 'js' , 'ts' ] ,
50
50
} ;
51
51
52
- export function directoryToAst ( m : NodeModule , options : Options = defaultOptions ) : AstResult {
52
+ export function directoryToAst (
53
+ m : NodeModule ,
54
+ options : DirectoryToAstOptions = defaultOptions
55
+ ) : AstResult {
53
56
// if no path was passed in, assume the equivelant of __dirname from caller
54
57
// otherwise, resolve path relative to the equivalent of __dirname
55
58
const schemaPath = options ?. relativePath
@@ -110,7 +113,7 @@ export function directoryToAst(m: NodeModule, options: Options = defaultOptions)
110
113
export function getAstForDir (
111
114
m : NodeModule ,
112
115
absPath : string ,
113
- options : Options = defaultOptions
116
+ options : DirectoryToAstOptions = defaultOptions
114
117
) : AstDirNode | void {
115
118
const name = basename ( absPath ) ;
116
119
@@ -162,7 +165,7 @@ export function getAstForDir(
162
165
export function getAstForFile (
163
166
m : NodeModule ,
164
167
absPath : string ,
165
- options : Options = defaultOptions
168
+ options : DirectoryToAstOptions = defaultOptions
166
169
) : AstFileNode | void {
167
170
const filename = basename ( absPath ) ;
168
171
if ( absPath !== m . filename && checkInclusion ( absPath , 'file' , filename , options ) ) {
@@ -181,7 +184,7 @@ function checkInclusion(
181
184
absPath : string ,
182
185
kind : 'dir' | 'file' ,
183
186
filename : string ,
184
- options : Options
187
+ options : DirectoryToAstOptions
185
188
) : boolean {
186
189
// Skip dir/files started from double underscore
187
190
if ( / ^ _ _ .* / i. test ( filename ) ) {
0 commit comments