-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (77 loc) · 2.5 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
var path = require('path');
var fs = require('fs');
var gulp = require('gulp');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var swig = require('gulp-swig');
var data = require('gulp-data');
var tap = require('gulp-tap');
var rename = require('gulp-rename');
var yaml = require('js-yaml');
var svgstore = require('gulp-svgstore');
var getComponentData = function(file) {
data = yaml.safeLoad(fs.readFileSync(file.path.replace('.html', '.yaml'), 'utf8'))
name = path.basename(file.path, '.html')
sample = {}
sample[name] = data.data ? data.data : {}
return {
name: name,
title: data.title ? data.title : '',
desc: data.desc ? data.desc : '',
data: data.data ? data.data : {},
sample: data.data ? yaml.safeDump(sample) : ''
}
};
getPageData = function(file) {
return yaml.safeLoad(fs.readFileSync(file.path.replace('.html', '.yaml'), 'utf8'))
};
// Iterate over components, extract their sample data
// and write everything to the YAML index file
gulp.task('components', function() {
files = []
return gulp.src('./components/**/*.html')
.pipe(data(getComponentData))
.pipe(tap(function(file) {
file.data.path = '../components/' + path.basename(file.path, '.html') + '/' + path.basename(file.path),
files.push(file.data)
}))
.on('end', function() {
fs.writeFileSync('./pages/index.yaml', yaml.safeDump({files: files}));
})
});
gulp.task('pages', function() {
return gulp.src('./pages/*.html')
.pipe(data(getPageData))
.pipe(swig())
.pipe(gulp.dest('public'));
});
gulp.task('sass', function() {
gulp.src([
'./styles/colors.scss',
'./styles/variables.scss',
'./node_modules/bootstrap/scss/_variables.scss',
'./node_modules/bootstrap/scss/bootstrap.scss',
'./styles/styles.scss',
'./components/**/*.scss',
'./layouts/*.scss',
'./pages/*.scss',
])
.pipe(concat('styles.scss'))
.pipe(sass({
includePaths: ['./node_modules/bootstrap/scss']
}))
.pipe(gulp.dest('./public/css'));
});
gulp.task('svg', function () {
return gulp
.src([
'./node_modules/material-design-icons/**/production/*_24px.svg',
'!./node_modules/material-design-icons/**/production/ic_rv_hookup_24px.svg'
])
.pipe(svgstore())
.pipe(rename(function (path) {
path.basename = 'icons'
}))
.pipe(gulp.dest('public/svg'));
});
gulp.task('default', ['components', 'pages', 'sass']);