Skip to content

Instantly share code, notes, and snippets.

@inad9300
Last active October 8, 2021 23:07
Show Gist options
  • Save inad9300/1725e25a3e844c6a574074a3ee15f6f3 to your computer and use it in GitHub Desktop.
Save inad9300/1725e25a3e844c6a574074a3ee15f6f3 to your computer and use it in GitHub Desktop.
Compile and run simple TypeScript scripts.
#!/usr/bin/env node
const { execSync } = require('child_process')
const [inputScript] = process.argv.slice(2)
const outputScript = inputScript.slice(0, -3) + '.js'
console.log('Compiling...')
execSync(`./node_modules/.bin/tsc --target ESNext --module CommonJS --outDir /tmp ${inputScript}`, { stdio: 'inherit' })
console.log('Running...')
execSync(`node /tmp/${outputScript}`, { stdio: 'inherit' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment