Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Last active December 30, 2019 15:28
Show Gist options
  • Save tomhodgins/f915de310aac666815d07743a8976cc5 to your computer and use it in GitHub Desktop.
Save tomhodgins/f915de310aac666815d07743a8976cc5 to your computer and use it in GitHub Desktop.
(be sure to run npm install to install those tasty dependencies!)
const babel = require('@babel/core')
const fs = require('fs')
let file = process.argv.slice(2)[0]
let text = file
if (fs.existsSync(file)) {
text = fs.readFileSync(file).toString()
}
console.log(
babel.transform(
text,
{
plugins: [
require.resolve('@babel/plugin-transform-template-literals'),
]
}
).code
)
{
"name": "babel",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.7.7",
"@babel/plugin-transform-template-literals": "^7.7.4"
}
}
`1 + 1 = ${1 + 1}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment