-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
content.mjs
45 lines (38 loc) · 1.2 KB
/
content.mjs
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
import path from "path";
import fs from "fs";
import { yaml, red } from "carbon-pipeline";
const configFile = argv("configFile") || "pipeline.yaml";
let purge = readPurgePath(configFile);
if (!purge) {
purge = readPurgePath("defaults.yaml", "Build/Carbon.Pipeline");
}
if (!Array.isArray(purge)) {
purge = [purge];
}
function readPurgePath(file, folder) {
const filePath = folder ? path.join(folder, file) : file;
try {
const definition = yaml.load(fs.readFileSync(path.join("./", filePath), "utf8"));
return definition?.buildDefaults?.purge;
} catch (err) {
const linebreak = () => console.log("\n");
linebreak();
console.error(red(`Error reading ${file}:`));
console.error(err);
linebreak();
process.exit(1);
}
}
function argv(key) {
// Return true if the key exists and a value is defined
if (process.argv.includes(`--${key}`)) {
return true;
}
const value = process.argv.find((element) => element.startsWith(`--${key}=`));
// Return null if the key does not exist and a value is not defined
if (!value) {
return null;
}
return value.replace(`--${key}=`, "");
}
export default purge;