-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
132 lines (117 loc) · 2.65 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
120
121
122
123
124
125
126
127
128
129
130
131
132
// Gulpfile.js
// Require the needed packages
var gulp = require('gulp');
var stylus = require('gulp-stylus');
var liveScript = require('gulp-livescript');
var watch = require('gulp-watch');
var gutil = require('gulp-util');
var nib = require('nib');
var $dir = {};
var $targets = [
'admin',
'home',
];
for (var i in $targets) {
if ($targets.hasOwnProperty(i)) {
var target = $targets[i];
$dir[target] = {
stylus: {},
ls: {}
}
}
}
$dir.admin.stylus.src = 'app/views/backend/styl/**/*.styl';
$dir.admin.stylus.dest = 'public/assets/css/admin/';
$dir.admin.ls.src = 'app/views/backend/ls/**/*.ls';
$dir.admin.ls.dest = 'public/assets/js/admin/';
$dir.home.stylus.src = 'app/views/home/styl/*.styl';
$dir.home.stylus.dest = 'public/assets/css/home';
function watch_stylus(obj) {
if (! obj.src) {
return;
}
gulp.src(obj.src)
.pipe(watch(function(files) {
console.log('watch for ' + files);
return files.pipe(stylus({errors: true}))
.pipe(gulp.dest(obj.dest))
}))
}
function watch_ls(obj) {
if (! obj.src) {
return;
}
gulp.src(obj.src)
.pipe(watch(function(files) {
console.log('watch for ' + files);
return files.pipe(liveScript({bare: true}))
.pipe(gulp.dest(obj.dest));
}));
}
function build_stylus(obj) {
if (! obj.src) {devDependencies
return;
}
console.log('build ' + obj.src);
var options = {
resolveUrl: true, // XXX not work
'resolve url': true, // XXX not work
'resolveUrl': true, // XXX not work
use: nib()
};
gulp.src(obj.src)
.pipe(stylus(options))
.pipe(gulp.dest(obj.dest));
}
function build_ls(obj) {
if (! obj.src) {
return;
}
gulp.src(obj.src)
.pipe(liveScript({bare:true})
.on('error', gutil.log))
.pipe(gulp.dest(obj.dest));
}
// Get and rnender all .styl files recursively
gulp.task('stylus-watch', function () {
for (var prop in $dir) {
if ($dir.hasOwnProperty(prop) && $dir[prop].hasOwnProperty('stylus')) {
watch_stylus($dir[prop].stylus);
}
}
});
gulp.task('ls-watch', function () {
for (var prop in $dir) {
if ($dir.hasOwnProperty(prop) && $dir[prop].hasOwnProperty('ls')) {
watch_ls($dir[prop].ls);
}
}
});
gulp.task('stylus-build', function () {
for (var prop in $dir) {
console.log ('prepare for ' + $dir[prop].stylus.src);
if ($dir.hasOwnProperty(prop) && $dir[prop].hasOwnProperty('stylus')) {
build_stylus($dir[prop].stylus);
}
}
});
gulp.task('ls-build', function () {
for (var prop in $dir) {
if ($dir.hasOwnProperty(prop) && $dir[prop].hasOwnProperty('ls')) {
build_ls($dir[prop].ls);
}
}
});
// Default gulp task to run
gulp.task('default',
[
'stylus-build',
'ls-build'
]
);
gulp.task('watch',
[
'stylus-watch',
'ls-watch'
]
);