mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat: add a CDN media-availability manifest and read it across install surfaces (#1737)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
import * as p from '@clack/prompts';
|
||||
import cdnMedia from '@/content/cdn-media.json';
|
||||
import { rendererSupportsCdn } from '@/utils/installation/cdn-code';
|
||||
import type { InstallationOptions } from '@/utils/installation/codegen';
|
||||
import { detectRenderer } from '@/utils/installation/detect-renderer';
|
||||
import type { InstallMethod, Renderer, Skin, UseCase } from '@/utils/installation/types';
|
||||
import { VALID_RENDERERS } from '@/utils/installation/types';
|
||||
import type { Framework } from './config.js';
|
||||
|
||||
const CDN_MEDIA_SUBPATHS = cdnMedia.map((entry) => entry.id);
|
||||
|
||||
export function supportsCdnInstall(renderer: Renderer): boolean {
|
||||
return rendererSupportsCdn(renderer, CDN_MEDIA_SUBPATHS);
|
||||
}
|
||||
|
||||
export async function promptFramework(): Promise<Framework> {
|
||||
const value = await p.select({
|
||||
message: 'Which framework?',
|
||||
@@ -50,14 +58,19 @@ function skinOptionsForUseCase(useCase: UseCase): Array<{ value: Skin; label: st
|
||||
];
|
||||
}
|
||||
|
||||
function installMethodOptions(framework: Framework): Array<{ value: InstallMethod; label: string }> {
|
||||
function installMethodOptions(
|
||||
framework: Framework,
|
||||
renderer: Renderer
|
||||
): Array<{ value: InstallMethod; label: string }> {
|
||||
const options: Array<{ value: InstallMethod; label: string }> = [
|
||||
{ value: 'npm', label: 'npm' },
|
||||
{ value: 'pnpm', label: 'pnpm' },
|
||||
{ value: 'yarn', label: 'yarn' },
|
||||
{ value: 'bun', label: 'bun' },
|
||||
];
|
||||
if (framework === 'html') {
|
||||
// CDN is HTML-only, and only when the renderer ships a CDN build — matching
|
||||
// the install page, which hides the CDN tab for renderers without one.
|
||||
if (framework === 'html' && supportsCdnInstall(renderer)) {
|
||||
options.unshift({ value: 'cdn', label: 'CDN' });
|
||||
}
|
||||
return options;
|
||||
@@ -154,7 +167,7 @@ export async function promptInstallOptions(
|
||||
(await (async () => {
|
||||
const value = await p.select({
|
||||
message: 'Install method',
|
||||
options: installMethodOptions(framework),
|
||||
options: installMethodOptions(framework, media),
|
||||
});
|
||||
if (p.isCancel(value)) process.exit(0);
|
||||
return value;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[
|
||||
{ "id": "dash-video" },
|
||||
{ "id": "hls-video" },
|
||||
{ "id": "mux-audio" },
|
||||
{ "id": "mux-video" },
|
||||
{ "id": "native-hls-video" },
|
||||
{ "id": "simple-hls-audio-only" },
|
||||
{ "id": "simple-hls-video" }
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { supportsCdnInstall } from '../prompts.js';
|
||||
|
||||
// Wires the cdn-media manifest into the CLI the same way the install page reads
|
||||
// the cdnMedia collection. Every current renderer ships (or is covered by) a
|
||||
// CDN build, so all resolve true; the no-CDN path (e.g. Vimeo) arrives with the
|
||||
// new rendering engines. `rendererSupportsCdn`'s false branch is unit-tested in
|
||||
// cdn-code.test.ts.
|
||||
describe('supportsCdnInstall', () => {
|
||||
it('returns true for preset renderers (covered by the preset bundle)', () => {
|
||||
expect(supportsCdnInstall('html5-video')).toBe(true);
|
||||
expect(supportsCdnInstall('html5-audio')).toBe(true);
|
||||
expect(supportsCdnInstall('background-video')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for hls, whose media bundle ships a CDN build', () => {
|
||||
expect(supportsCdnInstall('hls')).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user