forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jakefile.js
138 lines (122 loc) · 3.45 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
135
136
137
138
/**
* Jake build script for mathjs
*/
var jake = require('jake'),
util = require('./tools/jake-utils.js');
/**
* Constants
*/
var MATHJS = './math.js';
var MATHJS_MIN = './math.min.js';
var HEADER = './src/header.js';
// register start time
var start = +new Date();
/**
* default task
*/
desc('Execute all tasks: build and test the library');
task('default', ['build', 'test'], function () {
// calculate duration
var end = +new Date();
var duration = end - start;
console.log('Done (' + duration + ' ms)');
});
/**
* build task
*/
desc('Build the library');
task('build', ['concat', 'minify']);
/**
* concat task
*/
desc('Concatenate all source files into one file');
task('concat', function () {
var result = util.concat({
src: [
'./src/exports.js',
'./src/util.js',
'./src/type/**/*.js',
'./src/constants.js',
'./src/functions.js',
'./src/expr/node/Node.js',
'./src/expr/node/ConstantNode.js',
'./src/expr/node/OperatorNode.js',
'./src/expr/node/SymbolNode.js',
'./src/expr/node/ParamsNode.js',
'./src/expr/node/MatrixNode.js',
'./src/expr/node/BlockNode.js',
'./src/expr/node/AssignmentNode.js',
'./src/expr/node/UpdateNode.js',
'./src/expr/node/FunctionNode.js',
'./src/expr/Scope.js',
'./src/expr/Parser.js',
'./src/expr/Expression.js',
'./src/expr/Workspace.js',
'./src/function/**/*.js',
'./src/compatibility.js',
'./src/init.js'
],
dest: MATHJS,
header: util.read(HEADER) + '\n(function() {\n',
separator: '\n',
footer: '\n})();\n'
});
updateVersion(MATHJS);
console.log('Concatenated ' + result.src.length + ' files into ' +
MATHJS + ' (' + filesize(result.code.length, 1) + ')');
});
/**
* minify task
*/
desc('Minify the library');
task('minify', ['concat'], function () {
var result = util.minify({
src: MATHJS,
dest: MATHJS_MIN,
header: util.read(HEADER)
});
updateVersion(MATHJS_MIN);
console.log('Minified ' +
MATHJS + ' (' + filesize(util.read(result.src[0]).length, 1) + ') to ' +
MATHJS_MIN + ' (' + filesize(result.code.length, 1) + ')');
});
/**
* test task
*/
desc('Test the library');
task('test', ['concat'], function () {
// TODO: use a testing suite for testing: nodeunit, mocha, tap, ...
var filelist = new jake.FileList();
filelist.include([
'./test/**/*.js'
]);
var files = filelist.toArray();
files.forEach(function (file) {
require('./' + file);
});
console.log('Executed ' + files.length + ' test files successfully');
});
/**
* Update version and date patterns in given file.
* Patterns '@@date' and '@@version' will be replaced with current date and
* version.
* @param {String} file
*/
function updateVersion(file) {
// update date and version number
util.replace({
replacements: [
{pattern: '@@date', replacement: util.today()},
{pattern: '@@version', replacement: util.version()}
],
src: file
});
}
/**
* Return the filesize in kilo bytes
* @param {Number} size Size in Bytes
* @return {String} str Formatted string like "50.7KB"
*/
function filesize (size) {
return (size / 1024).toPrecision(3) + 'KB';
}