forked from Awesome-Support/importer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·210 lines (180 loc) · 4.82 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
// General Requirements
const gulp = require('gulp');
const gutil = require('gulp-util');
const notify = require('gulp-notify');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const sourcemaps = require('gulp-sourcemaps');
// Style Dependencies
const autoprefixer = require('autoprefixer');
const cssnano = require('gulp-cssnano');
const mqpacker = require('css-mqpacker');
const postcss = require( 'gulp-postcss' );
const sass = require('gulp-sass');
const sassLint = require('gulp-sass-lint');
// Script Dependencies
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const eslint = require('gulp-eslint');
const uglify = require('gulp-uglify');
// Set src paths.
const paths = {
'css': ['assets/styles/*.scss'],
'scripts': [
'assets/scripts/jquery.admin.js',
'assets/scripts/jquery.fields.js',
'assets/scripts/jquery.datepicker.js',
'assets/scripts/jquery.helpscout.js'
]
};
const destFolder = 'assets/dist/';
/**
* Handle errors and alert the user.
*/
function handleErrors() {
const 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);
gutil.beep(); // Beep 'sosumi' again.
// Prevent the 'watch' task from stopping.
this.emit('end');
}
/****************************
* Style Tasks
***************************/
/**
* 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
* https://www.npmjs.com/package/css-mqpacker
*/
gulp.task('postcss', () =>
gulp.src(paths.css)
// handle errors
.pipe(plumber({'errorHandler': handleErrors}))
// Init the sourcemaps
.pipe(sourcemaps.init())
// Let's compile the Sass
.pipe(sass({
// 'includePaths': [].concat(bourbon, neat),
'errLogToConsole': true,
'outputStyle': 'expanded' // Options: nested, expanded, compact, compressed
}))
// Autoprefix and package up the media queries
// moving them to the bottom
.pipe(postcss([
autoprefixer({
'browsers': ['last 2 version']
}),
mqpacker({
'sort': true
})
]))
// Create our sourcemap
.pipe(sourcemaps.write())
// Move it off to the destination and sync
.pipe(gulp.dest(destFolder))
);
/**
* Minify and optimize importer.css.
*
* https://www.npmjs.com/package/gulp-cssnano
*/
gulp.task('cssnano', ['postcss'], () =>
gulp.src(destFolder + 'importer.css')
// handle errors
.pipe(plumber({'errorHandler': handleErrors}))
.pipe(cssnano({
'safe': true // Use safe optimizations.
}))
// rename to our .min version
.pipe(rename('importer.min.css'))
// Move it off to the destination and sync
.pipe(gulp.dest(destFolder))
);
/**
* Sass linting.
*
* https://www.npmjs.com/package/sass-lint
*/
gulp.task('sass:lint', () =>
gulp.src([
'src/sass/**/*.scss',
])
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError())
);
/****************************
* Scripts Tasks
***************************/
/**
* Concatenate and transform JavaScript.
*
* https://www.npmjs.com/package/gulp-concat
* https://github.com/babel/gulp-babel
*/
gulp.task('concat', () =>
gulp.src(paths.scripts)
// Deal with errors.
.pipe(plumber(
{'errorHandler': handleErrors}
))
// Convert ES6+ to ES2015.
.pipe(babel({
presets: ['ES2015']
}))
// Concatenate partials into a single script.
.pipe(concat('importer.js'))
// Save the file.
.pipe(gulp.dest(destFolder))
);
/**
* Minify compiled JavaScript.
*
* https://www.npmjs.com/package/gulp-uglify
*/
gulp.task('uglify', ['concat'], () =>
gulp.src(destFolder + 'importer.js')
.pipe(plumber({'errorHandler': handleErrors}))
.pipe(rename({'suffix': '.min'}))
// Convert ES6+ to ES2015.
.pipe(babel({
presets: ['ES2015']
}))
.pipe(uglify({
'mangle': false
}))
.pipe(gulp.dest(destFolder))
);
/**
* JavaScript linting.
*
* https://www.npmjs.com/package/gulp-eslint
*/
gulp.task('js:lint', () =>
gulp.src(['scripts/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
/**
* Process tasks.
*/
gulp.task('watch', function() {
// Run tasks when files change.
gulp.watch(paths.css, ['styles']);
gulp.watch(paths.scripts, ['scripts']);
});
/**
* Create individual tasks.
*/
gulp.task('scripts', ['uglify']);
gulp.task('styles', ['cssnano']);
gulp.task('lint', ['js:lint']);
gulp.task('default', ['styles', 'scripts']);