forked from gilbarbara/logos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
123 lines (105 loc) · 3.18 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
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
browserSync = require('browser-sync'),
del = require('del'),
fs = require('fs'),
runSequence = require('run-sequence');
gulp.task('styles', function () {
return gulp.src('assets/styles/main.scss')
.pipe($.plumber())
.pipe($.sass.sync({
precision: 4
}).on('error', $.sass.logError))
.pipe($.plumber.stop())
.pipe($.autoprefixer({
browsers: ['last 4 versions']
}))
.pipe(gulp.dest('.tmp'));
});
gulp.task('templates', function () {
var json = JSON.parse(fs.readFileSync('./assets/logos.json')),
templateData = {
items: []
},
meta = [];
json.items.forEach(function (d) {
meta.push(d.name);
d.files.forEach(function (f) {
templateData.items.push({
name: d.name,
shortname: d.shortname,
url: d.url,
image: f
});
});
});
templateData.meta = meta.join(', ');
templateData.count = json.items.length;
return gulp.src('assets/templates/index.handlebars')
.pipe($.compileHandlebars(templateData, {
batch: ['./assets/templates']
}))
.pipe($.rename('index.html'))
.pipe(gulp.dest('.tmp'));
});
gulp.task('readme', function () {
var json = JSON.parse(fs.readFileSync('./assets/logos.json'));
return gulp.src('assets/templates/README.handlebars')
.pipe($.compileHandlebars(json.items, {
batch: ['./assets/templates']
}))
.pipe($.rename('README.md'))
.pipe(gulp.dest('./'));
});
gulp.task('copy', function () {
return gulp.src('assets/media/**/*')
.pipe(gulp.dest('.tmp'));
});
gulp.task('bundle', function () {
var assets = $.useref.assets();
return gulp.src('.tmp/*.html')
.pipe(assets)
.pipe($.if('*.css', $.cssmin()))
.pipe($.if('*.js', $.uglify()))
.pipe(assets.restore())
.pipe($.useref())
.pipe($.replace('../logos/', ''))
.pipe(gulp.dest('.tmp'));
});
gulp.task('clean', function (cb) {
del(['.tmp/*'], cb);
});
gulp.task('serve', ['clean', 'templates', 'copy', 'styles'], function () {
browserSync({
notify: false,
logPrefix: 'logos',
files: ['.tmp/*.html', '.tmp/*.css', 'logos', 'assets/scripts/*.js'],
server: {
baseDir: ['./', '.tmp', 'assets']
}
});
gulp.watch('assets/styles/**/*.scss', function (e) {
if (e.type === 'changed') {
gulp.start('styles');
}
});
gulp.watch(['assets/templates/**/*', 'assets/logos.json'], ['templates']);
});
gulp.task('build', function (cb) {
runSequence('readme', 'templates', 'bundle', 'styles', cb);
});
gulp.task('deploy', ['build'], function () {
return gulp.src([
'logos/*.svg',
'.tmp/*.html',
'.tmp/main.css',
'.tmp/main.js',
'assets/media/**/*',
'assets/CNAME',
'*.md'
])
.pipe($.ghPages({
force: true
}));
});
gulp.task('default', ['serve']);