@@ -2,13 +2,17 @@ import * as path from 'path';
22import { existsSync as exists , readFileSync as read } from 'fs' ;
33import { defaults , Dictionary } from 'lodash' ;
44import * as walk from 'walk-sync' ;
5- import * as requireDir from 'require-dir' ;
65import { sync as glob } from 'glob' ;
76import API from './api' ;
7+ import TypescriptSourceExtracter from './source-extracters/typescript' ;
8+ import JavascriptSourceExtracter from './source-extracters/javascript' ;
89import * as createDebug from 'debug' ;
910
1011const debug = createDebug ( 'documenter:extracter' ) ;
11- const extractersDir = path . join ( __dirname , 'extracters' ) ;
12+ const sourceExtracters = {
13+ 'typescript' : TypescriptSourceExtracter ,
14+ 'javascript' : JavascriptSourceExtracter
15+ } ;
1216
1317export interface ExtracterOptions {
1418 /**
@@ -76,12 +80,24 @@ export default class Extracter {
7680 */
7781 sourceDirs : string [ ] ;
7882
79- extracters = < Dictionary < { default : ExtracterMethod } > > requireDir ( extractersDir ) ;
80-
8183 constructor ( options : ExtracterOptions ) {
8284 defaults ( options , this . defaultOptions ( options . dir ) ) ;
8385 debug ( `Configuring for ${ options . dir } ` ) ;
84- Object . assign ( this , options ) ;
86+ this . dir = options . dir ;
87+ this . pagesDir = options . pagesDir || 'docs' ;
88+ this . sourceDirs = options . sourceDirs || [ 'src' ] ;
89+ this . projectName = options . projectName ;
90+ this . projectVersion = options . projectVersion ;
91+
92+ if ( ! path . isAbsolute ( this . pagesDir ) ) {
93+ this . pagesDir = path . join ( this . dir , this . pagesDir ) ;
94+ }
95+ this . sourceDirs = this . sourceDirs . map ( ( d ) => {
96+ if ( ! path . isAbsolute ( d ) ) {
97+ return path . join ( this . dir , d ) ;
98+ }
99+ return d ;
100+ } ) ;
85101 }
86102
87103 /**
@@ -118,10 +134,11 @@ export default class Extracter {
118134 if ( ! sourceType ) {
119135 throw new Error ( 'Cannot extract API docs from this directory: unknown source type. Source must be Typescript or JavaScript' ) ;
120136 }
121- return this . extracters [ sourceType ] . default . call ( null , this ) ;
137+ let sourceExtracter = new sourceExtracters [ sourceType ] ( this ) ;
138+ return sourceExtracter . extract ( ) ;
122139 }
123140
124- detectSourceType ( ) : string | null {
141+ detectSourceType ( ) : 'typescript' | 'javascript' | null {
125142 // Typescript
126143 if ( exists ( path . join ( this . dir , 'tsconfig.json' ) ) ) {
127144 return 'typescript' ;
0 commit comments