-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
152 lines (131 loc) · 3.9 KB
/
gulpfile.babel.js
File metadata and controls
152 lines (131 loc) · 3.9 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
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
const gulp = require('gulp');
const del = require('del');
const fs = require('fs');
const path = require('path');
const connect = require('gulp-connect');
const exec = require('child_process').exec;
const runSequence = require('run-sequence');
const cachebust = new require('gulp-cachebust')();
const port = 8080;
const hugoConfig = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
const activeTheme = hugoConfig.theme;
const distPath = __dirname + '/public';
const themesPath = __dirname + '/themes/';
const watchOptions = {interval: 1000, mode: 'poll'};
function getThemesFolders(dir) {
return fs.readdirSync(dir)
.filter((file) => {
return fs.statSync(path.join(dir, file)).isDirectory();
});
}
const toClean = [];
const toWatch = {};
getThemesFolders(themesPath).forEach((theme) => {
const themeBuilder = require(path.join(themesPath, theme, 'gulpfile.babel.js'));
const themeDir = path.join(themesPath, theme);
//declare tasks for theme
for (const i in themeBuilder.clean) {
toClean.push(path.join(themeDir,themeBuilder.clean[i]));
}
gulp.task(theme + '-deps', themeBuilder.deps(themeDir));
gulp.task(theme + '-js', themeBuilder.js(themeDir, cachebust));
gulp.task(theme + '-js-dev', themeBuilder.jsDev(themeDir));
gulp.task(theme + '-css', themeBuilder.css(themeDir, cachebust));
gulp.task(theme + '-css-dev', themeBuilder.cssDev(themeDir));
gulp.task(theme + '-css-dev-hugo-draft', (cb) => {
runSequence(theme+'-css-dev', 'hugo-draft', cb);
});
gulp.task(theme + '-js-dev-hugo-draft', (cb) => {
runSequence(theme+'-js-dev', 'hugo-draft', cb);
});
//setup watch for theme, if it is the active theme
if (theme === activeTheme) {
for (const j in themeBuilder.watchCSSSource) {
toWatch[path.join(themeDir,themeBuilder.watchCSSSource[j])] = [theme+'-css-dev-hugo-draft'];
}
for (const k in themeBuilder.watchJSSource) {
toWatch[path.join(themeDir,themeBuilder.watchJSSource[k])] = [theme+'-js-dev-hugo-draft'];
}
for (const l in themeBuilder.watchTheme) {
toWatch[path.join(themeDir,themeBuilder.watchTheme[l])] = ['hugo-draft'];
}
}
});
gulp.task('clean-themes', () => {
return del(toClean);
});
// clean dist folder
gulp.task('clean', ['clean-themes'], () => {
return del([
distPath
]);
});
// Hugo (without drafts)
gulp.task('hugo', [activeTheme+'-css', activeTheme+'-js'], (cb) => {
exec('hugo --verbose --baseURL="http://nomjs.com/"', (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
// Hugo (with drafts)
gulp.task('hugo-draft', (cb) => {
exec('hugo --verbose -D --baseURL=""', (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
gulp.src('public/').pipe(connect.reload());
cb(err);
});
});
// cachebust step
gulp.task('bust', ['hugo'], () => {
return gulp.src('public/**/*.html')
.pipe(cachebust.references())
.pipe(gulp.dest('public'));
});
// server
gulp.task('connect', () => {
connect.server({
root: 'public',
port: port,
livereload: {
port: 35729
}
});
});
// dist
gulp.task('dist', (cb) => {
runSequence('clean', activeTheme+'-deps', 'bust', cb);
});
gulp.task('draft-dist', (cb) => {
runSequence(
'clean',
activeTheme+'-deps',
activeTheme+'-css-dev',
activeTheme+'-js-dev',
'hugo-draft',
cb
);
});
// watch
gulp.task('watch', () => {
gulp.watch('content/**/*.md', watchOptions, ['hugo-draft']);
gulp.watch('layouts/**/*.html', watchOptions, ['hugo-draft']);
gulp.watch('static/**/*', watchOptions, ['hugo-draft']);
gulp.watch('config.json', watchOptions, ['hugo-draft']);
for (const w in toWatch) {
gulp.watch(w, watchOptions, toWatch[w]);
}
});
// default
gulp.task('serve', () => {
runSequence(
'clean',
activeTheme+'-deps',
activeTheme+'-css-dev',
activeTheme+'-js-dev',
'hugo-draft',
['connect','watch']
);
});
gulp.task('default', ['serve']);