Skip to content

Commit 3ba56dc

Browse files
authored
Merge pull request #28 from NativeScript/trifonov/improve-generation
improve generation
2 parents 282560b + f1f45af commit 3ba56dc

File tree

7 files changed

+21
-17
lines changed

7 files changed

+21
-17
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ Rename classes.jar if necessary
4747
```shell
4848
java -jar build\libs\dts-generator.jar -input classes.jar dependency-of-classes-jar.jar
4949
```
50+
51+
## Support libraries
52+
In the [lib](lib) folder there are android support libraries jars which are get from the following git repos:
53+
* [android-support-v4](https://github.com/dandar3/android-support-v4/tree/master/libs)
54+
* [android-support-v7-appcompat](https://github.com/dandar3/android-support-v7-appcompat/tree/master/libs)
55+
* [android-support-design](https://github.com/dandar3/android-support-design/tree/master/libs)

dts-generator/src/main/java/com/telerik/dts/DtsApi.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public class DtsApi {
3636
private Map<String, String> aliasedTypes;
3737
private String[] namespaceParts;
3838
private int indent = 0;
39+
private boolean writeMultipleFiles;
3940

40-
public DtsApi() {
41+
public DtsApi(boolean writeMultipleFiles) {
42+
this.writeMultipleFiles = writeMultipleFiles;
4143
this.indent = 0;
4244

4345
overrideFieldComparator();
@@ -157,10 +159,12 @@ public String generateDtsContent(List<JavaClass> javaClasses) {
157159
String[] refs = references.toArray(new String[references.size()]);
158160
Arrays.sort(refs);
159161

160-
for (String r : refs) {
161-
sbHeaders.append("/// <reference path=\"./");
162-
sbHeaders.append(r);
163-
sbHeaders.appendln(".d.ts\" />");
162+
if(this.writeMultipleFiles) {
163+
for (String r : refs) {
164+
sbHeaders.append("/// <reference path=\"./");
165+
sbHeaders.append(r);
166+
sbHeaders.appendln(".d.ts\" />");
167+
}
164168
}
165169
}
166170

dts-generator/src/main/java/com/telerik/dts/FileWriter.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class FileWriter {
1818
private boolean writeMultipleFiles;
1919
private PrintStream ps;
2020
private File outDir;
21-
private boolean isFirstRun = true;
2221

2322
public FileWriter(File outDir, boolean writeMultipleFiles) {
2423
this.writeMultipleFiles = writeMultipleFiles;
@@ -37,12 +36,6 @@ public void write(String content, String fileName) {
3736
String outFile = this.outDir.getAbsolutePath() + File.separator + this.defaultDtsFileName + ".d.ts";
3837
this.ps = new PrintStream(new FileOutputStream(outFile, /*append*/true));
3938

40-
// add helpers reference to the top of the file
41-
if(this.isFirstRun) {
42-
ps.println("/// <reference path=\"./_helpers.d.ts\" />");
43-
this.isFirstRun = false;
44-
}
45-
4639
this.ps.print(content);
4740
this.ps.println();
4841
}
@@ -58,11 +51,12 @@ public void write(String content, String fileName) {
5851

5952
public void writeHelperTypings(String content, boolean append) {
6053
try {
61-
String outFile = this.outDir.getAbsolutePath() + File.separator + "_helpers.d.ts";
62-
this.ps = new PrintStream(new FileOutputStream(outFile, append));
54+
String outFile = this.outDir.getAbsolutePath() + File.separator +
55+
(this.writeMultipleFiles ? "_helpers.d.ts": (this.defaultDtsFileName + ".d.ts"));
56+
this.ps = new PrintStream(new FileOutputStream(outFile, append));
6357

64-
this.ps.print(content);
65-
this.ps.println();
58+
this.ps.print(content);
59+
this.ps.println();
6660
} catch (FileNotFoundException e) {
6761
e.printStackTrace();
6862
}

dts-generator/src/main/java/com/telerik/dts/Generator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Generator {
2121
public void start(InputParameters inputParameters) throws IOException {
2222
outFolder = inputParameters.getOutputDir();
2323
this.fw = new FileWriter(inputParameters.getOutputDir(), inputParameters.isGenerateMultipleFiles());
24-
this.dtsApi = new DtsApi();
24+
this.dtsApi = new DtsApi(inputParameters.isGenerateMultipleFiles());
2525

2626
loadJavaClasses(inputParameters.getInputJars());
2727
ClassRepo.sortCachedProviders();
Binary file not shown.
792 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)