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
The fs. rename() method is used to asynchronously rename a file at the given old path to a given new path.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With