-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
221 lines (204 loc) · 6.37 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
'use strict';
//===============================================================/
// =initialization
//===============================================================/
// include plugins
var gulp = require('gulp'),
argv = require('yargs').argv,
concat = require('gulp-concat'),
changed = require('gulp-changed'),
cssBase64 = require('gulp-css-base64'),
cssImgSize = require("gulp-css-image-dimensions"),
del = require('del'),
es6Promise = require('es6-promise'), // required for autoprefixer
gulpif = require('gulp-if'),
gutil = require('gulp-util'), // this is used by 'del'
header = require('gulp-header'),
jeditor = require('gulp-json-editor'),
jshint = require('gulp-jshint'),
minifyCSS = require('gulp-clean-css'),
prefix = require('gulp-autoprefixer'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
sass = require('gulp-sass'),
stylish = require('jshint-stylish-ex'),
uglify = require('gulp-uglify');
// set project details here
var project = {
shortname: "Gridy", // do not add spaces or special chars (used on json)
name: "Gridy",
descr: "A Flexbox Gridy System",
version: "0.9.2",
url: "https://microcipcip.github.io/gridy/",
author: "http://www.jertix.org"
},
projectInfo = '/*!' + ' \n' +
' *Name: <%= pkg.name %>' + ' \n' +
' *Description: <%= pkg.descr %>' + ' \n' +
' *Version: <%= pkg.version %>' + ' \n' +
' *Website: <%= pkg.url %>' + ' \n' +
'*/' + ' \n';
// set variables for local/deployment/live
var isDev = argv.type === 'dev',
isDeployment = argv.type === 'depl',
isLive = argv.type === 'live';
// configure the path of each task
var gridPath = {
src: 'src/',
dist: 'dist/',
distFiles: [ 'dist/**/*' ],
root: ''
},
docsPath = {
src: 'docs/src/',
dist: 'docs/dist/',
distFiles: [ 'docs/dist/**/*' ],
root: ''
},
imgExt = '.{jpeg,jpg,png,gif,svg,cur,ico}',
fontExt = '.{eot,ttf,otf,woff,woff2,svg}',
audioExt = '.{wav,mp3}',
path = {
src: {
gridscss: gridPath.src + '',
gridscssFiles: gridPath.src + '**/*.scss',
gridcss: gridPath.src + '',
gridcssFiles: gridPath.src + '**/*.css',
scss: docsPath.src + 'scss/',
scssFiles: docsPath.src + 'scss/**/*.scss',
css: docsPath.src + 'css/',
cssFiles: docsPath.src + 'css/**/*.css',
font: docsPath.src + 'fonts/',
fontFiles: docsPath.src + 'fonts/**/*' + fontExt,
js: docsPath.src + 'js/',
jsFiles: docsPath.src + 'js/**/*.js',
img: docsPath.src + 'img/',
imgFiles: docsPath.src + 'img/**/*' + imgExt
},
dist: {
gridscss: gridPath.dist + '',
gridscssFiles: gridPath.dist + '**/*.scss',
gridcss: gridPath.dist + '',
gridcssFiles: gridPath.dist + '**/*.css',
css: docsPath.dist + 'css/',
cssFiles: docsPath.dist + 'css/**/*.css',
font: docsPath.dist + 'fonts/',
fontFiles: docsPath.dist + 'fonts/**/*' + fontExt,
js: docsPath.dist + 'js/',
jsFiles: docsPath.dist + 'js/**/*.js',
img: docsPath.dist + 'img/',
imgFiles: docsPath.dist + 'img/**/*' + imgExt
},
imgPath: '../img',
json: 'package.json'
};
//===============================================================/
// =tasks
//===============================================================/
// clean
gulp.task('clean', function (cb) {
del(gridPath.distFiles, cb);
del(docsPath.distFiles, cb);
});
// sass and css grid
gulp.task('cssGrid', function () {
gulp.src(path.src.gridscssFiles)
.pipe(plumber())
.pipe(sass({
sourceComments: null,
precision: 7
}))
.pipe(prefix({
browsers: [ 'last 2 versions', '> 1%' ],
cascade: false
}))
.pipe(header(projectInfo, { pkg: project }))
.pipe(gulp.dest('dist'))
.pipe(minifyCSS())
.pipe(rename('gridy.min.css'))
.pipe(gulp.dest(gridPath.dist));
});
// sass and css
gulp.task('css', function () {
gulp.src(path.src.scssFiles)
.pipe(plumber())
// compile sass, combine media queries, autoprefix and minify
.pipe(sass({ sourceComments: null }))
.pipe(prefix({
browsers: [ 'last 2 versions', '> 1%' ],
cascade: false
}))
.pipe(cssImgSize(path.imgPath))
.pipe(gulpif(!isDev, cssBase64({
baseDir: path.imgPath,
maxWeightResource: 10000,
extensionsAllowed: [ '.gif', '.jpg', '.png' ]
})))
.pipe(gulpif(!isDev, minifyCSS()))
.pipe(header(projectInfo, { pkg: project }))
.pipe(gulp.dest(path.dist.css));
});
// scripts
gulp.task('js', function () {
// detect errors in custom.js
gulp.src(path.src.js + 'custom.js')
.pipe(plumber())
.pipe(gulpif(isDev, jshint()))
.pipe(gulpif(isDev, jshint.reporter(stylish)))
// concatenate and minify files
gulp.src([
path.src.js + 'plugins/*.js',
path.src.js + 'custom.js'
])
.pipe(plumber())
.pipe(changed(path.dist.js))
.pipe(concat('./scripts.js'))
.pipe(gulpif(!isDev, uglify()))
.pipe(header(projectInfo, { pkg: project }))
.pipe(gulp.dest(path.dist.js));
// move vendors and polyfill files in the dist folder
gulp.src([
path.src.js + 'vendor/*.js',
path.src.js + 'polyfill/*.js'
])
.pipe(plumber())
.pipe(changed(path.dist.js))
.pipe(gulp.dest(path.dist.js));
});
// fonts
gulp.task('font', function () {
gulp.src(path.src.fontFiles)
.pipe(plumber())
.pipe(changed(path.dist.font))
.pipe(gulp.dest(path.dist.font));
});
// imgs
gulp.task('img', function () {
gulp.src([ path.src.imgFiles, '!' + path.src.img + 'test/**/*' + imgExt ]) // exclude test path
.pipe(plumber())
.pipe(changed(path.dist.img))
.pipe(gulp.dest(path.dist.img));
});
// json package editor
gulp.task('json', function () {
gulp.src(path.json)
.pipe(plumber())
.pipe(jeditor({
'version': project.version, // make sure this is a supported npm version
'name': project.shortname,
'description': project.descr,
'author': project.author
}))
.pipe(gulp.dest('./'));
});
// watch files
gulp.task('watch', function () {
gulp.watch(path.src.gridscssFiles, [ 'cssGrid' ]);
gulp.watch(path.src.scssFiles, [ 'css' ]);
gulp.watch(path.src.jsFiles, [ 'js' ]);
gulp.watch(path.src.fontFiles, [ 'font' ]);
gulp.watch(path.src.imgFiles, [ 'img' ]);
});
// default task
gulp.task('default', [ 'cssGrid', 'css', 'js', 'font', 'img', 'json', 'watch' ]);