-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The same as purge.js, but for modules
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; |