@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
96 lines • 4.34 kB
JavaScript
import { normalizeOptionalString } from '../../utils/value.js';
const SNAPSHOT_GENERIC_SUMMARY_PREFIXES = ['Function exported from ', 'Component exported from ', 'Hook exported from ', 'Type exported from ', 'Constant exported from ', 'Context exported from ', 'Enum exported from ', 'Class exported from ', 'Namespace export available from '];
export const hasSnapshotArrayValues = value => Array.isArray(value) && value.length > 0;
const createSnapshotGuideAppliesTo = appliesTo => {
const normalizedAppliesTo = {
...(hasSnapshotArrayValues(appliesTo?.packages) ? {
packages: [...appliesTo.packages]
} : {}),
...(hasSnapshotArrayValues(appliesTo?.entrypoints) ? {
entrypoints: [...appliesTo.entrypoints]
} : {}),
...(hasSnapshotArrayValues(appliesTo?.symbols) ? {
symbols: [...appliesTo.symbols]
} : {})
};
return Object.keys(normalizedAppliesTo).length > 0 ? normalizedAppliesTo : null;
};
export const isGenericSnapshotSymbolSummary = summary => {
const normalizedSummary = normalizeOptionalString(summary);
if (!normalizedSummary) {
return false;
}
return SNAPSHOT_GENERIC_SUMMARY_PREFIXES.some(summaryPrefix => normalizedSummary.startsWith(summaryPrefix));
};
export const createSnapshotSymbolKey = (symbol, entrypointPath = '') => normalizeOptionalString(symbol?.id) ?? [entrypointPath, normalizeOptionalString(symbol?.publicName) ?? normalizeOptionalString(symbol?.name)].filter(Boolean).join(':');
export const createSnapshotSelectedSymbolSummary = symbol => ({
id: normalizeOptionalString(symbol?.id) ?? normalizeOptionalString(symbol?.name),
name: normalizeOptionalString(symbol?.publicName) ?? normalizeOptionalString(symbol?.name),
...(normalizeOptionalString(symbol?.kind) ? {
kind: symbol.kind
} : {}),
...(normalizeOptionalString(symbol?.classification) ? {
classification: symbol.classification
} : {}),
...(normalizeOptionalString(symbol?.description) ? {
summary: symbol.description
} : {}),
...(normalizeOptionalString(symbol?.purpose) ? {
purpose: symbol.purpose
} : {}),
...(hasSnapshotArrayValues(symbol?.useWhen) ? {
useWhen: [...symbol.useWhen]
} : {}),
...(hasSnapshotArrayValues(symbol?.avoidWhen) ? {
avoidWhen: [...symbol.avoidWhen]
} : {}),
...(hasSnapshotArrayValues(symbol?.preferredFor) ? {
preferredFor: [...symbol.preferredFor]
} : {}),
...(hasSnapshotArrayValues(symbol?.notFor) ? {
notFor: [...symbol.notFor]
} : {}),
...(hasSnapshotArrayValues(symbol?.relatedSymbols) ? {
relatedSymbols: [...symbol.relatedSymbols]
} : {}),
...(hasSnapshotArrayValues(symbol?.composesWith) ? {
composesWith: [...symbol.composesWith]
} : {}),
...(normalizeOptionalString(symbol?.status) ? {
status: symbol.status
} : {})
});
export const createSnapshotSelectedGuideSummary = guide => {
const appliesTo = createSnapshotGuideAppliesTo(guide?.appliesTo);
return {
id: normalizeOptionalString(guide?.id) ?? normalizeOptionalString(guide?.title),
...(normalizeOptionalString(guide?.title) ? {
title: guide.title
} : {}),
...(normalizeOptionalString(guide?.summary) ? {
summary: guide.summary
} : {}),
...(normalizeOptionalString(guide?.scope) ? {
scope: guide.scope
} : {}),
...(appliesTo ? {
appliesTo
} : {}),
...(hasSnapshotArrayValues(guide?.tasks) ? {
tasks: [...guide.tasks]
} : {}),
...(hasSnapshotArrayValues(guide?.antiPatterns) ? {
antiPatterns: [...guide.antiPatterns]
} : {}),
...(hasSnapshotArrayValues(guide?.relatedSymbols) ? {
relatedSymbols: [...guide.relatedSymbols]
} : {}),
...(normalizeOptionalString(guide?.status) ? {
status: guide.status
} : {}),
...(normalizeOptionalString(guide?.reviewStatus) ? {
reviewStatus: guide.reviewStatus
} : {})
};
};
export const hasSemanticSnapshotSelectedSymbol = symbol => normalizeOptionalString(symbol?.purpose) || hasSnapshotArrayValues(symbol?.useWhen) || hasSnapshotArrayValues(symbol?.avoidWhen) || hasSnapshotArrayValues(symbol?.preferredFor) || hasSnapshotArrayValues(symbol?.notFor) || hasSnapshotArrayValues(symbol?.relatedSymbols) || hasSnapshotArrayValues(symbol?.composesWith) || normalizeOptionalString(symbol?.summary) && !isGenericSnapshotSymbolSummary(symbol.summary);