-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 835 Bytes
/
index.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
import through from 'through2'
import PluginError from 'plugin-error'
import { salute } from './salute'
const { name } = require('../package.json')
const PLUGIN_NAME = name
const myPlugin = () =>
through.obj(async function (file, _, callback) {
if (file.isNull()) {
callback(null, file)
return
}
if (file.isStream()) {
callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'))
return
}
if (file.contents.toString().length > 10) {
callback(new PluginError(PLUGIN_NAME, 'Name too long'))
return
}
try {
const newContents = await salute(file.contents)
file.contents = Buffer.from(newContents)
this.push(file)
} catch (err) {
this.emit('error', new PluginError(PLUGIN_NAME, err))
}
callback()
})
export default myPlugin