forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypings.ts
128 lines (114 loc) · 3.29 KB
/
typings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { IOptions } from "../declarations";
import { IChildProcess, IFileSystem } from "../common/declarations";
import { ICommand, ICommandParameter } from "../common/definitions/commands";
import { injector } from "../common/yok";
import { IProjectData } from "../definitions/project";
import * as path from "path";
export class TypingsCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];
constructor(
private $logger: ILogger,
private $options: IOptions,
private $fs: IFileSystem,
private $projectData: IProjectData,
private $mobileHelper: Mobile.IMobileHelper,
private $childProcess: IChildProcess
) {}
public async execute(args: string[]): Promise<void> {
const platform = args[0];
if (this.$mobileHelper.isAndroidPlatform(platform)) {
await this.handleAndroidTypings();
}
if (this.$mobileHelper.isiOSPlatform(platform)) {
await this.handleiOSTypings();
}
let typingsFolder = "./typings";
if (this.$options.copyTo) {
this.$fs.copyFile(
path.resolve(this.$projectData.projectDir, "typings"),
this.$options.copyTo
);
typingsFolder = this.$options.copyTo;
}
this.$logger.info(
"Typing have been generated in the following directory:",
typingsFolder
);
}
public async canExecute(args: string[]): Promise<boolean> {
const platform = args[0];
this.$mobileHelper.validatePlatformName(platform);
return true;
}
private async handleAndroidTypings() {
if (this.$options.aar) {
return this.$logger.warn(`Open the .aar archive
Extract the classes.jar and any dependencies it may have inside libs/
Rename classes.jar if necessary
ns typings android --jar classes.jar --jar dependency-of-classes-jar.jar
`);
} else if (!this.$options.jar) {
return this.$logger.warn(
"No .jar file specified. Please specify a .jar file with --jar <Jar>."
);
}
this.$fs.ensureDirectoryExists(
path.resolve(this.$projectData.projectDir, "typings", "android")
);
const dtsGeneratorPath = path.resolve(
this.$projectData.projectDir,
"platforms",
"android",
"build-tools",
"dts-generator.jar"
);
if (!this.$fs.exists(dtsGeneratorPath)) {
this.$logger.warn("No platforms folder found, preparing project now...");
await this.$childProcess.spawnFromEvent(
"ns",
["prepare", "android"],
"exit",
{ stdio: "inherit" }
);
}
if (this.$options.jar) {
const jars: string[] =
typeof this.$options.jar === "string"
? [this.$options.jar]
: this.$options.jar;
await this.$childProcess.spawnFromEvent(
"java",
[
"-jar",
dtsGeneratorPath,
"-input",
...jars,
"-output",
path.resolve(this.$projectData.projectDir, "typings", "android"),
],
"exit",
{ stdio: "inherit" }
);
}
}
private async handleiOSTypings() {
if (this.$options.filter !== undefined) {
this.$logger.warn("--filter flag is not supported yet.");
}
this.$fs.ensureDirectoryExists(
path.resolve(this.$projectData.projectDir, "typings", "ios")
);
await this.$childProcess.spawnFromEvent("ns", ["build", "ios"], "exit", {
env: {
...process.env,
TNS_TYPESCRIPT_DECLARATIONS_PATH: path.resolve(
this.$projectData.projectDir,
"typings",
"ios"
),
},
stdio: "inherit",
});
}
}
injector.registerCommand("typings", TypingsCommand);