-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
executable file
·87 lines (77 loc) · 2.46 KB
/
gulpfile.babel.js
File metadata and controls
executable file
·87 lines (77 loc) · 2.46 KB
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
import gulp from 'gulp'
import gutil from 'gulp-util'
import notify from 'gulp-notify'
import webpack from 'webpack'
import WebpackDevServer from 'webpack-dev-server'
import webpackConfig from './webpack.config'
import mocha from 'gulp-mocha'
import template from 'gulp-template'
import rename from 'gulp-rename'
import clean from 'gulp-clean'
import minimist from 'minimist'
import pluralize from 'pluralize'
import _ from 'lodash'
import run from 'gulp-run'
const dev = !process.argv.includes('--production')
gulp.task("default", ["server", "mocha"], () => {
gulp.watch(["app/**/*", "sass/**/*"], ["build"]);
gulp.watch(["app/**/*", "test/**/*.js"], ["mocha"]);
});
gulp.task("mocha", () => {
return gulp.src(['test/**/*.js'], {read: false})
.pipe(mocha())
.on('error', gutil.log)
.on('error', notify.onError("Error: <%= error.message %>"));
})
gulp.task("coverage", ["clean:coverage"], () => {
return run('nyc mocha').exec()
})
gulp.task("build", ["clean:build"], callback => {
const analyze = process.argv.includes('--analyze')
let config = webpackConfig(dev);
if (analyze){
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
config.plugins.push(new BundleAnalyzerPlugin())
}
webpack(config, (err, stats) => {
if (err) throw new gutil.PluginError("build", err)
gutil.log("[build]", stats.toString({
chunks: false,
colors: true
}))
callback()
});
});
gulp.task("clean", ["clean:build", "clean:coverage"])
gulp.task("clean:build", () => {
return gulp.src(['dist'], {read: false})
.pipe(clean())
})
gulp.task("clean:coverage", () => {
return gulp.src(['coverage'], {read: false})
.pipe(clean())
})
gulp.task("server", () => {
let port = dev ? 8100 : 9100
new WebpackDevServer(webpack(webpackConfig(dev)))
.listen(port, "localhost", err => {
if (err) throw new gutil.PluginError("webpack-dev-server", err)
gutil.log("[webpack-dev-server]", `http://localhost:${port}/`)
})
});
gulp.task('actions', () => {
let argv = minimist(process.argv.slice(2))
let {entity} = argv
let entities = pluralize(entity)
gulp.src('templates/apiActions.js')
.pipe(template({
entity,
entities,
ENTITY: entity.toUpperCase(),
ENTITIES: entities.toUpperCase(),
Entity: _.startCase(entity),
Entities: _.startCase(entities)
}, {interpolate: /<%=([\s\S]+?)%>/g}))
.pipe(rename(entity + '.generated.js'))
.pipe(gulp.dest('app/actions/'))
})