forked from night/betterttv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (79 loc) · 2.25 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
const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const del = require('del');
const eslint = require('gulp-eslint');
const fs = require('fs');
const git = require('git-rev-sync');
const gulp = require('gulp');
const gulpif = require('gulp-if');
const gzip = require('gulp-gzip');
const header = require('gulp-header');
const saveLicense = require('uglify-save-license');
const server = require('./dev/server');
const source = require('vinyl-source-stream');
const sourcemaps = require('gulp-sourcemaps');
const tar = require('gulp-tar');
const uglify = require('gulp-uglify');
process.env.EXT_VER = require('./package.json').version;
process.env.GIT_REV = git.long();
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
process.env.SENTRY_URL = process.env.SENTRY_URL || 'https://[email protected]/144851';
const IS_PROD = process.env.NODE_ENV === 'production';
const LICENSE = `/** @license
* ${fs.readFileSync('LICENSE').toString().replace(/\n/g, '\n * ')}
*/
`;
gulp.task(
'cleanup',
() => del('build/**/*')
);
gulp.task(
'prepare',
['cleanup', 'lint'],
() => gulp.src(['src/**/*'])
.pipe(gulp.dest('build/'))
);
gulp.task(
'lint',
() => gulp.src(['src/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError())
);
gulp.task(
'scripts',
['prepare'],
() => browserify('build/index.js', {debug: true})
.transform('require-globify')
.transform('babelify', {presets: ['es2015']})
.transform('envify')
.bundle()
.pipe(source('betterttv.js'))
.pipe(buffer())
.pipe(header(LICENSE + '\n'))
.pipe(gulpif(IS_PROD, sourcemaps.init({loadMaps: true})))
.pipe(gulpif(IS_PROD, uglify({preserveComments: saveLicense})))
.pipe(gulpif(IS_PROD, sourcemaps.write('./')))
.pipe(gulp.dest('build'))
);
gulp.task(
'server',
() => server()
);
gulp.task(
'watch',
['default', 'server'],
() => gulp.watch('src/**/*', ['default'])
);
gulp.task(
'default',
['scripts']
);
gulp.task(
'dist',
['scripts'],
() => gulp.src('build/**/*')
.pipe(tar('betterttv.tar'))
.pipe(gzip())
.pipe(gulp.dest('dist'))
);