Skip to content

Commit 9fa8f4f

Browse files
committed
Merge branch 'master' into chore/doctor-cleanup
2 parents 7c3e562 + 3b42042 commit 9fa8f4f

30 files changed

+368
-352
lines changed

lib/commands/plugin/build-plugin.ts

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export class BuildPluginCommand implements ICommand {
5252
);
5353

5454
const options: IPluginBuildOptions = {
55+
gradlePath: this.$options.gradlePath,
56+
gradleArgs: this.$options.gradleArgs,
5557
aarOutputDir: platformsAndroidPath,
5658
platformsAndroidDirPath: platformsAndroidPath,
5759
pluginName: pluginName,

lib/common/commands/device/list-devices.ts

+22-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ export class ListDevicesCommand implements ICommand {
2020
public allowedParameters = [this.$stringParameter];
2121

2222
public async execute(args: string[]): Promise<void> {
23+
const devices: {
24+
available?: any[];
25+
devices: any[];
26+
} = {
27+
devices: [],
28+
};
29+
2330
if (this.$options.availableDevices) {
2431
const platform = this.$mobileHelper.normalizePlatformName(args[0]);
2532
if (!platform && args[0]) {
@@ -38,10 +45,17 @@ export class ListDevicesCommand implements ICommand {
3845
const emulators = this.$emulatorHelper.getEmulatorsFromAvailableEmulatorsOutput(
3946
availableEmulatorsOutput
4047
);
41-
this.printEmulators("\nAvailable emulators", emulators);
48+
devices.available = emulators;
49+
50+
if (!this.$options.json) {
51+
this.printEmulators("\nAvailable emulators", emulators);
52+
}
53+
}
54+
55+
if (!this.$options.json) {
56+
this.$logger.info("\nConnected devices & emulators");
4257
}
4358

44-
this.$logger.info("\nConnected devices & emulators");
4559
let index = 1;
4660
await this.$devicesService.initialize({
4761
platform: args[0],
@@ -67,7 +81,7 @@ export class ListDevicesCommand implements ICommand {
6781
let action: (_device: Mobile.IDevice) => Promise<void>;
6882
if (this.$options.json) {
6983
action = async (device) => {
70-
this.$logger.info(JSON.stringify(device.deviceInfo));
84+
devices.devices.push(device.deviceInfo);
7185
};
7286
} else {
7387
action = async (device) => {
@@ -89,7 +103,11 @@ export class ListDevicesCommand implements ICommand {
89103
allowNoDevices: true,
90104
});
91105

92-
if (!this.$options.json && table.length) {
106+
if (this.$options.json) {
107+
return this.$logger.info(JSON.stringify(devices, null, 2));
108+
}
109+
110+
if (table.length) {
93111
this.$logger.info(table.toString());
94112
}
95113
}

lib/common/file-system.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class FileSystem implements IFileSystem {
174174
}
175175

176176
public async futureFromEvent(eventEmitter: any, event: string): Promise<any> {
177-
return new Promise((resolve, reject) => {
177+
return new Promise<any>((resolve, reject) => {
178178
eventEmitter.once(event, function () {
179179
const args = _.toArray(arguments);
180180

@@ -186,7 +186,7 @@ export class FileSystem implements IFileSystem {
186186

187187
switch (args.length) {
188188
case 0:
189-
resolve();
189+
resolve(undefined);
190190
break;
191191
case 1:
192192
resolve(args[0]);

lib/common/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export function settlePromises<T>(promises: Promise<T>[]): Promise<T[]> {
198198
const length = promises.length;
199199

200200
if (!promises.length) {
201-
resolve();
201+
resolve(null);
202202
}
203203

204204
_.forEach(promises, (currentPromise, index) => {
@@ -491,7 +491,7 @@ export async function getFuturesResults<T>(
491491
): Promise<T[] | T[][]> {
492492
const results = await Promise.all(promises);
493493

494-
return _(results).filter(predicate).flatten().value();
494+
return _(results).filter(predicate).flatten().value() as T[] | T[][];
495495
}
496496

497497
/**

lib/common/mobile/application-manager-base.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,25 @@ export abstract class ApplicationManagerBase
117117
}
118118
}
119119

120-
public abstract async installApplication(
120+
public abstract installApplication(
121121
packageFilePath: string,
122122
appIdentifier?: string,
123123
buildData?: IBuildData
124124
): Promise<void>;
125-
public abstract async uninstallApplication(
125+
public abstract uninstallApplication(
126126
appIdentifier: string
127127
): Promise<void>;
128-
public abstract async startApplication(
128+
public abstract startApplication(
129129
appData: Mobile.IApplicationData
130130
): Promise<void>;
131-
public abstract async stopApplication(
131+
public abstract stopApplication(
132132
appData: Mobile.IApplicationData
133133
): Promise<void>;
134-
public abstract async getInstalledApplications(): Promise<string[]>;
135-
public abstract async getDebuggableApps(): Promise<
134+
public abstract getInstalledApplications(): Promise<string[]>;
135+
public abstract getDebuggableApps(): Promise<
136136
Mobile.IDeviceApplicationInformation[]
137137
>;
138-
public abstract async getDebuggableAppViews(
138+
public abstract getDebuggableAppViews(
139139
appIdentifiers: string[]
140140
): Promise<IDictionary<Mobile.IDebugWebViewInfo[]>>;
141141

lib/common/mobile/ios/device/ios-device-operations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class IOSDeviceOperations
8484
}
8585

8686
// We need this because we need to make sure that we have devices.
87-
await new Promise((resolve, reject) => {
87+
await new Promise<void>((resolve, reject) => {
8888
let iterationsCount = 0;
8989
const maxIterationsCount = 3;
9090

lib/common/mobile/ios/ios-device-base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
5757
}, `ios-debug-socket-${this.deviceInfo.identifier}-${appId}.lock`);
5858
}
5959

60-
protected abstract async getDebugSocketCore(
60+
protected abstract getDebugSocketCore(
6161
appId: string
6262
): Promise<net.Socket>;
6363

lib/common/mobile/mobile-core/devices-service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,9 @@ export class DevicesService
882882
return;
883883
}
884884

885-
this.$logger.info("Searching for devices...");
885+
if (!this.$options.json) {
886+
this.$logger.info("Searching for devices...");
887+
}
886888

887889
deviceInitOpts = deviceInitOpts || {};
888890
this._data = deviceInitOpts;

lib/common/test/unit-tests/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe("helpers", () => {
9999
element: any,
100100
passedChunkSize: number
101101
) => {
102-
return new Promise((resolve) =>
102+
return new Promise<void>((resolve) =>
103103
setImmediate(() => {
104104
const remainingElements = _.difference(
105105
initialDataValues,

lib/common/test/unit-tests/mobile/devices-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ function resetDefaultSetInterval(): void {
300300
}
301301

302302
async function assertOnNextTick(assertionFunction: Function): Promise<void> {
303-
await new Promise((resolve) => {
303+
await new Promise<void>((resolve) => {
304304
setTimeout(() => {
305305
assertionFunction();
306306
resolve();

lib/data/build-data.ts

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export class AndroidBuildData extends BuildData {
4747
public keyStoreAliasPassword: string;
4848
public keyStorePassword: string;
4949
public androidBundle: boolean;
50+
public gradlePath: string;
51+
public gradleArgs: string;
5052

5153
constructor(projectDir: string, platform: string, data: any) {
5254
super(projectDir, platform, data);
@@ -56,5 +58,7 @@ export class AndroidBuildData extends BuildData {
5658
this.keyStoreAliasPassword = data.keyStoreAliasPassword;
5759
this.keyStorePassword = data.keyStorePassword;
5860
this.androidBundle = data.androidBundle || data.aab;
61+
this.gradlePath = data.gradlePath;
62+
this.gradleArgs = data.gradleArgs;
5963
}
6064
}

lib/declarations.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ interface IAndroidBundleOptions {
579579
aab: boolean;
580580
}
581581

582+
interface IAndroidOptions {
583+
gradlePath: string;
584+
gradleArgs: string;
585+
}
586+
582587
interface ITypingsOptions {
583588
jar: string;
584589
aar: string;
@@ -598,6 +603,7 @@ interface IOptions
598603
IClean,
599604
IProvision,
600605
ITeamIdentifier,
606+
IAndroidOptions,
601607
IAndroidReleaseOptions,
602608
IAndroidBundleOptions,
603609
INpmInstallConfigurationOptions,

lib/definitions/android-plugin-migrator.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ interface IAndroidBuildOptions {
1010
pluginName: string;
1111
aarOutputDir: string;
1212
tempPluginDirPath: string;
13+
gradlePath?: string;
14+
gradleArgs?: string;
1315
}
1416

1517
interface IAndroidPluginBuildService {
@@ -37,4 +39,14 @@ interface IBuildAndroidPluginData extends Partial<IProjectDir> {
3739
* Information about tools that will be used to build the plugin, for example compile SDK version, build tools version, etc.
3840
*/
3941
androidToolsInfo?: IAndroidToolsInfoData;
42+
43+
/**
44+
* Optional custom Gradle path.
45+
*/
46+
gradlePath?: string;
47+
48+
/**
49+
* Optional custom Gradle arguments.
50+
*/
51+
gradleArgs?: string,
4052
}

lib/definitions/build.d.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ interface IiOSBuildData extends IBuildData {
2929
interface IAndroidBuildData
3030
extends IBuildData,
3131
IAndroidSigningData,
32-
IHasAndroidBundle {}
32+
IHasAndroidBundle {
33+
gradlePath?: string;
34+
gradleArgs?: string;
35+
}
3336

3437
interface IAndroidSigningData {
3538
keyStoreAlias: string;

lib/definitions/gradle.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface IGradleCommandOptions {
1313
message?: string;
1414
stdio?: string;
1515
spawnOptions?: ISpawnFromEventOptions;
16+
gradlePath?: string;
1617
}
1718

1819
interface IGradleBuildService {

lib/options.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as helpers from "./common/helpers";
2-
import * as yargs from "yargs";
2+
import * as yargs from 'yargs';
3+
import { hideBin } from 'yargs/helpers';
34
import * as _ from "lodash";
45
import {
56
IDictionary,
@@ -215,6 +216,8 @@ export class Options {
215216
default: false,
216217
hasSensitiveValue: false,
217218
},
219+
gradlePath: { type: OptionType.String, hasSensitiveValue: false },
220+
gradleArgs: { type: OptionType.String, hasSensitiveValue: false },
218221
aab: { type: OptionType.Boolean, hasSensitiveValue: false },
219222
performance: { type: OptionType.Object, hasSensitiveValue: true },
220223
appleApplicationSpecificPassword: {
@@ -364,9 +367,9 @@ export class Options {
364367
opts[this.getDashedOptionName(key)] = value;
365368
});
366369

367-
const parsed = yargs(process.argv.slice(2)).version(false).help(false);
368-
this.initialArgv = parsed.argv;
369-
this.argv = parsed.options(<any>opts).argv;
370+
const parsed = yargs(hideBin(process.argv)).version(false).help(false);
371+
this.initialArgv = parsed.argv as any;
372+
this.argv = parsed.options(<any>opts).argv as any;
370373

371374
// For backwards compatibility
372375
// Previously profileDir had a default option and calling `this.$options.profileDir` always returned valid result.

lib/services/android-plugin-build-service.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
IWatchIgnoreListService,
1818
} from "../declarations";
1919
import { IPlatformsDataService } from "../definitions/platform";
20-
import { IProjectDataService } from "../definitions/project";
20+
import { IProjectData, IProjectDataService } from "../definitions/project";
2121
import {
2222
IAndroidPluginBuildService,
2323
IPluginBuildOptions,
@@ -49,6 +49,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
4949
private $androidToolsInfo: IAndroidToolsInfo,
5050
private $logger: ILogger,
5151
private $packageManager: INodePackageManager,
52+
private $projectData: IProjectData,
5253
private $projectDataService: IProjectDataService,
5354
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
5455
private $errors: IErrors,
@@ -260,6 +261,8 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
260261
options.projectDir
261262
);
262263
await this.buildPlugin({
264+
gradlePath: options.gradlePath,
265+
gradleArgs: options.gradleArgs,
263266
pluginDir: pluginTempDir,
264267
pluginName: options.pluginName,
265268
projectDir: options.projectDir,
@@ -715,15 +718,22 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
715718
);
716719
}
717720

718-
const gradlew = this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew";
721+
const gradlew =
722+
pluginBuildSettings.gradlePath ??
723+
(this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew");
719724

720725
const localArgs = [
721726
"-p",
722727
pluginBuildSettings.pluginDir,
723728
"assembleRelease",
724729
`-PcompileSdk=android-${pluginBuildSettings.androidToolsInfo.compileSdkVersion}`,
725730
`-PbuildToolsVersion=${pluginBuildSettings.androidToolsInfo.buildToolsVersion}`,
731+
`-PappPath=${this.$projectData.getAppDirectoryPath()}`,
732+
`-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}`
726733
];
734+
if (pluginBuildSettings.gradleArgs) {
735+
localArgs.push(pluginBuildSettings.gradleArgs);
736+
}
727737

728738
if (this.$logger.getLevel() === "INFO") {
729739
localArgs.push("--quiet");

lib/services/android-project-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
6161
$fs: IFileSystem,
6262
private $logger: ILogger,
6363
$projectDataService: IProjectDataService,
64+
private $options: IOptions,
6465
private $injector: IInjector,
6566
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
6667
private $androidPluginBuildService: IAndroidPluginBuildService,
@@ -603,6 +604,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
603604
);
604605
if (this.$fs.exists(pluginPlatformsFolderPath)) {
605606
const options: IPluginBuildOptions = {
607+
gradlePath: this.$options.gradlePath,
608+
gradleArgs: this.$options.gradleArgs,
606609
projectDir: projectData.projectDir,
607610
pluginName: pluginData.name,
608611
platformsAndroidDirPath: pluginPlatformsFolderPath,

lib/services/android/gradle-build-args-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export class GradleBuildArgsService implements IGradleBuildArgsService {
6464
`-PappPath=${this.$projectData.getAppDirectoryPath()}`,
6565
`-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}`
6666
);
67+
if (buildData.gradleArgs) {
68+
args.push(buildData.gradleArgs);
69+
}
6770

6871
if (buildData.release) {
6972
args.push(

lib/services/android/gradle-build-service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class GradleBuildService
3636
cwd: projectRoot,
3737
message: "Gradle build...",
3838
stdio: buildData.buildOutputStdio,
39+
gradlePath: buildData.gradlePath,
3940
spawnOptions,
4041
};
4142

@@ -60,6 +61,7 @@ export class GradleBuildService
6061
const gradleCommandOptions = {
6162
cwd: projectRoot,
6263
message: "Gradle clean...",
64+
gradlePath: buildData.gradlePath,
6365
};
6466
await this.$gradleCommandService.executeCommand(
6567
cleanTaskArgs,

lib/services/android/gradle-command-service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export class GradleCommandService implements IGradleCommandService {
2727
this.$logger.info(message);
2828

2929
const childProcessOptions = { cwd, stdio: stdio || "inherit" };
30-
const gradleExecutable = this.$hostInfo.isWindows
31-
? "gradlew.bat"
32-
: "./gradlew";
30+
const gradleExecutable =
31+
options.gradlePath ??
32+
(this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew");
3333

3434
const result = await this.executeCommandSafe(
3535
gradleExecutable,

0 commit comments

Comments
 (0)