-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
86 lines (76 loc) · 2.61 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
var gulp = require('gulp');
var shell = require('gulp-shell');
var less = require('gulp-less');
var autoprefixer = require('gulp-autoprefixer');
var minifyCss = require('gulp-minify-css');
var wrap = require("gulp-wrap");
var connect = require('gulp-connect');
// Runs the "documentjs" build command
gulp.task('styleguide', shell.task([
'./node_modules/.bin/documentjs'
]));
// This is used when editing template styles.
// It has to completely rebuild the style guide, note that this takes about 5s.
gulp.task('force-styleguide', shell.task([
'./node_modules/.bin/documentjs -f'
])
);
// Task that reloads the browser after force-styleguide
gulp.task('reload-styleguide', ['force-styleguide'], function (event) {
gulp.src('./styleguide/*')
.pipe(connect.reload());
});
// Compiles, autoprefixes & minifies the less files
gulp.task('less', function () {
return gulp
.src(['./less/styles.less'])
.pipe(less())
.pipe(autoprefixer())
.pipe(minifyCss())
.pipe(gulp.dest('./dist'));
});
// Copies the compiled styles to the style guide folder
gulp.task('copy-styles', ['less'], function() {
gulp.src('./dist/styles.css')
.pipe(gulp.dest('./styleguide/patterns'));
});
// Wraps each demo with _demo-container.html
// and copies them to the styleguide
gulp.task('copy-demos', function () {
gulp.src([
'./less/demos/**/*.html',
'!./less/demos/_demo-container.html'
])
.pipe(wrap({ src: './less/demos/_demo-container.html' }))
.pipe(gulp.dest('./styleguide/demos'));
});
// Copies the fonts folder
gulp.task('copy-fonts', function() {
return gulp.src(['./fonts/**/*'], {
base: 'src'
}).pipe(gulp.dest('./styleguide/fonts'));
});
// Runs a server at http://localhost:4200/
gulp.task('server', function () {
connect.server({
root: './styleguide',
port: process.env.PORT || '4200',
livereload: true
});
});
// Watches files and auto-refreshes when changes are saved
gulp.task('watch', function () {
gulp.watch(['./less/**/*'], function (event) {
// timeout gives documentjs a chance to finish compiling first
setTimeout(function() {
return gulp
.src(event.path)
.pipe(connect.reload());
}, 400);
});
gulp.watch(['./less/**/*.less'], ['styleguide', 'less', 'copy-styles']);
gulp.watch(['./less/demos/**/*.html'], ['copy-demos']);
// watches style guide theme files and runs a whole rebuild after saves
gulp.watch(['./style-guide-theme/**/*'], ['reload-styleguide', 'less', 'copy-styles', 'copy-demos', 'copy-fonts']);
});
gulp.task('dev', ['force-styleguide', 'less', 'copy-styles', 'copy-demos', 'copy-fonts', 'server', 'watch']);