NTypewriter
NTypewriter copied to clipboard
Sync/delete renamed/deleted files
I'm not sure if I am missing something but it seems that renamed/deleted files stays in the output folder and are not deleted.
So if I rename Class1
to Class2
I now have both Class1
and Class2
in files, instead of just Class2
.
Do I need to setup something or is this not supported?
It depends on a project type, not all VS projects support that. Also option AddGeneratedFilesToVSProject must be set to true.
When it works, your template and generated files should have the same id:
Would it be possible to have an option just to clean a folder before generating the files? This way no old files would be left inside. Because I have 2 projects at the moment: one in C# and the other one in TypeScript, and the first one generates the files for the second, so it makes little sense to include them in the first project.
I have a similar setup and every once in a while I delete the files manually and regenerate. The problem with deleting the files every time is that you are going to cause a lot of recompilation in your typescript project because all of the generated files will be brand new. One of the great features of NTypewriter is that it doesn't write files when they have not changed.
The ony way that I could see implementing something to solve this problem is to do something like this:
- before the run, list all of the files in the directory
- during the run, keep a list of all files that were created (this includes the files that were not updated because they were the same as on the one on disk)
- as a post step, delelete any file that is in the directory that isn't in the list of files generated.
This has a huge caveat that you would need to generate the files into an empty directory because any file that isn't NTypewriter generated is going to get deleted.
There is no such thing as "output" folder in NTypewriter. Every generated file has it is own path associated.
As a quick solution I propose to use a custom function:
public static void Clean()
{
System.IO.DirectoryInfo di = new DirectoryInfo(@"C:\\your_path");
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
}
and invoke it somewhere from the template, outside of any loop
{{ Custom.Clean
capture output
for class in data.Classes
class.FullName | String.Append "\r\n"
end
end
Save output "index.txt"
}}
There is only one caveat to this solution, the Clean function will be invoked during rendering preview too ....
Could it be possible to add a flag to distinguish preview from actual generation?
Sure, v0.3.8 will have env.IsPreviewRender
flag.