@@ -30,6 +30,8 @@ export class TypingsCommand implements ICommand {
3030 result = await this . handleAndroidTypings ( ) ;
3131 } else if ( this . $mobileHelper . isiOSPlatform ( platform ) ) {
3232 result = await this . handleiOSTypings ( ) ;
33+ } else if ( this . $mobileHelper . isWindowsPlatform ( platform ) ) {
34+ result = await this . handleWindowsTypings ( ) ;
3335 }
3436 let typingsFolder = "./typings" ;
3537 if ( this . $options . copyTo ) {
@@ -210,6 +212,83 @@ export class TypingsCommand implements ICommand {
210212 ) ;
211213 }
212214
215+ private async handleWindowsTypings ( ) {
216+ if ( ! this . $hostInfo . isWindows ) {
217+ this . $logger . warn ( "Windows typings can only be generated on Windows." ) ;
218+ return false ;
219+ }
220+
221+ const outDir = path . resolve (
222+ this . $projectData . projectDir ,
223+ "typings" ,
224+ "windows" ,
225+ ) ;
226+ this . $fs . ensureDirectoryExists ( outDir ) ;
227+
228+ const toolsDir = path . resolve (
229+ this . $projectData . projectDir ,
230+ "platforms" ,
231+ "windows" ,
232+ "tools" ,
233+ ) ;
234+ const arch = process . arch === "arm64" ? "arm64" : "x64" ;
235+ const resolveGenerator = ( ) =>
236+ [
237+ path . join ( toolsDir , `typings-generator-${ arch } .exe` ) ,
238+ path . join ( toolsDir , "typings-generator.exe" ) ,
239+ ] . find ( ( p ) => this . $fs . exists ( p ) ) ;
240+
241+ let generatorPath = resolveGenerator ( ) ;
242+ if ( ! generatorPath ) {
243+ this . $logger . warn ( "No platforms folder found, preparing project now..." ) ;
244+ await this . $childProcess . spawnFromEvent (
245+ this . $hostInfo . isWindows ? "ns.cmd" : "ns" ,
246+ [ "prepare" , "windows" ] ,
247+ "exit" ,
248+ { stdio : "inherit" , shell : this . $hostInfo . isWindows } ,
249+ ) ;
250+ generatorPath = resolveGenerator ( ) ;
251+ }
252+
253+ if ( ! generatorPath ) {
254+ this . $logger . warn (
255+ [
256+ `Could not find the Windows typings generator under ${ toolsDir } .` ,
257+ "Ensure @nativescript/windows is installed and the project has been prepared." ,
258+ ] . join ( "\n" ) ,
259+ ) ;
260+ return false ;
261+ }
262+
263+ const asArray = ( input : string | string [ ] ) => {
264+ if ( ! input ) {
265+ return [ ] ;
266+ }
267+ return typeof input === "string" ? [ input ] : input ;
268+ } ;
269+
270+ const generatorArgs : string [ ] = [ "--out-dir" , outDir ] ;
271+ if ( this . $options . root ) {
272+ generatorArgs . push ( "--root" , this . $options . root ) ;
273+ }
274+ if ( this . $options . roots ) {
275+ generatorArgs . push ( "--roots" , this . $options . roots ) ;
276+ }
277+ if ( this . $options . input ) {
278+ generatorArgs . push ( "--input" , this . $options . input ) ;
279+ }
280+ for ( const lib of asArray ( this . $options . lib ) ) {
281+ generatorArgs . push ( "--lib" , lib ) ;
282+ }
283+ if ( this . $options . libs ) {
284+ generatorArgs . push ( "--libs" , this . $options . libs ) ;
285+ }
286+
287+ await this . $childProcess . spawnFromEvent ( generatorPath , generatorArgs , "exit" , {
288+ stdio : "inherit" ,
289+ } ) ;
290+ }
291+
213292 private async handleiOSTypings ( ) {
214293 if ( this . $options . filter !== undefined ) {
215294 this . $logger . warn ( "--filter flag is not supported yet." ) ;
0 commit comments