This repository has been archived by the owner on May 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jakefile.js
74 lines (64 loc) · 1.84 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
/*global jake, desc, task, directory, file, complete*/
'use strict';
var pkg = require('./package.json'),
path = require('path'),
fs = require('fs'),
os = require('os'),
async = require('async'),
rimraf = require('rimraf');
var ROOT_DIR = __dirname,
BUILD_DIR = path.join(ROOT_DIR, 'build');
var VERSION_TEMPLATE_VAR = /\{\{VERSION\}\}/g;
namespace('package', function () {
// gets the project version from package.json
task('version', function () {
return pkg.version;
});
});
// creates the build directory
directory(BUILD_DIR);
desc('cleans previous builds');
task('clean', function () {
rimraf(BUILD_DIR, function (err) {
complete();
});
}, {async: true});
desc('builds project');
task('build', ['clean', BUILD_DIR], function () {
console.log('@@ ROOT_DIR', ROOT_DIR);
console.log('@@ BUILD_DIR', BUILD_DIR);
var inputFiles = [
path.join(ROOT_DIR, 'license.js'),
path.join(ROOT_DIR, 'l33teral.js')
];
var outputFile = path.join(BUILD_DIR, 'l33teral-latest.js');
concatFiles(inputFiles, outputFile, function (err) {
if (err) {
return console.error(err);
}
console.log('Build complete.');
console.log('Output:', outputFile);
});
});
task('default', function () {
console.log('l33teral -- l33t literals for JavaScript');
console.log('To see available tasks:');
console.log('$ jake --tasks');
});
function concatFiles(files, outputFile, callback) {
var readHandlers = files.map(function (file) {
return function (callback) {
fs.readFile(file, function (err, contentBuffer) {
callback(err, contentBuffer);
})
};
});
async.parallel(readHandlers, function (err, files) {
if (err) {
return callback(err);
}
var output = files.join(os.EOL)
.replace(VERSION_TEMPLATE_VAR, pkg.version);
fs.writeFile(outputFile, output, callback);
});
}