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

Webos cli installation check #1606

Merged
merged 10 commits into from
Jul 3, 2024
2 changes: 1 addition & 1 deletion packages/core/src/system/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const execCLI = (cli: string, command: string, opts: ExecOptions = {}) => {
);
}

return _execute(c, `${p} ${command}`, { ...opts, shell: true });
return _execute(c, `"${p}" ${command}`, { ...opts, shell: true });
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-webos/src/deviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const parseDevices = (c: RnvContext, devicesResponse: string): Promise<Array<Web
.filter((word) => word !== '');
let deviceInfo = '';
try {
deviceInfo = await execCLI(CLI_WEBOS_ARES_DEVICE_INFO, `-d ${name}`, {
deviceInfo = await execCLI(CLI_WEBOS_ARES_DEVICE_INFO, `-i ${name}`, {
silent: true,
timeout: 10000,
});
Expand Down
55 changes: 49 additions & 6 deletions packages/sdk-webos/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ import {
CLI_WEBOS_ARES_DEVICE_INFO,
} from './constants';

const SDK_LOCATIONS = [path.join('/opt/webOS_TV_SDK'), path.join('C:\\webOS_TV_SDK')];
import { exec as execCb } from 'child_process';
import { promisify } from 'util';
const exec = promisify(execCb);

const _logSdkWarning = (c: RnvContext) => {
logWarning(`Your ${c.paths.workspace.config} is missing SDK configuration object`);
};
const SDK_LOCATIONS = [path.join('/opt/webOS_TV_SDK'), path.join('C:\\webOS_TV_SDK')];

export const checkAndConfigureWebosSdks = async () => {
const c = getContext();
logDefault(`checkAndConfigureWebosSdks:${c.platform}`);
const sdk = c.buildConfig?.sdks?.WEBOS_SDK;
if (sdk) {

const clipathNewVersion = await getCliDirPath();
const clipathOldVersion = sdk && path.join(sdk, 'CLI/bin');

if (!fsExistsSync(sdk)) {
throw new Error('No Webos SDK found. Check if it is installed.');
}

if (sdk && fsExistsSync(clipathOldVersion)) {
c.cli[CLI_WEBOS_ARES] = getRealPath(path.join(sdk, `CLI/bin/ares${isSystemWin ? '.cmd' : ''}`));
c.cli[CLI_WEBOS_ARES_PACKAGE] = getRealPath(path.join(sdk, `CLI/bin/ares-package${isSystemWin ? '.cmd' : ''}`));
c.cli[CLI_WEBOS_ARES_INSTALL] = getRealPath(path.join(sdk, `CLI/bin/ares-install${isSystemWin ? '.cmd' : ''}`));
Expand All @@ -48,8 +56,28 @@ export const checkAndConfigureWebosSdks = async () => {
path.join(sdk, `CLI/bin/ares-device-info${isSystemWin ? '.cmd' : ''}`)
);
c.cli[CLI_WEBOS_ARES_NOVACOM] = getRealPath(path.join(sdk, `CLI/bin/ares-novacom${isSystemWin ? '.cmd' : ''}`));
} else if (sdk && clipathNewVersion && fsExistsSync(clipathNewVersion + '/ares')) {
c.cli[CLI_WEBOS_ARES] = getRealPath(path.join(clipathNewVersion, `ares${isSystemWin ? '.cmd' : ''}`));
c.cli[CLI_WEBOS_ARES_PACKAGE] = getRealPath(
path.join(clipathNewVersion, `ares-package${isSystemWin ? '.cmd' : ''}`)
);
c.cli[CLI_WEBOS_ARES_INSTALL] = getRealPath(
path.join(clipathNewVersion, `ares-install${isSystemWin ? '.cmd' : ''}`)
);
c.cli[CLI_WEBOS_ARES_LAUNCH] = getRealPath(
path.join(clipathNewVersion, `ares-launch${isSystemWin ? '.cmd' : ''}`)
);
c.cli[CLI_WEBOS_ARES_SETUP_DEVICE] = getRealPath(
path.join(clipathNewVersion, `ares-setup-device${isSystemWin ? '.cmd' : ''}`)
);
c.cli[CLI_WEBOS_ARES_DEVICE_INFO] = getRealPath(
path.join(clipathNewVersion, `ares-device${isSystemWin ? '.cmd' : ''}`)
);
c.cli[CLI_WEBOS_ARES_NOVACOM] = getRealPath(
path.join(clipathNewVersion, `ares-novacom${isSystemWin ? '.cmd' : ''}`)
);
} else {
_logSdkWarning(c);
throw new Error('No Webos CLI found. Check if it is installed.');
}
};

Expand All @@ -65,6 +93,21 @@ const _isSdkInstalled = (c: RnvContext) => {
return fsExistsSync(getRealPath(sdkPath));
};

const getCliDirPath = async () => {
try {
const { stdout } = isSystemWin ? await exec('where.exe ares') : await exec('which ares');
if (isSystemWin) {
// Windows returns multiple paths, we need to get the first one
const paths = stdout.split('\n');
return path.dirname(paths[0].trim());
} else {
return path.dirname(stdout.trim());
}
} catch (error) {
return false;
}
};

const _attemptAutoFix = async (c: RnvContext, shouldThrow?: boolean) => {
logDefault('_attemptAutoFix');

Expand Down
Loading