-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
72 lines (62 loc) · 2.06 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
var gulp = require('gulp');
// command-line 'gulp build' to build /src files to /css
var insert = require('gulp-insert');
var cleanCSS = require('gulp-clean-css');
var rename = require('gulp-rename');
var postcss = require('gulp-postcss');
// postcss plugins
var cssimport = require('postcss-import');
var rgbaTohex = require('postcss-rgba-hex');
var customProperties = require('postcss-custom-properties');
var colorFunction = require('postcss-color-function');
var perfectionist = require('postcss-perfectionist');
function buildNumber() {
// lazy build version number using YYMMDD date
var now = new Date();
var y = now.getFullYear().toString().substr(-2);
var m = now.getMonth() + 1;
var d = now.getDate();
var mm = m < 10 ? '0' + m : m;
var dd = d < 10 ? '0' + d : d;
return '' + y + mm + dd;
}
var pckg = require('./package.json');
var version = pckg.version;
// edit header here
var header = `/*! commoncolors.css v.${version} Build #${buildNumber()} */ \n`;
function compile() {
// process src files to /css
var plugins = [
cssimport(),
customProperties({preserve:false}),
colorFunction(),
rgbaTohex({silent:true}),
perfectionist({format:'compact'})
];
return gulp.src(['./src/[^_]*.css','!./src/commoncolors--vars.css'])
.pipe(insert.prepend(header))
.pipe(postcss(plugins))
.pipe(gulp.dest('./css'));
}
function compile_vars() {
// process colors, preserve css vars
var plugins = [
customProperties({preserve:true}),
colorFunction(),
rgbaTohex({silent:true}),
perfectionist()
];
return gulp.src('src/commoncolors--vars.css')
.pipe(insert.prepend(header))
.pipe(postcss(plugins))
.pipe(gulp.dest('./css'));
}
function minify() {
// minified files.
return gulp.src(['./css/*.css','!./css/commoncolors--vars.css'])
.pipe(cleanCSS({level: 1}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('css/min/'));
}
var build = gulp.series(compile, gulp.parallel(minify, compile_vars));
gulp.task('build', build);