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
45 changes: 39 additions & 6 deletions packages/sdk-webos/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ 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 getCliPath();
const clipathOldVersion = sdk && path.join(sdk, 'CLI/bin');

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 +52,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) {
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-info${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 +89,15 @@ const _isSdkInstalled = (c: RnvContext) => {
return fsExistsSync(getRealPath(sdkPath));
};

const getCliPath = async () => {
try {
const { stdout } = await exec('which ares');
return stdout.slice(0, -5); // cutting out the 'ares' part, so I can get ares, ares-package, ares-launch, ...
} catch (error) {
return false;
}
};

const _attemptAutoFix = async (c: RnvContext) => {
logDefault('_attemptAutoFix');

Expand Down
Loading