-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgulpfile.js
121 lines (101 loc) · 3.08 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
'use strict';
const gulp = require('gulp');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const sassLint = require('gulp-sass-lint');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const nano = require('gulp-cssnano');
const del = require('del');
const browserSync = require('browser-sync');
const spawn = require('child_process').spawn;
const path = require('path');
const transform = require('gulp-transform');
const rev = require('gulp-rev');
const revReplace = require('gulp-rev-replace');
let metalsmithPath = path.join('node_modules', '.bin', 'metalsmith');
if(process.platform.indexOf('win') === 0){
metalsmithPath += '.cmd';
}
gulp.task('clean', () => {
return del([
'dist',
'_gh_pages',
'npm-debug.log'
]);
});
gulp.task('lint', () => {
return gulp.src([
'./scss/**/*.scss',
'!./scss/_normalize.scss',
'!./scss/_icons.scss',
'./docs/scss/**/*.scss',
'!./docs/scss/_syntax.scss'
])
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError());
});
gulp.task('sass', () => {
gulp.src('./scss/elementsNoPlain.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer]))
.pipe(gulp.dest('./dist/css'))
.pipe(browserSync.reload({ stream: true }))
.pipe(rename({ extname: '.min.css' }))
.pipe(nano())
.pipe(gulp.dest('./dist/css'));
return gulp.src('./scss/elements.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer]))
.pipe(gulp.dest('./dist/css'))
.pipe(browserSync.reload({ stream: true }))
.pipe(rename({ extname: '.min.css' }))
.pipe(nano())
.pipe(gulp.dest('./dist/css'));
});
gulp.task('assets', ['sass'], () => {
gulp.src('./assets/icons/*')
.pipe(gulp.dest('./dist/icons'));
// TODO: Fix icon static asset fingerprinting for cache-busting
return gulp.src(['./assets/**', '!./assets/icons/*'])
.pipe(rev())
.pipe(gulp.dest('./dist'))
.pipe(rev.manifest())
.pipe(gulp.dest('./dist/temp'));
});
gulp.task('build', ['sass', 'assets'], () => {
const revManifest = gulp.src('./dist/temp/rev-manifest.json');
gulp.src('./dist/css/*.css')
.pipe(revReplace({ manifest: revManifest }))
.pipe(gulp.dest('./dist/css'));
return del(['dist/temp']);
});
gulp.task('build-docs', ['build'], (done) => {
browserSync.notify('Running: <kbd>$ metalsmith</kbd>');
gulp.src('./docs/scss/docs.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer]))
.pipe(gulp.dest('./_gh_pages/css'));
gulp.src('./assets/**')
.pipe(gulp.dest('./_gh_pages'));
spawn(metalsmithPath, { stdio: 'inherit' })
.on('close', done);
});
gulp.task('rebuild-docs', ['build-docs'], () => browserSync.reload());
gulp.task('browser-sync', ['build-docs'], () => {
browserSync({
server: {
baseDir: '_gh_pages'
}
});
});
gulp.task('watch', () => {
gulp.watch([
'./scss/**/*.scss',
'./docs/**/*.html',
'./docs/**/*.md',
'./docs/scss/**/*.scss'
], ['rebuild-docs']);
});
gulp.task('default', ['browser-sync', 'watch']);