This repository has been archived by the owner on May 2, 2023. It is now read-only.
forked from night/betterttv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
106 lines (90 loc) · 3.27 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
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 {src, dest, series, parallel, watch} = 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 postcssUrl = require('postcss-url');
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 * ')}
*/
`;
const cleanup = () => del('build/**/*');
const lint = () => src('src/**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
const prepare = () => src('src/**/*')
.pipe(dest('build'));
const license = () => src('build/index.js')
.pipe(header(LICENSE + '\n'))
.pipe(dest('build'));
const css = () => src('src/**/*.css')
.pipe(postcss([
precss,
autoprefixer,
hexrgba,
postcssUrl({url: asset => `${process.env.CDN_ENDPOINT}${asset.url}`})
]))
.pipe(concat('betterttv.css'))
.pipe(dest('build'));
const scripts = () => browserify('build/index.js', {debug: true})
.transform('require-globify')
.transform('babelify', {
global: true,
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime'],
ignore: [/node_modules/]
})
.transform('envify')
.bundle()
.pipe(gulpif(IS_PROD, source('betterttv.unmin.js'), source('betterttv.js')))
.pipe(buffer())
.pipe(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, dest('build')));
const dist = () => src('build/**/*')
.pipe(tar('betterttv.tar'))
.pipe(gzip())
.pipe(dest('dist'));
const build = series(
parallel(cleanup, lint),
prepare,
parallel(license, css),
scripts
);
const devServer = () => {
server();
watch('src/**/*', build);
};
exports.default = build;
exports.dist = series(build, dist);
exports.watch = parallel(devServer, build);