@liferay/generator-js
Version:
Yeoman generators for Liferay DXP and Portal CE JavaScript projects.
94 lines (93 loc) • 3.26 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 dot_prop_1 = __importDefault(require("dot-prop"));
const os_1 = __importDefault(require("os"));
const JsonModifier_1 = __importDefault(require("../JsonModifier"));
/**
* A class to help modifying the .npmbuildrc file.
*/
class default_1 extends JsonModifier_1.default {
/**
* @param {Generator} generator a Yeoman generator
*/
constructor(generator) {
super(generator, '.npmbuildrc');
}
/**
* Set local Liferay installation directory
* @param {string} liferayDir
*/
setLiferayDir(liferayDir) {
this.modifyJson((json) => {
dot_prop_1.default.set(json, 'liferayDir', liferayDir);
});
}
/**
* Set supported locales array
* @param {Array<string>} supportedLocales
*/
setSupportedLocales(supportedLocales) {
this.modifyJson((json) => {
dot_prop_1.default.set(json, 'supportedLocales', supportedLocales);
});
}
/**
* Set Microsoft Translator credentials
* @param {string} key
*/
setTranslatorTextKey(translatorTextKey) {
this.modifyJson((json) => {
dot_prop_1.default.set(json, 'translatorTextKey', translatorTextKey);
});
}
/**
* Set webpack's main module.
* @param {string} mainModule
*/
setWebpackMainModule(mainModule) {
this.modifyJson((json) => {
dot_prop_1.default.set(json, 'webpack.mainModule', mainModule);
});
}
/**
* Add a webpack rule to the .npmbuildrc file.
* @param {RegExp} regex a regex expression to match files
* @param {string} loader the name of a webpack loader
* @param {boolean} fixPathSepsInWindows wether to replace / path separators
* by \ when running on Windows
*/
addWebpackRule(regex, loader, fixPathSepsInWindows = true) {
if (fixPathSepsInWindows && os_1.default.platform() === 'win32') {
regex = new RegExp(regex.source.replace('/', '\\'), regex.flags);
}
this.modifyJson((json) => {
let test = regex.toString();
test = test.substring(1, test.length - 1);
const currentRules = dot_prop_1.default.get(json, 'webpack.rules', []);
currentRules.push({
test,
use: loader,
});
dot_prop_1.default.set(json, 'webpack.rules', currentRules);
});
}
/**
* Add webpack extensions to the .npmbuildrc file.
* @param {Array<string>} extensions the file extensions to add
*/
addWebpackExtensions(...extensions) {
this.modifyJson((json) => {
const currentExtensions = dot_prop_1.default.get(json, 'webpack.extensions', []);
currentExtensions.push(...extensions);
dot_prop_1.default.set(json, 'webpack.extensions', currentExtensions);
});
}
}
exports.default = default_1;