-
Notifications
You must be signed in to change notification settings - Fork 48
/
gulpfile.js
88 lines (73 loc) · 2.42 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
var fs = require('fs')
var browserify = require('browserify')
var gulp = require('gulp')
var source = require('vinyl-source-stream')
var concat = require('gulp-concat')
var flatten = require('gulp-flatten')
var flattenRequires = require('gulp-flatten-requires')
var header = require('gulp-header')
var jshint = require('gulp-jshint')
var plumber = require('gulp-plumber')
var react = require('gulp-react')
var rename = require('gulp-rename')
var streamify = require('gulp-streamify')
var uglify = require('gulp-uglify')
var gutil = require('gulp-util')
var pkg = require('./package.json')
var dev = gutil.env.release ? '' : ' (dev build at ' + (new Date()).toUTCString() + ')'
var srcHeader = '/**\n\
* newforms <%= pkg.version %><%= dev %> - https://github.com/insin/newforms\n\
* MIT Licensed\n\
*/\n'
process.env.NODE_ENV = gutil.env.production ? 'production' : 'development'
var jsSrcPath = './src/**/*.js*'
var jsLibPath = './lib/*.js*'
var jsEntryPoint = './lib/newforms.js'
gulp.task('transpile-js', function() {
return gulp.src(jsSrcPath)
.pipe(plumber())
.pipe(react({harmony: true}))
.pipe(flatten())
.pipe(flattenRequires())
.pipe(gulp.dest('./lib'))
})
gulp.task('lint', ['transpile-js'], function() {
return gulp.src(jsLibPath)
.pipe(jshint('./.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
})
gulp.task('browserify-js', ['lint'], function() {
var b = browserify(jsEntryPoint, {
debug: !!gutil.env.debug
, standalone: 'forms'
, detectGlobals: false
})
b.transform('browserify-shim')
var stream = b.bundle()
.pipe(source('newforms.js'))
.pipe(streamify(header(srcHeader, {pkg: pkg, dev: dev})))
.pipe(gulp.dest('./dist'))
if (gutil.env.production) {
stream = stream
.pipe(rename('newforms.min.js'))
.pipe(streamify(uglify()))
.pipe(streamify(header(srcHeader, {pkg: pkg, dev: dev})))
.pipe(gulp.dest('./dist'))
}
return stream
})
gulp.task('npm-copy', ['lint'], function() {
return gulp.src([jsLibPath, './LICENSE.md', './README.md'])
.pipe(gulp.dest('./npm-newforms'))
})
gulp.task('npm', ['npm-copy'], function(cb) {
var pkg = require('./package.json')
pkg.main = './newforms.js'
delete pkg.devDependencies
delete pkg.scripts
fs.writeFile('./npm-newforms/package.json', JSON.stringify(pkg, null, 2), cb)
})
gulp.task('watch', function() {
gulp.watch(jsSrcPath, ['browserify-js'])
})
gulp.task('default', ['browserify-js', 'watch'])