-
-
Save parhumm/9827355a24065f177e50 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 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 <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