Files
openmotion/shared/template-config.ts
lefarcen 378f5d5ed1 feat: deliver npm template catalogs from OpenMotion CDN (#458)
* feat: read npm templates from latest GitHub main

* fix: satisfy backend type checks for GitHub catalogs

* fix: keep built-in template detail local for GitHub catalogs

Resolve built-in template IDs before refreshing the remote GitHub catalog so bundled
examples answer without any network request, matching the previous get() path.

Align the public openmotion_list_templates and openmotion_get_template descriptions
and the phase-one tool documentation with the NPM GitHub main source, and make the
new catalog test use oss tmpdir() like the rest of the suite.

Generated-By: looper 0.16.2 (runner=fixer, agent=pi)

* fix: address template catalog review feedback

* feat: serve npm templates through hosted main snapshots

* fix: verify installed template flows and hydrate optional project assets

* docs: authorize automatic main template synchronization

* test: align publication policy checks with automatic template sync

* fix: keep the released template catalog at a versionless URL

---------

Co-authored-by: 罗高 <luogao@users.noreply.github.com>
2026-11-16 21:55:23 +08:00

21 lines
1.2 KiB
TypeScript

import { existsSync, readFileSync } from 'node:fs';
const defaults = JSON.parse(readFileSync(new URL('./template-config.json', import.meta.url), 'utf8'));
export type TemplateSource = 'repository' | 'hosted' | 'cms';
export function packageTemplateConfig(environment = 'prod', source: TemplateSource = 'cms') {
if (environment !== 'dev' && environment !== 'prod') throw new Error('Template environment must be dev or prod');
return { ...defaults, environment, source } as { environment: 'dev' | 'prod'; resourceId: string; locale: string; source: TemplateSource };
}
export function templateConfig(): ReturnType<typeof packageTemplateConfig> {
const source = process.env.MOTION_TEMPLATE_SOURCE ?? (existsSync(new URL('../library/templates/catalog/catalog.json', import.meta.url)) ? 'repository' : (defaults.source ?? 'cms'));
if (source !== 'repository' && source !== 'hosted' && source !== 'cms') throw new Error('MOTION_TEMPLATE_SOURCE must be repository, hosted or cms');
return {
...packageTemplateConfig(process.env.MOTION_TEMPLATE_ENV ?? defaults.environment, source),
resourceId: process.env.MOTION_TEMPLATE_RESOURCE_ID ?? defaults.resourceId,
locale: process.env.MOTION_TEMPLATE_LOCALE ?? defaults.locale,
source,
};
}