Skip to content

Commit

Permalink
Merge pull request #1771 from flexn-io/feat/add_uninstall_option
Browse files Browse the repository at this point in the history
Feat/add uninstall option
  • Loading branch information
ElenaDiachenko authored Nov 4, 2024
2 parents 27002cf + 5f15c31 commit e490af8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
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 @@ import {
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

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 @@ export const runReactNativeAndroid = async (device: { udid?: string } | undefine
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();
} 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

0 comments on commit e490af8

Please sign in to comment.