75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
const path = require("path");
|
|
const {
|
|
analyzeArea,
|
|
classifyAreaQuality,
|
|
defaultConfigPath,
|
|
formatBytes,
|
|
} = require("./lib/area-diagnostics");
|
|
|
|
const repoRoot = path.resolve(__dirname, "..");
|
|
|
|
function parseArgs(argv) {
|
|
const out = {};
|
|
for (let i = 0; i < argv.length; i += 1) {
|
|
const arg = argv[i];
|
|
if (!arg.startsWith("--")) continue;
|
|
const key = arg.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
const next = argv[i + 1];
|
|
if (!next || next.startsWith("--")) {
|
|
out[key] = "true";
|
|
} else {
|
|
out[key] = next;
|
|
i += 1;
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function main() {
|
|
const args = parseArgs(process.argv.slice(2));
|
|
const configPath = path.resolve(args.config || defaultConfigPath(repoRoot));
|
|
const result = analyzeArea(configPath, { repoRoot });
|
|
const gate = classifyAreaQuality(result);
|
|
|
|
printCheckReport(result, gate);
|
|
process.exitCode = gate.failures.length ? 1 : 0;
|
|
}
|
|
|
|
function printCheckReport(result, gate) {
|
|
console.log("Area quality gate");
|
|
console.log(`Area: ${result.area.id}`);
|
|
console.log(`Config: ${result.configPath}`);
|
|
console.log(`Output: ${result.area.outputs.areaDir}`);
|
|
if (result.glb) {
|
|
console.log(
|
|
`GLB: ${formatBytes(result.glb.fileBytes)}, ${result.glb.counts.nodes} nodes, ` +
|
|
`${result.glb.counts.images} images`,
|
|
);
|
|
}
|
|
console.log("");
|
|
|
|
const status = gate.failures.length ? "FAIL" : "PASS";
|
|
console.log(`${status}: ${gate.failures.length} failure(s), ${gate.warnings.length} warning(s)`);
|
|
console.log("");
|
|
|
|
console.log(`Failures (${gate.failures.length})`);
|
|
if (!gate.failures.length) {
|
|
console.log(" none");
|
|
} else {
|
|
for (const failure of gate.failures) console.log(` - ${failure}`);
|
|
}
|
|
console.log("");
|
|
|
|
console.log(`Warnings (${gate.warnings.length})`);
|
|
if (!gate.warnings.length) {
|
|
console.log(" none");
|
|
} else {
|
|
for (const warning of gate.warnings) console.log(` - ${warning}`);
|
|
}
|
|
}
|
|
|
|
main();
|