-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgit_deploy.js
78 lines (62 loc) · 1.79 KB
/
git_deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* grunt-git-deploy
* https://github.com/iclanzan/grunt-git-deploy
*
* Copyright (c) 2013 Sorin Iclanzan
* Licensed under the MIT license.
*/
'use strict';
var path = require("path");
module.exports = function(grunt) {
var file = grunt.file;
var spawn = grunt.util.spawn;
grunt.registerMultiTask('git_deploy', 'Push files to a git remote.', function() {
// Merge task options with these defaults.
var options = this.options({
message: 'autocommit',
branch: 'gh-pages',
quiet: true
});
if (!options.url) {
grunt.fail.warn('The URL to a remote git repository is required.');
return false;
}
var src = this.filesSrc[0];
if (!file.isDir(src)) {
grunt.fail.warn('A source directory is needed.');
return false;
}
function git(args) {
return function(cb) {
grunt.log.writeln('Running ' + args.join(' ').green);
git = spawn({
cmd: 'git',
args: args,
opts: {cwd: src}
}, cb);
if (!options.quiet) {
// Log git output to console
git.stdout.on('data', function (data) {
process.stdout.write(data);
});
git.stderr.on('data', function (data) {
process.stderr.write(data);
});
}
};
}
grunt.file.delete(path.join(src, '.git'));
var done = this.async();
var push_args = ['push', '--prune', '--force'];
if (options.quiet)
push_args.push('--quiet');
push_args.push(options.url, options.branch);
grunt.util.async.series([
git(['init']),
git(['checkout', '--orphan', options.branch]),
git(['add', '--all']),
git(['commit', '--message="' + options.message + '"']),
git(push_args)
], done);
});
};