在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):therealklanni/git-guppy开源软件地址(OpenSource Url):https://github.com/therealklanni/git-guppy开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):git-guppy
guppy streamlines and extends your git-hooks by integrating them with your gulp workflow. This enables you to have gulp tasks that run when triggered by a git-hook, which means you can do cool things like abort a commit if your tests are failing. Git-hooks can now be managed through npm, allowing them to automatically be installed and updated. And because they integrate with gulp, it's easy to modify the workflow and even combine hooks with your other gulp tasks. guppy leverages these powerful existing systems as its backbone, allowing guppy (and therefore your git-hooks) to remain as simple and lightweight as possible through interfaces you're already familiar with. A git-hook that lint-checks your code and makes sure your unit tests pass before committing could be as simple as gulp.task('pre-commit', ['lint', 'unit']); Installnpm i git-guppy --save-dev UsageGit integrationAutomatic! The actual scripts that git will run to trigger guppy's hooks will be automatically
installed to your Typically, a workflow can be added to your gulp tasks via a guppy-hook. A guppy-hook is like a git-hook preconfigured for specific gulp workflows. You can install guppy-hooks via Search "guppy-hook" on npm to find all
guppy-hook packages. Or run gulp integration
guppy exposes a few simple methods to help you superpower your git-hooks with gulp tasks. Before you dive in, initialize guppy by passing in your gulp reference: var gulp = require('gulp');
var guppy = require('git-guppy')(gulp); Then simply define some gulp tasks in your gulp.task('pre-commit', function () {
// see below
}); Note: if you are working directly with guppy rather than installing a guppy-hook you will need to manually install the associated git-hooks using the guppy-cli commandline tool. guppy.src(hookName)
Pass in the name of the desired git-hook and get back the related filenames. This allows you to work with the source file directly, for example to modify a commit-msg programmatically or lint changed files. Note for pre-commit and pre-applypatch this will give you the working-copy,
not the indexed (staged) changes. If you want the indexed changes, use
// contrived example
gulp.task('pre-commit', function () {
return gulp.src(guppy.src('pre-commit'))
.pipe(gulpFilter(['*.js']))
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'));
}); guppy.src(hookName[, fn])
If you pass the optional // less contrived example
gulp.task('pre-commit', guppy.src('pre-commit', function (filesBeingCommitted) {
return gulp.src(filesBeingCommitted)
.pipe(gulpFilter(['*.js']))
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'));
}));
// another contrived example
gulp.task('pre-push', guppy.src('pre-push', function (files, extra, cb) {
var branch = execSync('git rev-parse --abbrev-ref HEAD');
if (branch === 'master') {
cb('Don\'t push master!')
} else {
cb();
}
})); guppy.stream(hookName[, options])
Pass in the name of the git-hook to produce a stream of the related files. You can pass options as a second argument, please refer to the docs for gulp.src for more information on available options. Note that depending on the git-hook, you may be acting on files that differ from
your working copy, such as those staged for commit (as with 'pre-commit' for
example), rather than the working copy. If you need to act on the working-copy
files, use gulp.task('pre-commit', function () {
return guppy.stream('pre-commit')
.pipe(gulpFilter(['*.js']))
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'));
}); Additional notesFor many git-hooks there are no files associated, so for those it makes sense
to only add other gulp tasks as dependencies to invoke a workflow, however some
will still receive some arguments (passed in by gulp.task('post-checkout', ['lint']); Writing guppy-hooksstay tuned For details on what arguments each git-hook receives and what result a non-zero exit status would have, check the git-scm docs. AuthorKevin Lanni License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论