-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
108 lines (85 loc) · 2.59 KB
/
gulpfile.js
File metadata and controls
108 lines (85 loc) · 2.59 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
const gulp = require('gulp');
const gutil = require('gulp-util');
const babel = require('gulp-babel');
const path = require('path');
const changed = require('gulp-changed');
const del = require('del');
const nodemon = require('gulp-nodemon');
const nodemonConfig = require('./nodemon');
const eslint = require('gulp-eslint');
const spawn = require('child_process').spawn;
// Setup the directories of the project
const paths = {
src: 'src',
build: 'build',
vendor: 'vendor',
};
const PWD = process.env.PWD;
// Util that produeces a path refering to the files inside a given dir.
const files = dir => path.join(dir, '/**/*');
const out = dir => path.join(paths.build, dir);
const lib = dir => out(path.join('lib', 'node_modules', dir));
paths.lib = path.join(paths.build, 'lib', 'node_modules');
paths.server = lib('index.js');
gutil.log(paths.server);
nodemonConfig.watch = [paths.lib];
////////////////////////
gulp.task('default', ['server'])
// start dev server
gulp.task('dev', ['watch'], () => {
nodemonConfig.script = paths.server;
nodemonConfig.stdout = false;
nodemon(nodemonConfig)
.on('stdout', data => {
data.toString().trim().split(/\r\n|\r|\n/g).map(line => {
gutil.log(`[srv]: ${line}`);
});
});
});
gulp.task('server', ['build'], () => {
const server = spawn('node', ['build/lib/node_modules']);
server.stdout.on('data', (data) => {
data.toString().trim().split('\n').map(line => {
gutil.log(gutil.colors.blue('server'), ':', line);
});
});
server.stderr.on('data', (data) => {
data.toString().trim().split('\n').map(line => {
gutil.log(gutil.colors.red('server'), ':', line);
});
});
server.on('close', (code) => {
gutil.log(`server exited with code ${code}`);
});
});
gulp.task('eslint', () => {
return gulp.src(files(paths.src))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('watch', ['watch-src', 'watch-vendor']);
gulp.task('build', ['build-lib', 'build-vendor']);
// watches
gulp.task('watch-src', ['build-lib'], () => {
gulp.watch(files(paths.src), ['build-lib']);
});
gulp.task('watch-vendor', ['build-vendor'], () => {
gulp.watch(files(paths.vendor), ['build-vendor']);
});
///////////// builds
gulp.task('build-lib', () => {
return gulp.src(files(paths.src))
.pipe(changed(paths.lib))
.pipe(babel())
.pipe(gulp.dest(paths.lib));
});
gulp.task('build-vendor', () => {
return gulp.src(files(paths.vendor))
.pipe(changed(lib(paths.vendor)))
.pipe(gulp.dest(lib(paths.vendor)));
});
// clean
gulp.task('clean', () => {
return del(paths.build);
});