Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove TS from EpicReact.dev workshops
{
"name": "remove-ts",
"version": "1.0.0",
"description": "I use this to automatically fix feedback links in my workshops",
"bin": "./remove-ts.js",
"dependencies": {
"@babel/core": "7.13.8",
"@babel/preset-typescript": "7.13.0",
"glob": "7.1.6"
}
}
#!/usr/bin/env node
const path = require('path')
const fs = require('fs')
const glob = require('glob')
const babel = require('@babel/core')
const babelPresetTS = require('@babel/preset-typescript')
// Compiles away all TS from TS(X) files and renames them to .js
glob
.sync('src/**/*.+(ts|tsx)', {
ignore: ['*.d.ts'],
})
.forEach(filepath => {
const fullFilepath = path.join(process.cwd(), filepath)
const contents = fs.readFileSync(fullFilepath, {encoding: 'utf-8'})
const result = babel.transformSync(contents, {
babelrc: false,
presets: [babelPresetTS],
filename: fullFilepath,
})
fs.writeFileSync(fullFilepath, result.code)
fs.renameSync(fullFilepath, fullFilepath.replace(/\.tsx?$/, '.js'))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment