Skip to content

Instantly share code, notes, and snippets.

@julioxavierr
Created January 27, 2022 20:59
Show Gist options
  • Save julioxavierr/008a0cc3cd6e0123f7afba46f14451b5 to your computer and use it in GitHub Desktop.
Save julioxavierr/008a0cc3cd6e0123f7afba46f14451b5 to your computer and use it in GitHub Desktop.
Migrate JS file to TS
var join = require('path').join;
var cp = require('child_process');
/**
* Migrate a file to TypeScript.
*
* @example
* // will rename file and try to infer types
* yarn ts:migrate ./src/utils.js
*
*/
(() => {
const args = process.argv.filter((arg) => !arg.includes('node') && !arg.includes('scripts'));
args.forEach((path) => {
const tsPath = path.replace('js', 'ts');
cp.exec(`yarn ts-migrate rename . -s "${path}" && yarn ts-migrate migrate . -s "${tsPath}"`).stdout.pipe(
process.stdout
);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment