-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBuild.cs
More file actions
92 lines (74 loc) · 3.07 KB
/
Copy pathBuild.cs
File metadata and controls
92 lines (74 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
return BuildRunner.Execute(args, build =>
{
var codegen = "fsdgenjs";
var dotNetBuildSettings = new DotNetBuildSettings
{
NuGetApiKey = Environment.GetEnvironmentVariable("NUGET_API_KEY"),
PackageSettings = new DotNetPackageSettings
{
PushTagOnPublish = x => $"nuget.{x.Version}",
},
};
build.AddDotNetTargets(dotNetBuildSettings);
build.Target("codegen")
.DependsOn("build")
.Describe("Generates code from the FSD")
.Does(() => CodeGen(verify: false));
build.Target("verify-codegen")
.DependsOn("build")
.Describe("Ensures the generated code is up-to-date")
.Does(() => CodeGen(verify: true));
build.Target("test")
.DependsOn("verify-codegen");
void CodeGen(bool verify)
{
var configuration = dotNetBuildSettings.GetConfiguration();
var verifyOption = verify ? "--verify" : null;
RunCodeGen("example/ExampleApi.fsd", "example/js/", "--indent", "2", "--express", "--disable-eslint");
RunCodeGen("example/ExampleApi.fsd", "example/ts/src/", "--typescript", "--express", "--disable-eslint");
RunDotNet("FacilityConformance", "fsd", "--output", "conformance/ConformanceApi.fsd", verifyOption);
RunDotNet("FacilityConformance", "json", "--output", "conformance/ConformanceTests.json", verifyOption);
RunCodeGen("conformance/ConformanceApi.fsd", "conformance/src/", "--typescript", "--indent", "2", "--disable-eslint");
RunCodeGen("conformance/ConformanceApi.fsd", "conformance/src/fastify", "--typescript", "--fastify", "--indent", "2", "--disable-eslint");
RunCodeGen("conformance/ConformanceApi.fsd", "conformance/src/", "--indent", "2", "--disable-eslint", "--module", "jsConformanceApi");
RunCodeGen("conformance/ConformanceApi.fsd", "conformance/src/fastify/", "--fastify", "--indent", "2", "--disable-eslint", "--module", "jsConformanceApi");
void RunCodeGen(params string?[] args) =>
RunDotNet(new[] { "run", "--no-build", "--project", $"src/{codegen}", "-c", configuration, "--", "--newline", "lf", verifyOption }.Concat(args));
}
build.Target("build-npm")
.Describe("Builds the npm package.")
.Does(() =>
{
RunNpmFrom("./ts", "install");
RunNpmFrom("./ts", "run", "build");
});
build.Target("test-npm")
.DependsOn("build-npm")
.Describe("Tests the npm package.")
.Does(() =>
{
RunNpmFrom("./ts", "run", "test");
RunNpmFrom("./example/js", "install");
RunNpmFrom("./example/js", "run", "test");
RunNpmFrom("./example/ts", "install");
RunNpmFrom("./example/ts", "run", "test");
});
build.Target("publish-npm")
.DependsOn("test-npm")
.Describe("Publishes the npm package.")
.Does(() =>
{
var token = Environment.GetEnvironmentVariable("NPM_ACCESS_TOKEN") ?? throw new BuildException("Missing NPM_ACCESS_TOKEN.");
File.WriteAllText("./ts/.npmrc", $"//registry.npmjs.org/:_authToken={token}");
RunNpmFrom("./ts", "publish");
});
void RunNpmFrom(string directory, params string[] args) =>
RunApp("npm",
new AppRunnerSettings
{
Arguments = args,
WorkingDirectory = directory,
UseCmdOnWindows = true,
IsExitCodeSuccess = x => args[0] == "publish" ? x is 0 or 1 : x is 0,
});
});