-
Notifications
You must be signed in to change notification settings - Fork 15
/
dotnet-build.ts
66 lines (54 loc) · 1.98 KB
/
dotnet-build.ts
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
import child_process from "child_process";
import { Echo } from "./echo";
import shell from "shelljs";
import { CommandStringBuilder } from "../utilities/command-string-builder";
import { DotnetPath } from "./dotnet-path";
import { OptionStringBuilder } from "../utilities/option-string-builder";
import { DotnetClean } from "./dotnet-clean";
import { DotnetRestore } from "./dotnet-restore";
// -----------------------------------------------------------------------------------------
// #region Functions
// -----------------------------------------------------------------------------------------
const DotnetBuild = {
cmd(): CommandStringBuilder {
return new CommandStringBuilder(
"dotnet",
"build",
DotnetPath.solutionPath() ?? "",
"--no-restore"
);
},
description(): string {
return `Builds the dotnet project (via ${this.cmd()})`;
},
getOptions(): OptionStringBuilder {
return new OptionStringBuilder("build", "b");
},
run(clean: boolean, restore: boolean) {
// Verify that the solution path exists or exit early.
DotnetPath.solutionPathOrExit();
if (clean) {
DotnetClean.run();
}
if (restore) {
DotnetRestore.run();
}
const { cmd, args } = this.cmd();
Echo.message(`Building solution (via ${this.cmd()})...`);
const { status } = child_process.spawnSync(cmd, args, {
stdio: "inherit",
shell: true,
});
if (status != null && status !== 0) {
Echo.error("Solution failed to build. See output for details.");
shell.exit(status);
}
return status;
},
};
// #endregion Functions
// -----------------------------------------------------------------------------------------
// #region Exports
// -----------------------------------------------------------------------------------------
export { DotnetBuild };
// #endregion Exports