forked from WebDevStudios/custom-post-type-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
141 lines (124 loc) · 3.34 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
// Require dependencies.
var autoprefixer = require('autoprefixer');
var concat = require('gulp-concat');
var cssnano = require('gulp-cssnano');
var del = require('del');
var gulp = require('gulp');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
var postcss = require('gulp-postcss');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var sort = require('gulp-sort');
var uglify = require('gulp-uglify');
var shell = require('gulp-shell');
var log = require('fancy-log');
//set assets paths.
var paths = {
css: ['./*.css', '!*.min.css'],
php: ['./*.php', './**/*.php'],
sass: 'css/*.scss',
scripts: 'js/*.js',
};
/**
* Handle errors and alert the user.
*/
function handleErrors () {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: 'Task Failed [<%= error.message %>',
message: 'See console.',
sound: 'Sosumi' // See: https://github.com/mikaelbr/node-notifier#all-notification-options-with-their-defaults
}).apply(this, args);
// Prevent the 'watch' task from stopping
this.emit('end');
}
/**
* Delete cptui.css and cptui.min.css before we minify and optimize
*/
gulp.task('clean:styles', function() {
return del(['css/cptui.css', 'css/cptui.min.css'])
});
/**
* Run our documentation generation.
*/
gulp.task('docsgen', shell.task([
'apigen generate',
'php apigen/hook-docs.php',
]));
/**
* Compile Sass and run stylesheet through PostCSS.
*
* https://www.npmjs.com/package/gulp-sass
* https://www.npmjs.com/package/gulp-postcss
* https://www.npmjs.com/package/gulp-autoprefixer
*/
gulp.task('postcss', ['clean:styles'], function() {
return gulp.src('css/*.scss', paths.css)
.pipe(plumber({ errorHandler: handleErrors }))
// Compile Sass using LibSass.
.pipe(sass({
errLogToConsole: true,
outputStyle: 'expanded' // Options: nested, expanded, compact, compressed
}))
.pipe(postcss([
autoprefixer({
browsers: ['last 2 version']
}),
]))
// Create style.css.
.pipe(gulp.dest('./css'));
});
/**
* Minify and optimize style.css.
*
* https://www.npmjs.com/package/gulp-cssnano
*/
gulp.task('cssnano', ['postcss'], function() {
return gulp.src('./css/cptui.css')
.pipe(plumber({ errorHandler: handleErrors }))
.pipe(cssnano({
safe: true // Use safe optimizations
}))
.pipe(rename('cptui.min.css'))
.pipe(gulp.dest('./css'))
});
/**
* Delete scripts before we concat and minify
*/
gulp.task('clean:scripts', function() {
return del(['js/cptui.min.js', 'js/dashicons-picker.min.js']);
});
/**
* Concatenate and minify javascripts.
*
* https://www.npmjs.com/package/gulp-uglify
* https://www.npmjs.com/package/gulp-concat
*/
gulp.task('uglify', ['clean:scripts'], function() {
return gulp.src(paths.scripts)
.pipe(plumber({ errorHandler: handleErrors }))
.pipe(uglify({
mangle: false
}))
.on('error', function (err) {log(err.toString());})
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('js'))
});
/**
* Process tasks and reload browsers on file changes.
*
* https://www.npmjs.com/package/browser-sync
*/
gulp.task('watch', function () {
// Run tasks when files change.
gulp.watch(paths.sass, ['styles']);
gulp.watch(paths.scripts, ['scripts']);
});
/**
* Create indivdual tasks.
*/
gulp.task('scripts', ['uglify']);
gulp.task('styles', ['cssnano']);
gulp.task('default', ['styles', 'scripts']);
gulp.task('release', ['styles', 'scripts', 'docsgen']);