forked from night/betterttv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
123 lines (109 loc) · 3.34 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
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
const autoprefixer = require('autoprefixer');
const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const concat = require('gulp-concat');
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 hexrgba = require('postcss-hexrgba');
const postcss = require('gulp-postcss');
const precss = require('precss');
const rename = require('gulp-rename');
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.NODE_ENV = process.env.NODE_ENV || 'development';
const IS_PROD = process.env.NODE_ENV === 'production';
process.env.DEV_CDN_PORT = 2888;
process.env.DEV_CDN_ENDPOINT = `http://127.0.0.1:${process.env.DEV_CDN_PORT}/`;
process.env.PROD_CDN_ENDPOINT = 'https://cdn.betterttv.net/';
process.env.EXT_VER = require('./package.json').version;
process.env.GIT_REV = git.long();
process.env.SENTRY_URL = process.env.SENTRY_URL || 'https://[email protected]/144851';
process.env.CDN_ENDPOINT = IS_PROD ? process.env.PROD_CDN_ENDPOINT : process.env.DEV_CDN_ENDPOINT;
const LICENSE = `/** @license
* ${fs.readFileSync('LICENSE').toString().replace(/\n/g, '\n * ')}
*/
`;
gulp.task(
'css',
() => gulp.src('src/**/*.css')
.pipe(postcss([precss, autoprefixer, hexrgba]))
.pipe(concat('betterttv.css'))
.pipe(gulp.dest('build'))
);
gulp.task(
'cleanup',
() => del('build/**/*')
);
gulp.task(
'lint',
() => gulp.src('src/**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError())
);
gulp.task(
'prepare',
['cleanup', 'lint'],
() => gulp.src('src/**/*')
.pipe(gulp.dest('build'))
);
gulp.task(
'license',
['prepare'],
() => gulp.src('build/index.js')
.pipe(header(LICENSE + '\n'))
.pipe(gulp.dest('build'))
);
gulp.task(
'scripts',
['license', 'css'],
() => browserify('build/index.js', {debug: true})
.transform('require-globify')
.transform('babelify', {
global: true,
presets: ['es2015'],
plugins: ['transform-runtime'],
ignore: /node_modules\/(?!draggy)/
})
.transform('envify')
.bundle()
.pipe(gulpif(IS_PROD, source('betterttv.unmin.js'), source('betterttv.js')))
.pipe(buffer())
.pipe(gulp.dest('build'))
.pipe(gulpif(IS_PROD, rename('betterttv.js')))
.pipe(gulpif(IS_PROD, sourcemaps.init({loadMaps: true})))
.pipe(gulpif(IS_PROD, uglify({output: {comments: saveLicense}})))
.pipe(gulpif(IS_PROD, sourcemaps.write('./')))
.pipe(gulpif(IS_PROD, 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'))
);