forked from blackberry/bbUI.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJakefile
106 lines (88 loc) · 3.53 KB
/
Jakefile
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
var DEPLOY = __dirname + "/pkg/",
_path = require('path'),
UglifyJS = require('uglify-js'),
cleanCSS = require('clean-css'),
fs = require('fs');
function include(files, transform) {
files = files.map ? files : [files];
return files.map(function (file) {
var str = fs.readFileSync(file, "utf-8") + "\n";
return transform ? transform(str, file) : str;
}).join('\n');
}
function collect(path, files, matches) {
matches = matches || function (path) {
return path.match(/\.js$/);
};
if (fs.statSync(path).isDirectory()) {
fs.readdirSync(path).forEach(function (item) {
collect(_path.join(path, item), files, matches);
});
} else if (matches(path)) {
files.push(path);
}
}
desc("runs jake build");
task('default', ['build'], function () {});
desc("clean");
task('clean', [], function () {
var childProcess = require('child_process'),
cmd = 'rm -rf ' + DEPLOY + ' && ' +
'mkdir ' + DEPLOY;
childProcess.exec(cmd, complete);
}, true);
desc("package everything for a release");
task('build', ['clean'], function () {
var output = "",
css = "",
ext = "",
license = "",
minified,
version,
versionText = "",
plugins = [];
console.log("Gathering Files...");
// Retrieve the version information
version = JSON.parse(include("JakeVersion"));
version.build++;
versionText = '/* VERSION: ' + version.major + '.' + version.minor + '.' + version.revision + '.' + version.build + '*/\n\n';
pkg = JSON.parse(include("package.json"));
pkg.version = version.major + '.' + version.minor + '.' + version.revision;
// Retrieve our license information
license = include("JakeLicense");
license += versionText;
// Gather our core JS files
output = include("src/core.js");
collect(__dirname + "/src/plugins", plugins);
plugins.forEach(function (plugin) {
output += include(plugin);
});
// Write our our JS files
fs.writeFileSync(__dirname + "/pkg/bbui.js", license + output);
fs.writeFileSync(__dirname + "/samples/bbui.js", license + output);
// Grab our CSS information
css = include("src/bbUI.css");
fs.writeFileSync(__dirname + "/pkg/bbui.css", license + css);
fs.writeFileSync(__dirname + "/samples/bbui.css", license + css);
// Version our Extensions
ext = include("src/ext/client.js");
fs.writeFileSync(__dirname + "/ext/bbui/client.js", license + ext);
ext = include("src/ext/index.js");
fs.writeFileSync(__dirname + "/ext/bbui/index.js", license + ext);
ext = include("src/ext/manifest.json");
fs.writeFileSync(__dirname + "/ext/bbui/manifest.json", ext);
// Minify
console.log("Minifying...");
// First the JavaScript
license = '/*! bbUI VERSION: ' + version.major + '.' + version.minor + '.' + version.revision + '.' + version.build + ' | github.com/blackberry/bbUI.js/blob/master/LICENSE !*/';
minified = UglifyJS.minify(__dirname + "/pkg/bbui.js");
fs.writeFileSync(__dirname + "/pkg/bbui-min.js", license + minified.code);
// Then the CSS
minified = cleanCSS.process(include(__dirname + "/pkg/bbui.css"));
fs.writeFileSync(__dirname + "/pkg/bbui-min.css", license + minified);
// Update our build version
fs.writeFileSync("JakeVersion", JSON.stringify(version, undefined, 2));
// Update the build version in the npm package.json
fs.writeFileSync("package.json", JSON.stringify(pkg, undefined, 2));
console.log("Holy Chetara Batman, That was fast!");
});