feat: warnOnce & graceful error handling

This commit is contained in:
Igor Randjelovic
2021-04-01 17:55:45 +02:00
parent 7edb1e90b0
commit 1627f52043
4 changed files with 40 additions and 8 deletions

View File

@ -1,11 +1,15 @@
import { env } from '../index';
import { error } from './log';
import { error, warnOnce } from './log';
function getCLILib() {
if (!env.nativescriptLibPath) {
throw error(`
warnOnce(
'getCLILib',
`
Cannot find NativeScript CLI path. Make sure --env.nativescriptLibPath is passed
`);
`
);
return false;
}
return require(env.nativescriptLibPath);
@ -15,10 +19,15 @@ function getCLILib() {
* Utility to get a value from the nativescript.config.ts file.
*
* @param {string} key The key to get from the config. Supports dot-notation.
* @param defaultValue The fallback value if the key is not set in the config.
*/
export function getValue<T = any>(key: string, defaultValue?: any): T {
const lib = getCLILib();
if (!lib) {
return defaultValue;
}
return (lib.projectConfigService as {
getValue(key: string, defaultValue?: any): T;
}).getValue(key, defaultValue);