-
Notifications
You must be signed in to change notification settings - Fork 11
/
Gruntfile.js
112 lines (97 loc) · 2.42 KB
/
Gruntfile.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var config = require( "./lib/config" ),
update = require( "./lib/update" ),
fs = require( "fs" );
module.exports = function( grunt ) {
grunt.loadNpmTasks( "grunt-contrib-jshint" );
grunt.initConfig({
jshint: {
all: [ "Gruntfile.js", "lib/**.js" ],
options: {
jshintrc: ".jshintrc"
}
}
});
grunt.registerTask( "default", [ "jshint", "cron" ] );
grunt.registerTask( "clean", function() {
var data;
try {
data = require( config.output + "/data.json" );
} catch( e ) {
console.log( "No data.json found" );
return;
}
Object.keys( data.branches || {} )
.concat( Object.keys( data.tags || {} ) )
.forEach(function( directory ) {
grunt.log.writeln( "Removing " + directory );
grunt.file["delete"]( config.output + "/" + directory );
});
grunt.log.writeln( "Removing data.json" );
grunt.file["delete"]( config.output + "/data.json" );
});
grunt.registerTask( "update-repo", function() {
function thenFetch( err ) {
if ( err ) {
grunt.verbose.error();
done( err );
return;
}
grunt.util.spawn({
cmd: "git",
args: [ "fetch", "-fup", "origin", "+refs/tags/*:refs/tags/*", "+refs/heads/*:refs/heads/*" ],
opts: {
cwd: config.working
}
}, function( err, result ) {
if ( err ) {
grunt.verbose.error();
done( err );
return;
}
grunt.log.writeln( result );
done();
});
}
var done = this.async();
if ( !fs.existsSync( config.working ) ) {
grunt.log.writeln( "Cloning " + config.repo + " to " + config.working );
grunt.util.spawn({
cmd: "git",
args: [ "clone", "--bare", config.repo, config.working ]
}, thenFetch);
} else {
grunt.log.writeln( "Fetching updates from " + config.repo );
grunt.util.spawn({
cmd: "git",
args: [ "remote", "set-url", "origin", config.repo ],
opts: {
cwd: config.working
}
}, thenFetch );
}
});
grunt.registerTask( "check-versions", function() {
var done = this.async();
if ( !fs.existsSync( config.output ) ) {
grunt.file.mkdir( config.output );
}
update( done );
});
grunt.registerTask( "check-config", function() {
var done = this.async(),
errors = [];
if ( !config.repo ) {
errors.push( "Missing repo in config.json" );
}
if ( !config.title ) {
errors.push( "Missing title in config.json" );
}
if ( errors.length ) {
grunt.verbose.error();
done( new Error( errors.join(", ") ) );
} else {
done();
}
});
grunt.registerTask( "cron", [ "check-config", "update-repo", "check-versions" ]);
};