-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
157 lines (126 loc) · 3.63 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var uglify = require('gulp-uglify');
var cache = require('gulp-cached');
// var imagemin = require('gulp-imagemin');
// var pngcrush = require('imagemin-pngcrush');
var rename = require('gulp-rename');
var gutil = require('gulp-util');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var path = require('path');
var fs = require('fs-extra');
var Promise = require('bluebird');
var copy = Promise.promisify(fs.copy);
var sassdoc = require('sassdoc');
// Set your Sass project (the one you're generating docs for) path.
// Relative to this Gulpfile.
var projectPath = '../';
// Project path helper.
var project = function () {
var args = Array.prototype.slice.call(arguments);
args.unshift(projectPath);
return path.resolve.apply(path, args);
};
// Theme and project specific paths.
var dirs = {
scss: 'scss',
css: 'assets/css',
img: 'assets/img',
svg: 'assets/svg',
js: 'assets/js',
tpl: 'views',
src: project('sass'),
docs: project('sassdoc')
};
gulp.task('styles', function () {
var browsers = ['last 2 version', '> 1%', 'ie 9'];
var processors = [
require('autoprefixer-core')({ browsers: browsers }),
];
return gulp.src('./scss/**/*.scss')
.pipe(sass())
.pipe(postcss(processors))
.pipe(gulp.dest('assets/css'));
});
gulp.task('browser-sync', function () {
browserSync({
server: {
baseDir: dirs.docs
},
files: [
path.join(dirs.docs, '/*.html'),
path.join(dirs.docs, '/assets/css/**/*.css'),
path.join(dirs.docs, '/assets/js/**/*.js')
]
});
});
// SassDoc compilation.
// See: http://sassdoc.com/customising-the-view/
gulp.task('compile', function () {
var config = {
verbose: true,
dest: dirs.docs,
theme: './',
// Disable cache to enable live-reloading.
// Usefull for some template engines (e.g. Swig).
cache: false,
};
var sdStream = sassdoc(config);
gulp.src(path.join(dirs.src, '**/*.scss'))
.pipe(sdStream);
// Await for the full documentation process.
return sdStream.promise;
});
// Dump JS files from theme into `docs/assets` whenever they get modified.
// Prevent requiring a full `compile`.
gulp.task('dumpJS', function () {
var src = dirs.js;
var dest = path.join(dirs.docs, 'assets/js');
return copy(src, dest).then(function () {
gutil.log(src + ' copied to ' + path.relative(__dirname, dest));
});
});
// Dump CSS files from theme into `docs/assets` whenever they get modified.
// Prevent requiring a full `compile`.
gulp.task('dumpCSS', ['styles'], function () {
var src = dirs.css;
var dest = path.join(dirs.docs, 'assets/css');
return copy(src, dest).then(function () {
gutil.log(src + ' copied to ' + path.relative(__dirname, dest));
});
});
// Development task.
// While working on a theme.
gulp.task('develop', ['compile', 'styles', 'browser-sync'], function () {
gulp.watch('scss/**/*.scss', ['styles', 'dumpCSS']);
gulp.watch('assets/js/**/*.js', ['dumpJS']);
gulp.watch('views/**/*.jade', ['compile']);
});
gulp.task('svgmin', function () {
return gulp.src('assets/svg/*.svg')
.pipe(cache(
imagemin({
svgoPlugins: [{ removeViewBox: false }]
})
))
.pipe(gulp.dest('assets/svg'));
});
gulp.task('imagemin', function () {
return gulp.src('assets/img/{,*/}*.{gif,jpeg,jpg,png}')
.pipe(cache(
imagemin({
progressive: true,
use: [pngcrush()]
})
))
.pipe(gulp.dest('assets/img'));
});
// Pre release/deploy optimisation tasks.
gulp.task('dist', [
'jsmin',
'svgmin',
'imagemin',
]);