|
| 1 | +var target = Argument("target", defaultValue: "Default"); |
| 2 | +if (target == "Default") |
| 3 | +{ |
| 4 | + AnsiConsole.Write(new FigletText("OpenCLI")); |
| 5 | + AnsiConsole.Write( |
| 6 | + new Table() |
| 7 | + .AddColumns("Target", "") |
| 8 | + .AddRow("[yellow]clean[/]", "Cleans up artifacts") |
| 9 | + .AddRow("[yellow]build-schema[/]", "Builds the JSON schema") |
| 10 | + .AddRow("[yellow]build-site[/]", "Builds the site") |
| 11 | + .AddRow("[yellow]run-site[/]", "Runs the site locally") |
| 12 | + .AddRow("[yellow]ci[/]", "Runs the CI build locally") |
| 13 | + ); |
| 14 | + |
| 15 | + Environment.Exit(1); |
| 16 | +} |
| 17 | + |
| 18 | +////////////////////////////////////////////////////////////////////// |
| 19 | +// TARGETS |
| 20 | +////////////////////////////////////////////////////////////////////// |
| 21 | + |
| 22 | +Task("CI") |
| 23 | + .IsDependentOn("Build-Schema") |
| 24 | + .IsDependentOn("Build-Site"); |
| 25 | + |
| 26 | +////////////////////////////////////////////////////////////////////// |
| 27 | +// TASKS |
| 28 | +////////////////////////////////////////////////////////////////////// |
| 29 | + |
| 30 | +// Clears all artifacts |
| 31 | +Task("Clean") |
| 32 | + .Does(ctx => |
| 33 | +{ |
| 34 | + ctx.CleanDirectory("./.artifacts"); |
| 35 | +}); |
| 36 | + |
| 37 | +// Updates the site contents |
| 38 | +Task("Update-Site-Contents") |
| 39 | + .Does(ctx => |
| 40 | +{ |
| 41 | + // Copy the draft.md content into the site |
| 42 | + ctx |
| 43 | + .TransformTextFile("./site/docs/spec.template", "<%", "%>") |
| 44 | + .WithToken("SPEC", System.IO.File.ReadAllText("./draft.md")) |
| 45 | + .Save("./site/docs/spec.md"); |
| 46 | + |
| 47 | + // Copy the schema |
| 48 | + ctx.CopyFile("./schema.json", "./site/static/draft.json"); |
| 49 | +}); |
| 50 | + |
| 51 | +// Builds the JSON schema |
| 52 | +Task("Build-Schema") |
| 53 | + .IsDependentOn("Clean") |
| 54 | + .Does(ctx => |
| 55 | +{ |
| 56 | + ctx.Npm(arguments: ["install"], workingDirectory: "./typespec"); |
| 57 | + ctx.Npm(arguments: ["run", "tsp-compile"], workingDirectory: "./typespec"); |
| 58 | + |
| 59 | + // TODO: No overload for overwriting? |
| 60 | + if (ctx.FileExists("./schema.json")) |
| 61 | + { |
| 62 | + ctx.DeleteFile("./schema.json"); |
| 63 | + } |
| 64 | + |
| 65 | + ctx.CopyFile("./.artifacts/@typespec/json-schema/OpenCLI.json", "./.artifacts/schema.json"); |
| 66 | + ctx.CopyFile("./.artifacts/@typespec/json-schema/OpenCLI.json", "./schema.json"); |
| 67 | +}); |
| 68 | + |
| 69 | +// Builds the site |
| 70 | +Task("Build-Site") |
| 71 | + .IsDependentOn("Clean") |
| 72 | + .IsDependentOn("Update-Site-Contents") |
| 73 | + .Does(ctx => |
| 74 | +{ |
| 75 | + ctx.Npm( |
| 76 | + arguments: ["ci"], |
| 77 | + workingDirectory: "./site"); |
| 78 | + |
| 79 | + ctx.Npm( |
| 80 | + arguments: ["run build"], |
| 81 | + workingDirectory: "./site"); |
| 82 | +}); |
| 83 | + |
| 84 | +// Runs the site locally |
| 85 | +Task("Run-Site") |
| 86 | + .IsDependentOn("Update-Site-Contents") |
| 87 | + .Does(ctx => |
| 88 | +{ |
| 89 | + ctx.Npm( |
| 90 | + arguments: ["install"], |
| 91 | + workingDirectory: "./site"); |
| 92 | + |
| 93 | + ctx.Npx( |
| 94 | + arguments: ["docusaurus", "start"], |
| 95 | + workingDirectory: "./site"); |
| 96 | +}); |
| 97 | + |
| 98 | +////////////////////////////////////////////////////////////////////// |
| 99 | +// EXECUTION |
| 100 | +////////////////////////////////////////////////////////////////////// |
| 101 | + |
| 102 | +RunTarget(target); |
0 commit comments