This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
clean.ts
106 lines (99 loc) · 3.14 KB
/
clean.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(function () {
const
gulp = requireModule<Gulp>("gulp"),
promisifyStream = requireModule<PromisifyStream>("promisify-stream"),
tryDo = requireModule<TryDo<any>>("try-do"),
debug = requireModule<DebugFactory>("debug")(__filename),
throwIfNoFiles = requireModule<ThrowIfNoFiles>("throw-if-no-files"),
msbuild = requireModule<GulpMsBuild>("gulp-msbuild"),
dotnetClean = requireModule<GulpDotNetCli>("gulp-dotnet-cli").clean,
resolveMasks = requireModule<ResolveMasks>("resolve-masks"),
env = requireModule<Env>("env"),
chalk = requireModule<AnsiColors>("ansi-colors");
const myVars = [
env.BUILD_TOOLSVERSION,
env.BUILD_CONFIGURATION,
env.BUILD_VERBOSITY,
env.BUILD_MAX_CPU_COUNT,
env.BUILD_FAIL_ON_ERROR,
env.BUILD_PLATFORM,
env.BUILD_ARCHITECTURE,
env.BUILD_MSBUILD_NODE_REUSE,
env.BUILD_RETRIES,
env.BUILD_TARGETS,
env.BUILD_FRAMEWORK,
env.BUILD_RUNTIME
];
env.associate(myVars, "clean");
gulp.task(
"clean",
"Invokes the 'Clean' target on all solutions in the tree",
tryClean
);
function tryClean() {
return tryDo(
clean,
"BUILD_RETRIES",
e => console.error(chalk.red(`Clean fails: ${ e }`))
);
}
function clean() {
const useDotNetCore = env.resolveFlag("DOTNET_CORE");
if (useDotNetCore) {
return cleanWithDotnet();
} else {
return cleanWithMsBuild();
}
}
async function cleanWithDotnet() {
const
configuration = env.resolveArray("BUILD_CONFIGURATION"),
slnMasks = resolveBuildSolutionMasks(),
targets = env.resolveArray("BUILD_TARGETS", "BUILD_INCLUDE");
debug({
slnMasks,
targets,
cwd: process.cwd()
});
const solutions = gulp
.src(slnMasks, { allowEmpty: true })
.pipe(throwIfNoFiles(`No solutions found matching masks: ${ slnMasks }}`));
await promisifyStream(
solutions.pipe(
dotnetClean({
target: "(not set)",
configuration,
msbuildProperties: env.resolveMap(env.MSBUILD_PROPERTIES),
verbosity: env.resolve(env.BUILD_VERBOSITY),
framework: env.resolve(env.BUILD_FRAMEWORK),
runtime: env.resolve(env.BUILD_RUNTIME)
})
)
);
}
function resolveBuildSolutionMasks() {
return resolveMasks("BUILD_INCLUDE", [ "BUILD_EXCLUDE", "BUILD_ADDITIONAL_EXCLUDE" ]);
}
function cleanWithMsBuild() {
const
slnMasks = resolveBuildSolutionMasks();
return promisifyStream(
gulp.src(slnMasks)
.pipe(
msbuild({
toolsVersion: env.resolve("BUILD_TOOLSVERSION"),
targets: [ "Clean" ],
configuration: env.resolve("BUILD_CONFIGURATION"),
stdout: true,
logCommand: true,
errorOnFail: env.resolveFlag("BUILD_FAIL_ON_ERROR"),
solutionPlatform: env.resolve("BUILD_PLATFORM"),
architecture: env.resolve("BUILD_ARCHITECTURE"),
verbosity: env.resolve("BUILD_VERBOSITY"),
nodeReuse: env.resolveFlag("BUILD_MSBUILD_NODE_REUSE"),
maxcpucount: env.resolveNumber("BUILD_MAX_CPU_COUNT")
})
)
);
}
})();