Upload code deployment using gulp and Git
In projects, we often want to compile locally (such as NPM run build) and then deploy Git. In this case, we need to go through multiple steps, which can be quite tedious. Using this gulp script, you can package and deploy one line of commands and customize the commit content.
Github
The installation
Cloning project
git clone [email protected]:Hzy0913/gulp-push.git
Install dependencies
npm install
Concrete implementation code
var gulp = require('gulp');
var exec = require('child_process').exec;
var gulpSequence = require('gulp-sequence')
var argv = require('minimist')(process.argv.slice(2));
//RUN NPM RUN build package command (according to your project package command configuration)
gulp.task('build'.function (cb) {
exec('npm run build'.function (err, stdout, stderr) {
cb(err);
});
});
// CMD back returns to the previous layer
gulp.task('back'.function (cb) {
exec('cd .. '.function (err, stdout, stderr) {
cb(err);
});
});
// add is equivalent to git add * (you can configure it yourself, such as add -a or add.)
gulp.task('add'.function (cb) {
exec('git add *'.function (err, stdout, stderr) {
cb(err);
});
});
// push perform git push
gulp.task('push'.function (cb) {
exec('git push'.function (err, stdout, stderr) {
cb(err);
});
});
// pull Perform git pull
gulp.task('pull'.function (cb) {
exec('git pull'.function (err, stdout, stderr) {
cb(err);
});
});
// commit Adds a custom commit push operation
var commitdefault='s'
gulp.task('commit'.function (cb) {
if(! argv.a){ commitcon=commitdefault }else {
var commitcon=argv.a
}
exec('git commit -m '+commitcon, function (err, stdout, stderr) {
cb(err);
});
});
/ / * * * * * * * * * * * * * * * * * * * * * * specific use the command * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// The default gulp command is pushed to the repository (gulp -a custom commit is executed if a custom commit is required)
gulp.task( 'default', gulpSequence( 'add'.'commit'.'push'));
// gulp b execute build package and push to the repository (gulp b -a custom commit)
gulp.task( 'b', gulpSequence( 'build'.'add'.'commit'.'push'));
// run the gulp p command to update the remote repository
gulp.task( 'p', gulpSequence('pull'));
Copy the code
Use the command (Note that the command needs to be used in your Git Bash)
Git add * +git commit -m’s +git push
(git add * +git commit -m’s +git push
Git add * +git commit -m custom +git push
4. Create a custom commit (git add * +git commit -m +git push
5. Update the remote code repository (Git pull) gulp
Customize the commit command and package it to upload (on your Git bash command line)
The code repository has been updated
Specific code can see my githubgithub.com/Hzy0913/gul…