forked from tech-dojo/mern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
153 lines (134 loc) · 4.28 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
var gulp = require('gulp');
var LiveServer = require('gulp-live-server');
var browserSync = require('browser-sync');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var reactify = require('reactify');
var babelify = require('babelify');
var mocha = require('gulp-mocha');
var gulpJsx = require('gulp-jsx-coverage');
var uglify = require('gulp-uglify');
var isWatching = false;
gulp.on('stop', function() {
if (!isWatching) {
process.nextTick(function() {
process.exit(0);
});
}
});
gulp.task('env-set', function() {
var env = process.argv[3];
if (env == '--production') {
process.env.NODE_ENV = 'production';
} else if (env == '--test') {
process.env.NODE_ENV = 'test';
} else {
process.env.NODE_ENV = 'development';
}
});
gulp.task('env:test', function() {
process.env.NODE_ENV = 'test';
});
gulp.task('live-server', function() {
var server = new LiveServer('server/server.js');
server.start();
});
gulp.task('bundle', function() {
return browserify({
entries: 'app/main.jsx',
debug: true,
})
.transform("babelify", {presets: ["es2015", "react"]})
.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./.tmp'));
});
gulp.task('temp', function() {
gulp.src(['app/index.html', 'app/*.css'])
.pipe(gulp.dest('./.tmp'));
gulp.src(['app/images/**'])
.pipe(gulp.dest('./.tmp/images'));
});
gulp.task('observe-all', function() {
isWatching = true;
gulp.watch('app/**/**/*.*', ['bundle-n-reload']);
gulp.watch('app/**/*.*', ['bundle-n-reload']);
gulp.watch('app/*.*', ['temp']);
gulp.watch('./server/**/*.js', ['live-server']);
});
gulp.task('frontend_test_cover', gulpJsx.createTask({
src: ['tests/**/*.jsx'], // will pass to gulp.src as mocha tests
istanbul: { // will pass to istanbul or isparta
preserveComments: true, // required for istanbul 0.4.0+
coverageVariable: '__MY_TEST_COVERAGE__',
exclude: /node_modules|tests/ // do not instrument these files
},
transpile: {
babel: {
include: /\.jsx?$/,
exclude: /node_modules/,
omitExt: false
}
},
threshold: [ // fail the task when coverage lower than one of this array
{
type: 'lines', // one of 'lines', 'statements', 'functions', 'banches'
min: 50
}
],
coverage: {
reporters: ['text-summary', 'json', 'lcov'], // list of istanbul reporters
directory: 'coverage' // will pass to istanbul reporters
},
mocha: { // will pass to mocha
reporter: 'spec'
},
// Recommend moving this to .babelrc
babel: { // will pass to babel-core
presets: ['es2015', 'react'], // Use proper presets or plugins for your scripts
sourceMap: 'both' // get hints in covarage reports or error stack
}
}));
gulp.task('test_cover', ['frontend_test_cover'], gulpJsx.createTask({
src: ['tests/*.js'], // will pass to gulp.src as mocha tests
istanbul: { // will pass to istanbul or isparta
preserveComments: true, // required for istanbul 0.4.0+
coverageVariable: '__MY_TEST_COVERAGE__',
exclude: /node_modules|tests/ // do not instrument these files
},
transpile: {
babel: {
include: /\.jsx?$/,
exclude: /node_modules/,
omitExt: false
}
},
threshold: [ // fail the task when coverage lower than one of this array
{
type: 'lines', // one of 'lines', 'statements', 'functions', 'banches'
min: 60
}
],
coverage: {
reporters: ['text-summary', 'json', 'lcov'], // list of istanbul reporters
directory: 'coverage' // will pass to istanbul reporters
},
mocha: { // will pass to mocha
reporter: 'spec'
},
// Recommend moving this to .babelrc
babel: { // will pass to babel-core
presets: ['es2015', 'react'], // Use proper presets or plugins for your scripts
sourceMap: 'both' // get hints in covarage reports or error stack
}
}));
gulp.task('test', ['env:test', 'test_cover']);
gulp.task('serve', ['env-set', 'live-server', 'bundle', 'temp', 'observe-all'], function() {
browserSync.init(null, {
proxy: 'http://localhost:3000',
port: 9001,
});
});