-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
102 lines (92 loc) · 2.53 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
'use strict';
var gulp = require('gulp');
var _ = require('lodash');
var argv = require('yargs').argv;
var spawn = require('child_process').spawn;
require('./gulp/task-build-webpack-dev');
require('./gulp/task-build-webpack-prod');
/**
* Run custom scripts
*/
gulp.task('script', function() {
var env = _.cloneDeep(process.env);
env.NODE_ENV = 'development';
env.NODE_PATH = 'src';
spawn('node_modules/.bin/babel-node', [argv.path], {
env: env,
stdio: 'inherit'
});
});
gulp.task('prod-script', function() {
var env = _.cloneDeep(process.env);
env.NODE_ENV = 'production';
env.NODE_PATH = 'src';
spawn('node_modules/.bin/babel-node', [argv.path], {
env: env,
stdio: 'inherit'
});
});
/**
* Run Web Application Rendering Server in development environement
* Static files will be bundled and served by Webpack development server to enable hot reload
*/
gulp.task('webapp-dev', ['build-webpack-dev'], function () {
var developmentEnv = _.cloneDeep(process.env);
developmentEnv.NODE_ENV = 'development';
developmentEnv.BROWSER = false;
spawn('nodemon', ['-w', 'src/common', '-w', 'src/webapp', 'webapp-server.js'], {
env: developmentEnv,
stdio: 'inherit'
});
});
/**
* Run Web Application Rendering Server in production environment
* Static files will be bundled by Webpack and served by the rendering server
*/
gulp.task('webapp-prod', ['build-webpack-prod'], function () {
var productionEnv = _.cloneDeep(process.env);
productionEnv.NODE_ENV = 'production';
productionEnv.BROWSER = false;
spawn('node', ['webapp-server.js'], {
env: productionEnv,
stdio: 'inherit'
});
});
/**
* Run API Server in development environment
*/
gulp.task('api-dev', function () {
var developmentEnv = _.cloneDeep(process.env);
developmentEnv.NODE_ENV = 'development';
spawn('nodemon', ['-w', 'src/common', '-w', 'src/api', 'api-server.js'], {
env: developmentEnv,
stdio: 'inherit'
});
});
/**
* Run API Server in production environment
*/
gulp.task('api-prod', function () {
var productionEnv = _.cloneDeep(process.env);
productionEnv.NODE_ENV = 'production';
spawn('node', ['api-server.js'], {
env: productionEnv,
stdio: 'inherit'
});
});
/**
* Run PM2 to run both server for deployed environment
*/
gulp.task('pm2', ['build-webpack-prod'], function () {
spawn('pm2', ['start', 'processes.json'], {
stdio: 'inherit'
});
});
/**
* Bundle and build static web application files
*/
gulp.task('build', ['build-webpack-prod']);
/**
* Default task
*/
gulp.task('default', ['build']);