Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename a Typescript file

May be I'm missing something on this one (or may be I'm too tired :P ). In Visual Studio 2012 in a Typescript project, when I rename a ts file, instead of rename the js file linked with that ts file, it creates a new one.

Ex :
Old situation : (file1.ts --> file1.js) After renaming : (file1337.ts --> file.js) + file1337.js //file1337 isn't include in project, I need to do it manually ...

So is there a way to rename both the ts file and the js directly linked with this file at the same time without creating a new one and having to manually adding the new js file in the project?

Thanks

like image 521
NinjaFisherman Avatar asked Nov 07 '12 02:11

NinjaFisherman


People also ask

How to rename a file in Node js?

The fs. rename() method is used to asynchronously rename a file at the given old path to a given new path.

How do I rename a folder in node JS?

fs.rename() method accepts two arguments, the current folder name you want to rename and the new folder name, and asynchronously renames the folder. Here is an example: const fs = require('fs') // directory paths const oldDirName = './images' const newDirName = './img' // rename the directory fs.


3 Answers

I've found that if you delete the associated .js file and any source map (that is, delete the files nested inside the .ts in Solution Explorer), then rename the.ts file, then recompile, the .js files are regenerated with the new name, and are automatically added to the project (as long as the .ts file already is).

I should add that I have WebEssentials installed - I don't know how much of this behaviour is due to that, and how much is native to VS.

like image 117
Jude Fisher Avatar answered Sep 20 '22 10:09

Jude Fisher


There is a slight gap in the Visual Studio extension that means renames aren't handled perfectly.

The easiest option is to create a new file with the correct name, move the contents over and delete the old file.

The slightly harder option is to hand-edit the project file after the rename to update the associations.

With Web Essentials, you have a similar issue that the renamed file is associated to the incorrectly named JavaScript and Map file and you'll have to fiddle it to get it to work. It still feels like the cleanest option is to add a new file and transfer the contents rather than rename.

like image 30
Fenton Avatar answered Sep 22 '22 10:09

Fenton


This is old question, but in Visual Studio 2015 this problem also exists. In project BuildEvents Pre-build event command line you can insert following code:

del /S /Q "$(ProjectDir)\path\to\ts\code\*.js" && del /S /Q "$(ProjectDir)\path\to\ts\code\*.js.map"

This command will remove all generated .js and .js.map files before project build.

like image 32
Andzej Maciusovic Avatar answered Sep 21 '22 10:09

Andzej Maciusovic