@c8y/toolkit
Version:
Toolkit for Cumulocity applications, allows to e.g. deploy an application to an instance of Cumulocity.
58 lines • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dataToAppData = dataToAppData;
exports.getName = getName;
exports.getKey = getKey;
exports.getContextPath = getContextPath;
exports.getFromEnvVar = getFromEnvVar;
const lodash_1 = require("lodash");
/**
* Converts the provided file data to application data.
*
* @param fileData - The file data to convert.
* @returns The application data.
*/
function dataToAppData(fileData) {
return fileData.c8y && fileData.c8y.application ? fileData.c8y.application : fileData;
}
/**
* Gets the name from the application data.
*
* @param appData - The application data.
* @param fallbackStr - The fallback string to use if name is not found.
* @returns The name of the application.
*/
function getName(appData, fallbackStr = '') {
return (0, lodash_1.get)(appData, 'name', fallbackStr);
}
/**
* Gets the key from the application data.
*
* @param appData - The application data.
* @param name - The name to use in case the key is not found.
* @returns The key of the application.
*/
function getKey(appData, name) {
let key = (0, lodash_1.get)(appData, 'key');
if (!key) {
key = `${(0, lodash_1.kebabCase)(name)}-key`;
}
return key;
}
function getContextPath(appData, name) {
return (0, lodash_1.get)(appData, 'contextPath', name.toLowerCase());
}
const environmentVariables = {
C8Y_URL: 'C8Y_URL',
C8Y_PASSWORD: 'C8Y_PASSWORD',
C8Y_USER: 'C8Y_USER',
C8Y_TENANT: 'C8Y_TENANT'
};
function getFromEnvVar(envVar) {
const envValue = process.env[envVar];
if (envValue) {
console.log(`Using value passed via environment variable ${envVar}.`);
}
return envValue;
}
//# sourceMappingURL=helpers.js.map