forked from liferay/liferay-js-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-portlet.ts
78 lines (65 loc) · 2.05 KB
/
react-portlet.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
75
76
77
78
/**
* 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} from '../utils';
import ProjectAnalyzer from '../utils/ProjectAnalyzer';
import NpmbuildrcModifier from '../utils/modifier/npmbuildrc';
import PkgJsonModifier from '../utils/modifier/package.json.js';
import * as standardTarget from '../utils/target/standard';
import dependenciesJson from './dependencies.json';
/**
* Implementation of generation of React portlets.
*/
export default class extends Generator {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
answers: any;
namespace: string;
/**
* Standard Yeoman initialization function
*/
initializing() {
this.sourceRoot(path.join(__dirname, 'templates'));
this.namespace = 'target-react-portlet';
}
/**
* Standard Yeoman prompt function
*/
async prompting() {
await standardTarget.prompting(this);
}
/**
* Standard Yeoman generation function
*/
writing() {
const cp = new Copier(this);
const npmbuildrc = new NpmbuildrcModifier(this);
const pkgJson = new PkgJsonModifier(this);
const projectAnalyzer = new ProjectAnalyzer(this);
const {sampleWanted} = this.answers;
// Configure build
pkgJson.mergeDependencies(dependenciesJson);
pkgJson.addBuildStep('babel --source-maps -d build src');
cp.copyFile('.babelrc');
// Configure webpack
pkgJson.addDevDependency('babel-loader', '7.1.5');
npmbuildrc.addWebpackRule(/src\/.*\.js$/, 'babel-loader');
// Prepare text labels
const labels = standardTarget.generateLabels(this);
// Prepare context
const context = standardTarget.generateContext(this, {
labels: labels[projectAnalyzer.hasLocalization ? 'jsx' : 'raw'],
});
// Copy javascript files
pkgJson.setMain('index.js');
cp.copyFile('src/index.js', {context});
// Generate sample contents
standardTarget.generateSamples(this, labels);
if (sampleWanted) {
cp.copyDir('src', {context});
}
}
}
module.exports = exports['default'];