-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
47 lines (38 loc) · 1.3 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
const gulp = require('gulp');
const del = require('del');
const fs = require('fs');
const runSequence = require('run-sequence');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const cleanSemanticUI = require('./client/semantic/tasks/clean');
const buildSemanticUI = require('./client/semantic/tasks/build');
const revision = Date.now();
gulp.task('clean', () => {
return del(['dist']);
});
gulp.task('clean-semantic-ui', cleanSemanticUI);
gulp.task('semantic-ui', 'clean-semantic-ui', buildSemanticUI);
gulp.task('webpack', () => {
const webpackConfig = require('./webpack.config');
return gulp.src('client/entries/app.js').pipe(webpackStream(webpackConfig, webpack)).pipe(gulp.dest('dist/'));
});
gulp.task('local', (callback) => {
let local;
try {
local = fs.readFileSync('local.js', 'utf-8');
} catch (e) {
fs.writeFileSync('local.js', 'module.exports={};');
local = fs.readFileSync('local.js', 'utf-8');
}
fs.writeFileSync('local.js', local.replace(/(=\s*\{)[.\s]*(revision:.[^,]+)?/, (matched, $1, $2) => {
let newRevision = `={revision:'${revision}'`;
if (!$2) {
newRevision += ',';
}
return newRevision;
}));
callback();
});
gulp.task('build', (callback) => {
return runSequence('clean', 'webpack', 'local', callback);
});