Skip to content

Commit 791a140

Browse files
committed
feat(liferay-cli): add shared bundle project type
1 parent c2e987c commit 791a140

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com>
3+
* SPDX-License-Identifier: LGPL-3.0-or-later
4+
*/
5+
6+
import {FilePath, TemplateRenderer, format} from '@liferay/js-toolkit-core';
7+
8+
import prompt from '../../util/prompt';
9+
10+
import type {Options} from '../index';
11+
import type {LiferayTargetFacet} from '../target-liferay';
12+
13+
const {info, print} = format;
14+
15+
const facet: LiferayTargetFacet = {
16+
isPortlet: false,
17+
18+
async prompt(useDefaults: boolean, options: Options): Promise<Options> {
19+
return await prompt(useDefaults, options, [
20+
{
21+
type: 'confirm',
22+
name: 'createInitializer',
23+
message:
24+
'Does your shared bundle need an initializer?\n' +
25+
'\n' +
26+
' 💡 This is usually needed in frameworks which need a single point of\n' +
27+
' initialization.\n' +
28+
' 💡 It may also be useful if you need to load any polyfill that must be\n' +
29+
' loaded just once.\n' +
30+
'\n',
31+
default: false,
32+
},
33+
]);
34+
},
35+
36+
async render(options: Options): Promise<void> {
37+
if (!options['createInitializer']) {
38+
return;
39+
}
40+
41+
print(info`Generating initializer...`);
42+
43+
const renderer = new TemplateRenderer(
44+
new FilePath(__dirname).join('templates'),
45+
options.outputPath
46+
);
47+
48+
print(info` Configuring Babel`);
49+
50+
await renderer.render('.babelrc', options);
51+
52+
print(info` Creating initializer`);
53+
54+
await renderer.render('src/index.js', options);
55+
},
56+
};
57+
58+
export default facet;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Place any initialization of this shared bundle in this file. That way, you
3+
* can run:
4+
*
5+
* require('<%= name %>');
6+
*
7+
* in your dependent projects, before using this shared bundle and you will make
8+
* sure that this code is executed once.
9+
*/
10+

projects/js-toolkit/packages/liferay-cli/src/new/target-liferay/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import facetPortlet from '../facet-portlet';
2121
import facetProject from '../facet-project';
2222
import facetReact from '../facet-react';
2323
import facetSampleConfiguration from '../facet-sample-configuration';
24+
import facetSharedBundle from '../facet-shared-bundle';
2425
import facetSampleStyles from '../facet-sample-styles';
2526
import facetVuejs from '../facet-vuejs';
2627

@@ -39,6 +40,7 @@ const projectTypeFacets: {[name: string]: LiferayTargetFacet} = {
3940
'Angular': facetAngular,
4041
'Plain JavaScript': facetPlainJs,
4142
'React': facetReact,
43+
'Shared bundle': facetSharedBundle,
4244
'Vue.js': facetVuejs,
4345
};
4446
const platforms = dependencies['target-liferay']['platforms'];

0 commit comments

Comments
 (0)