-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGulpfile.js
More file actions
210 lines (162 loc) · 4.34 KB
/
Copy pathGulpfile.js
File metadata and controls
210 lines (162 loc) · 4.34 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
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
require('babel-core/register');
var gulp = require('gulp');
var git = require('gulp-git');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var shell = require('gulp-shell');
var os = require('os');
var open = require('gulp-open');
var gp_prompt = require('gulp-prompt');
var runSequence = require('run-sequence');
var mocha = require('gulp-mocha');
var fs = require('fs');
var browser = os.platform() === 'linux' ? 'google-chrome' : (
os.platform() === 'darwin' ? 'google chrome' : (
os.platform() === 'win32' ? 'chrome' : 'firefox'));
// Open an URL in a given browser:
gulp.task('open-browser', function(){
var options = {
uri: 'http://localhost:8090/dev.html',
app: browser
};
return gulp.src(__filename)
.pipe(open(options));
});
/**
* Generates front end production scripts
*/
gulp.task('frontprod', function (done) {
var compiler = webpack(require('./webpack.production.config.js'));
compiler.run(function(err,stats){
if(err){
return console.warn(err);
}
var statOptions = {
colors : true ,
assets : false,
hash : false,
chunkModules :false
} ;
var statsString = stats.toString(statOptions);
console.log(statsString);
});
compiler.plugin('done',function(){
console.log('front end webpack production script generation is done');
done();
});
});
/**
* Starts Webpack dev server and then opens chrome
*/
gulp.task('frontdev',function(done) {
var compiler = webpack(require('./webpack.dev.config.js'));
var server = new WebpackDevServer(compiler, {
hot : true,
quiet: false,
noInfo: false,
stats : {
colors : true,
assets : false,
hash : false,
chunkModules :false
},
publicPath:'/assets/'
});
server.listen(8080,'0.0.0.0');
compiler.plugin('done',function(){
console.log('front end webpack production script generation is done');
done();
runSequence('watch-test','open-browser');
});
});
/**
* Starts python server
*/
gulp.task('back',
shell.task(
['python -m SimpleHTTPServer 8090'],
{verbose: true}));
gulp.task('set-dev-node-env', function(done) {
process.env.NODE_ENV = 'development';
done();
});
gulp.task('set-prod-node-env', function(done) {
process.env.NODE_ENV = 'production';
done();
});
/**
* Git scripts
*/
var files_to_commit = '.';
// Run git add with options
gulp.task('add', function(done){
gulp.src(files_to_commit)
.pipe(git.add());
done();
});
gulp.task('commit', function(done) {
gulp.src(files_to_commit)
.pipe(gp_prompt.prompt({
type: 'input',
name: 'commit',
message: 'Please enter commit message...'
}, function(res) {
gulp.src(files_to_commit, {buffer: false})
.pipe(git.commit(res.commit))
.on('end',function(){
console.log('Done committing');
done();
});
}));
});
gulp.task('push',function(done){
git.push('origin', 'develop',{quiet : false},function(err){
if(err)return console.log(err);
console.log('Done pushing');
done();
});
});
gulp.task('add_commit_push',function(done){
runSequence('add','commit','push',done);
});
/**
* Test scripts
*/
var watching = false;
function onError(err) {
console.log(err.toString());
if (watching) {
this.emit('end');
} else {
// if you want to be really specific
watching = false;
process.exit(1);
}
}
gulp.task('test', function () {
return gulp.src(['./__tests__/**/*.js'], { read: false })
.pipe(mocha({
reporter: 'spec',
}))
.on('error', onError);
});
gulp.task('watch-test',['test'] ,function () {
watching = true;
gulp.watch(['./src/**', './__tests__/**'], ['test']);
});
/**
* Bulk scripts
*/
gulp.task('dev',['set-dev-node-env'],function(done){
runSequence(['back','frontdev'],done);
});
gulp.task('update_package',function(){
var packageDetails = JSON.parse(fs.readFileSync('./package.json'));
var ver = packageDetails.ver;
ver++;
var packageDetailsNew = JSON.stringify(Object.assign({},packageDetails,{ver : ver}),null,2);
fs.writeFileSync('./package.json',packageDetailsNew);
});
gulp.task('publish',function(done){
runSequence('update_package',['set-prod-node-env','frontprod'],'add_commit_push',done);
});