-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
189 lines (166 loc) · 4.91 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
'use strict';
// Require
const gulp = require('gulp'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
postcss = require('gulp-postcss'),
sourcemaps = require('gulp-sourcemaps'),
cssnano = require('gulp-cssnano'),
concat = require('gulp-concat'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
browserSync = require('browser-sync'),
imagemin = require('gulp-imagemin'),
console = require('better-console'),
del = require('del'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
markdown = require('gulp-markdown'),
cp = require('child_process'),
// PostCSS Plugins
cssnext = require('postcss-cssnext');
// Default source and build folder
var src = './_src',
dist = './assets';
// Folders ( Make sure you add new jekyll folders to the jekyll line as needed )
var path = {
scss: [src + '/scss/**/*.scss'],
js: [
// Vendors
'node_modules/jquery/dist/jquery.js',
'node_modules/clipboard/dist/clipboard.js',
// Local JS
src + '/js/**/*.js'
],
images: [src + '/images/**/*'],
fonts: [src + '/fonts/**/*'],
jekyll: ['index.html', '_pages/**/*', '_layouts/**/*', '_includes/**/*', '_data/**/*', 'assets/**/*']
};
var config = {
serverPort: 3000
};
// Jekyll build
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
// Build the Jekyll Site
gulp.task('jekyll-build', (code) => {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('error', (error) => gutil.log(gutil.colors.red(error.message)))
.on('close', code);
});
// Rebuild Jekyll & do page reload
gulp.task('jekyll-rebuild', gulp.series('jekyll-build', function() {
browserSync.reload();
}));
// CSS
gulp.task('css', () => {
var processors = [
cssnext({
browsers: ['last 6 version']
})
];
return gulp.src(src + '/scss/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(postcss(processors))
.pipe(cssnano({ discardComments: { removeAll: true }}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(dist + '/css/'))
.pipe(browserSync.stream());
});
// Javascript
gulp.task('js', () => {
return gulp.src(path.js)
.pipe(concat('bundle.js'))
.pipe(babel({
presets: ['env'],
compact: true
}))
.pipe(uglify())
.pipe(gulp.dest(dist + '/js/'))
.pipe(browserSync.stream());
});
// Images
gulp.task('imagemin', () => {
return gulp.src(path.images)
.pipe(plumber((error) => {
gutil.log(gutil.colors.red(error.message));
gulp.task('imagemin').emit('end');
}))
.pipe(imagemin())
.pipe(gulp.dest(dist + '/images/'))
.pipe(browserSync.stream());
});
// Copy font files
gulp.task('fonts', () => {
return gulp.src(path.fonts)
.pipe(gulp.dest(dist + '/fonts/'));
});
// Parse README.md to HTML
gulp.task('readme', () => {
return gulp.src('README.md')
.pipe(markdown())
.pipe(gulp.dest('_includes'));
});
// Clean build folders
gulp.task('clean', function() {
return del([
'_site',
'assets'
]);
});
// Wait for jekyll-build, then launch the Server
gulp.task('browser-sync', gulp.series('css', 'jekyll-build', function() {
browserSync({
server: {
baseDir: '_site'
},
port: config.serverPort,
notify: {
styles: {
top: '30px',
left: '50%',
width: '200px',
transform: 'translate(-50%,-50%)',
margin: '0px',
padding: '8px 12px',
position: 'fixed',
fontSize: '13px',
fontFamily: 'Helvetica',
zIndex: '9999',
borderRadius: '16px',
color: 'white',
textAlign: 'center',
display: 'block',
backgroundColor: 'rgba(0,0,0, 0.8)'
}
},
logLevel: 'silent'
});
// Some fancy console art
console.log('Starting DevelopmentServer');
console.log(' ');
console.log(' ');
console.log(' / / _ / \\ NWA');
console.log(' / \\ / \\/ \\/ - \\ Local Development Environment');
console.log(' ');
console.log(' ');
console.log('Listening on port ' + config.serverPort);
console.log(' ');
console.log(' ');
}));
// Watch files
gulp.task('watch', function() {
gulp.watch(paths.scss, gulp.series('css'));
gulp.watch(paths.js, gulp.series('js'));
gulp.watch(paths.images, gulp.series('imagemin'));
gulp.watch(paths.jekyll, gulp.series('jekyll-rebuild'));
});
// Re-build everything
gulp.task('build', gulp.series('clean', gulp.parallel('css', 'js', 'imagemin', 'fonts', 'readme'), function(done) {
done();
}));
// Start Everything with the default task
gulp.task('default', gulp.series('browser-sync', 'watch'));