@@ -7,9 +7,10 @@ import fs from 'fs';
7
7
8
8
import FilePath from '../../file/FilePath' ;
9
9
import LiferayJson , {
10
- BuildConfig ,
11
10
Bundler2BuildConfig ,
12
11
CustomElementBuildConfig ,
12
+ FDSCellRendererBuildConfig ,
13
+ ThemeSpritemapBuildConfig ,
13
14
} from '../../schema/LiferayJson' ;
14
15
import Project from './Project' ;
15
16
import persist , { Location } from './persist' ;
@@ -23,25 +24,31 @@ type BuildType =
23
24
type BuildOptions =
24
25
| Bundler2BuildOptions
25
26
| CustomElementBuildOptions
26
- | ThemeSpritemapBuildOptions
27
- | { } ;
27
+ | FDSCellRendererBuildOptions
28
+ | ThemeSpritemapBuildOptions ;
28
29
29
- export interface Bundler2BuildOptions {
30
- minify : boolean ;
31
- }
30
+ export type Bundler2BuildOptions = MinifiableBuildOptions ;
32
31
33
- export interface CustomElementBuildOptions {
34
- externals : { [ bareIdentifier : string ] : string } ;
32
+ export interface CustomElementBuildOptions extends WebpackBuildOptions {
35
33
htmlElementName : string | null ;
36
- minify : boolean ;
37
34
portletCategoryName : string ;
38
35
}
39
36
37
+ export type FDSCellRendererBuildOptions = WebpackBuildOptions ;
38
+
40
39
export interface ThemeSpritemapBuildOptions {
41
40
enableSVG4Everybody : boolean ;
42
41
extendClay : boolean ;
43
42
}
44
43
44
+ export interface MinifiableBuildOptions {
45
+ minify : boolean ;
46
+ }
47
+
48
+ export interface WebpackBuildOptions extends MinifiableBuildOptions {
49
+ externals : { [ bareIdentifier : string ] : string } ;
50
+ }
51
+
45
52
type OptionValue = boolean | number | string ;
46
53
47
54
export default class Build {
@@ -52,28 +59,30 @@ export default class Build {
52
59
constructor ( project : Project , liferayJson : LiferayJson ) {
53
60
this . _project = project ;
54
61
55
- const config : BuildConfig = liferayJson . build ?. options || { } ;
56
-
57
62
switch ( liferayJson . build . type ) {
58
63
case 'customElement' :
59
64
this . type = 'customElement' ;
60
65
this . dir = project . dir . join ( 'build' ) ;
61
66
this . options = this . _toCustomElementBuildOptions (
62
67
project ,
63
- config as CustomElementBuildConfig
68
+ liferayJson . build ?. options
64
69
) ;
65
70
break ;
66
71
67
72
case 'fdsCellRenderer' :
68
73
this . type = 'fdsCellRenderer' ;
69
74
this . dir = project . dir . join ( 'build' ) ;
70
- this . options = { } ;
75
+ this . options = this . _toFDSCellRendererBuildOptions (
76
+ liferayJson . build ?. options
77
+ ) ;
71
78
break ;
72
79
73
80
case 'themeSpritemap' :
74
81
this . type = 'themeSpritemap' ;
75
82
this . dir = project . dir . join ( 'build' ) ;
76
- this . options = config as ThemeSpritemapBuildOptions ;
83
+ this . options = this . _toThemeSpriteMapBuildOptions (
84
+ liferayJson . build ?. options
85
+ ) ;
77
86
break ;
78
87
79
88
case 'bundler2' : {
@@ -87,14 +96,16 @@ export default class Build {
87
96
bundler2Project . buildDir . asNative
88
97
) . resolve ( ) ;
89
98
this . options = this . _toBundler2BuildOptions (
90
- config as Bundler2BuildConfig
99
+ liferayJson . build ?. options
91
100
) ;
92
101
break ;
93
102
}
94
103
95
104
default :
96
105
throw new Error (
97
- `Unknown project build type type: ${ liferayJson . build . type } `
106
+ `Unknown project build type type: ${
107
+ ( liferayJson . build as unknown ) [ 'type' ]
108
+ } `
98
109
) ;
99
110
}
100
111
}
@@ -146,10 +157,68 @@ export default class Build {
146
157
config : CustomElementBuildConfig
147
158
) : CustomElementBuildOptions {
148
159
160
+ // Infer htmlElementName from source code if needed
161
+
162
+ if ( ! config . htmlElementName ) {
163
+ config . htmlElementName = findHtmlElementName (
164
+ project . mainModuleFile
165
+ ) ;
166
+ }
167
+
168
+ if ( ! config . portletCategoryName ) {
169
+ config . portletCategoryName = 'category.remote-apps' ;
170
+ }
171
+
172
+ const webpackOptions = this . _toWebpackBuildOptions ( config ) ;
173
+
174
+ return {
175
+ externals : webpackOptions . externals ,
176
+ htmlElementName : config . htmlElementName ,
177
+ minify : webpackOptions . minify ,
178
+ portletCategoryName : config . portletCategoryName ,
179
+ } ;
180
+ }
181
+
182
+ private _toFDSCellRendererBuildOptions (
183
+ config : FDSCellRendererBuildConfig
184
+ ) : FDSCellRendererBuildOptions {
185
+ const webpackOptions = this . _toWebpackBuildOptions ( config ) ;
186
+
187
+ return {
188
+ externals : webpackOptions . externals ,
189
+ minify : webpackOptions . minify ,
190
+ } ;
191
+ }
192
+
193
+ private _toThemeSpriteMapBuildOptions (
194
+ config : ThemeSpritemapBuildConfig
195
+ ) : ThemeSpritemapBuildOptions {
196
+ return {
197
+ enableSVG4Everybody : ! ! config . enableSVG4Everybody ,
198
+ extendClay : ! ! config . extendClay ,
199
+ } ;
200
+ }
201
+
202
+ private _toBundler2BuildOptions (
203
+ _config : Bundler2BuildConfig
204
+ ) : Bundler2BuildOptions {
205
+ return {
206
+ minify : process . env . NODE_ENV !== 'development' ,
207
+ } ;
208
+ }
209
+
210
+ private _toWebpackBuildOptions (
211
+ config : CustomElementBuildConfig | FDSCellRendererBuildConfig
212
+ ) : WebpackBuildOptions {
213
+ const options : WebpackBuildOptions = {
214
+ externals : { } ,
215
+ minify : process . env . NODE_ENV !== 'development' ,
216
+ } ;
217
+
149
218
// Turn arrays coming from liferay.json into objects
150
219
151
- if ( Array . isArray ( config [ ' externals' ] ) ) {
152
- config . externals = config . externals . reduce (
220
+ if ( Array . isArray ( config . externals ) ) {
221
+ options . externals = config . externals . reduce (
153
222
( map , bareIdentifier ) => {
154
223
map [ bareIdentifier ] = bareIdentifier ;
155
224
@@ -158,14 +227,9 @@ export default class Build {
158
227
{ }
159
228
) ;
160
229
}
161
-
162
- const options : CustomElementBuildOptions = {
163
- externals : config . externals || { } ,
164
- htmlElementName : config . htmlElementName ,
165
- minify : process . env . NODE_ENV !== 'development' ,
166
- portletCategoryName :
167
- config . portletCategoryName || 'category.remote-apps' ,
168
- } ;
230
+ else if ( config . externals ) {
231
+ options . externals = config . externals ;
232
+ }
169
233
170
234
// Remove externals mapped to null
171
235
@@ -180,25 +244,9 @@ export default class Build {
180
244
{ }
181
245
) ;
182
246
183
- // Infer htmlElementName from source code if needed
184
-
185
- if ( ! options . htmlElementName ) {
186
- options . htmlElementName = findHtmlElementName (
187
- project . mainModuleFile
188
- ) ;
189
- }
190
-
191
247
return options ;
192
248
}
193
249
194
- private _toBundler2BuildOptions (
195
- _config : Bundler2BuildConfig
196
- ) : Bundler2BuildOptions {
197
- return {
198
- minify : process . env . NODE_ENV !== 'development' ,
199
- } ;
200
- }
201
-
202
250
private _project : Project ;
203
251
}
204
252
0 commit comments