-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
68 lines (60 loc) · 1.57 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
const gulp = require('gulp');
const minify = require('gulp-minify');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const clean = require('gulp-clean');
const rev = require('gulp-rev');
const runSequence = require('run-sequence');
const merge = require('gulp-merge-json');
const insert = require('gulp-insert');
gulp.task('minify', () =>
gulp
.src(['dex-opt.js'])
.pipe(babel())
.pipe(minify())
.pipe(gulp.dest('.tmp'))
);
gulp.task('concat', () =>
gulp
.src([".tmp/config.json", ".tmp/dex-opt-min.js"])
.pipe(concat('dexecure.js', {newLine: ';'}))
.pipe(insert.prepend("var dexecure = "))
.pipe(gulp.dest('.tmp'))
);
gulp.task('move', () =>
gulp
.src(['dex-opt.js', 'index.html'])
.pipe(gulp.dest('.tmp'))
);
gulp.task('rev', () =>
gulp
.src('.tmp/dexecure.js')
.pipe(rev())
.pipe(gulp.dest('dist'))
.pipe(rev.manifest())
.pipe(gulp.dest('.tmp'))
);
gulp.task('clean', () =>
gulp
.src(['dist', '.tmp'], {read: false})
.pipe(clean())
);
gulp.task('html', () => {
var fs = require('fs');
var scriptName = JSON.parse(fs.readFileSync('.tmp/rev-manifest.json'))["dexecure.js"];
console.log(scriptName);
var scriptToInject = `<script>var DEXECURE_URL = "/${scriptName}";</script>`;
return gulp
.src('.tmp/index.html')
.pipe(insert.prepend(scriptToInject))
.pipe(gulp.dest("dist"));
});
gulp.task('config', () => {
gulp
.src(['config.default.json', 'config.user.json'])
.pipe(merge('config.json'))
.pipe(gulp.dest('.tmp'))
});
gulp.task('default', () => {
runSequence('clean', 'move', ['minify', 'config'], 'concat', 'rev', 'html');
});