Created
July 18, 2017 21:05
-
-
Save Lokua/b66455641ee5636dcffd8bea399a4907 to your computer and use it in GitHub Desktop.
convert es5 js to es2015 using lebab and prettier
This file contains hidden or 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
// requires node > 8 | |
const lebab = require('lebab') | |
const prettier = require('prettier') | |
const util = require('util') | |
const readFile = util.promisify(require('fs').readFile) | |
;(async () => { | |
try { | |
const input = process.argv.slice(2)[0] | |
const body = await readFile(input, 'utf8') | |
const { code, warnings } = lebab.transform(body, [ | |
'arrow', | |
'for-of', | |
'arg-spread', | |
'obj-method', | |
'obj-shorthand', | |
'no-strict', | |
'commonjs', | |
'exponent', | |
'multi-var', | |
'let', | |
'class', | |
'template', | |
'default-param', | |
'includes' | |
]) | |
const prettied = prettier.format(code, { | |
semi: false, | |
singleQuote: true | |
}) | |
console.log(prettied) | |
} catch (e) { | |
console.error('e:', e) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment