UNPKG

@liferay/generator-js

Version:

Yeoman generators for Liferay DXP and Portal CE JavaScript projects.

126 lines (125 loc) 3.94 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 path_1 = __importDefault(require("path")); const constants_1 = require("../facet-configuration/constants"); const constants_2 = require("../facet-localization/constants"); /** * A class to be able to analyze what the project does and doesn't. */ class ProjectAnalyzer { /** * @param {Generator} generator a Yeoman generator */ constructor(generator) { this._generator = generator; } /** * Get project name. * @return {string} */ get name() { return this._packageJson.name || ''; } /** * Get project description. * @return {string} */ get description() { return this._packageJson.description || ''; } /** * Get project display name (description if present, otherwise the name). * @return {string} */ get displayName() { let displayName = this.description; if (displayName === '') { displayName = this.name; } return displayName; } /** * Test if the project has localization enabled. * @return {boolean} */ get hasLocalization() { const fs = this._generator.fs; return (dot_prop_1.default.has(this._npmbundlerrc, 'create-jar.features.localization') || fs.exists(`${constants_2.DEFAULT_LOCALIZATION}.properties`)); } /** * Test if the project has configuration. * @return {boolean} */ get hasConfiguration() { const fs = this._generator.fs; return (dot_prop_1.default.has(this._npmbundlerrc, 'create-jar.features.configuration') || fs.exists(constants_1.DEFAULT_CONFIGURATION)); } /** * Get the basename of the localization file (without the .properties * extension) * @return {string} */ get localizationBundleName() { const bundleName = path_1.default.basename(this.localizationFilePath); const extname = path_1.default.extname(bundleName); return bundleName.replace(new RegExp(extname.replace('.', '\\.')), ''); } /** * Get the path to localization properties file. * @return {string} */ get localizationFilePath() { const fs = this._generator.fs; let localization = dot_prop_1.default.get(this._npmbundlerrc, 'create-jar.features.localization'); if (localization) { return `${localization}.properties`; } else { localization = `${constants_2.DEFAULT_LOCALIZATION}.properties`; if (fs.exists(localization)) { return localization; } } return undefined; } /** * Get the path to the configuration file. * @return {string} */ get configurationFilePath() { const fs = this._generator.fs; const configuration = dot_prop_1.default.get(this._npmbundlerrc, 'create-jar.features.configuration'); if (configuration) { return configuration; } else if (fs.exists(constants_1.DEFAULT_CONFIGURATION)) { return constants_1.DEFAULT_CONFIGURATION; } return undefined; } /** * Get the parsed '.npmbundlerrc' file * @return {object} */ get _npmbundlerrc() { return this._generator.fs.readJSON('.npmbundlerrc'); } /** * Get the parsed 'package.json' file * @return {object} */ get _packageJson() { return this._generator.fs.readJSON('package.json'); } } exports.default = ProjectAnalyzer;