announceSources
Where a package's release is announced as fetched from: the --source URLs given (kept for next time), else the
ones kept, else origin, if it's a server.
import { sourcesSetting } from "#codebase/tcmts/cli/announce"; import type { Codebase } from "#codebase/tcmts/cli/codebase"; import type { RemoteConfig } from "#codebase/tcmts/cli/sync"; import { UsageError } from "#codebase/tcmts/cli/ui"; import { releaseLexicon } from "#codebase/tcmts/records"; export function announceSources(cb: Codebase, pkg: string, given: string[]): string[] { const most = releaseLexicon.defs.main.record.properties.sources; if (given.length > most.maxLength) throw new UsageError( `a release is announced with at most ${most.maxLength} sources: ${given.length} --source were given`, ); if (given.length) { for (const s of given) if (!/^https?:\/\/[^/]/.test(s) || s.length > most.items.maxLength) throw new UsageError( `--source ${s}: a source people fetch from is a server's URL (http or https), as \`tcm serve\` serves it`, ); cb.store.setSetting(sourcesSetting(pkg), JSON.stringify(given)); return given; } const kept = cb.store.getSetting(sourcesSetting(pkg)); if (kept) return JSON.parse(kept) as string[]; const origin = cb.store.getSetting("remote.origin"); const url = origin && (JSON.parse(origin) as RemoteConfig).url; if (url && /^https?:\/\//.test(url)) return [url]; throw new UsageError( `announcing ${pkg} needs a URL it can be fetched from: --source <url> (a \`tcm serve\` server; kept for next time)`, ); }
uses
- tcmts.cli.announce.sourcesSetting
- tcmts.cli.codebase.Codebase
- tcmts.cli.sync.RemoteConfig
- tcmts.cli.ui.UsageError
- tcmts.records.releaseLexicon