11import fs from 'fs' ;
22import { join , resolve , dirname , basename } from 'path' ;
33
4- export interface Options {
4+ export interface DirectoryToAstOptions {
55 relativePath ?: string ;
66 extensions ?: string [ ] ;
77 include ?: RegExp | ( ( path : string , kind : 'dir' | 'file' , filename : string ) => boolean ) ;
88 exclude ?: RegExp | ( ( path : string , kind : 'dir' | 'file' , filename : string ) => boolean ) ;
99}
1010
11- type AstNodeKinds = 'rootType' | 'dir' | 'file' ;
11+ export type AstNodeKinds = 'rootType' | 'dir' | 'file' ;
1212
13- interface AstBaseNode {
13+ export interface AstBaseNode {
1414 kind : AstNodeKinds ;
1515 name : string ;
1616 absPath : string ;
@@ -45,11 +45,14 @@ export interface AstResult {
4545 subscription ?: AstRootTypeNode ;
4646}
4747
48- export const defaultOptions : Options = {
48+ export const defaultOptions : DirectoryToAstOptions = {
4949 extensions : [ 'js' , 'ts' ] ,
5050} ;
5151
52- export function directoryToAst ( m : NodeModule , options : Options = defaultOptions ) : AstResult {
52+ export function directoryToAst (
53+ m : NodeModule ,
54+ options : DirectoryToAstOptions = defaultOptions
55+ ) : AstResult {
5356 // if no path was passed in, assume the equivelant of __dirname from caller
5457 // otherwise, resolve path relative to the equivalent of __dirname
5558 const schemaPath = options ?. relativePath
@@ -110,7 +113,7 @@ export function directoryToAst(m: NodeModule, options: Options = defaultOptions)
110113export function getAstForDir (
111114 m : NodeModule ,
112115 absPath : string ,
113- options : Options = defaultOptions
116+ options : DirectoryToAstOptions = defaultOptions
114117) : AstDirNode | void {
115118 const name = basename ( absPath ) ;
116119
@@ -162,7 +165,7 @@ export function getAstForDir(
162165export function getAstForFile (
163166 m : NodeModule ,
164167 absPath : string ,
165- options : Options = defaultOptions
168+ options : DirectoryToAstOptions = defaultOptions
166169) : AstFileNode | void {
167170 const filename = basename ( absPath ) ;
168171 if ( absPath !== m . filename && checkInclusion ( absPath , 'file' , filename , options ) ) {
@@ -181,7 +184,7 @@ function checkInclusion(
181184 absPath : string ,
182185 kind : 'dir' | 'file' ,
183186 filename : string ,
184- options : Options
187+ options : DirectoryToAstOptions
185188) : boolean {
186189 // Skip dir/files started from double underscore
187190 if ( / ^ _ _ .* / i. test ( filename ) ) {
0 commit comments