-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpFile.js
119 lines (94 loc) · 2.79 KB
/
gulpFile.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
var gulp = require('gulp')
, exec = require('child_process').exec
, watch = require('gulp-watch')
, rename = require('gulp-rename')
, browserify = require('gulp-browserify')
, connect = require('gulp-connect')
, autoprefixer = require('gulp-autoprefixer')
, less =require('less')
, Stream = require('stream').Stream
gulp.task('browserify', function () {
/*
return gulp.src( './js/app.js' )
.pipe( browserify({
outfile : './js/bundle.js',
debug : true
}))
.on('data', function(e){
console.log(e)
})
.pipe(gulp.dest('./js/'))
*/
exec(
'node ./node_modules/browserify/bin/cmd.js js/app.js -o js/bundle.js --debug ' ,
function( err , out , code ){
if(err)
console.log( err )
}
)
});
gulp.task('test', function () {
var runner = require('./node_modules/jasmine-node/lib/jasmine-node/runner.js');
runner.runSpecs({
specFolders : ['./tests/specs'],
matchAll : true,
});
});
gulp.task('serve', function () {
connect.server({
root: '.',
livereload: false,
port : 8081
});
});
gulp.task('less', function () {
var lessify = function(options){
options = options || {}
var stream = new Stream();
stream.writable = stream.readable = true
var pending = 0,closed=false;
stream.write = function( file ){
options.fileName = file.path
pending++
less.render(
file.contents.toString('utf8'),
options,
function (e, css) {
if(e)
console.log(file.path+'\nline:'+e.line+': '+e.extract[2]+'\n'+e.message)
var f = file.path.split('.')
f[f.length-1] = 'css'
file.path = f.join('.')
file.contents = new Buffer(css.css||'')
stream.emit('data',file)
pending--
stream.end()
}
);
}
stream.destroy = function(){ this.emit('close') };
stream.end = function(){
if(closed||pending)
return
this.emit('end')
closed = true
}
return stream
}
return gulp.src( './css/style.less' )
.pipe( lessify({
compress: false,
paths: ['./css'],
}))
.pipe(autoprefixer({
cascade: true,
browsers: ['last 2 versions'],
}))
.pipe(rename('style.css'))
.pipe(gulp.dest('./css'))
});
gulp.task('watch', function () {
gulp.watch( ['css/**/*.less'] , ['less'] )
gulp.watch( ['tests/**/*' , 'js/**/*', '!js/bundle.js'] , ['browserify'] )
});
gulp.task('default', [ 'browserify' , 'less' , 'watch' , 'serve' ]);