Skip to content

Commit

Permalink
Merge pull request #15 from roblox-csharp/experimental
Browse files Browse the repository at this point in the history
feat: automatically infer project name from path
  • Loading branch information
SecondNewtonLaw authored Aug 3, 2024
2 parents 8f5b3bb + 3cf5555 commit c4b90de
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions RobloxCS.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,21 @@ public class Options

[Value(0, Required = false, HelpText = "Project directory path", MetaName = "Path")]
public string? Path { get; set; }

[Value(1, Required = false, HelpText = "Project name", MetaName = "Name")]
public string? Name { get; set; }
}

public static void Main(string[] args)
{
Parser.Default.ParseArguments<Options>(args)
.WithParsed(options =>
{
var name = options.Name ?? "Example";
var path = options.Path ?? ".";
if (options.Version)
{
Console.WriteLine($"roblox-cs {_version.Major}.{_version.Minor}.{_version.Build}");
}
else if (options.Init)
{
InitializeProject(path, name);
InitializeProject(path);
}
else if (options.WatchMode)
{
Expand Down Expand Up @@ -97,8 +93,9 @@ private static void OnFileChanged(string path, FileSystemEventArgs e)
}
}

private static void InitializeProject(string path, string projectName)
private static void InitializeProject(string path)
{
var projectName = Path.GetDirectoryName(path) == "" ? Path.GetFileName(path) : Path.GetDirectoryName(path) ?? "Example";
try
{
Repository.Clone(_exampleProjectRepo, path);
Expand All @@ -116,15 +113,15 @@ private static void InitializeProject(string path, string projectName)

if (projectName != "Example")
{
var projectFolder = Path.Combine(path, projectName);
var projectSourceFolder = Path.Combine(projectFolder, "src");
var projectFolder = path;
var projectSourceFolder = Path.Combine(projectFolder, projectName, "src");
var projectFile = Path.Combine(projectSourceFolder, $"{projectName}.csproj");
var rojoManifestFile = Path.Combine(projectFolder, "default.project.json");
var rojoManifestFile = Path.Combine(projectFolder, projectName, "default.project.json");

AnsiConsole.MarkupLine("[yellow]Renaming project...[/]");
File.Delete(Path.Combine(path, "Example.sln"));
DotNet.Command.Create("dotnet", ["new", "sln", "-n", projectName, "-o", path]).Execute();
Directory.Move(Path.Combine(path, "Example"), projectFolder);
Directory.Move(Path.Combine(path, "Example"), Path.Combine(projectFolder, projectName));
File.Move(Path.Combine(projectSourceFolder, "Example.csproj"), projectFile);

// Dynamicallty replace <Title>...</Title> inside of the csproj file. This sucks, and we must edit the solution to not lose the reference to it.
Expand Down

0 comments on commit c4b90de

Please sign in to comment.