@@ -41,45 +41,43 @@ export class DtsCreator {
4141 this . EOL = options . EOL || os . EOL ;
4242 }
4343
44- create ( filePath : string , initialContents ?: string , clearCache : boolean = false ) : Promise < DtsContent > {
45- return new Promise ( ( resolve , reject ) => {
46- let rInputPath : string ;
47- if ( path . isAbsolute ( filePath ) ) {
48- rInputPath = path . relative ( this . inputDirectory , filePath ) ;
49- } else {
50- rInputPath = path . relative ( this . inputDirectory , path . join ( process . cwd ( ) , filePath ) ) ;
51- }
52- if ( clearCache ) {
53- this . loader . tokensByFile = { } ;
54- }
55- this . loader . fetch ( filePath , "/" , undefined , initialContents ) . then ( ( res ) => {
56- if ( res ) {
57- var tokens = res ;
58- var keys = Object . keys ( tokens ) ;
44+ public async create ( filePath : string , initialContents ?: string , clearCache : boolean = false ) : Promise < DtsContent > {
45+ let rInputPath : string ;
46+ if ( path . isAbsolute ( filePath ) ) {
47+ rInputPath = path . relative ( this . inputDirectory , filePath ) ;
48+ } else {
49+ rInputPath = path . relative ( this . inputDirectory , path . join ( process . cwd ( ) , filePath ) ) ;
50+ }
51+ if ( clearCache ) {
52+ this . loader . tokensByFile = { } ;
53+ }
5954
60- var convertKey = this . getConvertKeyMethod ( this . camelCase ) ;
55+ const res = await this . loader . fetch ( filePath , "/" , undefined , initialContents ) ;
56+ if ( res ) {
57+ var tokens = res ;
58+ var keys = Object . keys ( tokens ) ;
6159
62- var result = keys
63- . map ( k => convertKey ( k ) )
64- . map ( k => 'readonly "' + k + '": string;' )
60+ var convertKey = this . getConvertKeyMethod ( this . camelCase ) ;
6561
66- var content = new DtsContent ( {
67- dropExtension : this . dropExtension ,
68- rootDir : this . rootDir ,
69- searchDir : this . searchDir ,
70- outDir : this . outDir ,
71- rInputPath,
72- rawTokenList : keys ,
73- resultList : result ,
74- EOL : this . EOL
75- } ) ;
62+ var result = keys
63+ . map ( k => convertKey ( k ) )
64+ . map ( k => 'readonly "' + k + '": string;' )
7665
77- resolve ( content ) ;
78- } else {
79- reject ( res ) ;
80- }
81- } ) . catch ( err => reject ( err ) ) ;
82- } ) ;
66+ var content = new DtsContent ( {
67+ dropExtension : this . dropExtension ,
68+ rootDir : this . rootDir ,
69+ searchDir : this . searchDir ,
70+ outDir : this . outDir ,
71+ rInputPath,
72+ rawTokenList : keys ,
73+ resultList : result ,
74+ EOL : this . EOL
75+ } ) ;
76+
77+ return content ;
78+ } else {
79+ throw res ;
80+ }
8381 }
8482
8583 private getConvertKeyMethod ( camelCaseOption : CamelCaseOption ) : ( str : string ) => string {
0 commit comments