preview-own-list.ts
Language TypeScript3.1 KB88 lines
/*** Render one person's board with their private list stamped in, to a file.** `pnpm dashboard` writes the COMPANY_VIEWER page, which has no* My Day card and therefore no private list, so the one command that renders a* page without credentials cannot show this feature at all. Without something* like this, the only way to look at the card is to deploy.** It is a preview, not a test. The numbers are fixtures and the lines below are* invented; nothing here reads or writes a real store, and it never touches D1.* The tests are what pin behaviour.** pnpm preview:own-list [email] [state]* state: ok (default) | empty | failed | unconfigured*/import { writeFile } from 'node:fs/promises'import { FIXTURE_SNAPSHOT } from '../apps/dashboard/src/fixtures.js'import { headline } from '../apps/dashboard/src/collect.js'import { render } from '../apps/dashboard/src/render.js'import { viewerFor } from '../apps/dashboard/src/viewer.js'import {ownListBlock,stampOwnList,type OwnItem,type OwnStore,} from '../apps/dashboard/src/own-list-view.js'const email = process.argv[2] ?? 'hello@meridiandisplay.example'const which = process.argv[3] ?? 'ok'const viewer = viewerFor(email)if (!viewer.person) {console.error(`${email} is not on the roster, so there is no private list to preview.`)process.exit(1)}const now = new Date()const day = (offset: number): string => {const d = new Date(now)d.setDate(d.getDate() + offset)return d.toISOString().slice(0, 10)}let id = 0const line = (over: Partial<OwnItem>): OwnItem => ({id: ++id,text: '',due: null,priority: 'normal',linkKey: null,createdAt: now.toISOString(),updatedAt: now.toISOString(),edits: 0,doneAt: null,...over,})const sample: OwnStore = {state: 'ok',person: viewer.person.name,open: [line({ text: 'Call the school booster club back about the 10 ft feather flag', due: day(-4), priority: 'high', linkKey: 'order:MD2639582' }),line({ text: 'Send Rafael the revised backdrop dimensions', due: day(0) }),line({ text: 'Chase the vinyl supplier on the January quote', due: day(3), linkKey: 'task:41837' }),line({ text: 'Reorder the sample kit', priority: 'low' }),],done: [line({ text: 'Approved the tabletop banner proof', doneAt: new Date(now.getTime() - 86_400_000).toISOString() })],truncated: false,doneHidden: 3,}const stores: Record<string, OwnStore> = {ok: sample,empty: { state: 'ok', person: viewer.person.name, open: [], done: [], truncated: false, doneHidden: 0 },failed: { state: 'failed', error: 'D1_ERROR: no such table: own_item' },unconfigured: { state: 'unconfigured' },}const store = stores[which]if (!store) {console.error(`unknown state "${which}": try ok, empty, failed or unconfigured`)process.exit(1)}const page = render(FIXTURE_SNAPSHOT, headline(FIXTURE_SNAPSHOT), [], day(0), null, viewer)const out = new URL('../own-list-preview.html', import.meta.url)await writeFile(out, stampOwnList(page, ownListBlock(viewer, store, now)), 'utf8')console.log(`Wrote ${out.pathname}: ${viewer.person.name}, store: ${which}`)