Skip to content

Commit 1975eaa

Browse files
committed
#changes 0.0.3
Replaced gulp-download and gulp-unzip with request and adm-zip. Added an elegant CLI-like terminal spinner (gulp logs can be enabled anytime, by removing the `--silent` flag in node scripts of `package.json`). Removed gulp-util usage from module ui5-lib-util. Fixed some JSDoc annotations. Renamed all .handlebars resources to .hbs.
1 parent 65b55fc commit 1975eaa

File tree

6 files changed

+421
-297
lines changed

6 files changed

+421
-297
lines changed

Diff for: gulpfile.babel.js

+145-5
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,30 @@ import ui5preload from 'gulp-ui5-preload'
3131
import ui5Bust from './modules/ui5-cache-buster'
3232
import { downloadUI5, buildUI5 } from './modules/ui5-lib-util'
3333
import LessAutoprefix from 'less-plugin-autoprefix'
34+
import ora from 'ora'
3435
import del from 'del'
3536
import path from 'path'
3637
import fs from 'fs'
38+
import commander from 'commander'
3739
import server from 'browser-sync'
3840
import handlebars from 'handlebars'
3941
import gulpHandlebars from 'gulp-handlebars-html'
4042

43+
// parse program commands
44+
commander.version(pkg.version).option('--silent').parse(process.argv)
45+
4146
const hdlbars = gulpHandlebars(handlebars)
47+
const spinner = ora()
4248

4349
// register handlebars helper function
4450
handlebars.registerHelper('secure', function(str) {
4551
return new handlebars.SafeString(str)
4652
})
4753

54+
// switch between gulp log and custom log
55+
spinner.enabled = commander.silent
56+
spinner.print = sText => spinner.stopAndPersist({ text: sText })
57+
4858
/*
4959
* CONFIGURATION
5060
*/
@@ -87,10 +97,43 @@ const paths = {
8797
* @public
8898
*/
8999
const start = gulp.series(
100+
function startSpinner(done) {
101+
spinner.print(' ')
102+
spinner.start('Start development server...')
103+
done()
104+
},
90105
gulp.parallel(gulp.series(downloadOpenUI5, buildOpenUI5), clean),
91106
gulp.parallel(entry, assets, scripts, styles),
107+
logStats,
92108
watch
93109
)
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+
}
94137
export default start
95138

96139
/**
@@ -99,11 +142,45 @@ export default start
99142
* @public
100143
*/
101144
const build = gulp.series(
145+
function startSpinner(done) {
146+
spinner.print(' ')
147+
spinner.start('Build start...')
148+
done()
149+
},
102150
gulp.parallel(gulp.series(downloadOpenUI5, buildOpenUI5), cleanDist),
103151
gulp.parallel(entryDist, assetsDist, scriptsDist, stylesDist),
104152
ui5preloads,
105-
ui5cacheBust
153+
ui5cacheBust,
154+
logStatsDist
106155
)
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+
}
107184
export { build }
108185

109186
/* ----------------------------------------------------------- *
@@ -187,10 +264,37 @@ export function downloadOpenUI5() {
187264
? path.resolve(__dirname, './.download')
188265
: path.resolve(__dirname, `./ui5`)
189266
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+
}
190286

191287
// 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+
})
194298
: Promise.resolve()
195299
}
196300

@@ -204,10 +308,37 @@ export function buildOpenUI5() {
204308

205309
const sDownloadPath = path.resolve(__dirname, './.download')
206310
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+
}
207325

208326
// 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+
})
211342
: Promise.resolve()
212343
}
213344

@@ -298,6 +429,9 @@ function entry() {
298429

299430
// [production build]
300431
function entryDist() {
432+
// update spinner state
433+
spinner.text = 'Compiling project resources...'
434+
301435
return (
302436
gulp
303437
.src(paths.entry.src)
@@ -472,6 +606,9 @@ function stylesDist() {
472606

473607
// [production build]
474608
function ui5preloads() {
609+
// update spinner state
610+
spinner.text = 'Bundling modules...'
611+
475612
const aPreloadPromise = pkg.ui5.apps.map(oApp => {
476613
const sDistAppPath = oApp.path.replace(new RegExp(`^${SRC}`), DIST)
477614
return new Promise(function(resolve, reject) {
@@ -506,6 +643,9 @@ function ui5preloads() {
506643

507644
// [production build]
508645
function ui5cacheBust(done) {
646+
// update spinner state
647+
spinner.text = 'Run cache buster...'
648+
509649
return (
510650
gulp
511651
.src(paths.cacheBuster.src)

Diff for: modules/ui5-cache-buster/index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,15 @@ export default function ui5Bust(oHTMLFile) {
137137

138138
// success message
139139
gutil.log(
140+
'ui5-cache-buster:',
140141
'⚡️ Successfully cache bust',
141-
gutil.colors.cyan(oHTMLFile.path),
142-
"(resources who have not changed, will still be fetched from the users browser's cache)"
142+
gutil.colors.cyan(oHTMLFile.path)
143+
)
144+
gutil.log(
145+
'ui5-cache-buster:',
146+
gutil.colors.cyan(
147+
"Resources who have not changed, will still be fetched from the users browser's cache."
148+
)
143149
)
144150

145151
// return updated index.html again

0 commit comments

Comments
 (0)