Created
August 3, 2015 13:16
-
-
Save par6n/7c07ca84e3be75824543 to your computer and use it in GitHub Desktop.
Git handler through Gulp, read hive.ir or contact me for more details.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example for handling git through gulp. Useful receipt for sometimes ;) | |
// hive.ir - made by Ehsaan <[email protected]> | |
// gulpfile.js | |
var gulp = require( 'gulp' ); | |
var git = require( 'gulp-git' ); | |
var minifyCss = require( 'gulp-minify-css' ); | |
var uglify = require( 'gulp-uglify' ); | |
var concat = require( 'gulp-concat' ); | |
var fs = require( 'fs' ); | |
const repo = "https://[email protected]/EhsaanF/wp.com-oauth.git"; | |
const repo_name = "wp.com-oauth"; | |
gulp.task( 'download', function() { | |
if ( fs.existsSync( repo_name ) ) { | |
git.pull( 'origin', 'master', { cwd: './' + repo_name + '/' }, function( err ) { | |
if ( err ) throw err; | |
} ); | |
} else { | |
git.clone( repo, function( err ) { | |
if ( err ) throw err; | |
} ); | |
} | |
} ); | |
gulp.task( 'build-css', [ 'download' ], function() { | |
return gulp.src( repo_name + '/css/*.css' ) | |
.pipe( minifyCss() ) | |
.pipe( concat( 'package.css' ) ) | |
.pipe( gulp.dest( repo_name + '/dist/' ) ); | |
} ); | |
gulp.task( 'build-js', [ 'download' ], function() { | |
return gulp.src( repo_name + '/js/*.js' ) | |
.pipe( uglify() ) | |
.pipe( concat( 'build.js' ) ) | |
.pipe( gulp.dest( repo_name + '/dist/' ) ); | |
} ); | |
gulp.task( 'add', [ 'build-css', 'build-js' ], function() { | |
return gulp.src( './' + repo_name + '/dist/**/*.*' ) | |
.pipe( git.add( { cwd: './' + repo_name + '/' } ) ); | |
} ); | |
gulp.task( 'commit', [ 'add' ], function() { | |
return gulp.src( './' + repo_name + '/dist/**/*.*' ) | |
.pipe( git.commit( 'Automated Build by Gulp', { cwd: './' + repo_name + '/' } ) ); | |
} ); | |
gulp.task( 'push', [ 'commit' ], function() { | |
git.push( 'origin', 'master', { cwd: './' + repo_name + '/', args: ' -u' }, function( err ) { | |
if ( err ) throw err; | |
} ); | |
} ); | |
// Now, default task to run all them in arrange | |
gulp.task( 'default', function() { | |
gulp.start( 'download', 'build-css', 'build-js', 'add', 'commit', 'push' ); // and Done! | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great tutorial ehsan !
Can I write my own commit message by using Gulp instead of 'Automated Build by Gulp' ?