forked from lexkrstn/jquery-sked-tape
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
89 lines (80 loc) · 2.41 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
const gulp = require('gulp'),
cleanDest = require('gulp-clean-dest'),
sass = require('gulp-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')
const DEBUG = ['prod', 'production'].indexOf(process.env.NODE_ENV) < 0
let TASK_NOTIFICATION = false,
LIVE_RELOAD = false
const plumberErrorHandler = {
errorHandler: notify.onError({
title: 'Gulp',
message: 'Error: <%= error.message %>'
})
}
gulp.task('sass', () => {
let main = gulp.src('src/jquery.skedTape.sass')
.pipe(plumber(plumberErrorHandler))
if (DEBUG) {
main = main.pipe(sourcemaps.init())
}
main = main.pipe(sass({
outputStyle: 'expanded',
sourcemap: true,
includePaths: [
//__dirname + '/node_modules/foundation-sites/scss'
],
errLogToConsole: true
}))
.pipe(autoprefixer())
if (DEBUG) {
main = main.pipe(sourcemaps.write('.'))
}
// Remove piped files so that if there was an error
// their old versions wont exist.
return main.pipe(cleanDest('dist'))
.pipe(gulp.dest('dist'))
.pipe(gulpif(TASK_NOTIFICATION, notify({message: 'SASS built'})))
})
gulp.task('copy-js', () =>
gulp.src(`src/*.js`)
.pipe(plumber(plumberErrorHandler))
.pipe(cleanDest('dist'))
.pipe(wrap({ src: './umd.template.txt' }))
.pipe(gulp.dest('dist'))
.pipe(gulpif(TASK_NOTIFICATION, notify({message: 'JS copied'})))
)
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'))
gulp.watch('src/*.js', gulp.parallel('copy-js'))
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', 'copy-js'),
'dist-to-docs'
))
gulp.task('default', gulp.series('build', 'watch'))