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

rnv target fixes #1383

Merged
merged 11 commits into from
Feb 9, 2024
10 changes: 5 additions & 5 deletions packages/core/src/system/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ export const writeCleanFile = (
// console.log('writeCleanFile', destination);
const api = getApi();
if (!fs.existsSync(source)) {
logError(`Cannot write file. source path doesn't exists: ${source}`);
logError(`Cannot write file. source path doesn't exist: ${source}`);
return;
}
if (!fs.existsSync(destination)) {
logDebug(`destination path doesn't exists: ${destination}. will create new one`);
logDebug(`destination path doesn't exist: ${destination}. will create new one`);
// return;
}
const ext = path.extname(source);
Expand Down Expand Up @@ -164,7 +164,7 @@ export const readCleanFile = (source: string, overrides?: OverridesOptions) => {
// logTask(`writeCleanFile`)
// console.log('readCleanFile', source);
if (!fs.existsSync(source)) {
logError(`Cannot read file. source path doesn't exists: ${source}`);
logError(`Cannot read file. source path doesn't exist: ${source}`);
return;
}

Expand Down Expand Up @@ -842,7 +842,7 @@ export const copyContentsIfNotExistsRecursiveSync = (src: string, dest: string)
}
}
}
}
};

export default {
sanitizeDynamicRefs,
Expand All @@ -867,5 +867,5 @@ export default {
getDirectories,
resolvePackage,
cleanEmptyFoldersRecursively,
copyContentsIfNotExistsRecursiveSync
copyContentsIfNotExistsRecursiveSync,
};
2 changes: 1 addition & 1 deletion packages/engine-core/src/tasks/task.rnv.target.launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const taskRnvTargetLaunch: RnvTaskFn = async (c, parentTask, originTask)
options.push({ name: `${workspaceTarget} (global default)`, value: workspaceTarget });
}

options.push({ name: 'Pick from available targets...', value: null });
options.push({ name: 'Pick from available targets...', value: true });

