forked from luixaviles/angularconferences.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
executable file
·112 lines (98 loc) · 2.53 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
import gulp from 'gulp';
import util from 'gulp-util';
import concat from 'gulp-concat';
import header from 'gulp-header';
import plumber from 'gulp-plumber';
import babel from 'gulp-babel';
import uglify from 'gulp-uglify';
import addsrc from 'gulp-add-src';
import sass from 'gulp-sass';
import autoprefixer from 'gulp-autoprefixer';
import browserSync from 'browser-sync';
import child from 'child_process';
import hygienist from 'hygienist-middleware';
import del from 'del';
import fs from 'fs';
const parsed = JSON.parse(fs.readFileSync('./package.json'));
const siteRoot = '_site';
const jekyllLogger = buffer => {
buffer
.toString()
.split(/\n/)
.forEach(message => util.log(`Jekyll: ${message}`));
};
const banner = `/*! ultimateangular.com | (c) ${new Date().getFullYear()} Ultimate Angular Limited */\n`;
const paths = {
scripts: '_scripts/*.js',
libs: [],
dist: 'assets/js/',
scss: 'assets/css/source/*.scss',
css: 'assets/css/',
};
browserSync.create();
gulp.task('clean', fn => del([paths.dist, siteRoot], fn));
gulp.task('scripts', ['clean'], () => {
return gulp
.src(paths.scripts)
.pipe(plumber())
.pipe(babel())
.pipe(addsrc.prepend(paths.libs))
.pipe(concat('bundle.min.js'))
.pipe(uglify())
.pipe(
header(banner, {
parsed,
})
)
.pipe(gulp.dest(paths.dist));
});
const sassConfig = {
errLogToConsole: true,
outputStyle: 'compressed',
};
gulp.task('css', () => {
return gulp
.src(paths.scss)
.pipe(sass(sassConfig).on('error', sass.logError))
.pipe(
autoprefixer({
browsers: ['last 10 versions'],
})
)
.pipe(gulp.dest(paths.css));
});
gulp.task('jekyll', () => {
const jekyll = child.spawn('jekyll', [
'serve',
'--watch',
'--incremental',
'--drafts',
]);
jekyll.stdout.on('data', jekyllLogger);
jekyll.stderr.on('data', jekyllLogger);
});
gulp.task('jekyll-ci-build', () => {
const jekyll = child.spawn('jekyll', ['build']);
jekyll.stdout.on('data', jekyllLogger);
jekyll.stderr.on('data', jekyllLogger);
});
gulp.task('ci-build', ['scripts', 'jekyll-ci-build']);
gulp.task('serve', () => {
browserSync.init({
files: [`${siteRoot}/**`],
port: 4000,
server: {
baseDir: siteRoot,
middleware: hygienist(siteRoot),
},
open: false,
});
});
gulp.task('watch', () => {
gulp.watch(paths.scripts, ['scripts']);
gulp.watch(
['assets/css/source/**/*.scss', 'assets/css/source/*.scss'],
['css']
);
});
gulp.task('default', ['scripts', 'serve', 'jekyll', 'watch']);