-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
117 lines (99 loc) · 2.51 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
/*!
* Gulpfile Setup
* author: Raúl Hernández <[email protected]>
*/
'use strict';
// Include Gulp and other build lautomation tools and utilities.
// See: https://github.com/gulpjs/gulp/blob/master/docs/API.md
/**
Settings
*/
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
runSequence = require('run-sequence'),
SRC = './src',
DEST = './dist',
vars = {
name: require('./package.json').name,
authors: require('./package.json').authors,
version: require('./package.json').version,
homepage: require('./package.json').homepage,
description: require('./package.json').description,
colors: require(SRC + '/data/colors.json'),
prefix: 'mbc',
date: new Date()
},
template = {
name: vars.name,
version: vars.version,
colors: vars.colors,
prefix: vars.prefix,
comments: ['/*!',
' ' + vars.name + ' ' + vars.version,
' ' + vars.homepage,
' Licensed under the MIT license - http://opensource.org/licenses/MIT',
' Copyright (c) ' + vars.date.getFullYear() + ' Raúl Hernández',
'*/'].join('\n')
};
var parseJson = function(obj, prefix) {
if (typeof obj !== 'object' || !obj) {
return false;
}
var keys = Object.keys(obj),
keysLen = keys.length,
prefix = prefix || '';
for (var i=0; i<keysLen ;i++) {
obj[prefix+keys[i]] = obj[keys[i]];
if(typeof obj[keys[i]] === 'object') {
parseJson(obj[prefix+keys[i]],prefix);
}
delete obj[keys[i]];
}
return JSON.stringify(obj, null, '\t');
};
/**
Tasks
*/
// Render templates
gulp.task('render', function () {
return gulp.src(SRC + '/templates/**/*')
.pipe($.data(function() {
return template;
}))
.pipe($.template())
.pipe(gulp.dest(DEST));
});
// Minify CSS
gulp.task('minifyCss', function () {
return gulp.src(DEST + '/css/index.css')
.pipe($.cssnano())
.pipe($.rename('index.min.css'))
.pipe(gulp.dest(DEST + '/css'));
});
// Render JSON
gulp.task('json', function () {
$.file('index.json', parseJson(template.colors))
.pipe(gulp.dest(DEST + '/json'));
});
// Render List
gulp.task('list', function () {
return gulp.src(SRC + '/list.md')
.pipe($.data(function() {
return template;
}))
.pipe($.template())
.pipe(gulp.dest('./'));
});
// Test
gulp.task('test', function () {
return gulp.src(SRC + '/test/index.html')
.pipe($.data(function() {
return template;
}))
.pipe($.template())
.pipe(gulp.dest('./test'));
});
// Default task
gulp.task('default', function () {
runSequence('render', 'minifyCss', 'json', 'list', 'test');
});