-
Notifications
You must be signed in to change notification settings - Fork 167
/
gulpfile.js
124 lines (105 loc) · 3.01 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
/* jshint node: true */
var join = require("path").join
var gulp = require('gulp'),
gutil = require('gulp-util'),
requirejs = require('gulp-requirejs'),
uglify = require('gulp-uglify'),
rename = require("gulp-rename"),
jshint = require('gulp-jshint'),
less = require('gulp-less'),
jade = require('gulp-jade'),
qunit = require('gulp-qunit'),
watch = require('gulp-watch'),
livereload = require('gulp-livereload'),
tinnylr = require('tiny-lr')
var server = tinnylr()
var exec = require("child_process").exec
var paths = {
distRoot: './build',
docsRoot: './docs',
demosRoot: './docs/demos'
}
var pkg = {
name: "bootstrap"
}
gulp.task('requirejs', function() {
//目前requirejs还不支持gulp.src
var jsDist = join(paths.distRoot, 'js')
var requirejsConfig= {
baseUrl: "js",
name: "almond",
optimize: "none",
include: pkg.name,
insertRequire: [pkg.name],
mainConfigFile: "js/requirejs-config.js",
out: pkg.name + '.js',
wrap: true
}
requirejs(requirejsConfig)
//uncompressed
.pipe(gulp.dest(jsDist))
//uglify
.pipe(uglify({preserveComments: 'some'}))
.pipe(rename(pkg.name + '.min.js'))
.pipe(gulp.dest(jsDist))
.pipe(livereload(server))
})
gulp.task('less', function() {
var cssDist = join(paths.distRoot, 'css')
var recess = function(input, output) {
output = output || input
gulp.src(join('less', input + '.less'))
.pipe(less())
.pipe(rename(output + '.css'))
.pipe(gulp.dest(cssDist))
.pipe(less({compress: true}))
.pipe(rename(output + '.min.css'))
.pipe(gulp.dest(cssDist))
.pipe(livereload(server))
}
recess('bootstrap')
recess('responsive', pkg.name + '-responsive')
})
// compile jade template
gulp.task('jade', function() {
gulp.src(['**/*.jade', '!base.jade', '!com-*', '!*-com.jade'], {cwd: join(paths.demosRoot, 'templates')})
.pipe(jade({pretty: true}))
.pipe(gulp.dest(paths.demosRoot))
.pipe(livereload(server))
})
//compile mastache template
gulp.task('hogan', function(callback) {
var child = exec('node docs/build', function(e) {
callback()
})
})
gulp.task('jshint', function() {
var jsfiles = [
'gulpfile.js',
'js/*.js',
'js/tests/unit/*.js'
]
gulp.src(jsfiles)
.pipe(jshint('js/.jshintrc'))
.pipe(jshint.reporter('default'))
})
gulp.task('qunit', function(callback) {
gulp.src('js/tests/*.html')
.pipe(qunit());
})
// copy fonts to build
gulp.task('fonts', function() {
gulp.src('./fonts/*')
.pipe(gulp.dest(join(paths.distRoot, 'fonts')))
})
gulp.task('watch', function() {
server.listen(3456)
gulp.watch('js/**/*.js', ['requirejs'])
gulp.watch('less/**/*.less', ['less'])
gulp.watch(join(paths.docsRoot, 'templates/**/*.mustache'), ['hogan'])
gulp.watch(join(paths.demosRoot, 'templates/**/*.jade'), ['jade'])
gulp.watch('./fonts/*', ['jade'])
})
gulp.task('test', ['jshint', 'qunit'])
gulp.task('docs', ['fonts', 'jade', 'hogan'])
gulp.task('default', ['less', 'test', 'requirejs', 'docs'])