-
Notifications
You must be signed in to change notification settings - Fork 29
/
Jakefile.js
134 lines (107 loc) · 3.27 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var fs = require("fs"),
path = require("path"),
_ = require("underscore"),
req = require("requirejs"),
seq = require("seq"),
child_process = require("child_process"),
exec = child_process.exec;
var recurseDir = function (dir) {
var out = [];
var list = fs.readdirSync(dir);
for (var i = 0; i < list.length; i++) {
var file = list[i];
var fullname = path.join(dir, file);
if (fs.statSync(fullname).isDirectory()) {
var child = recurseDir(fullname);
for (var j = 0; j < child.length; j++) {
out.push(child[j]);
}
} else {
out.push(fullname);
}
}
return out;
};
task("default", ["deploy"]);
desc("create build directory");
task("mkdir", ["clean"], function (params) {
fs.mkdirSync('build');
fs.mkdirSync('build/lib');
});
desc("build the project");
task("build", ["clean", "mkdir", "version"], {async: true}, function (params) {
console.log('Buliding...');
var libFiles = _.union(recurseDir('lib/inventory'), recurseDir('lib/sprites'));
var include = _.map(libFiles, function (file) {
var name = path.basename(file, '.js');
var filename = [path.dirname(file), name].join('/').slice(4);
return filename;
});
_.each(['assets', 'stylesheets', 'vendor', 'maps'], function (dir) {
exec(['cp -r', dir, 'build/'+dir].join(' '));
});
exec('cp favicon.ico build');
// insert the ad and dump the index in build
exec('sed -e "/{ad}/r ad.html" -e "/{ad}/d" index.html > build/index.html');
// set the latest version number for display
exec('sed -i "s/###/`git describe --abbrev=0 --tags`/" build/index.html');
var version;
var cont = function (that) {
return function (output) {
console.log(output);
that();
};
};
seq().seq(function () {
// get current version
// awk so it strips the trailing \n
exec("git log -1 --format=%h | awk '{ printf $1 }'", this);
}).par(function (version) {
req.optimize({
baseUrl: "./",
name: "config",
out: "build/config.js",
wrap: {
start: "window.DV = {debug:false,version:'"+version+"'};",
end: " "
}
}, cont(this));
}).par(function () {
req.optimize({
baseUrl: "lib",
name: "Main",
out: "build/lib/Main.js",
include: include
}, cont(this));
}).par(function (version) {
req.optimize({
baseUrl: "lib",
name: "MapWorker",
out: "build/lib/MapWorker.js",
wrap: {
start: "var version = '"+version+"'; importScripts('../vendor/underscore-min.js', '../vendor/require.js');",
end: " "
}
}, cont(this));
}).seq(complete);
});
desc("create version file");
task("version", ["mkdir"], function (params) {
exec('git log -1 > build/version.txt');
});
desc("clean up");
task("clean", {async: true}, function (params) {
console.log('Cleaning...');
exec('rm -r build', complete);
});
desc("deploy to S3");
task("deploy", {async: true}, function (target) {
if (target === undefined) {
console.log('FAIL: Need to specify an S3 target bucket, such as:');
console.log(' jake deploy[deadvalley2]');
} else {
jake.exec(['s3cmd sync --recursive build/ s3://'+target+' --acl-public'],
{printStdout: true},
complete);
}
});