jenkins-bot has submitted this change and it was merged.
Change subject: adding gulp watch task and refactoring gulpfile.js
......................................................................
adding gulp watch task and refactoring gulpfile.js
Change-Id: I5ac3e83be9ec1298a619359c0f53f86978730e9d
---
M .gitignore
M gulpfile.js
2 files changed, 99 insertions(+), 28 deletions(-)
Approvals:
JGirault: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.gitignore b/.gitignore
index 71553e8..24280a8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
node_modules
.idea
-cache
\ No newline at end of file
+cache
+dev/wikipedia.org/index.html
diff --git a/gulpfile.js b/gulpfile.js
index f1d9140..b592fde 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -12,6 +12,7 @@
var baseDir, prodDir,
plugins = gulpLoadPlugins(),
+ config = {},
portalParam = argv.portal;
// Help
@@ -30,6 +31,8 @@
console.log( '| gulp lint --portal wikipedia.org - run
jslint on JS files on portal JS files |' );
console.log( '| gulp inline-assets --portal wikipedia.org - build
inline CSS and JS assets |' );
console.log( '| gulp optimize-images --portal wikipedia.org - run
imagemin on image directory |' );
+ console.log( '| gulp watch --portal wikipedia.org
- watches dev directory and generates an index.html |' );
+ console.log( '|
file in it without inlined/minified assets
|' );
console.log( '| gulp --portal wikipedia.org - run all
of the above on the specified portal page |' );
console.log( '|
|' );
console.log( '| gulp fetch-meta --portal wikipedia.org - overwrite
the portal page with source from Meta |' );
@@ -37,7 +40,10 @@
console.log();
} );
-// This task is a preliminary task for the tasks that require the portal param.
+/**
+ * Preliminary task for tasks that require the portal param.
+ * Also sets config for remaining tasks.
+ */
gulp.task( 'build', function () {
if ( !portalParam ) {
console.log( '\x1b[31m' );
@@ -49,14 +55,16 @@
baseDir = 'dev/' + portalParam + '/';
prodDir = 'prod/' + portalParam + '/';
-} );
-/* List of tasks
- =========================================================================== */
+ config.hb = {
+ src: baseDir + 'index.handlebars',
+ templateData: require( './' + baseDir + 'controller' ),
+ options: {
+ batch: [ './' + baseDir + '/templates' ],
+ helpers: require( './hbs-helpers.global' )
+ }
+ };
-gulp.task( 'inline-assets', [ 'build' ], function () {
-
- // extend minifyCss plugins to pass some options.
var minifyCss = function () {
var options = {
compatibility: 'ie7',
@@ -65,38 +73,100 @@
return plugins.minifyCss.call( this, options );
};
- var templateData = require( './' + baseDir + 'controller' ),
- hbsHelpers = require( './hbs-helpers.global' ),
- options = {
- batch: [ './' + baseDir + '/templates' ],
- helpers: hbsHelpers
- };
-
- gulp.src( baseDir + 'index.handlebars' )
- .pipe( plugins.compileHandlebars( templateData, options ) )
- .pipe( plugins.inline( {
+ config.inline = {
+ src: baseDir + 'index.html',
+ options: {
base: baseDir,
js: plugins.uglify,
css: minifyCss,
disabledTypes: [ 'svg', 'img' ]
- } ) )
- .pipe( plugins.htmlmin( {
+ }
+ };
+
+ config.htmlmin = {
+ src: prodDir + 'index.html',
+ dest: prodDir + 'index.html',
+ options: {
preventAttributesEscaping: true,
collapseWhitespace: true,
preserveLineBreaks: true,
collapseBooleanAttributes: true
- } ) )
+ }
+ };
+
+ config.watch = {
+ hb: [ baseDir + '**/*.handlebars', baseDir + '.json', baseDir +
'controller.js' ]
+ };
+
+ config.optImage = {
+ src: baseDir + 'assets/img/*',
+ pngQuantOptions: { quality: '80-95', speed: 1 },
+ dest: prodDir + 'assets/img'
+ };
+
+} );
+
+/* List of tasks
+ =========================================================================== */
+
+/**
+ * Compiles Handlebars templates into dev folder.
+ * executes 'build' task if config is undefined
+ */
+
+gulp.task( 'compile-handlebars', function () {
+
+ if ( !config.hb ) {
+ gulp.start( 'build' );
+ }
+
+ return gulp.src( config.hb.src )
+ .pipe( plugins.compileHandlebars( config.hb.templateData,
config.hb.options ) )
.pipe( plugins.rename( 'index.html' ) )
+ .pipe( gulp.dest( baseDir ) );
+} );
+
+/**
+ * Inlines assets of index.html in dev folder,
+ * moves index.html into prod folder
+ */
+gulp.task( 'inline-assets', [ 'compile-handlebars' ], function () {
+ return gulp.src( config.inline.src )
+ .pipe( plugins.inline( config.inline.options ) )
.pipe( gulp.dest( prodDir ) );
} );
-gulp.task( 'optimize-images', [ 'build' ], function () {
- gulp.src( baseDir + 'assets/img/*' )
- .pipe( imageminPngquant( { quality: '80-95', speed: 1 } )() )
- .pipe( plugins.imagemin() )
- .pipe( gulp.dest( prodDir + 'assets/img' ) );
+/**
+ * Minifies index.html file in prod folder,
+ * depends on inline-assets which moves index.html from dev to prod.
+ */
+gulp.task( 'minify-html', [ 'inline-assets' ], function () {
+ return gulp.src( config.htmlmin.src )
+ .pipe( plugins.htmlmin( config.htmlmin.options ) )
+ .pipe( gulp.dest( prodDir ) );
} );
+/**
+ * Optimizes images in dev folder and moves them into prod folder
+ */
+gulp.task( 'optimize-images', [ 'build' ], function () {
+ gulp.src( config.optImage.src )
+ .pipe( imageminPngquant( config.optImage.pngQuantOptions )() )
+ .pipe( plugins.imagemin() )
+ .pipe( gulp.dest( config.optImage.dest ) );
+} );
+
+/**
+ * Watches for changes in dev folder and compiles handlebars
+ * into dev folder.
+ */
+gulp.task( 'watch', [ 'build', 'compile-handlebars' ], function () {
+ gulp.watch( config.watch.hb, [ 'compile-handlebars' ] );
+} );
+
+/**
+ * Lints js in dev folder as well as in root folder.
+ */
gulp.task( 'lint', function () {
var devFolder = 'dev/**/*.js';
if ( portalParam ) {
@@ -128,8 +198,8 @@
url:
'https://meta.wikimedia.org/w/index.php?title=Www.' + portalParam +
'_template&action=raw'
}
} )
- .pipe( gulp.dest( prodDir ) );
+ .pipe( gulp.dest( prodDir ) );
} );
-gulp.task( 'default', [ 'build', 'lint', 'inline-assets', 'optimize-images' ]
);
+gulp.task( 'default', [ 'build', 'lint', 'compile-handlebars',
'inline-assets', 'minify-html', 'optimize-images' ] );
gulp.task( 'test', [ 'lint' ] );
--
To view, visit https://gerrit.wikimedia.org/r/257882
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5ac3e83be9ec1298a619359c0f53f86978730e9d
Gerrit-PatchSet: 5
Gerrit-Project: wikimedia/portals
Gerrit-Branch: master
Gerrit-Owner: Jdrewniak <[email protected]>
Gerrit-Reviewer: JGirault <[email protected]>
Gerrit-Reviewer: Jdrewniak <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits