forked from NativeScript/nativescript-cli
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradle-build-args-service.ts
76 lines (60 loc) · 2.36 KB
/
gradle-build-args-service.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
import * as path from "path";
import { Configurations } from "../../common/constants";
export class GradleBuildArgsService implements IGradleBuildArgsService {
constructor(private $androidToolsInfo: IAndroidToolsInfo,
private $hooksService: IHooksService,
private $analyticsService: IAnalyticsService,
private $staticConfig: Config.IStaticConfig,
private $logger: ILogger) { }
public async getBuildTaskArgs(buildData: IAndroidBuildData): Promise<string[]> {
const args = this.getBaseTaskArgs(buildData);
args.unshift(this.getBuildTaskName(buildData));
if (await this.$analyticsService.isEnabled(this.$staticConfig.TRACK_FEATURE_USAGE_SETTING_NAME)) {
args.push("-PgatherAnalyticsData=true");
}
// allow modifying gradle args from a `before-build-task-args` hook
await this.$hooksService.executeBeforeHooks('build-task-args', { hookArgs: { args } });
return args;
}
public getCleanTaskArgs(buildData: IAndroidBuildData): string[] {
const args = this.getBaseTaskArgs(buildData);
args.unshift("clean");
return args;
}
private getBaseTaskArgs(buildData: IAndroidBuildData): string[] {
const args = this.getBuildLoggingArgs();
const toolsInfo = this.$androidToolsInfo.getToolsInfo({projectDir: buildData.projectDir});
args.push(
`-PcompileSdk=android-${toolsInfo.compileSdkVersion}`,
`-PtargetSdk=${toolsInfo.targetSdkVersion}`,
`-PbuildToolsVersion=${toolsInfo.buildToolsVersion}`,
`-PgenerateTypings=${toolsInfo.generateTypings}`
);
if (buildData.release) {
args.push(
"-Prelease",
`-PksPath=${path.resolve(buildData.keyStorePath)}`,
`-Palias=${buildData.keyStoreAlias}`,
`-Ppassword=${buildData.keyStoreAliasPassword}`,
`-PksPassword=${buildData.keyStorePassword}`
);
}
return args;
}
private getBuildLoggingArgs(): string[] {
const args = [];
const logLevel = this.$logger.getLevel();
if (logLevel === "TRACE") {
args.push("--stacktrace", "--debug");
} else if (logLevel === "INFO") {
args.push("--quiet");
}
return args;
}
private getBuildTaskName(buildData: IAndroidBuildData): string {
const baseTaskName = buildData.androidBundle ? "bundle" : "assemble";
const buildTaskName = buildData.release ? `${baseTaskName}${Configurations.Release}` : `${baseTaskName}${Configurations.Debug}`;
return buildTaskName;
}
}
$injector.register("gradleBuildArgsService", GradleBuildArgsService);