Last active
November 11, 2017 10:42
-
-
Save erukiti/43c69353e7b353fd5c6e58dec1148b34 to your computer and use it in GitHub Desktop.
s2s-handler-peg s2s-handler-json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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