1- import { glob } from "glob " ;
1+ import { glob } from "node:fs/promises " ;
22import { homedir } from "os" ;
33import * as path from "path" ;
44import { PromptObject } from "prompts" ;
@@ -20,7 +20,7 @@ export class TypingsCommand implements ICommand {
2020 private $childProcess : IChildProcess ,
2121 private $hostInfo : IHostInfo ,
2222 private $staticConfig : IStaticConfig ,
23- private $prompter : IPrompter
23+ private $prompter : IPrompter ,
2424 ) { }
2525
2626 public async execute ( args : string [ ] ) : Promise < void > {
@@ -35,15 +35,15 @@ export class TypingsCommand implements ICommand {
3535 if ( this . $options . copyTo ) {
3636 this . $fs . copyFile (
3737 path . resolve ( this . $projectData . projectDir , "typings" ) ,
38- this . $options . copyTo
38+ this . $options . copyTo ,
3939 ) ;
4040 typingsFolder = this . $options . copyTo ;
4141 }
4242
4343 if ( result !== false ) {
4444 this . $logger . info (
4545 "Typings have been generated in the following directory:" ,
46- typingsFolder
46+ typingsFolder ,
4747 ) ;
4848 }
4949 }
@@ -56,7 +56,7 @@ export class TypingsCommand implements ICommand {
5656
5757 private async resolveGradleDependencies ( target : string ) {
5858 const gradleHome = path . resolve (
59- process . env . GRADLE_USER_HOME ?? path . join ( homedir ( ) , `/.gradle` )
59+ process . env . GRADLE_USER_HOME ?? path . join ( homedir ( ) , `/.gradle` ) ,
6060 ) ;
6161 const gradleFiles = path . resolve ( gradleHome , "caches/modules-2/files-2.1/" ) ;
6262
@@ -67,33 +67,32 @@ export class TypingsCommand implements ICommand {
6767
6868 const pattern = `${ target . replaceAll ( ":" , "/" ) } /**/*.{jar,aar}` ;
6969
70- const res = await glob ( pattern , {
70+ const items = [ ] ;
71+ for await ( const item of glob ( pattern , {
7172 cwd : gradleFiles ,
72- } ) ;
73-
74- if ( ! res || res . length === 0 ) {
75- this . $logger . warn ( "No files found" ) ;
76- return [ ] ;
77- }
78-
79- const items = res . map ( ( item ) => {
73+ } ) ) {
8074 const [ group , artifact , version , sha1 , file ] = item . split ( path . sep ) ;
81- return {
75+ items . push ( {
8276 id : sha1 + version ,
8377 group,
8478 artifact,
8579 version,
8680 sha1,
8781 file,
8882 path : path . resolve ( gradleFiles , item ) ,
89- } ;
90- } ) ;
83+ } ) ;
84+ }
85+
86+ if ( items . length === 0 ) {
87+ this . $logger . warn ( "No files found" ) ;
88+ return [ ] ;
89+ }
9190
9291 this . $logger . clearScreen ( ) ;
9392
9493 const choices = await this . $prompter . promptForChoice (
9594 `Select dependencies to generate typings for (${ color . greenBright (
96- target
95+ target ,
9796 ) } )`,
9897 items
9998 . sort ( ( a , b ) => {
@@ -108,17 +107,18 @@ export class TypingsCommand implements ICommand {
108107 . map ( ( item ) => {
109108 return {
110109 title : `${ color . white ( item . group ) } :${ color . greenBright (
111- item . artifact
112- ) } :${ color . yellow ( item . version ) } - ${ color . cyanBright . bold (
113- item . file
110+ item . artifact ,
111+ ) } :${ color . yellow ( item . version ) } - ${ color . styleText (
112+ [ "cyanBright" , "bold" ] ,
113+ item . file ,
114114 ) } `,
115115 value : item . id ,
116116 } ;
117117 } ) ,
118118 true ,
119119 {
120120 optionsPerPage : process . stdout . rows - 6 , // 6 lines are taken up by the instructions
121- } as Partial < PromptObject >
121+ } as Partial < PromptObject > ,
122122 ) ;
123123
124124 this . $logger . clearScreen ( ) ;
@@ -139,7 +139,7 @@ export class TypingsCommand implements ICommand {
139139 } catch ( err ) {
140140 this . $logger . trace (
141141 `Failed to resolve gradle dependencies for target "${ target } "` ,
142- err
142+ err ,
143143 ) ;
144144 }
145145 }
@@ -151,29 +151,29 @@ export class TypingsCommand implements ICommand {
151151 "No .jar or .aar file specified. Please specify at least one of the following:" ,
152152 " - path to .jar file with --jar <jar>" ,
153153 " - path to .aar file with --aar <aar>" ,
154- ] . join ( "\n" )
154+ ] . join ( "\n" ) ,
155155 ) ;
156156 return false ;
157157 }
158158
159159 this . $fs . ensureDirectoryExists (
160- path . resolve ( this . $projectData . projectDir , "typings" , "android" )
160+ path . resolve ( this . $projectData . projectDir , "typings" , "android" ) ,
161161 ) ;
162162
163163 const dtsGeneratorPath = path . resolve (
164164 this . $projectData . projectDir ,
165165 "platforms" ,
166166 "android" ,
167167 "build-tools" ,
168- "dts-generator.jar"
168+ "dts-generator.jar" ,
169169 ) ;
170170 if ( ! this . $fs . exists ( dtsGeneratorPath ) ) {
171171 this . $logger . warn ( "No platforms folder found, preparing project now..." ) ;
172172 await this . $childProcess . spawnFromEvent (
173173 this . $hostInfo . isWindows ? "ns.cmd" : "ns" ,
174174 [ "prepare" , "android" ] ,
175175 "exit" ,
176- { stdio : "inherit" , shell : this . $hostInfo . isWindows }
176+ { stdio : "inherit" , shell : this . $hostInfo . isWindows } ,
177177 ) ;
178178 }
179179
@@ -206,7 +206,7 @@ export class TypingsCommand implements ICommand {
206206 path . resolve ( this . $projectData . projectDir , "typings" , "android" ) ,
207207 ] ,
208208 "exit" ,
209- { stdio : "inherit" }
209+ { stdio : "inherit" } ,
210210 ) ;
211211 }
212212
@@ -216,7 +216,7 @@ export class TypingsCommand implements ICommand {
216216 }
217217
218218 this . $fs . ensureDirectoryExists (
219- path . resolve ( this . $projectData . projectDir , "typings" , "ios" )
219+ path . resolve ( this . $projectData . projectDir , "typings" , "ios" ) ,
220220 ) ;
221221
222222 await this . $childProcess . spawnFromEvent (
@@ -229,11 +229,11 @@ export class TypingsCommand implements ICommand {
229229 TNS_TYPESCRIPT_DECLARATIONS_PATH : path . resolve (
230230 this . $projectData . projectDir ,
231231 "typings" ,
232- "ios"
232+ "ios" ,
233233 ) ,
234234 } ,
235235 stdio : "inherit" ,
236- }
236+ } ,
237237 ) ;
238238 }
239239}
0 commit comments