UNPKG

@liferay/generator-js

Version:

Yeoman generators for Liferay DXP and Portal CE JavaScript projects.

61 lines (60 loc) 2.35 kB
"use strict"; /** * SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com> * SPDX-License-Identifier: LGPL-3.0-or-later */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const dot_prop_1 = __importDefault(require("dot-prop")); const JsonModifier_1 = __importDefault(require("../../JsonModifier")); const ProjectAnalyzer_1 = __importDefault(require("../../ProjectAnalyzer")); /** * A class to help modifying the configuration.json file. */ class ConfigurationJsonModifier extends JsonModifier_1.default { /** * @param {Generator} generator a Yeoman generator */ constructor(generator) { super(generator, new ProjectAnalyzer_1.default(generator).configurationFilePath); } /** * Add a field to the file * @param {string} section one of the values in `ConfigurationJsonModifier.Section` * @param {string} id * @param {string} type * @param {string} name * @param {string} description * @param {boolean} required * @param {any} defaultValue * @param {object} options a hash of option ids as keys and objects with a * name field as values */ addField(section, id, type, { defaultValue, description, name, options, required }) { this.modifyJson((json) => { dot_prop_1.default.set(json, `${section}.fields.${id}.type`, type); if (name) { dot_prop_1.default.set(json, `${section}.fields.${id}.name`, name); } if (description) { dot_prop_1.default.set(json, `${section}.fields.${id}.description`, description); } if (required) { dot_prop_1.default.set(json, `${section}.fields.${id}.required`, required); } if (defaultValue) { dot_prop_1.default.set(json, `${section}.fields.${id}.default`, defaultValue); } if (options) { dot_prop_1.default.set(json, `${section}.fields.${id}.options`, options); } }); } } exports.default = ConfigurationJsonModifier; ConfigurationJsonModifier.Section = { PORTLET_INSTANCE: 'portletInstance', SYSTEM: 'system', };