@@ -615,6 +615,63 @@ task buildMetadata (type: JavaExec) {
615615 }
616616}
617617
618+ task generateTypescriptDefinitions (type : JavaExec ) {
619+ def paramz = new ArrayList<String > ();
620+ def includeDirs = [" com.android.support" , " /platforms/" + android. compileSdkVersion]
621+
622+ doFirst {
623+ delete " build-tools/typings"
624+
625+ workingDir " build-tools"
626+
627+ main " -jar"
628+
629+ paramz. add(" dts-generator.jar" );
630+ paramz. add(" -input" );
631+
632+ for (String jarPath : project. jarFiles) {
633+ // don't generate typings for runtime jars and classes
634+ if (shouldIncludeDirForTypings(jarPath, includeDirs)) {
635+ paramz. add(jarPath);
636+ }
637+ }
638+
639+ paramz. add(" -output" );
640+ paramz. add(" typings" );
641+
642+ args paramz. toArray();
643+ }
644+ }
645+
646+ generateTypescriptDefinitions. onlyIf {
647+ project. hasProperty(" generateTypings" ) && Boolean . parseBoolean(project. generateTypings)
648+ }
649+
650+ def shouldIncludeDirForTypings (path , includeDirs ) {
651+ for (String p : includeDirs) {
652+ if (path. indexOf(p) > -1 ) {
653+ return true ;
654+ }
655+ }
656+
657+ return false ;
658+ }
659+
660+ task copyTypings {
661+ doLast {
662+ println " Copied generated typings to application root level."
663+
664+ copy {
665+ from " $projectDir /build-tools/typings"
666+ into " $projectDir /../../"
667+ }
668+ }
669+ }
670+
671+ copyTypings. onlyIf({
672+ generateTypescriptDefinitions. didWork;
673+ })
674+
618675task myMergeDex {
619676 doLast {
620677 def prefix = " ${ buildDir} " . replace(' \\ ' , ' /' ) + " /intermediates/transforms/dex/"
@@ -670,7 +727,7 @@ task setProperties {
670727 }
671728}
672729
673- setProperties. finalizedBy(" asbg:generateBindings" )
730+ setProperties. finalizedBy(" asbg:generateBindings" , generateTypescriptDefinitions )
674731
675732// //////////////////////////////////////////////////////////////////////////////////
676733// //////////////////////////// EXECUTION ORDER /////////////////////////////////////
@@ -687,6 +744,7 @@ setProperties.finalizedBy("asbg:generateBindings")
687744ensureMetadataOutDir. dependsOn(cleanLocalAarFiles)
688745collectAllJars. dependsOn(ensureMetadataOutDir)
689746buildMetadata. dependsOn(collectAllJars)
747+ generateTypescriptDefinitions. finalizedBy(copyTypings)
690748
691749// DO NOT UNCOMMENT
692750// mergeAssets.dependsOn(copyMetadata) -> look in CONFIGURATIONS(top) in android.applicationVariants to see how it's done
0 commit comments