const { selectedOption } = await inquirerPrompt({
name: 'selectedOption',
Expand Down
41 changes: 33 additions & 8 deletions packages/sdk-android/src/deviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ export const composeDevicesArray = (devices: Array<AndroidDevice>) => {
return devicesArray;
};

const ERROR_MSG = {
TARGET_EXISTS: 'Running multiple emulators with the same AVD',
UNKNOWN_AVD: 'Unknown AVD name',
};

export const launchAndroidSimulator = async (
c: RnvContext,
target: true | { name: string } | string,
isIndependentThread = false
) => {
): Promise<boolean> => {
logTask(
'launchAndroidSimulator',
`target:${typeof target === 'object' ? target?.name : target} independentThread:${!!isIndependentThread}`
Expand Down Expand Up @@ -93,21 +98,41 @@ export const launchAndroidSimulator = async (
).catch((err) => {
if (err.includes && err.includes('WHPX')) {
logWarning(err);
return logError(
logError(
'It seems you do not have the Windows Hypervisor Platform virtualization enabled. Enter windows features in the Windows search box and select Turn Windows features on or off in the search results. In the Windows Features dialog, enable both Hyper-V and Windows Hypervisor Platform.',
true
);
return false;
}
logError(err);
});
return Promise.resolve();
return true;
}

return executeAsync(
c,
`${c.cli[CLI_ANDROID_EMULATOR]} -avd ${actualTarget}`,
ExecOptionsPresets.SPINNER_FULL_ERROR_SUMMARY
);
try {
await executeAsync(
c,
`${c.cli[CLI_ANDROID_EMULATOR]} -avd ${actualTarget}`,
ExecOptionsPresets.SPINNER_FULL_ERROR_SUMMARY
);
return true;
} catch (e) {
if (typeof e === 'string') {
if (e.includes(ERROR_MSG.UNKNOWN_AVD)) {
logWarning(
`Target with name ${chalk().red(
newTarget
)} does not exist. You can update it here: ${chalk().cyan(c.paths.GLOBAL_RNV_CONFIG)}`
);
await launchAndroidSimulator(c, true, false);
return true;
} else if (e.includes(ERROR_MSG.TARGET_EXISTS)) {
logToSummary(`Target with name ${chalk().red(newTarget)} already running. SKIPPING.`);
return true;
}
}
return Promise.reject(e);
}
}
return Promise.reject('No simulator -t target name specified!');
};
Expand Down
34 changes: 32 additions & 2 deletions packages/sdk-apple/src/deviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import {
logSuccess,
} from '@rnv/core';
import { AppiumAppleDevice, AppleDevice } from './types';
import { execFileSync } from 'child_process';

const ERROR_MSG = {
TARGET_EXISTS: 'Unable to boot device in current state: Booted',
};

export const getAppleDevices = async (c: RnvContext, ignoreDevices?: boolean, ignoreSimulators?: boolean) => {
const { platform } = c;
Expand Down Expand Up @@ -194,7 +199,7 @@ export const launchAppleSimulator = async (c: RnvContext, target: string | boole
await _launchSimulator(selectedDevice);
return selectedDevice.name;
} else if (target !== true && target !== undefined) {
logWarning(`Your specified simulator target ${chalk().white(target)} doesn't exists`);
logWarning(`Your specified simulator target ${chalk().white(target)} doesn't exist`);
}

const devices = devicesArr.map((v) => ({
Expand Down Expand Up @@ -224,7 +229,32 @@ const _launchSimulator = async (selectedDevice: AppleDevice) => {
return false;
}

await executeAsync(`xcrun simctl boot ${selectedDevice.udid}`, ExecOptionsPresets.NO_SPINNER_FULL_ERROR_SUMMARY);
// We need to have simulator app launched for "xcrun simctl boot" to take effect
const developerDir = execFileSync('xcode-select', ['-p'], {
encoding: 'utf8',
}).trim();
execFileSync('open', [
`${developerDir}/Applications/Simulator.app`,
'--args',
'-CurrentDeviceUDID',
selectedDevice.udid,
]);

try {
await executeAsync(
`xcrun simctl boot ${selectedDevice.udid}`,
ExecOptionsPresets.NO_SPINNER_FULL_ERROR_SUMMARY
);
} catch (e) {
if (typeof e === 'string') {
if (e.includes(ERROR_MSG.TARGET_EXISTS)) {
logToSummary(`Target with udid ${chalk().red(selectedDevice.udid)} already running. SKIPPING.`);
return true;
}
}
return Promise.reject(e);
}

logSuccess(`Succesfully launched ${selectedDevice.name}`);
return true;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-tizen/src/__tests__/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('sdk_tizen runner', () => {
await expect(checkTizenStudioCert(c)).resolves.toBe(true);
//THEN
});
it("should return false if the certificate profile doesn't exists", async () => {
it("should return false if the certificate profile doesn't exist", async () => {
//GIVEN
const c = getContext();
jest.spyOn(require('@rnv/core'), 'execCLI').mockResolvedValueOnce(new Error('Error'));
Expand Down
49 changes: 45 additions & 4 deletions packages/sdk-tizen/src/deviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
waitForExecCLI,
inquirerPrompt,
DEFAULTS,
executeAsync,
ExecOptionsPresets,
} from '@rnv/core';
import { CLI_SDB_TIZEN, CLI_TIZEN, CLI_TIZEN_EMULATOR } from './constants';

Expand All @@ -28,6 +30,11 @@ const parser = new xml2js.Parser();

export const DEFAULT_CERTIFICATE_NAME = 'tizen_author';

const ERROR_MSG = {
UNKNOWN_VM: 'does not match any VM',
ALREADY_RUNNING: 'is running now',
};

type PlatKeyObj = {
_: string;
$: {
Expand Down Expand Up @@ -63,13 +70,47 @@ const formatXMLObject = (
return {};
};

export const launchTizenSimulator = (c: RnvContext, name: string) => {
export const launchTizenSimulator = async (c: RnvContext, name: string | true): Promise<boolean> => {
logTask(`launchTizenSimulator:${name}`);

if (name) {
return execCLI(c, CLI_TIZEN_EMULATOR, `launch --name ${name}`, {
if (name === true) {
const targets = await execCLI(c, CLI_TIZEN_EMULATOR, 'list-vm', {
detached: true,
});
const lines = targets.split('\n');
const devicesArray = lines.map((line) => ({ id: line, name: line }));
const choices = _composeDevicesString(devicesArray);
const { chosenEmulator } = await inquirerPrompt({
name: 'chosenEmulator',
type: 'list',
message: 'What emulator would you like to launch?',
choices,
});

name = chosenEmulator;
}

if (name) {
try {
await executeAsync(
c,
`${c.cli[CLI_TIZEN_EMULATOR]} launch --name ${name}`,
ExecOptionsPresets.SPINNER_FULL_ERROR_SUMMARY
);
return true;
} catch (e) {
if (typeof e === 'string') {
if (e.includes(ERROR_MSG.UNKNOWN_VM)) {
logError(`The VM "${name}" does not exist.`);
return launchTizenSimulator(c, true);
}

if (e.includes(ERROR_MSG.ALREADY_RUNNING)) {
logError(`The VM "${name}" is already running.`);
return true;
}
}
}
}
return Promise.reject('No simulator -t target name specified!');
};
Expand Down Expand Up @@ -235,7 +276,7 @@ const _waitForEmulatorToBeReady = (c: RnvContext, target: string): Promise<boole
return res;
});

const _composeDevicesString = (devices: Array<TizenDevice>) =>
const _composeDevicesString = (devices: Array<Pick<TizenDevice, 'id' | 'name'>>) =>
devices.map((device) => ({
key: device.id,
name: device.name,
Expand Down
Loading