Last change
on this file since 516 was
516,
checked in by hendrikvanantwerpen, 11 years ago
|
Enable deployment with Grunt.
|
File size:
1.4 KB
|
Line | |
---|
1 | /* |
---|
2 | * grunt-git-deploy |
---|
3 | * https://github.com/iclanzan/grunt-git-deploy |
---|
4 | * |
---|
5 | * Copyright (c) 2013 Sorin Iclanzan |
---|
6 | * Licensed under the MIT license. |
---|
7 | */ |
---|
8 | |
---|
9 | 'use strict'; |
---|
10 | |
---|
11 | var path = require("path"); |
---|
12 | |
---|
13 | module.exports = function(grunt) { |
---|
14 | var file = grunt.file; |
---|
15 | var spawn = grunt.util.spawn; |
---|
16 | |
---|
17 | grunt.registerMultiTask('git_deploy', 'Push files to a git remote.', function() { |
---|
18 | // Merge task options with these defaults. |
---|
19 | var options = this.options({ |
---|
20 | message: 'autocommit', |
---|
21 | branch: 'gh-pages' |
---|
22 | }); |
---|
23 | |
---|
24 | if (!options.url) { |
---|
25 | grunt.fail.warn('The URL to a remote git repository is required.'); |
---|
26 | return false; |
---|
27 | } |
---|
28 | |
---|
29 | var src = this.filesSrc[0]; |
---|
30 | |
---|
31 | if (!file.isDir(src)) { |
---|
32 | grunt.fail.warn('A source directory is needed.'); |
---|
33 | return false; |
---|
34 | } |
---|
35 | |
---|
36 | function git(args) { |
---|
37 | return function(cb) { |
---|
38 | grunt.log.writeln('Running ' + args.join(' ').green); |
---|
39 | spawn({ |
---|
40 | cmd: 'git', |
---|
41 | args: args, |
---|
42 | opts: {cwd: src} |
---|
43 | }, cb); |
---|
44 | }; |
---|
45 | } |
---|
46 | |
---|
47 | grunt.file.delete(path.join(src, '.git')); |
---|
48 | |
---|
49 | var done = this.async(); |
---|
50 | |
---|
51 | grunt.util.async.series([ |
---|
52 | git(['init']), |
---|
53 | git(['checkout', '--orphan', options.branch]), |
---|
54 | git(['add', '--all']), |
---|
55 | git(['commit', '--message="' + options.message + '"']), |
---|
56 | git(['push', '--prune', '--force', '--quiet', options.url, options.branch]) |
---|
57 | ], done); |
---|
58 | |
---|
59 | }); |
---|
60 | }; |
---|
61 | |
---|
Note: See
TracBrowser
for help on using the repository browser.