forked from foundation/foundation-emails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
231 lines (204 loc) · 6.97 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
var $ = require('gulp-load-plugins')();
var gulp = require('gulp');
var sequence = require('run-sequence');
var panini = require('panini');
var supercollider = require('supercollider');
var rimraf = require('rimraf');
var browser = require('browser-sync');
var foundationDocs = require('foundation-docs');
var octophant = require('octophant');
var inky = require('inky');
var siphon = require('siphon-media-query');
var lazypipe = require('lazypipe');
var fs = require('fs');
var yargs = require('yargs');
// Configuration for the documentation generator
supercollider
.config({
template: foundationDocs.componentTemplate,
marked: foundationDocs.marked,
handlebars: foundationDocs.handlebars,
keepFm: true,
quiet: false,
pageRoot: 'docs/pages',
data: {
repoName: 'foundation-emails',
editBranch: 'develop'
}
})
.searchConfig({
sort: ['page', 'component', 'sass variable', 'sass mixin', 'sass function', 'js class', 'js function', 'js plugin option', 'js event'],
pageTypes: {
library: function(item) {
return !!(item.library);
}
}
})
.adapter('sass')
.adapter('js');
// Cleans the build folder
gulp.task('clean', function(cb) {
rimraf('_build', cb);
});
// Copies static documentation assets
gulp.task('copy', function() {
return gulp.src(['docs/assets/**/*', '!docs/assets/scss/**/*', '!docs/assets/js/**/*'])
.pipe(gulp.dest('_build/assets'));
});
// Copies inky-browser
gulp.task('copy-inky', function() {
return gulp.src(['node_modules/inky/dist/inky-browser.js'])
.pipe(gulp.dest('_build/assets/js'));
});
// Builds documentation pages
gulp.task('html', function() {
return gulp.src('docs/pages/**/*')
.pipe($.cached('docs'))
.pipe(supercollider.init())
.pipe(panini({
root: 'docs/pages/',
layouts: 'docs/layouts/',
partials: 'docs/partials/',
helpers: foundationDocs.handlebarsHelpers
}))
.pipe(gulp.dest('_build'))
.on('finish', function() {
supercollider.buildSearch('_build/data/search.json', function() {});
});
});
gulp.task('sass', ['sass:docs', 'sass:foundation']);
// Compiles documentation-specific CSS
gulp.task('sass:docs', function() {
return gulp.src('docs/assets/scss/docs.scss')
.pipe($.sass({ includePaths: [process.cwd()] }).on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: ['last 2 versions', 'ie >= 9']
}))
.pipe(gulp.dest('_build/assets/css'));
});
// Compiles Foundation-specific CSS
gulp.task('sass:foundation', function() {
return gulp.src('scss/foundation-emails.scss')
.pipe($.sass().on('error', $.sass.logError))
.pipe(gulp.dest('_build/assets/css'));
});
// Compiles documentation JavaScript
gulp.task('javascript:docs', function() {
return gulp.src(['node_modules/foundation-docs/js/*.js', 'docs/assets/js/**/*.js'])
.pipe($.concat('docs.js'))
.pipe(gulp.dest('_build/assets/js'));
});
// Generates a Sass settings file from the current codebase
gulp.task('settings', function() {
octophant('scss/**/*.scss', {
title: 'Foundation for Emails Settings',
output: 'scss/settings/_settings.scss',
sort: ['global', 'grid', 'block-grid', 'type']
});
});
// Lints the Sass codebase
gulp.task('lint', function() {
return gulp.src('scss/**/*.scss')
.pipe($.sassLint())
.pipe($.sassLint.format())
.pipe($.sassLint.failOnError());
});
// Creates a BrowserSync server
gulp.task('server', ['build'], function() {
browser.init({
server: './_build',
port: yargs.argv.port || 3001
});
});
// Uploads the documentation to the live server
gulp.task('deploy:docs', ['build'], function() {
return gulp.src('./_build/**')
.pipe($.prompt.confirm('Make sure everything looks right before you deploy.'))
.pipe($.rsync({
root: './_build',
hostname: 'deployer@72.32.134.77',
destination: '/home/deployer/sites/foundation-emails-march16'
}));
});
// Runs the entire build process
gulp.task('build', function(cb) {
sequence('clean', ['copy', 'copy-inky', 'html', 'sass', 'javascript:docs'], cb);
});
// Runs the build process, spins up a server, and watches for file changes
gulp.task('default', ['server'], function() {
gulp.watch('docs/**/*', ['html', browser.reload]);
gulp.watch(['docs/assets/scss/**/*', 'node_modules/foundation-docs/scss/**/*'], ['sass:docs', browser.reload]);
gulp.watch('scss/**/*.scss', ['sass:foundation', browser.reload]);
});
gulp.task('test', ['sass', 'test:compile'], function() {
browser.init({ server: 'test/visual/_build', directory: true });
gulp.watch('scss/**/*.scss', ['sass:foundation', browser.reload]);
gulp.watch('test/visual/pages/*.html', ['test:compile', browser.reload]);
});
gulp.task('test:compile', function() {
gulp.src('test/visual/pages/*.html')
.pipe($.wrap({ src: 'test/visual/_template.html' }))
.pipe(inky())
.pipe(inliner('_build/assets/css/foundation-emails.css'))
.pipe(gulp.dest('test/visual/_build'));
});
gulp.task('templates', function() {
return gulp.src('templates/*.html')
.pipe($.wrap({ src: 'test/visual/_template.html' }))
.pipe(inky())
.pipe($.prettify({ indent_size: 2 }))
.pipe(gulp.dest('.templates'))
.pipe($.zip('all-templates.zip'))
.pipe(gulp.dest('.templates'));
});
gulp.task('download:build:index', function() {
return gulp.src('test/visual/_template.html', { base: 'test/visual' })
.pipe($.injectString.replace('<%= contents %>', ''))
.pipe($.injectString.replace('../assets/', ''))
.pipe($.rename('index.html'))
.pipe(gulp.dest('.download'));
});
gulp.task('download:build:templates', ['templates'], function() {
return gulp.src('.templates/*.html')
.pipe(gulp.dest('.download/templates'));
});
gulp.task('download:build:css', ['sass:foundation'], function() {
return gulp.src('_build/assets/css/foundation-emails.css')
.pipe(gulp.dest('.download/css'));
})
gulp.task('download:build', ['download:build:index', 'download:build:templates', 'download:build:css'], function() {
return gulp.src('.download/**/*')
.pipe($.zip('foundation-emails.zip'))
.pipe(gulp.dest('.'));
});
gulp.task('download', ['download:build'], function(done) {
return gulp.src('foundation-emails.zip')
.pipe($.rsync({
hostname: 'deployer@72.32.134.77',
destination: '/home/deployer/sites/foundation-sites-6-marketing/downloads/'
}));
});
gulp.task('dist', ['sass:foundation'], function() {
return gulp.src('_build/assets/css/foundation-emails.css')
.pipe(gulp.dest('dist'))
.pipe($.cssnano())
.pipe($.rename('foundation-emails.min.css'))
.pipe(gulp.dest('dist'));
});
function inliner(css) {
var css = fs.readFileSync(css).toString();
var mqCss = siphon(css);
var pipe = lazypipe()
.pipe($.inlineCss, {
applyStyleTags: false,
removeStyleTags: false,
removeLinkTags: false
})
.pipe($.injectString.replace, '<!-- <style> -->', '<style>'+mqCss+'</style>')
.pipe($.htmlmin, {
collapseWhitespace: false,
minifyCSS: false,
maxLineLength: 800
});
return pipe();
}