0768e8fa29
- add Intl-backed locale definitions, formatters, catalog loaders, and runtime hooks\n- compile hashed production catalogs from package-scoped catalog sources\n- drive Lingui extraction and compilation directly from project JSON config\n- redesign the devtool with localized controls, draggable persistence, settings, navigation, copy actions, ANSI output, and fullscreen support\n- extend repository APIs, CLI coverage, documentation, and runtime tests
43 lines
972 B
TypeScript
43 lines
972 B
TypeScript
export type DevtoolAction = "compile" | "extract"
|
|
|
|
export interface DevtoolProject {
|
|
locales: readonly string[]
|
|
sourceLocale: string
|
|
}
|
|
|
|
interface ApiError {
|
|
error?: string
|
|
}
|
|
|
|
export async function requestDevtoolJson<T>(
|
|
url: string,
|
|
init?: RequestInit
|
|
): Promise<T> {
|
|
const response = await fetch(url, init)
|
|
const body = (await response.json()) as T & ApiError
|
|
|
|
if (!response.ok) {
|
|
throw new Error(body.error ?? `Request failed with ${response.status}.`)
|
|
}
|
|
|
|
return body
|
|
}
|
|
|
|
export async function runDevtoolAction(
|
|
action: DevtoolAction,
|
|
baseUrl = "/__i18n"
|
|
) {
|
|
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "")
|
|
|
|
return requestDevtoolJson<{ output: string }>(
|
|
`${normalizedBaseUrl}/actions/${action}`,
|
|
{ method: "POST" }
|
|
)
|
|
}
|
|
|
|
export async function requestDevtoolProject(baseUrl = "/__i18n") {
|
|
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "")
|
|
|
|
return requestDevtoolJson<DevtoolProject>(`${normalizedBaseUrl}/project`)
|
|
}
|