forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
160 lines (129 loc) · 3.34 KB
/
gulpfile.babel.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
'use strict';
import path from "path";
import gulp from "gulp";
import uglify from "gulp-uglify";
import cleanCSS from "gulp-clean-css";
import autoprefixer from "gulp-autoprefixer";
import concat from "gulp-concat";
import header from "gulp-header";
import gutil from "gulp-util";
import sourcemaps from "gulp-sourcemaps";
import connect from "gulp-connect";
import browserify from "browserify";
import babelify from "babelify";
import source from "vinyl-source-stream";
import buffer from "vinyl-buffer";
import pkg from "./package.json";
const appName = 'algorithm_visualizer';
const appEntryPoint = './js/index.js';
const outputPaths = {
javascript: './public',
css: './public',
sourceMaps: './'
};
const banner = [
'/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @author <%= pkg.author %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''
].join('\n');
// build directories
const cssDir = path.join(__dirname, 'css', '**', '*.css');
const jsDir = path.join(__dirname, 'js', '**', '*.js');
// CSS
gulp.task('minify-css', () => {
gutil.log('\n\nBuild CSS Paths: \n', cssDir, '\n\n');
return gulp.src(cssDir)
.pipe(autoprefixer())
.pipe(cleanCSS({
compatibility: 'ie8'
}))
.pipe(concat(`${appName}.min.css`))
.pipe(header(banner, {
pkg
}))
.pipe(gulp.dest(outputPaths.css))
.pipe(connect.reload());
});
gulp.task('build-css', () => {
gutil.log('\n\nBuild CSS Paths: \n', cssDir, '\n\n');
return gulp.src(cssDir)
.pipe(autoprefixer())
.pipe(concat(`${appName}.css`))
.pipe(header(banner, {
pkg
}))
.pipe(gulp.dest(outputPaths.css))
.pipe(connect.reload());
});
// JS
gulp.task('minify-js', () => {
gutil.log('\n\nBuild JS Paths: \n', jsDir, '\n\n');
return browserify({
entries: './js/index.js',
debug: true
})
.transform('babelify', {
presets: ['es2015']
})
.bundle()
.pipe(source(`${appName}.min.js`))
.pipe(header(banner, {
pkg
}))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write(outputPaths.sourceMaps))
.pipe(gulp.dest(outputPaths.javascript))
.pipe(connect.reload());
});
gulp.task('build-js', () => {
gutil.log('\n\nBuild JS Paths: \n', jsDir, '\n\n');
return browserify({
entries: './js/index.js',
debug: true
})
.transform('babelify', {
presets: ['es2015']
})
.bundle()
.pipe(source(`${appName}.js`))
.pipe(header(banner, {
pkg
}))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(sourcemaps.write(outputPaths.sourceMaps))
.pipe(gulp.dest(outputPaths.javascript))
.pipe(connect.reload());
});
// Build
gulp.task('compile-css', ['build-css', 'minify-css']);
gulp.task('compile-js', ['build-js', 'minify-js']);
gulp.task('build', ['compile-css', 'compile-js']);
// Server
gulp.task('connect', function () {
connect.server({
port: process.env.PORT || 8080,
livereload: true
});
});
// Watch
gulp.task('watch', ['build'], function () {
gulp.watch(jsDir, ['compile-js']);
gulp.watch(cssDir, ['compile-css']);
});
// Heroku Production
gulp.task('prod', ['build'], function () {
connect.server({
port: process.env.PORT || 8080,
livereload: false
});
});
// Default
gulp.task('default', ['connect', 'watch']);