Files
inbuxa-admin/well-known-source.ts
jcoffey-dev 991912ef4f
ci / build (pull_request) Skipped
ci / publish (pull_request) Skipped
ci / notices (pull_request) Successful in 18s
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 58s
Write .well-known/source into the build
The console's public repository and the commit it was built from, in
the form https://coffeylabs.org/specs/well-known-source/ defines. The
commit comes from INBUXA_REVISION, which the image build passes in; a
build without one writes nothing, and nginx answers that address with a
404 rather than the app. tsconfig.node.json drops source-archive.ts,
gone since #7.
2026-10-28 21:57:30 -07:00

47 lines
1.6 KiB
TypeScript

// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
// SPDX-License-Identifier: AGPL-3.0-only
/**
* inbuxa: writes `.well-known/source` into the build, in the form
* https://coffeylabs.org/specs/well-known-source/ gives it: the console's
* public repository and the commit it was built from.
*
* The commit comes from INBUXA_REVISION, which the image build and the
* deploy pass in; neither has a .git to ask. A build without a full commit id
* writes nothing, since a repository without a revision doesn't name the
* build.
*/
import type { Plugin } from 'vite'
export const REPOSITORY = 'https://git.coffeylabs.org/inbuxa/inbuxa-admin'
/** A full commit id: 40 hex digits (SHA-1) or 64 (SHA-256). */
export function isCommitId(revision: string | undefined): revision is string {
return revision !== undefined && /^([0-9a-f]{40}|[0-9a-f]{64})$/i.test(revision)
}
/** The document for a build of `version` at `revision`, if it names one. */
export function sourceDocument(version: string, revision: string | undefined): string | undefined {
if (!isCommitId(revision)) return undefined
return `${JSON.stringify(
{
version: 1,
software: [
{ name: 'inbuxa Admin', version, license: 'AGPL-3.0-only', repository: REPOSITORY, revision },
],
},
null,
2,
)}\n`
}
export function wellKnownSource(version: string): Plugin {
return {
name: 'inbuxa-well-known-source',
apply: 'build',
generateBundle() {
const source = sourceDocument(version, process.env.INBUXA_REVISION)
if (source) this.emitFile({ type: 'asset', fileName: '.well-known/source', source })
},
}
}