generator-liferay-js
Version:
Yeoman generators for Liferay DXP and Portal CE JavaScript projects.
74 lines (73 loc) • 3.23 kB
JavaScript
;
/**
* 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 path_1 = __importDefault(require("path"));
const yeoman_generator_1 = __importDefault(require("yeoman-generator"));
const utils_1 = require("../utils");
const ProjectAnalyzer_1 = __importDefault(require("../utils/ProjectAnalyzer"));
const Language_properties_1 = __importDefault(require("../utils/modifier/features/localization/Language.properties"));
const npmbundlerrc_1 = __importDefault(require("../utils/modifier/npmbundlerrc"));
const package_json_1 = __importDefault(require("../utils/modifier/package.json"));
/**
* Generator to add portlet support to projects.
*/
class default_1 extends yeoman_generator_1.default {
/**
* Standard Yeoman initialization function
*/
initializing() {
this.sourceRoot(path_1.default.join(__dirname, 'templates'));
}
/**
* Standard Yeoman prompt function
*/
async prompting() {
this.answers = await utils_1.promptWithConfig(this, 'facet-portlet', [
{
type: 'input',
name: 'category',
message: 'Under which category should your widget be listed?',
default: 'category.sample',
},
]);
}
/**
* Standard Yeoman generation function
*/
writing() {
const cp = new utils_1.Copier(this);
const npmbundlerrc = new npmbundlerrc_1.default(this);
const pkgJson = new package_json_1.default(this);
const projectAnalyzer = new ProjectAnalyzer_1.default(this);
const portletName = utils_1.getPortletName(projectAnalyzer);
const portletDisplayName = projectAnalyzer.displayName;
// Require extender
npmbundlerrc.setFeature('js-extender', true);
// Copy static assets
cp.copyDir('assets');
// Add portlet properties
pkgJson.addPortletProperty('com.liferay.portlet.display-category', this.answers.category);
pkgJson.addPortletProperty('com.liferay.portlet.header-portlet-css', '/css/styles.css');
pkgJson.addPortletProperty('com.liferay.portlet.instanceable', true);
pkgJson.addPortletProperty('javax.portlet.name', portletName);
pkgJson.addPortletProperty('javax.portlet.security-role-ref', 'power-user,user');
// Add portlet display name as needed
if (projectAnalyzer.hasLocalization) {
// Add resource bundle portlet property
pkgJson.addPortletProperty('javax.portlet.resource-bundle', `content.${projectAnalyzer.localizationBundleName}`);
// Add portlet display name localization key
new Language_properties_1.default(this).addProperty(`javax.portlet.title.${portletName}`, portletDisplayName);
}
else {
pkgJson.addPortletProperty('javax.portlet.display-name', portletDisplayName);
}
}
}
exports.default = default_1;
module.exports = exports['default'];