nativescript
Version:
Command-line interface for building NativeScript projects
114 lines • 4.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigSetCommand = exports.ConfigGetCommand = exports.ConfigListCommand = void 0;
const yok_1 = require("../common/yok");
const color_1 = require("../color");
class ConfigListCommand {
constructor($projectConfigService, $logger) {
this.$projectConfigService = $projectConfigService;
this.$logger = $logger;
this.allowedParameters = [];
}
async execute(args) {
try {
const config = this.$projectConfigService.readConfig();
this.$logger.info(this.getValueString(config));
}
catch (error) {
this.$logger.info("Failed to read config. Error is: ", error);
}
}
getValueString(value, depth = 0) {
const indent = () => " ".repeat(depth);
if (typeof value === "object") {
return (`${depth > 0 ? "\n" : ""}` +
Object.keys(value)
.map((key) => {
return (color_1.color.green(`${indent()}${key}: `) +
// @ts-ignore
this.getValueString(value[key], depth + 1));
})
.join("\n"));
}
else {
return color_1.color.yellow(value.toString());
}
}
}
exports.ConfigListCommand = ConfigListCommand;
class ConfigGetCommand {
constructor($projectConfigService, $logger, $errors) {
this.$projectConfigService = $projectConfigService;
this.$logger = $logger;
this.$errors = $errors;
this.allowedParameters = [];
}
async execute(args) {
try {
const [key] = args;
const current = this.$projectConfigService.getValue(key);
this.$logger.info(current);
}
catch (err) {
// ignore
}
}
async canExecute(args) {
if (!args[0]) {
this.$errors.failWithHelp("You must specify a key. Eg: ios.id");
}
return true;
}
}
exports.ConfigGetCommand = ConfigGetCommand;
class ConfigSetCommand {
constructor($projectConfigService, $logger, $errors) {
this.$projectConfigService = $projectConfigService;
this.$logger = $logger;
this.$errors = $errors;
this.allowedParameters = [];
}
async execute(args) {
const [key, value] = args;
const current = this.$projectConfigService.getValue(key);
if (current && typeof current === "object") {
this.$errors.fail(`Unable to change object values. Please update individual values instead.\nEg: ns config set android.codeCache true`);
}
const convertedValue = this.getConvertedValue(value);
const existingKey = current !== undefined;
const keyDisplay = color_1.color.green(key);
const currentDisplay = color_1.color.yellow(current);
const updatedDisplay = color_1.color.cyan(convertedValue);
this.$logger.info(`${existingKey ? "Updating" : "Setting"} ${keyDisplay}${existingKey ? ` from ${currentDisplay} ` : " "}to ${updatedDisplay}`);
try {
await this.$projectConfigService.setValue(key, convertedValue);
this.$logger.info("Done");
}
catch (error) {
this.$logger.info("Could not update conifg. Error is: ", error);
}
}
async canExecute(args) {
if (!args[0]) {
this.$errors.failWithHelp("You must specify a key. Eg: ios.id");
}
if (!args[1]) {
this.$errors.failWithHelp("You must specify a value.");
}
return true;
}
getConvertedValue(v) {
try {
return JSON.parse(v);
}
catch (e) {
// just treat it as a string
return `${v}`;
}
}
}
exports.ConfigSetCommand = ConfigSetCommand;
yok_1.injector.registerCommand("config|*list", ConfigListCommand);
yok_1.injector.registerCommand("config|get", ConfigGetCommand);
yok_1.injector.registerCommand("config|set", ConfigSetCommand);
//# sourceMappingURL=config.js.map
;