AdrianWilczynski / CSharpToTypeScript

Convert C# Models, ViewModels and DTOs into their TypeScript equivalents using webapps, CLI Tool or VSCode extension. Links: https://marketplace.visualstudio.com/items?itemName=adrianwilczynski.csharp-to-typescript - https://csharptotypescript.azurewebsites.net - https://adrianwilczynski.github.io/CSharpToTypeScript/ - https://www.nuget.org/packages/CSharpToTypeScript.CLITool/
MIT License
114 stars 32 forks source link

CLI tool improperly recognizing directories #45

Open GravlLift opened 2 years ago

GravlLift commented 2 years ago

When attempting to use command line tool on a directory with a . in the final folder level, the input is incorrectly assumed to be a file. For instance, C:/A.Directory is assumed to be a file, even if it's a folder name.

The root cause is a result of using a regex to determine filenames at: https://github.com/AdrianWilczynski/CSharpToTypeScript/blob/f36b19e402047890912224d95e90088f01d07692/src/CSharpToTypeScript.CLITool/Utilities/FileSystem.cs#L18-L19

I'd propose ditching the use of that extension method and just checking both file/directory existence at the same time.

So change the existing: https://github.com/AdrianWilczynski/CSharpToTypeScript/blob/f36b19e402047890912224d95e90088f01d07692/src/CSharpToTypeScript.CLITool/Validation/InputExists.cs#L20-L27

to simply:

else if (!File.Exists(command.Input) && !Directory.Exists(command.Input))
{
    return new ValidationResult($"The file or directory path '{command.Input}' does not exist.");
}

Might resolve #44?