liferay-npm-bundler-preset-reactjs
Version:
liferay npm bundler preset react
125 lines (124 loc) • 5.25 kB
JavaScript
"use strict";
/**
* SPDX-FileCopyrightText: © 2020 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 read_json_sync_1 = __importDefault(require("read-json-sync"));
const file_path_1 = __importDefault(require("../file-path"));
const util_1 = require("./util");
/**
* Reflects JAR file configuration of JS Toolkit projects.
*/
class Jar {
constructor(project) {
this._project = project;
}
/**
* Get compression level to apply when making the JAR file.
* @return a number between 0 (no compression) and 9 (maximum compression)
*/
get compressionLevel() {
const { _project } = this;
const { npmbundlerrc } = _project;
if (this._compressionLevel === undefined) {
this._compressionLevel = dot_prop_1.default.get(npmbundlerrc, 'create-jar.compression-level', 6);
}
return this._compressionLevel;
}
/**
* Get configuration description file path.
* @return path of the file or undefined if not configured
*/
get configurationFile() {
const { _project } = this;
const absPath = util_1.getFeaturesFilePath(_project, 'create-jar.features.configuration', 'features/configuration.json');
if (!absPath) {
return undefined;
}
return new file_path_1.default(absPath);
}
/**
* Get user configured manifest headers
*/
get customManifestHeaders() {
const { npmbundlerrc } = this._project;
if (this._customManifestHeaders === undefined) {
const manifestFilePath = util_1.getFeaturesFilePath(this._project, 'create-jar.features.manifest', 'features/manifest.json');
const featuresHeaders = manifestFilePath
? read_json_sync_1.default(manifestFilePath)
: {};
const npmbundlerrcHeaders = dot_prop_1.default.get(npmbundlerrc, 'create-jar.customManifestHeaders', {});
this._customManifestHeaders = Object.assign(npmbundlerrcHeaders, featuresHeaders);
}
return this._customManifestHeaders;
}
/**
* Get output directory for JAR file relative to `project.dir` and starting
* with `./`
*/
get outputDir() {
const { _project } = this;
const { npmbundlerrc } = _project;
if (this._outputDir === undefined) {
let outputDirPosixPath = dot_prop_1.default.get(npmbundlerrc, 'create-jar.output-dir', this.supported ? _project.buildDir.asPosix : undefined);
if (outputDirPosixPath !== undefined) {
if (!outputDirPosixPath.startsWith('./')) {
outputDirPosixPath = `./${outputDirPosixPath}`;
}
this._outputDir = new file_path_1.default(outputDirPosixPath, {
posix: true,
});
}
}
return this._outputDir;
}
/**
* Get filename of output JAR file
*/
get outputFilename() {
const { npmbundlerrc, pkgJson } = this._project;
if (this._outputFilename === undefined) {
let defaultValue;
if (this.supported) {
defaultValue =
pkgJson['name'] + '-' + pkgJson['version'] + '.jar';
defaultValue = defaultValue.replace(/\//g, '_');
}
this._outputFilename = dot_prop_1.default.get(npmbundlerrc, 'create-jar.output-filename', defaultValue);
}
return this._outputFilename;
}
/**
* Whether or not to add a manifest header in JAR file to make the JS
* extender process this bundle.
* @return can be a boolean, a string forcing an extender version number or
* 'any' to leave version unbounded
*/
get requireJsExtender() {
const { npmbundlerrc } = this._project;
return dot_prop_1.default.get(npmbundlerrc, 'create-jar.features.js-extender',
// TODO: deprecated 'auto-deploy-portlet', remove for the next major version
dot_prop_1.default.get(npmbundlerrc, 'create-jar.auto-deploy-portlet', !!this._project.pkgJson['portlet']));
}
get supported() {
const { npmbundlerrc } = this._project;
return !!dot_prop_1.default.get(npmbundlerrc, 'create-jar', false);
}
get webContextPath() {
const { npmbundlerrc, pkgJson } = this._project;
if (!this._webContextPath) {
this._webContextPath = dot_prop_1.default.get(npmbundlerrc, 'create-jar.features.web-context',
// TODO: deprecated 'web-context-path', remove for the next major version
dot_prop_1.default.get(npmbundlerrc, 'create-jar.web-context-path',
// TODO: deprecated 'osgi.Web-ContextPath', remove for the next major version
dot_prop_1.default.get(pkgJson, 'osgi.Web-ContextPath', `/${pkgJson['name']}-${pkgJson['version']}`)));
}
return this._webContextPath;
}
}
exports.default = Jar;