Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add uninstall option #1771

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/sdk-android/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
RnvPlatform,
logInfo,
RnvPlatformKey,
execCLI,
} from '@rnv/core';
import { parseAndroidManifestSync } from './manifestParser';
import {
Expand Down Expand Up @@ -186,7 +187,18 @@ export const getAndroidDeviceToRunOn = async () => {

export const runAndroid = async (device: AndroidDevice) => {
logDefault('runAndroid', `target:${device.udid}`);

const c = getContext();
const { uninstall } = c.program.opts();
if (uninstall) {
const packageId = getConfigProp('id');
if (packageId) {
try {
await execCLI(CLI_ANDROID_ADB, `uninstall ${packageId}`, { silent: true });
} catch (e) {
return Promise.reject(`Failed to uninstall ${packageId}`);
}
}
}
await runReactNativeAndroid(device);
};

Expand Down
4 changes: 4 additions & 0 deletions packages/sdk-android/src/taskOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ export const TaskOptions = createTaskOptionsMap([
altKey: 'resetAdb',
description: 'Forces to reset android adb',
},
{
key: 'uninstall',
description: 'Uninstall the app with the current id',
},
]);
1 change: 1 addition & 0 deletions packages/sdk-android/src/tasks/taskRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default createTask({
...RnvTaskOptionPresets.withRun(),
TaskOptions.resetAdb,
TaskOptions.skipTargetCheck,
TaskOptions.uninstall,
],
platforms: SdkPlatforms,
});
65 changes: 52 additions & 13 deletions packages/sdk-react-native/src/androidRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
CoreEnvVars,
ExecOptionsPresets,
getContext,
execCLI,
logWarning,

Check failure on line 16 in packages/sdk-react-native/src/androidRunner.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'logWarning' is defined but never used
inquirerPrompt,
} from '@rnv/core';
import { EnvVars } from './env';
import { getEntryFile } from '@rnv/sdk-utils';
Expand Down Expand Up @@ -95,20 +98,56 @@
if (udid) {
command += ` --deviceId=${udid}`;
}
const executeCommand = async () => {
return executeAsync(command, {
env: {
...CoreEnvVars.BASE(),
...CoreEnvVars.RNV_EXTENSIONS(),
...EnvVars.RCT_METRO_PORT(),
...EnvVars.RNV_REACT_NATIVE_PATH(),
...EnvVars.RNV_APP_ID(),
...EnvVars.RNV_SKIP_LINKING(),
},
cwd: appFolder,
// To display react-native CLI logs in RNV executed terminal
...ExecOptionsPresets.INHERIT_OUTPUT_NO_SPINNER,
});
};

return executeAsync(command, {
env: {
...CoreEnvVars.BASE(),
...CoreEnvVars.RNV_EXTENSIONS(),
...EnvVars.RCT_METRO_PORT(),
...EnvVars.RNV_REACT_NATIVE_PATH(),
...EnvVars.RNV_APP_ID(),
...EnvVars.RNV_SKIP_LINKING(),
},
cwd: appFolder,
//This is required to make rn cli logs visible in rnv executed terminal
...ExecOptionsPresets.INHERIT_OUTPUT_NO_SPINNER,
});
try {
return await executeCommand();
} catch (error) {
const packageId = getConfigProp('id');
if (packageId) {
const { confirm } = await inquirerPrompt({
name: 'confirm',
type: 'confirm',
message: `Failed to build the app. Try to uninstall and retry?`,
});

if (confirm) {
try {
await execCLI('androidAdb', `uninstall ${packageId}`, { silent: true });
} catch (e) {
return Promise.reject(`Failed to uninstall ${packageId}`);
}

return await executeCommand();
ElenaDiachenko marked this conversation as resolved.
Show resolved Hide resolved
} else {
if (typeof error === 'string') {
return Promise.reject(error);
} else if (error instanceof Error) {
return Promise.reject(error.message);
}
}
} else {
if (typeof error === 'string') {
return Promise.reject(error);
} else if (error instanceof Error) {
return Promise.reject(error.message);
}
}
}
};

export const buildReactNativeAndroid = async () => {
Expand Down
Loading