Skip to content

Commit 67fdd0a

Browse files
authored
feat(typings): support --aar inputs (#5641)
1 parent d16a932 commit 67fdd0a

File tree

1 file changed

+50
-40
lines changed

1 file changed

+50
-40
lines changed

lib/commands/typings.ts

+50-40
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ export class TypingsCommand implements ICommand {
1414
private $projectData: IProjectData,
1515
private $mobileHelper: Mobile.IMobileHelper,
1616
private $childProcess: IChildProcess,
17-
private $hostInfo: IHostInfo,
17+
private $hostInfo: IHostInfo
1818
) {}
1919

2020
public async execute(args: string[]): Promise<void> {
2121
const platform = args[0];
22-
22+
let result;
2323
if (this.$mobileHelper.isAndroidPlatform(platform)) {
24-
await this.handleAndroidTypings();
25-
}
26-
27-
if (this.$mobileHelper.isiOSPlatform(platform)) {
28-
await this.handleiOSTypings();
24+
result = await this.handleAndroidTypings();
25+
} else if (this.$mobileHelper.isiOSPlatform(platform)) {
26+
result = await this.handleiOSTypings();
2927
}
3028
let typingsFolder = "./typings";
3129
if (this.$options.copyTo) {
@@ -35,10 +33,13 @@ export class TypingsCommand implements ICommand {
3533
);
3634
typingsFolder = this.$options.copyTo;
3735
}
38-
this.$logger.info(
39-
"Typings have been generated in the following directory:",
40-
typingsFolder
41-
);
36+
37+
if (result !== false) {
38+
this.$logger.info(
39+
"Typings have been generated in the following directory:",
40+
typingsFolder
41+
);
42+
}
4243
}
4344

4445
public async canExecute(args: string[]): Promise<boolean> {
@@ -48,17 +49,15 @@ export class TypingsCommand implements ICommand {
4849
}
4950

5051
private async handleAndroidTypings() {
51-
if (this.$options.aar) {
52-
return this.$logger.warn(`Open the .aar archive
53-
Extract the classes.jar and any dependencies it may have inside libs/
54-
Rename classes.jar if necessary
55-
56-
ns typings android --jar classes.jar --jar dependency-of-classes-jar.jar
57-
`);
58-
} else if (!this.$options.jar) {
59-
return this.$logger.warn(
60-
"No .jar file specified. Please specify a .jar file with --jar <Jar>."
52+
if (!(this.$options.jar || this.$options.aar)) {
53+
this.$logger.warn(
54+
[
55+
"No .jar or .aar file specified. Please specify at least one of the following:",
56+
" - path to .jar file with --jar <jar>",
57+
" - path to .aar file with --aar <aar>",
58+
].join("\n")
6159
);
60+
return false;
6261
}
6362

6463
this.$fs.ensureDirectoryExists(
@@ -82,25 +81,36 @@ ns typings android --jar classes.jar --jar dependency-of-classes-jar.jar
8281
);
8382
}
8483

85-
if (this.$options.jar) {
86-
const jars: string[] =
87-
typeof this.$options.jar === "string"
88-
? [this.$options.jar]
89-
: this.$options.jar;
90-
await this.$childProcess.spawnFromEvent(
91-
"java",
92-
[
93-
"-jar",
94-
dtsGeneratorPath,
95-
"-input",
96-
...jars,
97-
"-output",
98-
path.resolve(this.$projectData.projectDir, "typings", "android"),
99-
],
100-
"exit",
101-
{ stdio: "inherit" }
102-
);
103-
}
84+
const asArray = (input: string | string[]) => {
85+
if (!input) {
86+
return [];
87+
}
88+
89+
if (typeof input === "string") {
90+
return [input];
91+
}
92+
93+
return input;
94+
};
95+
96+
const inputs: string[] = [
97+
...asArray(this.$options.jar),
98+
...asArray(this.$options.aar),
99+
];
100+
101+
await this.$childProcess.spawnFromEvent(
102+
"java",
103+
[
104+
"-jar",
105+
dtsGeneratorPath,
106+
"-input",
107+
...inputs,
108+
"-output",
109+
path.resolve(this.$projectData.projectDir, "typings", "android"),
110+
],
111+
"exit",
112+
{ stdio: "inherit" }
113+
);
104114
}
105115

106116
private async handleiOSTypings() {

0 commit comments

Comments
 (0)