-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathgulpfile.js
106 lines (90 loc) · 2.32 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
import gulp from 'gulp'
import File from 'vinyl'
import zip from 'gulp-zip'
import yaml from 'js-yaml'
import rimraf from 'rimraf'
import { Transform } from 'stream'
import { setOutput } from '@actions/core'
import rawManifest from './manifest.json'
import pkg from './package.json'
const { version } = pkg
const { name } = rawManifest
/**
* @param {funciton} handler - deal with object stream
*/
const transform = (handler) => (
new Transform({
objectMode: true,
transform(stream, encoding, callback) {
callback(null, handler(stream))
},
})
)
gulp.task('clean', async () => {
rimraf.sync(`{dist,build,*.log}`)
})
gulp.task('copy-assets', () => (
gulp.src('{*.md,*.csv,{avatars,voices}/**/*}')
.pipe(gulp.dest(`build`))
))
/**
* depends on `changelog` step in release.yml
*/
gulp.task('build-manifest', () => (
gulp.src('keywords-voices.yml')
.pipe(
transform((file) => {
const voiceConfig = yaml.load(file.contents.toString())
const { languages, contributes } = voiceConfig
const manifest = {
version,
...rawManifest,
languages,
contributes,
}
// gulp built-in File class in vinyl
return new File({
path: `manifest.json`,
contents: Buffer.from(JSON.stringify(manifest, null, 2)),
})
}),
)
.pipe(gulp.dest(`build`))
))
gulp.task('bundle', async () => {
const bundleName = `${name}-${version}.zip`
if (process.env.CI) {
console.log('set actions output - "bundle-file", "bundle-path"')
setOutput('bundle-file', bundleName)
setOutput('bundle-path', `./dist/${bundleName}`)
}
return await gulp.src('build/**')
.pipe(zip(bundleName))
.pipe(gulp.dest('dist'))
})
gulp.task('output-changelog', async () => (
gulp.src('change.log')
.pipe(
transform((file) => {
const changelog = file.contents.toString()
.replace(/^---$/mg, '')
.trim()
return changelog
}),
)
.pipe(
transform((changelog) => {
console.log('changelog', changelog)
if (process.env.CI) {
console.log('set actions output - "changelog"')
setOutput('changelog', changelog)
}
}),
)
))
gulp.task('default', gulp.series(
'clean',
'copy-assets',
'build-manifest',
'bundle',
))