-
-
Save chriswitko/e881aa8f024be07cb7d4643879aac86b to your computer and use it in GitHub Desktop.
Remove TS from EpicReact.dev workshops
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
| { | |
| "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" | |
| } | |
| } |
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
| #!/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