-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
102 lines (87 loc) · 2.4 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
'use strict';
var path = require('path');
var del = require('del');
var exec = require('child_process').exec;
var gulp = require('gulp');
var less = require('gulp-less');
var plugins = require('gulp-load-plugins')();
var path = require('path');
var modRewrite = require('connect-modrewrite');
var serveStatic = require('serve-static');
var runSequence = require('run-sequence');
// Function to clean files using del()
function clean(path) {
return del.sync(path);
}
var build = false;
// Object with directory paths for further usage
var rootPath = '/';
var dirs = {
source: path.join('.', 'src'),
build: path.join('.', 'build', rootPath)
};
// Task to compile using metalsmith
gulp.task('metalsmith', function(cb) {
exec('node index.js ' + rootPath, function(err) {
if (!err) {
if (!build) {
gulp.src(dirs.build + '/**/*')
.pipe(plugins.connect.reload())
.on('end', cb);
} else {
cb();
}
}
});
});
// Connect task to serve web server and reload automatically
gulp.task('connect', ['metalsmith'], function() {
plugins.connect.server({
root: 'build',
livereload: true,
port: 8090,
middleware: function() {
return [
serveStatic('build', { extensions: ['html'] })
];
}
});
});
// Task to clean/trash folders
gulp.task('clean', function() {
var files = [
dirs.source,
dirs.build
];
return clean(files);
});
gulp.task('less', ['metalsmith'], function(cb) {
return gulp.src('./layouts/styles/main.less')
.pipe(less({
paths: './layouts/styles'
}))
.pipe(gulp.dest('./build' + rootPath + 'assets'));
});
// Watch for changes in files
gulp.task('watch', function() {
gulp.watch('./layouts/**/*.less', ['less']);
gulp.watch('./index.js', ['metalsmith', 'less']);
gulp.watch(dirs.source + '/**/*', ['metalsmith', 'less']);
gulp.watch('./plugins/**/*', ['metalsmith', 'less']);
gulp.watch('./assets/**/*', ['metalsmith', 'less']);
gulp.watch('./layouts/**/*.html', ['metalsmith', 'less']);
});
// Git clone task to fetch source files from Rocket.Chat.Docs which is also
// dependent on the 'clean' task
gulp.task('git', ['clean'], function(cb) {
plugins.git.clone('https://github.com/RocketChat/Rocket.Chat.Docs', { args: dirs.source }, function(err) {
if (err) throw err;
cb();
});
});
gulp.task('fetch', ['git']);
gulp.task('default', ['connect', 'metalsmith', 'less', 'watch']);
gulp.task('build', function() {
build = true;
runSequence(['metalsmith', 'less']);
});