-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
163 lines (143 loc) · 4.44 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
158
159
160
161
162
163
'use strict'
var
// defaults
consoleLog = false, // set true for metalsmith file and meta content logging
devBuild = ((process.env.NODE_ENV || '').trim().toLowerCase() !== 'production'),
pkg = require('./package.json'),
// main directories
dir = {
base: __dirname + '/',
src: 'src/',
dest: 'build/',
vf: 'node_modules/vanilla-framework/'
},
// template config
templateConfig = {
engine: 'handlebars',
directory: 'src/templates/',
partials: 'src/partials/',
default: 'default.hbt'
},
siteMeta = {
devBuild: devBuild,
version: pkg.version,
name: 'Vanilla Framework',
desc: 'A living Pattern Library showcasing Vanilla Framework',
author: 'Canonical Web Team',
contact: 'https://mobile.twitter.com/vanillaframewrk'
},
// modules
gulp = require('gulp'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
gutil = require('gulp-util'),
scsslint = require('gulp-scss-lint'),
cssnano = require('gulp-cssnano'),
util = require('util'),
concat = require('gulp-concat'),
browserSync = require('browser-sync').create(),
reload = browserSync.reload,
ghPages = require('gulp-gh-pages'),
plumber = require('gulp-plumber'),
// Metalmsith - pattern library generation
metalsmith = require('metalsmith'),
markdown = require('metalsmith-markdown'),
layouts = require('metalsmith-layouts'),
collections = require('metalsmith-collections'),
permalinks = require('metalsmith-permalinks');
/* Gulp instructions start here */
gulp.task('help', function() {
console.log('sass-build - Generate the min and unminified css from sass');
console.log('develop - Generate Pattern Library and watch assets');
console.log('watch - Watch sass files and generate unminified css');
console.log('test - Lints Sass');
console.log('deploy - Deploy sites to Github pages');
});
// Static server
gulp.task('browser-sync', function() {
var files = [
"build/**/*.css",
"build/**/*.html"
];
browserSync.init(
files,
{
server: {
baseDir: "./build",
noOpen: true
}
});
});
/* Import docs from Vanilla Framework dep */
gulp.task('import-docs', function() {
gulp.src([dir.vf + 'docs/**/*.md']).pipe(gulp.dest('src/docs'));
});
/* Generate Pattern Library with Metalsmith */
gulp.task('pattern-library', ['import-docs'], function() {
metalsmith(dir.base)
.clean(!devBuild) // clean folder before a production build
.source(dir.src) // source folder (src/)
.destination(dir.dest) // build folder (build/)
.use(collections({
pages: {
reverse: true
}
}))
.use(markdown()) // convert markdown to html
.use(permalinks({
pattern: ':collection/:title'
}))
.use(layouts(templateConfig)) // layout templating
.build(function (err) { // build or error log
if(err) console.log(err)
})
});
/* Helper functions */
function throwSassError(sassError) {
throw new gutil.PluginError({
plugin: 'sass',
message: util.format(
"Sass error: '%s' on line %s of %s",
sassError.message,
sassError.line,
sassError.file
)
});
}
gulp.task('sasslint', function() {
var path = (gutil.env.file)? gutil.env.file : '**/*.scss';
return gulp.src('scss/' + path)
.pipe(scsslint())
.pipe(scsslint.failReporter());
});
gulp.task('sass-build', function() {
return gulp.src('scss/**/*.scss')
.pipe(sass({
includePaths: ['node_modules']
}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
.pipe(gulp.dest('build/css/'));
});
gulp.task('sass-develop', function() {
return gulp.src(['scss/**/*.scss'])
.pipe(plumber())
.pipe(sass({
includePaths: ['node_modules']
}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
.pipe(gulp.dest('build/css/'))
.pipe(browserSync.stream());
});
gulp.task('deploy', ['build'], function() {
return gulp.src('./build/**/*')
.pipe(ghPages());
});
gulp.task('watch', function() {
gulp.watch(['scss/**/*.scss', dir.vf + 'scss/**/*.scss'], ['sass-develop']);
gulp.watch([dir.vf + 'docs/**/*.md', '*.md', 'partials/**/*.hbt', 'templates/**/*.hbt', 'pages/**/*.md'], ['pattern-library']);
});
gulp.task('develop', ['pattern-library', 'sass-develop', 'watch', 'browser-sync']);
gulp.task('test', ['sasslint']);
gulp.task('build', ['pattern-library', 'sass-build']);
gulp.task('default', ['help']);