-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
120 lines (105 loc) · 3.76 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
var gulp = require('gulp'),
gutil = require('gulp-util'),
clean = require('gulp-clean'),
header = require('gulp-header'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
stylus = require('gulp-stylus'),
autoprefixer = require('gulp-autoprefixer'),
csso = require('gulp-csso'),
jade = require('gulp-jade'),
connect = require('gulp-connect'),
plumber = require('gulp-plumber'),
opn = require('opn'),
pkg = require('./package.json'),
browserify = require('gulp-browserify'),
through = require('through'),
path = require('path'),
ghpages = require('gh-pages'),
template = require('lodash').template,
isDemo = process.argv.indexOf('demo') > 0;
gulp.task('default', ['clean', 'compile']);
gulp.task('demo', ['compile', 'watch', 'connect']);
gulp.task('compile', ['compile:lib', 'compile:demo']);
gulp.task('compile:lib', ['stylus', 'browserify:lib']);
gulp.task('compile:demo', ['jade', 'browserify:demo']);
gulp.task('watch', function() {
gulp.watch('lib/*', ['compile:lib', 'browserify:demo']);
gulp.watch('demo/src/*.jade', ['jade']);
gulp.watch('demo/src/**/*.js', ['browserify:demo']);
});
gulp.task('clean', ['clean:browserify', 'clean:stylus', 'clean:jade']);
gulp.task('clean:browserify', ['clean:browserify:lib', 'clean:browserify:demo']);
gulp.task('clean:browserify:lib', function() {
return gulp.src(['dist'], { read: false })
.pipe(clean());
});
gulp.task('clean:browserify:demo', function() {
return gulp.src(['demo/dist/build'], { read: false })
.pipe(clean());
});
gulp.task('clean:stylus', function() {
return gulp.src(['lib/tmp'], { read: false })
.pipe(clean());
});
gulp.task('clean:jade', function() {
return gulp.src(['demo/dist/index.html'], { read: false })
.pipe(clean());
});
gulp.task('stylus', ['clean:stylus'], function() {
return gulp.src('lib/theme.styl')
.pipe(isDemo ? plumber() : through())
.pipe(stylus({ pretty: true }))
.pipe(autoprefixer('last 2 versions'))
.pipe(csso())
.pipe(gulp.dest('lib/tmp'));
});
gulp.task('browserify', ['browserify:lib', 'browserify:demo']);
gulp.task('browserify:lib', ['clean:browserify:lib', 'stylus'], function() {
return gulp.src('lib/bespoke-theme-cube.js')
.pipe(isDemo ? plumber() : through())
.pipe(browserify({ transform: ['brfs'], standalone: 'bespoke.themes.cube' }))
.pipe(header(template([
'/*!',
' * <%= name %> v<%= version %>',
' *',
' * Copyright <%= new Date().getFullYear() %>, <%= author.name %>',
' * This content is released under the <%= licenses[0].type %> license',
' * <%= licenses[0].url %>',
' */\n\n'
].join('\n'), pkg)))
.pipe(gulp.dest('dist'))
.pipe(rename('bespoke-theme-cube.min.js'))
.pipe(uglify())
.pipe(header(template([
'/*! <%= name %> v<%= version %> ',
'© <%= new Date().getFullYear() %> <%= author.name %>, ',
'<%= licenses[0].type %> License */\n'
].join(''), pkg)))
.pipe(gulp.dest('dist'));
});
gulp.task('browserify:demo', ['clean:browserify:demo'], function() {
return gulp.src('demo/src/scripts/main.js')
.pipe(isDemo ? plumber() : through())
.pipe(browserify({ transform: ['brfs'] }))
.pipe(rename('build.js'))
.pipe(gulp.dest('demo/dist/build'))
.pipe(connect.reload());
});
gulp.task('jade', ['clean:jade'], function() {
return gulp.src('demo/src/index.jade')
.pipe(isDemo ? plumber() : through())
.pipe(jade())
.pipe(gulp.dest('demo/dist'))
.pipe(connect.reload());
});
gulp.task('connect', ['compile'], function(done) {
connect.server({
root: 'demo/dist',
livereload: true
});
opn('http://localhost:8080', done);
});
gulp.task('deploy', ['compile:demo'], function(done) {
ghpages.publish(path.join(__dirname, 'demo/dist'), { logger: gutil.log }, done);
});