Skip to content

Instantly share code, notes, and snippets.

@rxgx
Created August 1, 2019 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rxgx/0faa7d4a052c34b3bc3ee3fd236fd45e to your computer and use it in GitHub Desktop.
Save rxgx/0faa7d4a052c34b3bc3ee3fd236fd45e to your computer and use it in GitHub Desktop.
Rename files with Flow annotation to TypeScript
const { genSummarizedReport } = require('flow-annotation-check');
const fs = require('fs');
const options = {
include: ['src/**/*.js'],
exclude: ['+(node_modules|build|flow-typed)/**/*.js'],
absolute: true,
};
function renameFile(srcPath, srcExt, destExt) {
const destPath = srcPath.replace(srcExt, destExt);
fs.rename(srcPath, destPath, err => {
if (err) throw err;
console.log(srcPath);
console.log(destPath);
});
}
genSummarizedReport('.', options).then(report => {
console.log('Running on JS files...', report.files.length);
report.files.filter(entry => entry.status === 'flow').forEach(entry => renameFile(entry.file, /.js$/, '.ts'));
});
const optionsReact = {
include: ['src/**/*.jsx'],
exclude: ['+(node_modules|build|flow-typed)/**/*.jsx'],
absolute: true,
};
genSummarizedReport('.', optionsReact).then(report => {
console.log('Running on JSX files...', report.files.length);
report.files.filter(entry => entry.status === 'flow').forEach(entry => renameFile(entry.file, /.jsx$/, '.tsx'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment