forked from nforge/devnote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jakefile
175 lines (152 loc) · 5.06 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env jake
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var Mocha = require('mocha');
var fs = require('fs');
var util = require('util');
var async = require('async');
var path = require('path');
//ansi color set
var red = '\u001b[31m';
var blue = '\u001b[34m';
var green = '\u001b[32m';
var reset = '\u001b[0m';
var cp_async = function(src, dst, callback) {
var stream = fs.createReadStream(src);
stream.pipe(fs.createWriteStream(dst));
stream.on("end", function() {
console.log(src, "is copied to", dst);
});
}
var cp_r_async = function(src, dst, callback) {
var self = this;
fs.stat(src, function(err, stat) {
if (err) throw err;
if (stat.isDirectory()) {
fs.mkdir(dst, function(err) {
fs.readdir(src, function(err, files) {
async.forEach(files, function(file, cb) {
cp_r_async(path.join(src, file), path.join(dst, file), cb);
}, callback);
});
});
} else {
cp_async(src, dst, callback);
}
});
};
task('default', function (params) {
console.log('This is the default task.');
});
task('build', function() {
console.log(green,'Required files are being copied', reset);
var targetsToCopy = [
{from: 'node_modules/hljs/hljs.js', to: 'public/scripts/highlight.js'},
{from: 'node_modules/github-flavored-markdown/scripts/showdown.js', to: 'public/scripts/showdown.js'},
{from: 'lib/highlight-c.js', to: 'public/scripts/highlight-c.js'},
{from: 'node_modules/hljs/styles/zenburn.css', to: 'public/stylesheets/zenburn.css'},
{from: 'lib/i18n.js', to: 'public/scripts/i18n.js'},
{from: 'lib/sprintf.js', to: 'public/scripts/sprintf.js'},
{from: 'locales', to: 'public/locales'}
];
targetsToCopy.forEach(function(element, index){
cp_r_async(element.from, element.to, function(err){
if (err) throw new Error('copy failed');
});
});
if ( process.platform !== 'win32' ){
var proc;
fs.stat('node_modules/zombie', function(err, stat) {
if (err) {
console.log(green, 'installing zombie test module. please be patient!');
proc = exec('npm install zombie');
proc.on('exit', function(){
console.log(green, '....build end');
jake.Task['test'].invoke();
});
proc.stdout.on('data', function(data){
console.log(data);
});
proc.stderr.on('data', function(data){
console.log(data)
});
} else {
jake.Task['test'].invoke();
}
});
} else {
jake.Task['test'].invoke();
}
}, true);
task('start', function() {
// spawn('coffee', ['app.coffee'], {customFds: [0, 1, 2]});
var proc = exec('coffee app.coffee');
proc.on('exit', process.exit);
proc.stdout.pipe(process.stdout, { end: false });
proc.stderr.pipe(process.stderr, { end: false });
});
task('test', function() {
if( process.platform === 'win32' ) {
jake.Task['testWin'].invoke();
} else{
jake.Task['testAll'].invoke();
}
});
desc("mocha test - process run style")
task('testAll', function(){
// spawn('mocha', ['-t', '5000', '-R', 'spec', '-u', 'tdd', '--compilers', 'coffee:coffee-script'], {customFds: [0, 1, 2]});
var proc = exec('mocha --colors -t 5000 -R spec -u tdd --compilers coffee:coffee-script');
proc.on('exit', process.exit);
proc.stdout.pipe(process.stdout, { end: false });
proc.stderr.pipe(process.stderr, { end: false });
}, {async: true})
desc("mocha test in *nix os - run with node")
task('testnix', function(){
var options = {};
options.timeout = 5000;
var mocha = new Mocha(options);
mocha.reporter('spec').ui('tdd');
var files = fs.readdirSync('./test')
for(var i=0, length = files.length; i< length; i += 1){
if ( files[i].lastIndexOf('test') !== -1 ) {
mocha.addFile('./test/'+files[i]);
}
}
var runner = mocha.run(function(){
console.log('finished');
});
runner.on('pass', function(test){
});
runner.on('fail', function(test){
});
})
desc("mocha test in windows - run with node")
task('testWin', function(){
var mocha = new Mocha;
mocha.reporter('spec').ui('tdd');
var files = fs.readdirSync('./test')
for(var i=0, length = files.length; i< length; i += 1){
//Excluded CoffeeScipt bacause zombie doesn't work in windows
if ( files[i].lastIndexOf('test') !== -1 && files[i].lastIndexOf('coffee') === -1) {
mocha.addFile('./test/'+files[i]);
}
}
var runner = mocha.run(function(){
console.log('finished');
});
runner.on('pass', function(test){
});
runner.on('fail', function(test){
});
})
desc("mocha test - build coverage report")
task('testCov', function(){
// spawn('mocha', ['-t', '5000', '-R', 'spec', '-u', 'tdd', '--compilers', 'coffee:coffee-script'], {customFds: [0, 1, 2]});
exec('jscoverage --no-highlight lib lib-cov').on('exit', function() {
process.env['LIB_COV'] = 1;
var proc = exec('mocha --colors -t 5000 -R html-cov -u tdd');
proc.on('exit', process.exit);
proc.stdout.pipe(process.stdout, { end: false });
proc.stderr.pipe(process.stderr, { end: false });
});
}, {async: true})