forked from frontendbr/eventos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
173 lines (154 loc) · 4.02 KB
/
gulpfile.babel.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
'use strict'
import gulp from 'gulp'
import plumber from 'gulp-plumber'
import stylus from 'gulp-stylus'
import poststylus from 'poststylus'
import rucksack from 'rucksack-css'
import fontMagician from 'postcss-font-magician'
import gcmq from 'gulp-group-css-media-queries'
import cssnano from 'gulp-cssnano'
import sourcemaps from 'gulp-sourcemaps'
import lost from 'lost'
import rupture from 'rupture'
import concat from 'gulp-concat'
import uglify from 'gulp-uglify'
import ejs from 'gulp-ejs'
import imagemin from 'gulp-imagemin'
import browserSync from 'browser-sync'
import ghPages from 'gulp-gh-pages'
import svgmin from 'gulp-svgmin'
import svgstore from 'gulp-svgstore'
import cheerio from 'gulp-cheerio'
import jspm from 'gulp-jspm'
import standard from 'gulp-standard'
const srcPaths = {
js: 'src/js/**/*.js',
mainJS: 'src/js/index.js',
css: 'src/styl/**/*.styl',
mainStyl: 'src/styl/main.styl',
ejs: 'src/templates/**/*.ejs',
img: 'src/img/**/*',
icons: 'src/svg/icons/*',
svg: 'src/svg/',
data: 'src/data/**/*',
gulpfile: 'gulpfile.babel.js'
}
const buildPaths = {
build: 'build/**/*',
js: 'build/js/',
css: 'build/css/',
ejs: 'build/',
img: 'build/img',
svg: 'build/svg/',
data: 'build/data'
}
gulp.task('css', () => {
gulp.src(srcPaths.mainStyl)
.pipe(sourcemaps.init())
.pipe(stylus({
use: [
rupture(),
poststylus([
lost(),
fontMagician(),
rucksack({ autoprefixer: true })
])
]
}))
.pipe(gcmq())
.pipe(cssnano())
.pipe(sourcemaps.write())
.pipe(gulp.dest(buildPaths.css))
})
gulp.task('lint', () => {
gulp.src([srcPaths.js, srcPaths.gulpfile])
.pipe(standard())
.pipe(standard.reporter('default', {}))
})
gulp.task('js', ['lint'], () => {
return gulp.src(srcPaths.mainJS)
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(jspm({ selfExecutingBundle: true }))
.pipe(concat('main.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(buildPaths.js))
})
gulp.task('ejs', () => {
const settings = { ext: '.html' }
const config = {
data: {
env: process.env.NODE_ENV
// analytics: { ga: 1010 }
}
}
gulp.src(srcPaths.ejs)
.pipe(plumber())
.pipe(ejs(config, settings))
.pipe(gulp.dest(buildPaths.ejs))
})
gulp.task('images:img', () => {
gulp.src(srcPaths.img)
.pipe(plumber())
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(buildPaths.img))
})
gulp.task('images:svg', () => {
gulp.src(`${srcPaths.svg}/logo.svg`)
.pipe(gulp.dest(buildPaths.svg))
})
gulp.task('images', ['images:img', 'images:svg'])
gulp.task('icons', () => {
gulp.src(srcPaths.icons)
.pipe(svgmin())
.pipe(svgstore({ fileName: 'icons.svg', inlineSvg: true }))
.pipe(cheerio({
run: ($, file) => {
$('svg').addClass('hide')
$('[fill]').removeAttr('fill')
},
parserOptions: { xmlMode: true }
}))
.pipe(gulp.dest(buildPaths.svg))
})
gulp.task('copy-data', () => {
gulp.src(srcPaths.data)
.pipe(gulp.dest(buildPaths.data))
})
gulp.task('watch', () => {
gulp.watch(srcPaths.ejs, ['ejs'])
gulp.watch(srcPaths.css, ['css'])
gulp.watch(srcPaths.img, ['images'])
gulp.watch(srcPaths.data, ['copy-data'])
})
gulp.task('watch:js', () => {
gulp.watch(srcPaths.js, ['js'])
})
gulp.task('watch:lint', ['lint'], () => {
gulp.watch(srcPaths.js, ['lint'])
})
gulp.task('browser-sync', () => {
var files = [
buildPaths.build
]
browserSync.init(files, {
server: {
baseDir: './build/'
}
})
})
gulp.task('pages', () => {
gulp.src(buildPaths.build)
.pipe(ghPages({
remoteUrl: '[email protected]:frontendbr/eventos.git'
}))
})
gulp.task('default', ['css', 'ejs', 'js', 'images', 'icons', 'copy-data', 'watch', 'watch:js', 'browser-sync'])
gulp.task('dev', ['css', 'ejs', 'images', 'icons', 'copy-data', 'watch', 'watch:lint'])
gulp.task('build', ['css', 'ejs', 'js', 'images', 'copy-data'])
gulp.task('deploy', ['pages'])