-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
133 lines (115 loc) · 3.96 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
133
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var to5ify = require('6to5ify');
var paths = require('./paths.js');
var argv = process.argv;
var PROD = argv[argv.length - 1] === '--prod' || argv[2] === 'deploy';
process.env.NODE_ENV = PROD ? 'production' : 'development';
gulp.task('lint', function () {
return gulp.src(paths.client.scripts.all)
.pipe($.jshint())
.pipe($.jshint.reporter('default'));
});
gulp.task('demo_lint', function () {
return gulp.src(paths.demo.scripts.all)
.pipe($.jshint())
.pipe($.jshint.reporter('default'));
});
var bundler =
browserify(paths.client.scripts.entry, {
debug: !PROD,
standalone: 'challenger',
});
var demo_bundler =
browserify(paths.demo.scripts.entry, {
debug: !PROD,
});
gulp.task('scripts', function() {
return bundler.transform(to5ify)
.bundle()
.on('error', $.util.log.bind($.util, 'Browserify Error: Client'))
.pipe(source('challenger.min.js'))
.pipe(buffer())
// if we're in production, uglify it
.pipe($.if(PROD, $.uglify()))
// maybe hook up sourcemaps at some point...
//.pipe($.if(PROD, $.sourcemaps.init({loadMaps: true})))
//.pipe($.if(PROD, $.sourcemaps.write('./')))
.pipe(gulp.dest(paths.client.dist))
.pipe(gulp.dest(paths.demo.dist));
});
gulp.task('demo_scripts', ['demo_lint'], function() {
return demo_bundler.transform(to5ify)
.bundle()
.on('error', $.util.log.bind($.util, 'Browserify Error: Demo'))
.pipe(source('demo.js'))
.pipe(buffer())
.pipe(gulp.dest(paths.demo.dist));
});
gulp.task('sass', function () {
return gulp.src(paths.client.stylesheets.entry)
.pipe($.sass({ indentedSyntax: true }))
.pipe($.autoprefixer({ browsers: [
'ie >= 9',
'ff >= 9',
'Chrome >= 18',
'Opera >= 15',
'Safari >= 5.1',
'> 1%',
'last 2 versions',
'Firefox ESR'
]}))
.pipe(gulp.dest(paths.client.temp));
});
gulp.task('demo_sass', function () {
return gulp.src(paths.demo.stylesheets.entry)
.pipe($.sass({ indentedSyntax: true }))
.pipe($.autoprefixer({
browsers: ['ie >= 8', '> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1']
}))
.pipe(gulp.dest(paths.demo.dist));
});
gulp.task('css_concat', ['sass'], function () {
return gulp.src([paths.client.temp + '*.css'].concat(paths.client.stylesheets.plugins))
.pipe($.concat('challenger.min.css'))
.pipe($.if(PROD, $.minifyCss()))
.pipe(gulp.dest(paths.client.dist))
.pipe(gulp.dest(paths.demo.dist));
});
gulp.task('static', function () {
return gulp.src(paths.client.static.all, { dot: true })
.pipe(gulp.dest(paths.client.dist));
});
gulp.task('demo_static', function () {
return gulp.src(paths.demo.static.all, { dot: true })
.pipe(gulp.dest(paths.demo.dist));
});
gulp.task('watch', function () {
gulp.watch([paths.client.scripts.all, paths.shared.scripts.all], [/*'lint', 'test',*/ 'scripts']);
gulp.watch([paths.client.stylesheets.all], ['css_concat']);
gulp.watch([paths.demo.scripts.all], ['demo_scripts']);
gulp.watch([paths.demo.stylesheets.all], ['demo_sass']);
gulp.watch([paths.demo.static.dir], ['demo_static']);
});
gulp.task('webserver', function () {
return gulp.src(paths.demo.dist)
.pipe($.webserver({
host: 'localhost',
livereload: true,
open: true
}));
});
gulp.task('test', ['scripts'], function () {
return gulp.src(paths.tests.entry, {read: false})
.pipe($.mocha({reporter: 'nyan'}));
});
gulp.task( 'build', ['scripts', 'css_concat', 'static']);
gulp.task( 'demo', ['demo_scripts', 'demo_sass', 'demo_static']);
gulp.task( 'default', [ 'build', 'demo', 'watch', 'webserver' ] );
gulp.task('deploy', ['build', 'demo'], function () {
return gulp.src(paths.demo.dist + '/**/*', { dot: true })
.pipe($.ghPages('https://github.com/rileyjshaw/challenger.git', 'origin'));
});