forked from lexkrstn/jquery-sked-tape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
108 lines (98 loc) · 3.24 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
const gulp = require('gulp'),
cleanDest = require('gulp-clean-dest'),
sass = require('gulp-sass')(require('sass')),
sourcemaps = require('gulp-sourcemaps'),
connect = require('gulp-connect'),
autoprefixer = require('gulp-autoprefixer'),
gulpif = require('gulp-if'),
plumber = require('gulp-plumber'),
notify = require('gulp-notify'),
open = require('gulp-open'),
wrap = require('gulp-wrap'),
headerComment = require('gulp-header-comment'),
rename = require('gulp-rename'),
terser = require('gulp-terser'),
stripCssComments = require('gulp-strip-css-comments')
let TASK_NOTIFICATION = false,
LIVE_RELOAD = false
const plumberErrorHandler = {
errorHandler: notify.onError({
title: 'Gulp',
message: 'Error: <%= error.message %>'
})
}
const buildSass = (minify) => () => {
return gulp.src('src/jquery.skedTape.sass')
.pipe(plumber(plumberErrorHandler))
.pipe(gulpif(minify, sourcemaps.init()))
.pipe(sass({
outputStyle: minify ? 'compressed' : 'expanded',
sourcemap: true,
includePaths: [
//__dirname + '/node_modules/foundation-sites/scss'
],
errLogToConsole: true
}))
.pipe(autoprefixer())
.pipe(stripCssComments())
.pipe(headerComment(`
jQuery.skedTape v<%= pkg.version %>
License: <%= pkg.license %>
Author: <%= pkg.author %>
`))
.pipe(gulpif(minify, rename({suffix: '.min'})))
.pipe(gulpif(minify, sourcemaps.write('.')))
// Remove piped files so that in case of an error their old versions don't exist.
.pipe(cleanDest('dist'))
.pipe(gulp.dest('dist'))
.pipe(gulpif(TASK_NOTIFICATION, notify({message: 'SASS built'})))
}
gulp.task('sass', buildSass(false))
gulp.task('sass:min', buildSass(true))
const copyJs = (minify) => () => {
return gulp.src(`src/*.js`)
.pipe(plumber(plumberErrorHandler))
.pipe(cleanDest('dist'))
.pipe(gulpif(minify, sourcemaps.init()))
.pipe(wrap({ src: './umd.template.txt' }))
.pipe(gulpif(minify, terser()))
.pipe(headerComment(`
jQuery.skedTape v<%= pkg.version %>
License: <%= pkg.license %>
Author: <%= pkg.author %>
`))
.pipe(gulpif(minify, rename({suffix: '.min'})))
.pipe(gulpif(minify, sourcemaps.write('.')))
.pipe(gulp.dest('dist'))
.pipe(gulpif(TASK_NOTIFICATION, notify({message: 'JS copied'})))
}
gulp.task('copy-js', copyJs(false))
gulp.task('copy-js:min', copyJs(true))
gulp.task('dist-to-docs', () =>
gulp.src(`dist/*`)
.pipe(plumber(plumberErrorHandler))
.pipe(cleanDest('docs'))
.pipe(gulp.dest('docs'))
.pipe(gulpif(LIVE_RELOAD, connect.reload()))
)
gulp.task('watch', () => {
LIVE_RELOAD = true
TASK_NOTIFICATION = true
connect.server({
name: 'Dist App',
root: 'docs',
host: '0.0.0.0',
port: 8080,
livereload: true
});
gulp.watch('src/*.sass', gulp.parallel('sass', 'sass:min'))
gulp.watch('src/*.js', gulp.parallel('copy-js', 'copy-js:min'))
gulp.watch('dist/*', gulp.parallel('dist-to-docs'))
// Open browser
gulp.src(__filename).pipe(open({uri: 'http://localhost:8080'}))
})
gulp.task('build', gulp.series(
gulp.parallel('sass', 'sass:min', 'copy-js', 'copy-js:min'),
'dist-to-docs'
))
gulp.task('default', gulp.series('build', 'watch'))