Skip to content

Instantly share code, notes, and snippets.

@par6n
Created August 3, 2015 13:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save par6n/7c07ca84e3be75824543 to your computer and use it in GitHub Desktop.
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.
// Example for handling git through gulp. Useful receipt for sometimes ;)
// hive.ir - made by Ehsaan <iehsan.ir@gmail.com>
// 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://EhsaanF@github.com/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!
} );
@mmdsharifi
Copy link

Great tutorial ehsan !
Can I write my own commit message by using Gulp instead of 'Automated Build by Gulp' ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment