-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jakefile.js
78 lines (62 loc) · 1.62 KB
/
Jakefile.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
#!/usr/bin/env node
const sys = require("sys");
const fs = require("fs");
const exec = require('child_process').exec;
/**
Returns a function to be executed
@param cmd {string} the command to run
@param callback {Function} the Function to execute after the command finishes running
*/
var run = function (cmd, callback) {
return function () {
console.log("Now running: " + cmd);
exec(cmd, function (err, stdout) {
if (err) {
throw err;
}
console.log(stdout);
if (callback) {
callback();
}
});
}
},
/**
Executes a set of instructions -- recursively builds using the run() function
@param instructions {Array} the commands to execute
@return Function
*/
build = function (instructions) {
var cmd = null;
if (instructions.length === 0) {
return cmd;
} else {
cmd = instructions.shift();
return run(cmd, build(instructions));
}
};
/** Tasks */
task("install", [], function () {
var launch = arguments[0] ? (arguments[0].launch) : false;
// read version
fs.readFile('application/appinfo.json', 'utf8', function (err, data) {
if (err) {
throw err;
}
var version = (function (appinfo) {
return appinfo.version;
}(JSON.parse(data))),
instructions = [
"palm-package application",
"palm-install com.goatslacker.dreamcatcher_" + version + "_all.ipk"
],
go = null;
if (launch) {
instructions.push("palm-launch com.goatslacker.dreamcatcher");
}
// build the instructions into an executable function
go = build(instructions);
// run the listed commands
go();
});
}, false);