Skip to content

Instantly share code, notes, and snippets.

@parhumm

parhumm/gulpfile.js

Forked from par6n/gulpfile.js
Last active Aug 29, 2015
Embed
What would you like to do?
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!
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.