-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
148 lines (131 loc) · 3.51 KB
/
gulpfile.js
File metadata and controls
148 lines (131 loc) · 3.51 KB
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
'use strict'
const path = require('path')
const gulp = require('gulp')
const $ = require('gulp-load-plugins')()
const args = require('yargs').argv
const del = require('del')
const Parcel = require('parcel-bundler')
const chalk = require('chalk')
const resizer = require('node-image-resizer')
const isRelease = args.release !== false
console.log('build for', chalk.magenta(isRelease ? `release` : `development`))
////////
// ICONS
////////
const materialName = /(?:outline|baseline)-([^\d]*)-24px/
const icons = () => {
return gulp
.src(`./source/icons/*.svg`)
.pipe(
$.cheerio({
run: $ => $(`#Bounding_Boxes`).remove(),
parserOptions: {
xmlMode: true,
},
})
)
.pipe(
$.svgo({
plugins: [{ removeViewBox: false }],
})
)
.pipe(
$.rename(path => {
const { basename } = path
const isMaterialIcon = materialName.test(basename)
if (!isMaterialIcon) return
path.basename = materialName.exec(basename)[1].replace(/_/g, `-`)
})
)
.pipe(
$.svgSymbols({
svgAttrs: {
class: `svg-symbol`,
xmlns: false,
},
class: `.svg-symbol--%f`,
templates: [`default-demo`, `default-vue`],
})
)
.pipe($.if(/[.]vue$/, gulp.dest(`src/components`)))
.pipe($.if(/[.]html$/, gulp.dest(`source/icons`)))
}
icons.description = `build SVG icons`
exports[`build:icons`] = icons
////////
// APP LOGO
////////
const cleanAppLogo = () => {
return del([`public/touch-*`, `public/launcher-*`])
}
const LOGO_PATH = path.join(__dirname, `source/application-logo/touch-icon.png`)
const RESIZER_SETUP = {
all: {
path: path.join(__dirname, `/src/assets/`),
},
versions: [
{
prefix: `launcher-`,
suffix: `-4x`,
width: 192,
height: 192,
},
{ suffix: `-iphone-6-plus`, width: 180, height: 180 },
{ suffix: `-ipad-retina`, width: 152, height: 152 },
{ suffix: `-web-app`, width: 144, height: 144 },
{ suffix: `-iphone-retina`, width: 120, height: 120 },
{ suffix: `-ipad`, width: 76, height: 76 },
{ suffix: `-iphone`, width: 57, height: 57 },
],
}
const appLogo = async () => {
await resizer(LOGO_PATH, RESIZER_SETUP)
}
appLogo.description = `resize favicon for different devices`
exports[`application-logo`] = gulp.series(cleanAppLogo, appLogo)
////////
// BUMP
////////
const bump = done => {
if (!args.to) {
console.log(chalk.red(`bump task needs the --to argument`))
return done()
}
// TODO: bump production webmanifest
return gulp
.src([`package.json`, `manifest.webmanifest`])
.pipe($.jsonEditor({ version: args.to }))
.pipe(gulp.dest(`.`))
}
bump.description = `bump to the --to=`
exports[`bump`] = bump
////////
// BUILD FOR PRODUCTION
////////
//----- APPLICATION
const cleanDist = () => del([`dist/**/*`])
exports[`clean-dist`] = cleanDist
const pwaEntryFile = path.join(__dirname, `./src/index.pug`)
const pwaBundler = new Parcel(pwaEntryFile, {
outDir: process.env.RELEASE ? `./dist` : `./public`,
// outFile: `thaime`,
watch: false,
sourceMaps: !process.env.RELEASE,
detailedReport: false,
cache: false,
logLevel: 2,
})
const pwaApplication = done => {
pwaBundler.bundle()
pwaBundler.on(`buildEnd`, () => {
done()
})
}
pwaApplication.description = `bundle vue pwa application with parcel.js`
exports[`build:pwa`] = gulp.series(cleanDist, pwaApplication)
//----- BUILD ALL
exports.build = gulp.series(
cleanDist,
gulp.parallel(icons, appLogo),
pwaApplication
)