Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
[xdl][cli] Add support for --latest flag in client:install:x (#2804)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne authored Oct 19, 2020
1 parent 6ba2cf1 commit 1c1fcee
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 27 deletions.
109 changes: 88 additions & 21 deletions packages/expo-cli/src/commands/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,47 @@ export default function (program: Command) {
program
.command('client:install:ios')
.description('Install the Expo client for iOS on the simulator')
.option(
'--latest',
'Ignore the local project version and install the latest available version of Expo client'
)
.helpGroup('client')
.asyncAction(async () => {
.asyncAction(async (command: Command) => {
const forceLatest = !!command.latest;
const currentSdkConfig = await ClientUpgradeUtils.getExpoSdkConfig(process.cwd());
const currentSdkVersion = currentSdkConfig ? currentSdkConfig.sdkVersion : undefined;
const sdkVersions = await Versions.sdkVersionsAsync();
const latestSdk = await Versions.newestReleasedSdkVersionAsync();
const currentSdk = sdkVersions[currentSdkVersion!];
const recommendedClient = ClientUpgradeUtils.getClient('ios', currentSdk);
const latestClient = ClientUpgradeUtils.getClient('ios', latestSdk.data);

if (forceLatest) {
if (!latestClient?.url) {
log.error(
`Unable to find latest client version. Check your internet connection or run this command again without the ${chalk.bold(
'--latest'
)} flag.`
);
return;
}

if (
await Simulator.upgradeExpoAsync({ url: latestClient.url, version: latestClient.version })
) {
log('Done!');
} else {
log.error(`Unable to install Expo client ${latestClient.version} for iOS.`);
}
return;
}

if (!currentSdkVersion) {
log(
'Could not find your Expo project. If you run this from a project, we can help pick the right Expo client version!'
);
}

const sdkVersions = await Versions.sdkVersionsAsync();
const latestSdk = await Versions.newestReleasedSdkVersionAsync();
const currentSdk = sdkVersions[currentSdkVersion!];
const recommendedClient = ClientUpgradeUtils.getClient('ios', currentSdk);
const latestClient = ClientUpgradeUtils.getClient('ios', latestSdk.data);

if (currentSdk && !recommendedClient) {
log(
`You are currently using SDK ${currentSdkVersion}. Unfortunately, we couldn't detect the proper client version for this SDK.`
Expand All @@ -318,7 +342,10 @@ export default function (program: Command) {
message: `You are currently using SDK ${currentSdkVersion}. Would you like to install client ${recommendedClientVersion} released for this SDK?`,
});
if (answer) {
await Simulator.upgradeExpoAsync({ url: recommendedClient.url });
await Simulator.upgradeExpoAsync({
url: recommendedClient.url,
version: recommendedClient.version,
});
log('Done!');
return;
}
Expand All @@ -329,7 +356,10 @@ export default function (program: Command) {
: 'Do you want to install the latest client?',
});
if (answer) {
await Simulator.upgradeExpoAsync({ url: latestClient?.url });
await Simulator.upgradeExpoAsync({
url: latestClient?.url,
version: latestClient?.version,
});
log('Done!');
return;
}
Expand All @@ -348,7 +378,10 @@ export default function (program: Command) {
: "It looks like we don't have a compatible client. Do you want to try the latest client?",
});
if (answer) {
await Simulator.upgradeExpoAsync({ url: latestClient?.url });
await Simulator.upgradeExpoAsync({
url: latestClient?.url,
version: latestClient?.version,
});
log('Done!');
} else {
log('No client to install');
Expand All @@ -370,23 +403,48 @@ export default function (program: Command) {
program
.command('client:install:android')
.description('Install the Expo client for Android on a connected device or emulator')
.option(
'--latest',
'Ignore the local project version and install the latest available version of Expo client'
)
.helpGroup('client')
.asyncAction(async () => {
.asyncAction(async (command: Command) => {
const forceLatest = !!command.latest;
const currentSdkConfig = await ClientUpgradeUtils.getExpoSdkConfig(process.cwd());
const currentSdkVersion = currentSdkConfig ? currentSdkConfig.sdkVersion : undefined;
const sdkVersions = await Versions.sdkVersionsAsync();
const latestSdk = await Versions.newestReleasedSdkVersionAsync();
const currentSdk = sdkVersions[currentSdkVersion!];
const recommendedClient = ClientUpgradeUtils.getClient('android', currentSdk);
const latestClient = ClientUpgradeUtils.getClient('android', latestSdk.data);

if (forceLatest) {
if (!latestClient?.url) {
log.error(
`Unable to find latest client version. Check your internet connection or run this command again without the ${chalk.bold(
'--latest'
)} flag.`
);
return;
}

if (
await Android.upgradeExpoAsync({ url: latestClient.url, version: latestClient.version })
) {
log('Done!');
} else {
log.error(`Unable to install Expo client ${latestClient.version} for Android.`);
}

return;
}

if (!currentSdkVersion) {
log(
'Could not find your Expo project. If you run this from a project, we can help pick the right Expo client version!'
);
}

const sdkVersions = await Versions.sdkVersionsAsync();
const latestSdk = await Versions.newestReleasedSdkVersionAsync();
const currentSdk = sdkVersions[currentSdkVersion!];
const recommendedClient = ClientUpgradeUtils.getClient('android', currentSdk);
const latestClient = ClientUpgradeUtils.getClient('android', latestSdk.data);

if (currentSdk && !recommendedClient) {
log(
`You are currently using SDK ${currentSdkVersion}. Unfortunately, we couldn't detect the proper client version for this SDK.`
Expand All @@ -399,7 +457,10 @@ export default function (program: Command) {
message: `You are currently using SDK ${currentSdkVersion}. Would you like to install client ${recommendedClientVersion} released for this SDK?`,
});
if (answer) {
await Android.upgradeExpoAsync(recommendedClient.url);
await Android.upgradeExpoAsync({
url: recommendedClient.url,
version: recommendedClient.version,
});
log('Done!');
return;
}
Expand All @@ -410,7 +471,10 @@ export default function (program: Command) {
: 'Do you want to install the latest client?',
});
if (answer) {
await Android.upgradeExpoAsync(latestClient?.url);
await Android.upgradeExpoAsync({
url: latestClient?.url,
version: latestClient?.version,
});
log('Done!');
return;
}
Expand All @@ -429,7 +493,10 @@ export default function (program: Command) {
: "It looks like we don't have a compatible client. Do you want to try the latest client?",
});
if (answer) {
await Android.upgradeExpoAsync(latestClient?.url);
await Android.upgradeExpoAsync({
url: latestClient?.url,
version: latestClient?.version,
});
log('Done!');
} else {
log('No client to install');
Expand All @@ -443,7 +510,7 @@ export default function (program: Command) {
clients: availableClients,
});

if (await Android.upgradeExpoAsync(targetClient.clientUrl)) {
if (await Android.upgradeExpoAsync({ url: targetClient.clientUrl })) {
log('Done!');
}
});
Expand Down
25 changes: 21 additions & 4 deletions packages/xdl/src/Android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,15 @@ export async function downloadApkAsync(
return apkPath;
}

export async function installExpoAsync({ device, url }: { device: Device; url?: string }) {
export async function installExpoAsync({
device,
url,
version,
}: {
device: Device;
url?: string;
version?: string;
}) {
const bar = new ProgressBar('Downloading the Expo client app [:bar] :percent :etas', {
total: 100,
width: 64,
Expand All @@ -403,7 +411,11 @@ export async function installExpoAsync({ device, url }: { device: Device; url?:
const path = await downloadApkAsync(url, progress => bar.tick(1, progress));
Logger.notifications.info({ code: NotificationCode.STOP_LOADING });

Logger.global.info(`Installing Expo client on device`);
if (version) {
Logger.global.info(`Installing Expo client ${version} on device`);
} else {
Logger.global.info(`Installing Expo client on device`);
}
Logger.notifications.info({ code: NotificationCode.START_LOADING });
warningTimer = setWarningTimer();
const result = await getAdbOutputAsync(adbPidArgs(device.pid, 'install', path));
Expand Down Expand Up @@ -444,7 +456,12 @@ export async function uninstallExpoAsync(device: Device): Promise<string | undef
}
}

export async function upgradeExpoAsync(url?: string): Promise<boolean> {
export async function upgradeExpoAsync(options?: {
url?: string;
version?: string;
}): Promise<boolean> {
const { url, version } = options || {};

try {
const devices = await getAttachedDevicesAsync();
if (!devices.length) {
Expand All @@ -457,7 +474,7 @@ export async function upgradeExpoAsync(url?: string): Promise<boolean> {
}

await uninstallExpoAsync(device);
await installExpoAsync({ device, url });
await installExpoAsync({ device, url, version });
if (_lastUrl) {
Logger.global.info(`Opening ${_lastUrl} in Expo.`);
await getAdbOutputAsync([
Expand Down
16 changes: 14 additions & 2 deletions packages/xdl/src/Simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,11 @@ export async function _downloadSimulatorAppAsync(
export async function installExpoOnSimulatorAsync({
url,
simulator,
version,
}: {
simulator: Pick<SimControl.Device, 'name' | 'udid'>;
url?: string;
version?: string;
}) {
const bar = new ProgressBar(
`Installing the Expo client app on ${simulator.name} [:bar] :percent :etas`,
Expand Down Expand Up @@ -461,7 +463,12 @@ export async function installExpoOnSimulatorAsync({
const dir = await _downloadSimulatorAppAsync(url, progress => bar.tick(1, progress));
Logger.notifications.info({ code: NotificationCode.STOP_LOADING });

Logger.global.info(`Installing Expo client on ${simulator.name}`);
if (version) {
Logger.global.info(`Installing Expo client ${version} on ${simulator.name}`);
} else {
Logger.global.info(`Installing Expo client on ${simulator.name}`);
}

Logger.notifications.info({ code: NotificationCode.START_LOADING });
warningTimer = setWarningTimer();

Expand Down Expand Up @@ -495,6 +502,7 @@ export async function upgradeExpoAsync(
options: {
udid?: string;
url?: string;
version?: string;
} = {}
): Promise<boolean> {
if (!(await isSimulatorInstalledAsync())) {
Expand All @@ -504,7 +512,11 @@ export async function upgradeExpoAsync(
const simulator = await ensureSimulatorOpenAsync(options);

await uninstallExpoAppFromSimulatorAsync(simulator);
const installResult = await installExpoOnSimulatorAsync({ url: options.url, simulator });
const installResult = await installExpoOnSimulatorAsync({
url: options.url,
version: options.version,
simulator,
});
if (installResult.status !== 0) {
return false;
}
Expand Down

0 comments on commit 1c1fcee

Please sign in to comment.