noodl-loader
Version:
Loader for noodl applications
93 lines • 3.37 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const noodl_core_1 = require("noodl-core");
const yml_1 = require("./utils/yml");
const replace_1 = require("./utils/replace");
const key_value_cache_1 = tslib_1.__importDefault(require("./cache/key-value-cache"));
class NoodlConfig extends key_value_cache_1.default {
constructor() {
super(...arguments);
this.rootConfigUrl = '';
this.appKey = '';
this.configKey = '';
}
[Symbol.for('nodejs.util.inspect.custom')]() {
return this.toJSON();
}
get baseUrl() {
return (this.get('cadlBaseUrl') || '');
}
getTimestamp() {
let date = new Date();
let dateStr = '';
dateStr += date.getMonth();
dateStr += date.getDate();
dateStr += date.getFullYear();
dateStr += '.';
// TODO - Implement this correctly
dateStr += 'PDT';
return dateStr;
}
resolve(arg1, arg2 = {}, arg3) {
var _a, _b;
if (!arguments.length) {
const props = this.toJSON();
const values = {
apiHost: this.get('apiHost'),
apiPort: this.get('apiPort'),
cadlBaseUrl: this.get('cadlBaseUrl'),
cadlVersion: this.resolve('version', 'web'),
};
if (this.has('designSuffix')) {
values.designSuffix = this.get('designSuffix');
}
for (const [key, value] of noodl_core_1.fp.entries(props)) {
if (noodl_core_1.is.str(value) && this.has(value)) {
props[key] = this.get(value);
}
}
return (0, replace_1.replacePlaceholders)(props, values);
}
if (arg1) {
if (arg1 === 'version') {
if (noodl_core_1.is.str(arg2)) {
const env = arg3 || 'stable';
return (_b = (_a = this.get(arg2)) === null || _a === void 0 ? void 0 : _a.cadlVersion) === null || _b === void 0 ? void 0 : _b[env];
}
else {
throw new Error(`deviceType is not a string`);
}
}
if (noodl_core_1.is.str(arg1)) {
return (0, replace_1.replacePlaceholders)(arg1, this.toJSON());
}
}
return arg1;
}
set(key, value) {
var _a;
if (['web', 'ios', 'android'].includes(key)) {
if (noodl_core_1.is.obj(value)) {
super.set(key, Object.assign(Object.assign({}, (_a = this.get(key)) === null || _a === void 0 ? void 0 : _a.cadlVersion), value));
}
else {
super.set(key, value);
}
}
else {
if (key === 'cadlMain')
this.appKey = value;
super.set(key, value);
}
return this;
}
toJSON() {
return Object.assign({ cadlMain: this.appKey, cadlVersion: this.resolve('version', 'web'), timestamp: this.getTimestamp() }, this.get());
}
toString() {
return (0, yml_1.stringify)(this.toJSON());
}
}
exports.default = NoodlConfig;
//# sourceMappingURL=config.js.map