-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
60 lines (46 loc) · 1.52 KB
/
Copy pathgulpfile.js
File metadata and controls
60 lines (46 loc) · 1.52 KB
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
"use strict";
const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
const hljs = require('highlight.js');
const plugins = gulpLoadPlugins();
gulp.task('img', () => gulp.src('src/img/**/*')
.pipe(gulp.dest('dist/img'))
);
gulp.task('css', () => gulp.src('src/stylesheet.scss')
.pipe(plugins.sass())
.pipe(plugins.addSrc('node_modules/highlight.js/styles/agate.css'))
.pipe(plugins.concat('stylesheet.min.css'))
.pipe(plugins.cleanCss())
.pipe(gulp.dest('dist/css'))
);
gulp.task('markdown', () => gulp.src('src/TUTORIAL.md')
.pipe(plugins.marked({
highlight: (code, lang) => (lang ? hljs.highlight(lang, code).value : code)
}))
.pipe(plugins.wrap({
src: 'src/template.html'
}))
.pipe(plugins.rename('index.html'))
.pipe(gulp.dest('dist'))
);
gulp.task('build', [ 'markdown', 'css', 'img' ]);
gulp.task('watch', [ 'build' ], () => {
console.log('watching for source changes...');
function watch(path, tasks) {
gulp.watch(path, tasks).on('change', event => {
console.log(`${event.path.substring(__dirname.length)} was ${event.type}, rebuilding...`);
});
}
watch([ 'src/TUTORIAL.md', 'src/template.html' ], [ 'markdown' ]);
watch('src/stylesheet.scss', [ 'css' ]);
watch('src/img/**/*', [ 'img' ]);
});
gulp.task('serve', [ 'watch' ], () => {
const server = plugins.liveServer.static(
'dist', Number(process.env['HTTP_PORT']) || 8080);
server.start();
gulp.watch('dist/**/*', { debounceDelay: 1000 }, event => {
server.notify(event);
});
});
gulp.task('default', [ 'build' ]);