-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgruntHelper.js
60 lines (49 loc) · 1.56 KB
/
gruntHelper.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
'use strict';
var fs = require('fs');
var http = require('http');
module.exports = {
getElectronAppReload: function (done, gpid) {
var config = {
host: 'localhost',
path: '/utility/electronreload?gpid='+gpid,
port: '1337'
}
return http.get(config, function(res) {
var parsed,
body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
parsed = JSON.parse(body);
console.log('electron reload request status: ', parsed);
// Tell grunt the async task is complete
done();
});
}).on('error', function(e) {
console.log("Got error on electronreload: " + e.message);
// Tell grunt the async task failed
done(false);
});
},
createNewPackageJson: function(packagejson, done) {
var str = '',
jsonStr = packagejson,
destPath = 'dist/',
fileName = 'package.json',
callback = function (err) {
if (err) throw err;
// Tell grunt task is complete
done();
},
// To format JSON
options = {
spaces: 2
};
delete jsonStr.devDependencies;
delete jsonStr.scripts;
str = JSON.stringify(jsonStr, null, options.spaces) + '\n';
//console.log(str);
fs.writeFile(destPath + fileName, str, callback);
}
}