-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgulpfile.js
125 lines (102 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
120
121
122
123
124
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jshintReporter = require('jshint-stylish');
var watch = require('gulp-watch');
var shell = require('gulp-shell')
var watchify = require('watchify')
var browserify = require('browserify')
var babelify = require('babelify')
var chalk = require('chalk')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var merge = require('utils-merge')
var rename = require('gulp-rename')
var sourcemaps = require('gulp-sourcemaps')
var uglify = require('gulp-uglify')
var gutil = require('gulp-util')
var stylus = require('gulp-stylus')
var nib = require('nib')
var publicJS = 'public/js'
var jsxPath = '/src/jsx'
var paths = {
'src':['./models/**/*.js','./routes/**/*.js', 'keystone.js', 'package.json']
,
'style': {
main: './public/styles/site.styl',
all: './public/styles/**/*.styl',
output: './public/styles/'
}
};
// gulp lint
gulp.task('lint', function(){
gulp.src(paths.src)
.pipe(jshint())
.pipe(jshint.reporter(jshintReporter));
});
// gulp watcher for lint
gulp.task('watch:lint', function () {
gulp.watch(paths.src, ['lint']);
});
gulp.task('watch:stylus', function () {
gulp.watch(paths.style.all, ['stylus']);
});
gulp.task('stylus', function () {
gulp.src(paths.style.main)
.pipe(stylus({
use: nib()
}))
.pipe(gulp.dest(paths.style.output));
});
gulp.task('runKeystone', shell.task('node keystone.js'));
gulp.task('watch', [
'watch:stylus',
'watch:lint'
]);
// Watchify
gulp.task('watchify', function () {
var args = merge(watchify.args, { debug: true })
var bundler = watchify(browserify('.' + jsxPath + '/cart.jsx', args)).transform(babelify, { presets: ['es2015', 'react'] })
bundle_js(bundler)
bundler.on('update', function () {
bundle_js(bundler)
})
})
function bundle_js(bundler) {
return bundler.bundle()
.on('error', map_error)
.pipe(source('cart.js'))
.pipe(buffer())
.pipe(gulp.dest(publicJS))
.pipe(rename('cart.min.js'))
.pipe(sourcemaps.init({ loadMaps: true }))
// capture sourcemaps from transforms
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(publicJS))
}
// Color errors with chalk
function map_error(err) {
if (err.fileName) {
// regular error
gutil.log(chalk.red(err.name)
+ ': '
+ chalk.yellow(err.fileName.replace(__dirname + jsxPath + '/', ''))
+ ': '
+ 'Line '
+ chalk.magenta(err.lineNumber)
+ ' & '
+ 'Column '
+ chalk.magenta(err.columnNumber || err.column)
+ ': '
+ chalk.blue(err.description))
} else {
// browserify error..
gutil.log(chalk.red(err.name)
+ ': '
+ chalk.yellow(err.message))
}
if (this.end) {
this.end()
}
}
gulp.task('default', ['watch', 'watchify', 'runKeystone']);