Skip to content

Commit

Permalink
Update: Add content script
Browse files Browse the repository at this point in the history
The same as purge.js, but for modules
  • Loading branch information
jonnitto committed Mar 27, 2024
1 parent 5bbe4cd commit c31a3b4
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions content.mjs
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;

0 comments on commit c31a3b4

Please sign in to comment.