@liferay/generator-js
Version:
Yeoman generators for Liferay DXP and Portal CE JavaScript projects.
68 lines (67 loc) • 2.4 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 package_json_1 = __importDefault(require("../utils/modifier/package.json"));
/**
* Implementation of generation of shared bundles.
*/
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, 'target-shared-bundle', [
{
default: false,
message: 'Does your shared bundle need an initializer?\n' +
'\n' +
' 💡 This is usually needed in frameworks which need a single point of\n' +
' initialization.\n' +
' 💡 It may also be useful if you need to load any polyfill that must be\n' +
' loaded just once.\n' +
'\n',
name: 'createInitializer',
type: 'confirm',
},
]);
}
/**
* Standard Yeoman generation function
*/
writing() {
if (!this.answers.createInitializer) {
return;
}
const cp = new utils_1.Copier(this);
const pkgJson = new package_json_1.default(this);
// Configure build
pkgJson.addDevDependency('babel-cli', '6.26.0');
pkgJson.addDevDependency('babel-preset-env', '1.7.0');
pkgJson.addBuildStep('babel --source-maps -d build src');
cp.copyFile('.babelrc');
// Copy JavaScript files
pkgJson.setMain('index.js');
cp.copyFile('src/index.js', {
context: {
pkgJson: JSON.parse(this.fs.read('package.json')),
},
});
}
}
exports.default = default_1;
module.exports = exports['default'];