/* eslint-env node */ import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const currentDir = path.dirname(fileURLToPath(import.meta.url)) const pageFile = path.join(currentDir, 'index.vue') const apiFile = path.resolve(currentDir, '../../../api/steady/steadyDataView/index.ts') const interfaceFile = path.resolve(currentDir, '../../../api/steady/steadyDataView/interface/index.ts') const componentDir = path.join(currentDir, 'components') const utilsDir = path.join(currentDir, 'utils') const read = file => fs.readFileSync(file, 'utf8') const pageSource = read(pageFile) const apiSource = read(apiFile) const interfaceSource = read(interfaceFile) const componentSource = fs.existsSync(componentDir) ? fs .readdirSync(componentDir) .filter(file => file.endsWith('.vue')) .map(file => read(path.join(componentDir, file))) .join('\n') : '' const utilitySource = fs.existsSync(utilsDir) ? fs .readdirSync(utilsDir) .filter(file => file.endsWith('.ts')) .map(file => read(path.join(utilsDir, file))) .join('\n') : '' const expectations = [ ['page imports ledger tree panel', /SteadyLedgerTree/], ['page imports indicator tree panel', /SteadyIndicatorTree/], ['page imports trend toolbar', /SteadyTrendToolbar/], ['page imports trend chart panel', /SteadyTrendChartPanel/], ['page does not import trend summary panel', /SteadyTrendSummaryPanel/], ['page does not import data table panel', /SteadyDataTablePanel/], ['page renders floating indicator panel', /indicator-floating-panel/], ['page defaults floating indicator panel expanded', /indicatorPanelCollapsed\s*=\s*ref\(false\)/], ['API exposes ledger tree endpoint', /\/steady\/data-view\/ledger-tree/], ['API exposes indicator tree endpoint', /\/steady\/data-view\/indicator-tree/], ['API exposes trend query endpoint', /\/steady\/data-view\/trend\/query/], ['API exposes trend day endpoint', /\/steady\/data-view\/trend\/day/], ['API does not expose trend summary endpoint', /\/steady\/data-view\/trend\/summary/], ['interfaces define trend query params', /interface\s+SteadyTrendQueryParams/], ['interfaces define trend series', /interface\s+SteadyTrendSeries/], ['interfaces do not define trend summary', /interface\s+SteadyTrendSummary/], ['components render ledger checkbox tree', /show-checkbox[\s\S]*@check/], ['components render indicator checkbox tree', /indicator-tree[\s\S]*show-checkbox[\s\S]*@check/], ['components reuse LineChart', / { const matched = pattern.test(sourceByExpectation[index]) return name.includes('does not') || name.includes('do not') ? matched : !matched }) if (failures.length) { console.error('steadyDataView trend contract failed:') for (const [name] of failures) { console.error(`- ${name}`) } process.exit(1) } console.log('steadyDataView trend contract passed')