@@ -31,20 +31,30 @@ import ui5preload from 'gulp-ui5-preload'
31
31
import ui5Bust from './modules/ui5-cache-buster'
32
32
import { downloadUI5 , buildUI5 } from './modules/ui5-lib-util'
33
33
import LessAutoprefix from 'less-plugin-autoprefix'
34
+ import ora from 'ora'
34
35
import del from 'del'
35
36
import path from 'path'
36
37
import fs from 'fs'
38
+ import commander from 'commander'
37
39
import server from 'browser-sync'
38
40
import handlebars from 'handlebars'
39
41
import gulpHandlebars from 'gulp-handlebars-html'
40
42
43
+ // parse program commands
44
+ commander . version ( pkg . version ) . option ( '--silent' ) . parse ( process . argv )
45
+
41
46
const hdlbars = gulpHandlebars ( handlebars )
47
+ const spinner = ora ( )
42
48
43
49
// register handlebars helper function
44
50
handlebars . registerHelper ( 'secure' , function ( str ) {
45
51
return new handlebars . SafeString ( str )
46
52
} )
47
53
54
+ // switch between gulp log and custom log
55
+ spinner . enabled = commander . silent
56
+ spinner . print = sText => spinner . stopAndPersist ( { text : sText } )
57
+
48
58
/*
49
59
* CONFIGURATION
50
60
*/
@@ -87,10 +97,43 @@ const paths = {
87
97
* @public
88
98
*/
89
99
const start = gulp . series (
100
+ function startSpinner ( done ) {
101
+ spinner . print ( ' ' )
102
+ spinner . start ( 'Start development server...' )
103
+ done ( )
104
+ } ,
90
105
gulp . parallel ( gulp . series ( downloadOpenUI5 , buildOpenUI5 ) , clean ) ,
91
106
gulp . parallel ( entry , assets , scripts , styles ) ,
107
+ logStats ,
92
108
watch
93
109
)
110
+ function logStats ( done ) {
111
+ const sSourceID = pkg . ui5 . src
112
+ const oSource = pkg . ui5 . srcLinks [ sSourceID ]
113
+ const sUI5Version = oSource . version
114
+ const sOnlineUI5State =
115
+ ! oSource . isArchive && oSource . isPrebuild ? '(remote)' : ''
116
+ const sUI5Details = ! oSource . isPrebuild ? '(custom build)' : sOnlineUI5State
117
+
118
+ const iApps = ( pkg . ui5 . apps || [ ] ) . length
119
+ const iThemes = ( pkg . ui5 . themes || [ ] ) . length
120
+ const iLibs = ( pkg . ui5 . libraries || [ ] ) . length
121
+
122
+ // print success message
123
+ spinner
124
+ . succeed (
125
+ 'Development server started, use Ctrl+C to stop and go back to the console...'
126
+ )
127
+ . print ( ' ' )
128
+ . print ( `UI5 Version: ${ sUI5Version } ${ sUI5Details } ` )
129
+ . print ( ' ' )
130
+ . print ( 'UI5 assets:' )
131
+ . print ( `\u{25FB} ${ iApps } app${ iApps !== 1 ? 's' : '' } ` )
132
+ . print ( `\u{25FB} ${ iThemes } theme${ iThemes !== 1 ? 's' : '' } ` )
133
+ . print ( `\u{25FB} ${ iLibs } librar${ iLibs !== 1 ? 'ies' : 'y' } ` )
134
+ . print ( ' ' )
135
+ done ( )
136
+ }
94
137
export default start
95
138
96
139
/**
@@ -99,11 +142,45 @@ export default start
99
142
* @public
100
143
*/
101
144
const build = gulp . series (
145
+ function startSpinner ( done ) {
146
+ spinner . print ( ' ' )
147
+ spinner . start ( 'Build start...' )
148
+ done ( )
149
+ } ,
102
150
gulp . parallel ( gulp . series ( downloadOpenUI5 , buildOpenUI5 ) , cleanDist ) ,
103
151
gulp . parallel ( entryDist , assetsDist , scriptsDist , stylesDist ) ,
104
152
ui5preloads ,
105
- ui5cacheBust
153
+ ui5cacheBust ,
154
+ logStatsDist
106
155
)
156
+ function logStatsDist ( done ) {
157
+ const sSourceID = pkg . ui5 . src
158
+ const oSource = pkg . ui5 . srcLinks [ sSourceID ]
159
+ const sUI5Version = oSource . version
160
+ const sOnlineUI5State =
161
+ ! oSource . isArchive && oSource . isPrebuild ? '(remote)' : ''
162
+ const sUI5Details = ! oSource . isPrebuild ? '(custom build)' : sOnlineUI5State
163
+
164
+ const iApps = ( pkg . ui5 . apps || [ ] ) . length
165
+ const iThemes = ( pkg . ui5 . themes || [ ] ) . length
166
+ const iLibs = ( pkg . ui5 . libraries || [ ] ) . length
167
+
168
+ // print success message
169
+ spinner
170
+ . succeed ( 'Build successfull.' )
171
+ . print ( ' ' )
172
+ . print ( `Build entry: ${ pkg . main } ` )
173
+ . print ( `Build output: ${ path . relative ( __dirname , DIST ) } ` )
174
+ . print ( ' ' )
175
+ . print ( `UI5 Version: ${ sUI5Version } ${ sUI5Details } ` )
176
+ . print ( ' ' )
177
+ . print ( 'UI5 assets created:' )
178
+ . print ( `\u{25FB} ${ iApps } app${ iApps !== 1 ? 's' : '' } ` )
179
+ . print ( `\u{25FB} ${ iThemes } theme${ iThemes !== 1 ? 's' : '' } ` )
180
+ . print ( `\u{25FB} ${ iLibs } librar${ iLibs !== 1 ? 'ies' : 'y' } ` )
181
+ . print ( ' ' )
182
+ done ( )
183
+ }
107
184
export { build }
108
185
109
186
/* ----------------------------------------------------------- *
@@ -187,10 +264,37 @@ export function downloadOpenUI5() {
187
264
? path . resolve ( __dirname , './.download' )
188
265
: path . resolve ( __dirname , `./ui5` )
189
266
const sUI5TargetPath = path . resolve ( __dirname , `./ui5/${ sUI5Version } ` )
267
+ const isDownloadRequired =
268
+ oSource . isArchive &&
269
+ isRemoteLink &&
270
+ // !fs.existsSync(sUI5TargetPath) &&
271
+ ! fs . existsSync ( `${ sDownloadPath } /${ sUI5Version } ` )
272
+ const oDownloadOptions = {
273
+ onProgress ( iStep , iTotalSteps , oStepDetails ) {
274
+ // update spinner state
275
+ spinner . text = `Downloading UI5... [${ iStep } /${ iTotalSteps } ] ${ Math . round (
276
+ oStepDetails . progress || 0
277
+ ) } % (${ oStepDetails . name } )`
278
+ }
279
+ }
280
+
281
+ if ( isDownloadRequired ) {
282
+ // update spinner state
283
+ spinner . text =
284
+ 'Downloading UI5... (this task can take several minutes, please be patient)'
285
+ }
190
286
191
287
// return promise
192
- return oSource . isArchive && isRemoteLink && ! fs . existsSync ( sUI5TargetPath )
193
- ? downloadUI5 ( sCompiledURL , sDownloadPath , sUI5Version )
288
+ return isDownloadRequired
289
+ ? downloadUI5 ( sCompiledURL , sDownloadPath , sUI5Version , oDownloadOptions )
290
+ . then ( sSuccessMessage => {
291
+ spinner . success ( sSuccessMessage )
292
+ spinner . start ( '' )
293
+ } )
294
+ . catch ( sErrorMessage => {
295
+ spinner . fail ( sErrorMessage )
296
+ spinner . start ( '' )
297
+ } )
194
298
: Promise . resolve ( )
195
299
}
196
300
@@ -204,10 +308,37 @@ export function buildOpenUI5() {
204
308
205
309
const sDownloadPath = path . resolve ( __dirname , './.download' )
206
310
const sUI5TargetPath = path . resolve ( __dirname , `./ui5/${ sUI5Version } ` )
311
+ const isBuildRequired =
312
+ oSource . isPrebuild === false && ! fs . existsSync ( sUI5TargetPath )
313
+ const oBuildOptions = {
314
+ onProgress ( iStep , iTotalSteps , oStepDetails ) {
315
+ // update spinner state
316
+ spinner . text = `Build UI5... [${ iStep } /${ iTotalSteps } ] (${ oStepDetails . name } )`
317
+ }
318
+ }
319
+
320
+ if ( isBuildRequired ) {
321
+ // update spinner state
322
+ spinner . text =
323
+ 'Build UI5... (this task can take several minutes, please be patient)'
324
+ }
207
325
208
326
// define build Promise
209
- return oSource . isPrebuild === false
210
- ? buildUI5 ( `${ sDownloadPath } /${ sUI5Version } ` , sUI5TargetPath , sUI5Version )
327
+ return isBuildRequired
328
+ ? buildUI5 (
329
+ `${ sDownloadPath } /${ sUI5Version } ` ,
330
+ sUI5TargetPath ,
331
+ sUI5Version ,
332
+ oBuildOptions
333
+ )
334
+ . then ( sSuccessMessage => {
335
+ spinner . success ( sSuccessMessage )
336
+ spinner . start ( '' )
337
+ } )
338
+ . catch ( sErrorMessage => {
339
+ spinner . fail ( sErrorMessage )
340
+ spinner . start ( '' )
341
+ } )
211
342
: Promise . resolve ( )
212
343
}
213
344
@@ -298,6 +429,9 @@ function entry() {
298
429
299
430
// [production build]
300
431
function entryDist ( ) {
432
+ // update spinner state
433
+ spinner . text = 'Compiling project resources...'
434
+
301
435
return (
302
436
gulp
303
437
. src ( paths . entry . src )
@@ -472,6 +606,9 @@ function stylesDist() {
472
606
473
607
// [production build]
474
608
function ui5preloads ( ) {
609
+ // update spinner state
610
+ spinner . text = 'Bundling modules...'
611
+
475
612
const aPreloadPromise = pkg . ui5 . apps . map ( oApp => {
476
613
const sDistAppPath = oApp . path . replace ( new RegExp ( `^${ SRC } ` ) , DIST )
477
614
return new Promise ( function ( resolve , reject ) {
@@ -506,6 +643,9 @@ function ui5preloads() {
506
643
507
644
// [production build]
508
645
function ui5cacheBust ( done ) {
646
+ // update spinner state
647
+ spinner . text = 'Run cache buster...'
648
+
509
649
return (
510
650
gulp
511
651
. src ( paths . cacheBuster . src )
0 commit comments