@@ -632,6 +632,63 @@ task buildMetadata (type: JavaExec) {
632632 }
633633}
634634
635+ task generateTypescriptDefinitions (type : JavaExec ) {
636+ def paramz = new ArrayList<String > ();
637+ def includeDirs = [" com.android.support" , " /platforms/" + android. compileSdkVersion]
638+
639+ doFirst {
640+ delete " build-tools/typings"
641+
642+ workingDir " build-tools"
643+
644+ main " -jar"
645+
646+ paramz. add(" dts-generator.jar" );
647+ paramz. add(" -input" );
648+
649+ for (String jarPath : project. jarFiles) {
650+ // don't generate typings for runtime jars and classes
651+ if (shouldIncludeDirForTypings(jarPath, includeDirs)) {
652+ paramz. add(jarPath);
653+ }
654+ }
655+
656+ paramz. add(" -output" );
657+ paramz. add(" typings" );
658+
659+ args paramz. toArray();
660+ }
661+ }
662+
663+ generateTypescriptDefinitions. onlyIf {
664+ project. hasProperty(" generateTypings" ) && Boolean . parseBoolean(project. generateTypings)
665+ }
666+
667+ def shouldIncludeDirForTypings (path , includeDirs ) {
668+ for (String p : includeDirs) {
669+ if (path. indexOf(p) > -1 ) {
670+ return true ;
671+ }
672+ }
673+
674+ return false ;
675+ }
676+
677+ task copyTypings {
678+ doLast {
679+ println " Copied generated typings to application root level."
680+
681+ copy {
682+ from " $projectDir /build-tools/typings"
683+ into " $projectDir /../../"
684+ }
685+ }
686+ }
687+
688+ copyTypings. onlyIf({
689+ generateTypescriptDefinitions. didWork;
690+ })
691+
635692task myMergeDex {
636693 doLast {
637694 def prefix = " ${ buildDir} " . replace(' \\ ' , ' /' ) + " /intermediates/transforms/dex/"
@@ -687,7 +744,7 @@ task setProperties {
687744 }
688745}
689746
690- setProperties. finalizedBy(" asbg:generateBindings" )
747+ setProperties. finalizedBy(" asbg:generateBindings" , generateTypescriptDefinitions )
691748
692749// //////////////////////////////////////////////////////////////////////////////////
693750// //////////////////////////// EXECUTION ORDER /////////////////////////////////////
@@ -704,6 +761,7 @@ setProperties.finalizedBy("asbg:generateBindings")
704761ensureMetadataOutDir. dependsOn(cleanLocalAarFiles)
705762collectAllJars. dependsOn(ensureMetadataOutDir)
706763buildMetadata. dependsOn(collectAllJars)
764+ generateTypescriptDefinitions. finalizedBy(copyTypings)
707765
708766// DO NOT UNCOMMENT
709767// mergeAssets.dependsOn(copyMetadata) -> look in CONFIGURATIONS(top) in android.applicationVariants to see how it's done
0 commit comments