-
Notifications
You must be signed in to change notification settings - Fork 6
/
TaskRunner.js
54 lines (46 loc) · 1.64 KB
/
TaskRunner.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
var fs = require('fs');
var grunt = require('grunt');
var path = require('path');
function TaskRunner(config) {
/**
* run a task
* @param task object
* @param output object
*/
this.run = function (t, o) {
var fname = t.name + "-" + new Date().toISOString() + ".log";
fname = fname.replace(":", "-");
var log = fs.createWriteStream(config.locations.libraryLocation + "/data/logs/" + fname);
var arguments = [t.name];
if (t.name == "buildShow") {
arguments.push("--showname");
arguments.push( this.generateShowName() );
}
var child = grunt.util.spawn({ cmd: "grunt", args: arguments }, function(err) { console.log(err)});
child.stdout.pipe(log);
child.stderr.pipe(log);
if (o) {
child.stdout.pipe(o);
child.stderr.pipe(o);
}
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
}
/**
* generate a show name
* @returns {string}
*/
this.generateShowName = function() {
var episodesFile = config.locations.libraryLocation + "/data/show-list.json";
var episodeOffset = config.show.episodeOffset;
var digits = config.show.numericPlaces;
var showname = config.show.shortname;
if ( fs.existsSync(episodesFile) == false) {
fs.writeFileSync(episodesFile, JSON.stringify([]));
}
var ep = grunt.file.readJSON(episodesFile).length + parseInt(episodeOffset);
var epstr = ('000000000' + ep).substr(-digits);
return showname + epstr;
}
}
exports = module.exports = TaskRunner;