forked from victrme/Bonjourr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
159 lines (131 loc) · 4.08 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
import gulp from 'gulp'
import rename from 'gulp-rename'
import replace from 'gulp-replace'
import htmlmin from 'gulp-htmlmin'
import gulpsass from 'gulp-sass'
import esbuild from 'esbuild'
import * as sasscompiler from 'sass'
const { series, parallel, src, dest, watch } = gulp
const sass = gulpsass(sasscompiler)
function html(platform) {
//
// Index & settings minified
// Multiple scripts tags => only main.js
//
return () => {
const assets = ['src/*.html']
// no background.html on chrome because manifest v3
if (/edge|chrome|online/.test(platform)) assets.push('!src/background.html')
const stream = src(assets)
if (platform === 'edge') {
stream.pipe(replace(`favicon.ico`, `monochrome.png`))
}
if (platform === 'online') {
stream.pipe(replace(`<!-- icon -->`, `<link rel="apple-touch-icon" href="src/assets/apple-touch-icon.png" />`))
stream.pipe(replace(`<!-- manifest -->`, `<link rel="manifest" href="manifest.webmanifest">`))
} else {
stream.pipe(replace(`<!-- webext-storage -->`, `<script src="src/scripts/webext-storage.js"></script>`))
}
return stream.pipe(htmlmin({ collapseWhitespace: true })).pipe(dest(`release/${platform}`))
}
}
function scripts(platform, prod) {
return () => {
esbuild.buildSync({
entryPoints: ['src/scripts/index.ts'],
outfile: 'release/online/src/scripts/main.js',
format: 'iife',
bundle: true,
minifySyntax: prod,
minifyWhitespace: prod,
})
return src('release/online/src/scripts/main.js').pipe(dest(`release/${platform}/src/scripts`))
}
}
function ressources(platform) {
return () => {
const assetPath = ['src/assets/**', '!src/assets/bonjourr.png']
if (platform !== 'online') {
assetPath.push('!src/assets/screenshots/**')
}
return src(assetPath).pipe(dest(`release/${platform}/src/assets`))
}
}
function worker(platform) {
return () => {
if (platform === 'online') {
return src('src/scripts/services/service-worker.js').pipe(dest('release/online'))
} else {
const services = ['src/scripts/services/background.js', 'src/scripts/services/webext-storage.js']
return src(services).pipe(dest('release/' + platform + '/src/scripts'))
}
}
}
function manifest(platform) {
return () => {
return platform === 'online'
? src(`src/manifests/manifest.webmanifest`).pipe(dest(`release/${platform}`))
: src(`src/manifests/${platform}.json`)
.pipe(rename('manifest.json'))
.pipe(dest(`release/${platform}`))
}
}
function styles(platform) {
return () =>
src('src/styles/style.scss')
.pipe(sass.sync({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(dest(`release/${platform}/src/styles/`))
}
function locales(platform) {
const filenames = platform === 'online' ? 'translations' : '*'
return () => src(`_locales/**/${filenames}.json`).pipe(dest(`release/${platform}/_locales/`))
}
//
// Tasks
//
// Watches style map to make sure everything is compiled
const filesToWatch = ['./_locales/**', './src/*.html', './src/scripts/**', './src/styles/**', './src/manifests/*.json']
// prettier-ignore
const taskOnline = (prod) => [
html('online'),
styles('online'),
worker('online'),
locales('online'),
manifest('online'),
scripts('online', prod),
ressources('online', false),
]
const taskExtension = (from, prod) => [
html(from),
worker(from),
styles(from),
locales(from),
manifest(from),
ressources(from),
scripts(from, prod),
]
//
// All Exports
//
export const online = async function () {
watch(filesToWatch, series(parallel(...taskOnline())))
}
export const chrome = async function () {
watch(filesToWatch, series(parallel(...taskExtension('chrome'))))
}
export const edge = async function () {
watch(filesToWatch, series(parallel(...taskExtension('edge'))))
}
export const firefox = async function () {
watch(filesToWatch, series(parallel(...taskExtension('firefox'))))
}
export const safari = async function () {
watch(filesToWatch, series(parallel(...taskExtension('safari'))))
}
export const build = parallel(
...taskOnline(),
...taskExtension('firefox', true),
...taskExtension('chrome', true),
...taskExtension('edge', true),
...taskExtension('safari', true)
)