forked from liferay/liferay-js-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared-bundle.ts
74 lines (64 loc) · 1.76 KB
/
shared-bundle.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
import path from 'path';
import Generator from 'yeoman-generator';
import {Copier, promptWithConfig} from '../utils';
import PkgJsonModifier from '../utils/modifier/package.json';
/**
* Implementation of generation of shared bundles.
*/
export default class extends Generator {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
answers: any;
/**
* Standard Yeoman initialization function
*/
initializing() {
this.sourceRoot(path.join(__dirname, 'templates'));
}
/**
* Standard Yeoman prompt function
*/
async prompting() {
this.answers = await promptWithConfig(this, 'target-shared-bundle', [
{
type: 'confirm',
name: 'createInitializer',
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',
default: false,
},
]);
}
/**
* Standard Yeoman generation function
*/
writing() {
if (!this.answers.createInitializer) {
return;
}
const cp = new Copier(this);
const pkgJson = new PkgJsonModifier(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')),
},
});
}
}
module.exports = exports['default'];