forked from affinipay/react-bootstrap-autosuggest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
165 lines (141 loc) · 4.21 KB
/
gulpfile.babel.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import child_process from 'child_process'
import del from 'del'
import flow from 'flow-bin'
import gulp from 'gulp'
import babel from 'gulp-babel'
import eslint from 'gulp-eslint'
import gulpReactDocs from 'gulp-react-docs'
import gulpReplace from 'gulp-replace'
import { Server as KarmaServer } from 'karma'
import webpack from 'webpack'
import webpackStream from 'webpack-stream'
import demoConfig from './webpack/demo.config.babel'
import webpackConfig from './webpack/webpack.config.babel'
const apidocs = './site/apidocs'
const demo = './demo'
const dist = './dist'
const lib = './lib'
const site = './site'
const src = './src'
const test = './test'
if (!Object.values) {
Object.values = obj => Object.keys(obj).map(key => obj[key])
}
function getWebpackEntries(config) {
const { entry } = config
return (Array.isArray(entry) || typeof entry !== 'object') ? entry : Object.values(entry)
}
function execute(command, args, options, callback) {
const child = child_process.spawn(command, args, options)
child.stdout.on('data', data => process.stdout.write(data.toString()))
child.stderr.on('data', data => process.stderr.write(data.toString()))
child.on('close', code => {
callback(code != 0 ? new Error(`${command} exited with code ${code}`) : null)
})
}
gulp.task('clean', function() {
return del([dist, lib, site])
})
gulp.task('clean-dist', function() {
return del([dist])
})
gulp.task('clean-lib', function() {
return del([lib])
})
gulp.task('clean-site', function() {
return del([site])
})
gulp.task('clean-apidocs', function() {
return del([apidocs])
})
gulp.task('clean-demo', function() {
return del([site, '!' + apidocs])
})
gulp.task('babel', ['clean-lib'], function() {
return gulp.src(src + '/*.js')
.pipe(babel())
.pipe(gulp.dest(lib))
})
gulp.task('webpack', ['clean-dist'], function() {
return gulp.src(getWebpackEntries(webpackConfig))
.pipe(webpackStream(webpackConfig))
.pipe(gulp.dest(dist))
})
gulp.task('webpack-min', ['clean-dist'], function() {
const baseConfig = webpackConfig.withOptions({
optimizeMinimize: true
})
const config = {
...baseConfig,
bail: true,
plugins: [
...baseConfig.plugins,
new webpack.optimize.UglifyJsPlugin()
]
}
return gulp.src(getWebpackEntries(webpackConfig))
.pipe(webpackStream(config))
.pipe(gulp.dest(dist))
})
gulp.task('default', ['babel', 'webpack', 'webpack-min'])
gulp.task('apidocs', ['clean-apidocs'], function() {
return gulp.src('./src/Autosuggest.js')
// react-docgen uses an old version of babylon
// that doesn't support inferred type parameter syntax
.pipe(gulpReplace(/<\*[^>]*>/g, ''))
.pipe(gulpReactDocs({
path: apidocs
}))
.pipe(gulpReplace(''', '\''))
.pipe(gulpReplace(
'From [`../../src/Autosuggest.js`](../../src/Autosuggest.js)',
'From [`src/Autosuggest.js`](../../master/src/Autosuggest.js)'))
.pipe(gulp.dest(apidocs))
})
gulp.task('demo-copy', ['clean-demo'], function() {
return gulp.src([
demo + '/*.ico',
demo + '/*.json',
demo + '/*.png',
demo + '/*.svg',
demo + '/*.xml',
demo + '/images/*',
demo + '/index.html'
], { base: demo })
.pipe(gulp.dest(site))
})
gulp.task('demo-webpack', ['clean-demo'], function() {
const baseConfig = demoConfig.withOptions({
optimizeMinimize: true
})
const config = {
...baseConfig,
bail: true,
plugins: [
...baseConfig.plugins,
new webpack.optimize.UglifyJsPlugin()
]
}
const entries = getWebpackEntries(demoConfig)
return gulp.src(entries[entries.length - 1])
.pipe(webpackStream(config))
.pipe(gulp.dest(site))
})
gulp.task('site', ['apidocs', 'demo-copy', 'demo-webpack'])
gulp.task('lint', function() {
return gulp.src([src, test, demo].map(s => s + '/**/*.js'))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
})
gulp.task('flow', function(callback) {
execute(flow, ['--color', 'always'], undefined, callback)
})
gulp.task('karma', function (callback) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, callback).start()
})
gulp.task('test', ['lint', 'flow', 'karma'])
gulp.task('all', ['default', 'site', 'test'])