feat(reporting-governance): add profile artifact binding slice
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const packageRoot = path.resolve(import.meta.dirname, '..', '..');
|
||||
const repoRoot = path.resolve(packageRoot, '..', '..');
|
||||
|
||||
function readJsonFile(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
}
|
||||
|
||||
export function resolvePackageArtifactPath(...segments) {
|
||||
return path.resolve(packageRoot, ...segments);
|
||||
}
|
||||
|
||||
export function loadDeploymentProfileArtifact({ artifactPath, profileId } = {}) {
|
||||
const resolvedPath = path.resolve(
|
||||
artifactPath
|
||||
?? resolvePackageArtifactPath('profiles', `${profileId ?? 'strict-manager-mode'}.profile.json`)
|
||||
);
|
||||
const artifact = readJsonFile(resolvedPath);
|
||||
return {
|
||||
artifactPath: resolvedPath,
|
||||
artifact,
|
||||
};
|
||||
}
|
||||
|
||||
export function createDeploymentBindingContract({ artifact, repoRootOverride } = {}) {
|
||||
if (!artifact?.spec?.bindings) {
|
||||
throw new Error('deployment profile artifact bindings are required');
|
||||
}
|
||||
|
||||
const root = path.resolve(repoRootOverride ?? repoRoot);
|
||||
const scripts = Object.fromEntries(
|
||||
Object.entries(artifact.spec.bindings.scripts ?? {}).map(([key, relativePath]) => [key, path.resolve(root, relativePath)])
|
||||
);
|
||||
const artifactRoots = Object.fromEntries(
|
||||
Object.entries(artifact.spec.bindings.artifact_roots ?? {}).map(([key, relativePath]) => [key, path.resolve(root, relativePath)])
|
||||
);
|
||||
|
||||
return {
|
||||
runtime: artifact.spec.bindings.runtime ?? artifact.metadata?.runtime ?? 'unknown-runtime',
|
||||
entrypoint: path.resolve(root, artifact.spec.bindings.entrypoint),
|
||||
pluginVersion: artifact.spec?.package?.pluginVersion ?? null,
|
||||
compatibilityMode: artifact.metadata?.compatibility_mode ?? 'strict_envelope',
|
||||
scripts,
|
||||
artifactRoots,
|
||||
};
|
||||
}
|
||||
|
||||
export const __testables = {
|
||||
packageRoot,
|
||||
repoRoot,
|
||||
readJsonFile,
|
||||
};
|
||||
Reference in New Issue
Block a user