mirror of
https://github.com/zoriya/v10.git
synced 2026-08-14 18:04:49 +00:00
feat(cli): add @videojs/cli docs command for LLM-friendly installation (#1214)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
9681515446
commit
24b8b77c8a
@@ -0,0 +1,55 @@
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { dirname, join } from 'node:path';
|
||||
|
||||
const CONFIG_FILE = join(homedir(), '.videojs', 'config.json');
|
||||
|
||||
export type Framework = 'html' | 'react';
|
||||
|
||||
interface CliConfig {
|
||||
framework?: Framework;
|
||||
}
|
||||
|
||||
export function readConfig(): CliConfig {
|
||||
if (!existsSync(CONFIG_FILE)) return {};
|
||||
try {
|
||||
return JSON.parse(readFileSync(CONFIG_FILE, 'utf-8')) as CliConfig;
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function writeConfig(config: CliConfig): void {
|
||||
const dir = dirname(CONFIG_FILE);
|
||||
mkdirSync(dir, { recursive: true });
|
||||
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
||||
}
|
||||
|
||||
const VALID_CONFIG: Record<keyof CliConfig, readonly string[]> = {
|
||||
framework: ['html', 'react'],
|
||||
};
|
||||
|
||||
export function getConfigValue(key: string): string | undefined {
|
||||
if (!(key in VALID_CONFIG)) {
|
||||
throw new Error(`Unknown config key: "${key}". Valid keys: ${Object.keys(VALID_CONFIG).join(', ')}`);
|
||||
}
|
||||
const config = readConfig();
|
||||
return config[key as keyof CliConfig];
|
||||
}
|
||||
|
||||
export function setConfigValue(key: string, value: string): void {
|
||||
const validValues = VALID_CONFIG[key as keyof CliConfig];
|
||||
if (!validValues) {
|
||||
throw new Error(`Unknown config key: "${key}". Valid keys: ${Object.keys(VALID_CONFIG).join(', ')}`);
|
||||
}
|
||||
if (!validValues.includes(value)) {
|
||||
throw new Error(`Invalid value "${value}" for "${key}". Valid values: ${validValues.join(', ')}`);
|
||||
}
|
||||
const config = readConfig();
|
||||
(config as Record<string, string>)[key] = value;
|
||||
writeConfig(config);
|
||||
}
|
||||
|
||||
export function listConfig(): CliConfig {
|
||||
return readConfig();
|
||||
}
|
||||
Reference in New Issue
Block a user