@zendesk/zcli-themes
Version:
zcli theme commands live here
24 lines (23 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const errors_1 = require("@oclif/core/lib/errors");
const getLocalServerBaseUrl_1 = require("./getLocalServerBaseUrl");
function getVariables(themePath, settings, flags) {
const settingsPath = `${themePath}/settings`;
const filenames = fs.existsSync(settingsPath) ? fs.readdirSync(settingsPath) : [];
return settings
.reduce((variables, setting) => [...variables, ...setting.variables], [])
.map((variable) => {
if (variable.type === 'file') {
const file = filenames.find(filename => path.parse(filename).name === variable.identifier);
if (!file) {
throw new errors_1.CLIError(`The setting "${variable.identifier}" of type "file" does not have a matching file within the "settings" folder`);
}
variable.value = file && `${(0, getLocalServerBaseUrl_1.getLocalServerBaseUrl)(flags)}/guide/settings/${file}`;
}
return variable;
});
}
exports.default = getVariables;