-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.ts
147 lines (112 loc) · 3.41 KB
/
gulpfile.ts
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
'use strict'
import fs = require('fs')
import { spawn } from 'child_process'
import gulp = require('gulp')
import log = require('fancy-log')
import _if = require('gulp-if')
import jsonminify = require('gulp-jsonminify')
import mustache = require('gulp-mustache')
import plumber = require('gulp-plumber')
import rename = require('gulp-rename')
import zip = require('gulp-zip')
import chalk = require('chalk')
import del = require('del')
import _ = require('lodash')
// ----------------------------------------------------------------------------
const pkg: { [key: string]: string } =
JSON.parse(fs.readFileSync('./package.json').toString('utf-8'))
const isDev = process.argv.includes('watch')
// ----- assets ---------------------------------------------------------------
gulp.task('assets', () =>
gulp.src('./assets/**/*')
.pipe(gulp.dest('./dist/manifest-v2'))
.pipe(gulp.dest('./dist/manifest-v3'))
)
gulp.task('assets-watch', () =>
gulp.watch('./assets/**/*', gulp.task('assets'))
)
// ----- clean ----------------------------------------------------------------
gulp.task('clean', async () =>
await del(['dist'])
)
// ----- manifest -------------------------------------------------------------
gulp.task('manifest', () =>
gulp.src('./src/manifest-*.json')
.pipe(plumber())
.pipe(mustache({
isDev,
version: pkg.version,
}))
.pipe(rename(path => {
return {
dirname: path.basename,
basename: 'manifest',
extname: '.json'
}
}))
.pipe(_if(!isDev, jsonminify()))
.pipe(gulp.dest('./dist'))
)
gulp.task('manifest-watch', () => {
gulp.watch('./src/manifest-*.json', gulp.task('manifest'))
})
// ----- webpack --------------------------------------------------------------
gulp.task('webpack-prod', done => {
log('Executing command \'' + chalk.cyan('webpack') + '\'...')
const proc = spawn('webpack', [], { stdio: 'inherit' })
proc.on('close', done)
})
gulp.task('webpack-watch', done => {
log('Executing command \'' + chalk.cyan('webpack --watch') + '\'...')
const proc = spawn('webpack', ['--watch'], { stdio: 'inherit' })
proc.on('close', done)
})
// ----- zip ------------------------------------------------------------------
gulp.task('zip-product-v2', () =>
gulp.src('dist/manifest-v2/**/*')
.pipe(zip('manifest-v2.zip'))
.pipe(gulp.dest('dist'))
)
gulp.task('zip-product-v3', () =>
gulp.src('dist/manifest-v3/**/*')
.pipe(zip('manifest-v3.zip'))
.pipe(gulp.dest('dist'))
)
gulp.task('zip-source', () =>
gulp.src([
'assets/**/*',
'src/**/*',
'test/**/*',
'.editorconfig',
'.gitignore',
'.node-version',
'LICENSE',
'yarn.lock',
'*.js',
'*.json',
'*.ts',
'*.yml',
'*.md',
], { base: '.' })
.pipe(zip('source.zip'))
.pipe(gulp.dest('dist'))
)
gulp.task('zip', gulp.parallel('zip-product-v2', 'zip-product-v3', 'zip-source'))
// ----- for production -------------------------------------------------------
gulp.task('build-prod', gulp.series(
'clean',
gulp.parallel('assets', 'manifest', 'webpack-prod'),
'zip',
))
gulp.task('default', gulp.series('build-prod'))
// ----- for development ------------------------------------------------------
gulp.task('build-watch', gulp.parallel('assets', 'manifest'))
gulp.task('watch', gulp.series(
'clean',
'build-watch',
gulp.parallel(
'assets-watch',
'manifest-watch',
'webpack-watch',
),
))