Skip to content

Instantly share code, notes, and snippets.

@curiousercreative
Created March 6, 2018 17:35
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 curiousercreative/76edc6b95a47f46c71e497df689b68ee to your computer and use it in GitHub Desktop.
Save curiousercreative/76edc6b95a47f46c71e497df689b68ee to your computer and use it in GitHub Desktop.
Node script for renaming files with .ts or .tsx file extensions to .js or .jsx
const glob = require("glob");
const { execSync } = require('child_process');
console.log('building list of files');
const opts = { absolute: true };
var files = glob.sync("**/*.ts", opts).concat(glob.sync("**/*.tsx", opts)).filter(f => f.indexOf('node_modules') < 0);
console.log(`found ${files.length} files`);
files.forEach(f => {
const newName = f.replace(/\.ts(x)?$/, '.js$1');
console.log(`renaming ${f} to ${newName}`);
execSync(`git mv ${f} ${f.replace(/\.ts(x)?$/, '.js$1')}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment