53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const { initialize } = require("..");
|
|
|
|
function getArtifactName(args) {
|
|
const inline = args.find(arg => arg.startsWith("--artifact="));
|
|
if (inline) return inline.slice("--artifact=".length);
|
|
|
|
const index = args.indexOf("--artifact");
|
|
if (index === -1) return null;
|
|
if (!args[index + 1]) throw new Error("--artifact requires a name");
|
|
return args[index + 1];
|
|
}
|
|
|
|
function getSettingOverlays(args) {
|
|
const overlays = [];
|
|
for (let i = 0; i < args.length; i++) {
|
|
const arg = args[i];
|
|
if (arg.startsWith("--setting=")) {
|
|
const value = arg.slice("--setting=".length);
|
|
if (!value) throw new Error("--setting requires a file path");
|
|
overlays.push(value);
|
|
continue;
|
|
}
|
|
if (arg !== "--setting") continue;
|
|
if (!args[i + 1]) throw new Error("--setting requires a file path");
|
|
overlays.push(args[++i]);
|
|
}
|
|
return overlays;
|
|
}
|
|
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
const optimus = initialize(process.cwd(), { settingOverlays: getSettingOverlays(args) });
|
|
const artifactName = getArtifactName(args);
|
|
|
|
if (artifactName) {
|
|
await optimus.buildArtifact(artifactName);
|
|
console.log(`Artifact complete: ${artifactName}`);
|
|
return;
|
|
}
|
|
|
|
const artifacts = optimus.getSettings("artifacts");
|
|
const names = Object.keys(artifacts);
|
|
await optimus.buildAll();
|
|
console.log(names.length ? `Artifacts complete: ${names.join(", ")}` : "No artifacts configured.");
|
|
}
|
|
|
|
main().catch(error => {
|
|
console.error(error.message || error);
|
|
process.exitCode = 1;
|
|
});
|