Created
August 1, 2019 03:42
-
-
Save rxgx/0faa7d4a052c34b3bc3ee3fd236fd45e to your computer and use it in GitHub Desktop.
Rename files with Flow annotation to TypeScript
This file contains 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
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