This repository has been archived by the owner on Apr 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.js
206 lines (170 loc) · 4.45 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
var gulp = require('gulp');
var deploy = require('gulp-gh-pages');
var gulpWebpack = require('gulp-webpack');
var react = require('gulp-react');
var jshint = require('gulp-jshint');
// hijack task fn and add help
require('gulp-help')(gulp);
var connect = require('connect');
var serveStatic = require('serve-static');
var livereload = require('livereload');
var rimraf = require('rimraf');
var webpack = require('webpack');
var karma = require('karma').server;
var argv = require('yargs').argv;
var stylish = require('jshint-stylish');
gulp.task('deploy', 'Deploy demo to gh-pages', function () {
gulp.src([
'./demo/demo-built.js',
'./demo/index.html',
'./demo/styles.css',
'./demo/bootstrap.min.css'
])
.pipe(deploy());
});
gulp.task('lint', 'lint project code (post jsx transformation', function() {
gulp.src('src/**/*')
.pipe(react())
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('watch:lint', false, function() {
gulp.watch('./src/**/*', ['lint']);
});
gulp.task('build:clean', false, function(done) {
rimraf('./dist', done);
});
function buildTest(once) {
return gulp.src('test/index.js')
.pipe(gulpWebpack({
output: {
filename: './index-built.js'
},
watch: !once,
module: {
loaders: [
{ test: /\.js$/, loader: 'jsx-loader' }
]
}
}))
.pipe(gulp.dest('test/'));
}
gulp.task('test:buildTest', false, function() {
buildTest(true);
});
gulp.task('watch:buildTest', false, function() {
buildTest(false);
});
function test(once, done) {
karma.start({
configFile: __dirname + '/test/karma.conf.js',
browsers: argv.travis ? ['Firefox'] : ['Chrome'],
singleRun: !!once
}, done);
}
gulp.task('test', 'Run tests once', ['test:buildTest'], function(done) {
test(true, done);
});
gulp.task('watch:test', false, ['watch:buildTest'], function(done) {
test(false, done);
});
function buildLib(once, uglify) {
var buildLibConfig = getBuildWebpack(once);
if (uglify) {
buildLibConfig.plugins.push(new webpack.optimize.UglifyJsPlugin());
buildLibConfig.output.filename = 'react-formly.min.js';
buildLibConfig.devtool = 'source-map';
}
return gulp.src('index.js')
.pipe(gulpWebpack(buildLibConfig))
.pipe(gulp.dest('dist/'));
}
gulp.task('build:lib', false, function() {
buildLib(true, false);
});
gulp.task('watch:build:lib', false, function() {
buildLib(false, false);
});
gulp.task('build:uglify', false, function() {
buildLib(true, true);
});
gulp.task('watch:build:uglify', false, function() {
buildLib(false, true);
});
gulp.task('watch:demo', false, function() {
return gulp.src('demo/demo.js')
.pipe(gulpWebpack({
output: {
path: __dirname + 'demo',
filename: 'demo-built.js'
},
watch: true,
devtool: 'inline-source-map',
module: {
loaders: [
{test: /\.js$/, loader: 'jsx-loader'}
]
}
}))
.pipe(gulp.dest('demo/'));
});
gulp.task('watch:serve:server', false, function(next) {
var server = connect();
server.use(serveStatic('demo'));
server.listen(process.env.PORT || 3000, next);
});
gulp.task('watch:serve', false, ['watch:serve:server'], function() {
var server = livereload.createServer({
interval: 300
});
server.watch(__dirname + '/demo');
});
gulp.task('watch', 'Use this for development. Will build, test, and serve the demo automgagically', [
'watch:build:lib',
'watch:build:uglify',
'watch:lint',
'watch:buildTest',
'watch:test',
'watch:demo',
'watch:serve'
]);
gulp.task('build', 'Build the library', ['build:clean', 'build:lib', 'build:uglify']);
gulp.task('default', false, ['help']);
gulp.task('ci', 'Run the tests and build. Use --travis for the travis version of the build.', [
'test',
'build'
]);
// UTILS
function getBuildWebpack(once) {
return {
entry: './index.js',
output: {
filename: 'react-formly.js',
library: 'ReactFormly',
libraryTarget: 'umd'
},
externals: {
'react': 'react'
},
debug: false,
devtool: 'inline-source-map',
watch: !once,
stats: {
colors: true,
reasons: false
},
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin()
],
resolve: {
extensions: ['', '.js']
},
module: {
loaders: [
{ test: /src\/.*\.js$/, loader: 'jsx-loader' }
]
}
}
}