import type { Inventory, InventorySource } from "#types/inventory.types"; import { LINES_SUFFIX, READ_SOURCE, RECORDS_SUFFIX, WROTE } from "#configuration/strings/derivation.strings"; import { inventoryTarget, readInventorySources } from "#core/loaders/inventory.loader"; import { lineCount, scanRules } from "#core/converters/inventory.converter"; import { INVENTORY_COMMAND } from "#configuration/constants/contract.constants"; import { INVENTORY_SUMMARY } from "#configuration/strings/contract.strings"; import { persistJson } from "#core/persistence/report.persistence"; import { resolveArgv } from "@govlab/argv"; import { say } from "#core/reporters/derivation.reporter"; resolveArgv({ command: INVENTORY_COMMAND, flags: [], summary: INVENTORY_SUMMARY }); const sources = await readInventorySources(); const inventorySources: InventorySource[] = []; const records = sources.flatMap((source) => { const found = scanRules(source.text, source.path); const lines = lineCount(source.text); inventorySources.push({ lines, path: source.path, records: found.length }); say(`${READ_SOURCE}${source.path}: ${String(lines)}${LINES_SUFFIX}${String(found.length)}${RECORDS_SUFFIX}`); return found; }); const inventory: Inventory = { records, sources: inventorySources }; const target = inventoryTarget(); await persistJson(target, inventory); say(`${WROTE}${target}`);