Last active
June 22, 2017 17:08
-
-
Save LoyEgor/a5f73055f0119459204e388bacbcf9ec to your computer and use it in GitHub Desktop.
gulp git settings
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
// install | |
// npm i gulp-bump gulp-git run-sequence | |
var bump = require('gulp-bump'); | |
var git = require('gulp-git'); | |
var runSequence = require('run-sequence'); | |
var fs = require('fs'); | |
// get project files | |
var allgit = ['./app/**/*', './gulpfile.js', './package.json', './faviconData.json']; | |
// get project version | |
// get project version | |
function getversion() { | |
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version; | |
}; | |
var version = getversion(); | |
gulp.task('bump', function() { | |
return gulp.src('./package.json') | |
.pipe(bump({ | |
type: 'importance' | |
})) | |
// major: 1.0.0 | |
// minor: 0.1.0 | |
// patch: 0.0.2 - Default | |
// prerelease: 0.0.1-2 | |
.pipe(gulp.dest('./')); | |
}); | |
gulp.task('git:init', function() { | |
return git.init(function(err) { | |
if (err) throw err; | |
// add gitignore | |
// fs.appendFileSync for add to end of file | |
// fs.writeFile to overwrite file | |
fs.writeFile('./.git/info/exclude', '/bower_components/\n/node_modules/\n/dist/\n*.zip\n.DS_Store'); | |
}); | |
}); | |
gulp.task('git:add', function() { | |
return gulp.src(allgit) | |
.pipe(git.add()); | |
}); | |
gulp.task('git:initial-commit', function() { | |
return gulp.src(allgit) | |
.pipe(git.commit('initial commit')); | |
}); | |
gulp.task('git:build-commit', function() { | |
// update version | |
var version = getversion(); | |
return gulp.src(allgit) | |
.pipe(git.commit('Build ' + version)); | |
return git.tag(version, '', function(err) { | |
if (err) throw err; | |
}); | |
}); | |
gulp.task('git:addremote', function() { | |
return gulp.src(allgit) | |
.pipe(git.addRemote('origin', 'https://[email protected]/loyegor/test.git')); | |
}); | |
gulp.task('git:push', function() { | |
git.push('origin', 'master', { | |
args: '-u' | |
}, function(err) { | |
if (err) throw err; | |
}); | |
}); | |
// init and create first git commit and push | |
gulp.task('git:first', function(callback) { | |
runSequence( | |
'git:init', | |
'git:add', | |
'git:initial-commit', | |
'git:addremote', | |
'git:push', | |
function(err) { | |
if (err) throw err; | |
callback(err); | |
}); | |
}); | |
// create build git commit add version and push | |
gulp.task('git:build', function(callback) { | |
runSequence( | |
'bump', | |
'git:add', | |
'git:build-commit', | |
'git:push', | |
function(err) { | |
if (err) throw err; | |
callback(err); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment