Skip to content

Instantly share code, notes, and snippets.

@chriswitko
Forked from kentcdodds/package.json
Created March 7, 2021 14:20
Show Gist options
  • Save chriswitko/e881aa8f024be07cb7d4643879aac86b to your computer and use it in GitHub Desktop.
Save chriswitko/e881aa8f024be07cb7d4643879aac86b to your computer and use it in GitHub Desktop.
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