Skip to content

Instantly share code, notes, and snippets.

@erukiti
Last active November 11, 2017 10:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erukiti/43c69353e7b353fd5c6e58dec1148b34 to your computer and use it in GitHub Desktop.
Save erukiti/43c69353e7b353fd5c6e58dec1148b34 to your computer and use it in GitHub Desktop.
s2s-handler-peg s2s-handler-json
const path = require('path')
const peg = require('pegjs')
const pegHandler = (code, {eventPath, plugin, filename}) => {
return peg.generate(code, {output: 'source', format: 'commonjs'})
}
const jsonHandler = (code, {eventPath, plugin, filename}) => {
const objectName = path.basename(filename, '.json').replace(/-[a-z]/g, s => s.substr(1).toUpperCase())
return `const ${objectName} = ${code}\nmodule.exports = ${objectName}`
}
module.exports = {
watch: './**/*.(pegjs|json)',
plugins: [
{
test: /.*.pegjs$/,
output: '[name].js',
handler: pegHandler,
},
{
test: /.*.json$/,
output: '[name].js',
handler: jsonHandler
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment