This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
135 lines (102 loc) · 3.43 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
var gulp = require('gulp');
var fs = require('fs');
var path = require('path');
var autoprefixer = require('autoprefixer');
var browserSync = require('browser-sync').create();
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var debug = require('gulp-debug');
var postcss = require('gulp-postcss');
var rename = require("gulp-rename");
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var surge = require('gulp-surge');
var watch = require('gulp-watch');
gulp.task('cssclean', function(){
return gulp.src('dist/*.css', { read: false }).pipe(clean());
});
gulp.task('csscompile', ['cssclean'], function(){
return gulp
.src('src/sass/index.scss')
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.init())
.pipe(postcss([autoprefixer()]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
gulp.task('jsclean', function(){
return gulp.src('dist/*.js', { read: false }).pipe(clean());
});
gulp.task('jsconcat', ['jsclean'], function(){
return gulp.src([
'src/js/highlight.pack.js',
'src/js/jquery-3.1.1.min.js',
'src/js/marked.js',
'src/js/flat-file.js',
'src/js/gitter.js'
])
.pipe(concat('all.js'))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
gulp.task('lekceclean', function(){
return gulp
.src(['lekce/**/*.html', '!lekce/*.html'], { read: false })
.pipe(clean());
});
// function to get list of future html files from .md present
var getHtmlFileList = function(dir, filelist){
var files = fs.readdirSync(dir); // where to find .md
filelist = filelist || [];
files.forEach(function(file){
if (fs.statSync(path.join(dir, file)).isDirectory()){
filelist = getHtmlFileList(path.join(dir, file), filelist);
} else if (path.parse(file).ext == '.md'){
filelist.push(path.join(dir, path.parse(file).name + '.html'));
}
});
return filelist;
};
gulp.task('lekcecreate', ['lekceclean'], function(){
var filelist = getHtmlFileList('lekce');
var p = gulp.src('lekce/sablona.html'); // source to be copied
// copy source to each location on the list
for (var i = 0; i < filelist.length; i++){
p = p
.pipe(rename(filelist[i]))
.pipe(gulp.dest(''));
}
// return and reload browserSync
return p.pipe(browserSync.stream());
});
gulp.task('develop', ['distprep'], function(){
browserSync.init({
server: {
baseDir: './',
serveStaticOptions: {
extensions: ['html']
}
},
open: false,
port: 3030,
files: ['*.html'] // only root html files watched
// for other files browserSync is called manually via browserSync.stream()
});
gulp.watch('src/sass/*.scss', ['csscompile']);
gulp.watch('src/js/*.js', ['jsconcat']);
gulp.watch(['lekce/**/*.md', 'lekce/sablona.html'])
.on('change', function(event){
if (event.type != 'renamed'){ // preventing multiple calls
gulp.start('lekcecreate');
}
});
});
gulp.task('distprep', ['csscompile', 'jsconcat', 'lekcecreate']);
gulp.task('deploy', ['distprep'], function(){
return surge({
project: './',
domain: 'webkurz.pyladies.cz'
})
});
gulp.task('default', ['develop']);