-
Notifications
You must be signed in to change notification settings - Fork 4
/
tasks.js
40 lines (34 loc) · 1.25 KB
/
tasks.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
var child_process = require( 'child_process' );
var fs = require( 'fs' );
var Q = require( 'q' );
var emailService = require( './emailService' );
exports.runTests = function() {
var currentTime = new Date();
currentTime = currentTime.toString() + "\n";
var run = Q.nfbind( child_process.exec );
var appendFile = Q.nfbind( fs.appendFile );
return run( 'npm test' )
.then(function() {
return appendFile( __dirname + '/public/runlog.txt', currentTime );
})
.catch(function( error ) {
emailService.sendEmail( 'Error', 'There was an error running the tests. Visit the logs. ' + error );
});
};
exports.resetLog = function() {
var currentTime = new Date();
currentTime = currentTime.toString() + ": Started new file\n";
var readFile = Q.nfbind( fs.readFile );
var writeFile = Q.nfbind( fs.writeFile );
return readFile( __dirname + '/public/runlog.txt', 'utf8' )
.then(function( data ) {
var message = 'I\'ve been working hard all week. Here\'s what I\'ve been up to:\n' + data;
return emailService.sendEmail( 'Weekly Summary', message );
})
.then(function() {
return writeFile( __dirname + '/public/runlog.txt', currentTime );
})
.catch(function( error ) {
emailService.sendEmail( 'Error Resetting Log', error );
});
};