-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
60 lines (51 loc) · 1.82 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
const $ = require('gulp');
const $changed = require('gulp-changed');
const $htmlmin = require('gulp-htmlmin');
const $plumber = require('gulp-plumber');
const del = require('del');
const server = require('browser-sync').create();
$.task('clean', clean);
$.task('publish', publish);
$.task('minimize', pages);
$.task('build', $.series('clean', 'publish', 'minimize'));
$.task('rebuild', $.series('publish', 'minimize'));
$.task('default', $.series('build', $.parallel(serve, watch)));
function clean() {
// TODO Find home dir : https://stackoverflow.com/questions/34713622/accessing-home-directory-with-base-in-gulp
return del(['build', '/home/nono/.org-timestamps/org-r-notes.cache', '/home/nono/.org-timestamps/org-r-static.cache'], {force:true});
}
var spawn = require('child_process').spawn;
function publish(cb) {
//var cmd = spawn('cmd', ['arg1', 'agr2'], {stdio: 'inherit'});
// var cmd = spawn('ls', [], {stdio: 'inherit'});
// Emacs Workaround : conflict between whitespace-style and org-publish.
var cmd = spawn('emacs', ['--eval', '(prog1 (setq whitespace-style \'(face))(org-publish-project "org-r")(kill-emacs))'], {stdio: 'inherit'});
cmd.on('close', function (code) {
console.log('emacs org-publish exited with code ' + code);
cb(code);
});
}
function reload(done) {
server.reload();
done();
}
function watch() {
$.watch(['build/*.html'], $.series(pages, reload));
}
function serve(done) {
server.init({server: 'build'});
done();
}
function pages() {
// https://github.com/gulpjs/gulp/issues/267
return $.src('build/*.html', {base: './'})
.pipe($changed('build'))
.pipe($plumber())
.pipe($htmlmin({
removeComments: true,
collapseWhitespace: true,
removeEmptyAttributes: true,
minifyJS: true,
minifyCSS: true}))
.pipe($.dest('./'));
}