-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
executable file
·186 lines (166 loc) · 4.17 KB
/
gulpfile.babel.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
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
import gulp from 'gulp'
import sass from 'gulp-sass'
import autoprefixer from 'gulp-autoprefixer'
import sourcemaps from 'gulp-sourcemaps'
import uglifycss from 'gulp-uglifycss'
import concat from 'gulp-concat'
import imgmin from 'gulp-imagemin'
import del from 'del'
import webpack from 'webpack'
import webpackGulp from 'webpack2-stream-watch'
import { exec } from 'child_process'
const dirs = {
dest: 'build',
}
const apps = ['editor', 'multipart-player', 'recipe-browser']
gulp.task('clean', () => {
return del(dirs.dest)
})
gulp.task('css', () => {
return gulp
.src('./static/css/*.scss')
.pipe(sourcemaps.init())
.pipe(sass(require('sass')).sync())
.pipe(autoprefixer())
.pipe(uglifycss())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${dirs.dest}/static/css`))
})
apps.forEach(app => {
const webpackConfig = require(`./client/${app}/webpack.config.js`)(
process.env
)
if (!process.env.DEBUG) {
webpackConfig.plugins = [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true,
},
compress: {
screw_ie8: true,
},
comments: false,
}),
]
}
gulp.task(app, () => {
return gulp
.src(`client/${app}/app.js`)
.pipe(sourcemaps.init())
.pipe(webpackGulp(webpackConfig, webpack))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${dirs.dest}/static/js`))
})
})
gulp.task('server-env', () => {
return gulp
.src(['./package.json', './.env', './package-lock.json'])
.pipe(gulp.dest(dirs.dest))
})
gulp.task(
'server',
gulp.series('server-env', () => {
return gulp
.src([
'!static/**/', // ignore client JS
'!flow-typed/**/', // ignore client JS
'!coverage/**/', // ignore client JS
'!test/**/', // ignore client JS
'!client/**/', // ignore client JS
'!build/**/', // ignore built JS
'!node_modules/**/', // ignore node module JS
'!gulpfile.babel.js', // ignore node module JS
'**/*.js',
'**/*.ts',
])
.pipe(gulp.dest(dirs.dest))
})
)
gulp.task('data', () => {
return gulp
.src('./data/dump/**/*')
.pipe(gulp.dest(`${dirs.dest}/data/dump`))
})
gulp.task('images', () => {
return gulp
.src('./static/images/*')
.pipe(imgmin())
.pipe(gulp.dest(`${dirs.dest}/static/images`))
})
gulp.task('static_js', () => {
return gulp
.src('./static/js/*.js')
.pipe(gulp.dest(`${dirs.dest}/static/js`))
})
gulp.task('bin', () => {
return gulp.src('./bin/*').pipe(gulp.dest(`${dirs.dest}/bin`))
})
gulp.task('templates', () => {
return gulp
.src('./templates/**/*.hbs')
.pipe(gulp.dest(`${dirs.dest}/templates`))
})
gulp.task('tests', () => {
return gulp
.src('./test/*.js')
.pipe(sourcemaps.init())
.pipe(concat('tests.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${dirs.dest}/test`))
})
gulp.task('other', () => {
return gulp.src('./static/*').pipe(gulp.dest(`${dirs.dest}/static`))
})
gulp.task('js', gulp.series(apps.concat('static_js')))
gulp.task(
'default',
gulp.series([
'bin',
'images',
'css',
'other',
'js',
'data',
'templates',
'server',
'tests',
])
)
gulp.task(
'watch',
gulp.series('default', () => {
const watchers = [
gulp.watch('./static/js/**/*.js', ['static_js']),
gulp.watch('./static/css/**/*.scss', ['css']),
gulp.watch('./templates/**/*.hbs', ['templates']),
gulp.watch('./static/images/**/*', ['images']),
gulp.watch('./test/*.js', ['tests']),
gulp.watch('./data/dump/**/*', ['data']),
gulp.watch('./bin/*', ['bin']),
gulp.watch(
[
'./**/*.js',
'!./static/**/*.js', // ignore client JS
'!./flow-typed/**/*.js', // ignore client JS
'!./coverage/**/*.js', // ignore client JS
'!./test/**/*.js', // ignore client JS
'!./client/**/*.js', // ignore client JS
'!./build/**/*', // ignore built files
'!./node_modules/**/*.js', // ignore node module JS
'!./gulpfile.babel.js', // ignore node module JS
],
['server']
),
// Also processes for each client app
].concat(apps.map(app => gulp.watch(`./client/${app}/**/*`, [app])))
watchers.forEach(watcher =>
watcher.on('change', _ => exec('npm run docker:restart'))
)
})
)