feat: M0 monorepo skeleton with services, clients, deploy and CI
ci / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 3m55s
ci / api (push) Successful in 51s
ci / mobile (Metro-бандл Android) (push) Canceled after 0s
release / images (services/api/Dockerfile, storage-agent, storage-agent) (push) Canceled after 0s
release / images (services/recommender/Dockerfile, recommender, ) (push) Canceled after 0s
ci / recommender (push) Successful in 1m11s
ci / ts (packages + web) (push) Canceled after 3s
release / verify (push) Successful in 1m16s
release / images (apps/web/Dockerfile, web, ) (push) Failing after 2m40s
release / android + release (push) Skipped
release / images (services/api/Dockerfile, api, api) (push) Canceled after 1s
ci / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 3m55s
ci / api (push) Successful in 51s
ci / mobile (Metro-бандл Android) (push) Canceled after 0s
release / images (services/api/Dockerfile, storage-agent, storage-agent) (push) Canceled after 0s
release / images (services/recommender/Dockerfile, recommender, ) (push) Canceled after 0s
ci / recommender (push) Successful in 1m11s
ci / ts (packages + web) (push) Canceled after 3s
release / verify (push) Successful in 1m16s
release / images (apps/web/Dockerfile, web, ) (push) Failing after 2m40s
release / android + release (push) Skipped
release / images (services/api/Dockerfile, api, api) (push) Canceled after 1s
- api/openapi.yaml: contract with /healthz, /readyz, /api/v1/server-info - services/api (Go): api with oapi-codegen strict server, goose migrations, readiness checks for Postgres/Redis; storage-agent stub with internal token - services/recommender (Python, uv): FastAPI health/readiness/internal status, `pipu-rec serve` and `pipu-rec analyze` entrypoints - packages: generated api-client, core (server URL + server check), i18n (ru/en + dictionary check), design-tokens (CSS vars + TS from tokens.json) - apps/web: Vite + React shell showing server status, language switch - apps/mobile: Expo (SDK 53) Android app with server connect screen - deploy: Dockerfiles, compose (prod + dev), nginx template, install/update scripts - .gitea/workflows: ci.yml and tag-based release.yml (images, signed APK, release) - scripts/version.mjs: version and Android versionCode from git tag - tests/fixtures/music/generate.sh: synthetic test library via ffmpeg - docs: versionCode formula, OpenAPI 3.0.3, dev instructions in README Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9eb1c25147
commit
ebf296542c
98 files changed
+12130
-4
No files matched your search
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@pipu/api-client",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"scripts": {
|
||||
"generate": "openapi-typescript ../../api/openapi.yaml -o src/generated/schema.ts",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"openapi-fetch": "^0.14.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"openapi-typescript": "^7.8.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* This file was auto-generated by openapi-typescript.
|
||||
* Do not make direct changes to the file.
|
||||
*/
|
||||
|
||||
export interface paths {
|
||||
"/healthz": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
/** Живость процесса */
|
||||
get: operations["getHealthz"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/readyz": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
/** Готовность обслуживать запросы (зависимости доступны) */
|
||||
get: operations["getReadyz"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/server-info": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
/**
|
||||
* Сведения о сервере для клиентов
|
||||
* @description Вызывается без аутентификации: веб и Android проверяют версию сервера,
|
||||
* совместимость клиента и поддерживаемые языки (экран подключения).
|
||||
*/
|
||||
get: operations["getServerInfo"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
}
|
||||
export type webhooks = Record<string, never>;
|
||||
export interface components {
|
||||
schemas: {
|
||||
HealthStatus: {
|
||||
/** @enum {string} */
|
||||
status: "ok";
|
||||
};
|
||||
ReadyStatus: {
|
||||
/** @enum {string} */
|
||||
status: "ok" | "degraded";
|
||||
/** @description Результат проверки каждой зависимости */
|
||||
checks: {
|
||||
[key: string]: string;
|
||||
};
|
||||
};
|
||||
ServerInfo: {
|
||||
/** @example pipu-music */
|
||||
name: string;
|
||||
/**
|
||||
* @description Версия сервера (SemVer)
|
||||
* @example 0.1.0
|
||||
*/
|
||||
version: string;
|
||||
/** @example v1 */
|
||||
api_version: string;
|
||||
/**
|
||||
* @example [
|
||||
* "ru",
|
||||
* "en"
|
||||
* ]
|
||||
*/
|
||||
supported_locales: string[];
|
||||
/**
|
||||
* @description Минимальный versionCode Android-приложения, которое поддерживает сервер
|
||||
* @example 10099
|
||||
*/
|
||||
min_android_version_code: number;
|
||||
};
|
||||
Problem: {
|
||||
/** @default about:blank */
|
||||
type: string;
|
||||
status: number;
|
||||
/** @description Машинный код ошибки для i18n, например `auth.invalid_credentials` */
|
||||
code: string;
|
||||
/** @description Пояснение для логов (не для показа пользователю) */
|
||||
detail?: string;
|
||||
params?: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description Ошибка (RFC 9457) */
|
||||
Problem: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/problem+json": components["schemas"]["Problem"];
|
||||
};
|
||||
};
|
||||
};
|
||||
parameters: never;
|
||||
requestBodies: never;
|
||||
headers: never;
|
||||
pathItems: never;
|
||||
}
|
||||
export type $defs = Record<string, never>;
|
||||
export interface operations {
|
||||
getHealthz: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Процесс жив */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["HealthStatus"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
getReadyz: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Все зависимости доступны */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["ReadyStatus"];
|
||||
};
|
||||
};
|
||||
/** @description Одна или несколько зависимостей недоступны */
|
||||
503: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["ReadyStatus"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
getServerInfo: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Сведения о сервере */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["ServerInfo"];
|
||||
};
|
||||
};
|
||||
default: components["responses"]["Problem"];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import createClient, { type Client } from 'openapi-fetch';
|
||||
|
||||
import type { components, paths } from './generated/schema';
|
||||
|
||||
export type { components, paths };
|
||||
export type ServerInfo = components['schemas']['ServerInfo'];
|
||||
export type Problem = components['schemas']['Problem'];
|
||||
export type ApiClient = Client<paths>;
|
||||
|
||||
export interface ApiClientOptions {
|
||||
/** Адрес сервера без завершающего слеша; пусто — тот же origin (веб). */
|
||||
baseUrl?: string;
|
||||
fetch?: typeof globalThis.fetch;
|
||||
}
|
||||
|
||||
/** Создаёт типизированный клиент публичного API (контракт — api/openapi.yaml). */
|
||||
export function createApiClient(opts: ApiClientOptions = {}): ApiClient {
|
||||
return createClient<paths>({ baseUrl: opts.baseUrl ?? '', fetch: opts.fetch });
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../../tsconfig.base.json", "compilerOptions": { "lib": ["ES2022", "DOM"] }, "include": ["src"] }
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@pipu/core",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pipu/api-client": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitest": "^3.2.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { checkServer, normalizeServerUrl, type ServerCheck } from './server';
|
||||
@@ -0,0 +1,59 @@
|
||||
import { createApiClient } from '@pipu/api-client';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { checkServer, normalizeServerUrl } from './server';
|
||||
|
||||
describe('normalizeServerUrl', () => {
|
||||
it.each([
|
||||
['music.home.lan', 'https://music.home.lan'],
|
||||
[' https://music.home.lan/ ', 'https://music.home.lan'],
|
||||
['http://192.168.1.10:8080', 'http://192.168.1.10:8080'],
|
||||
['https://home.lan/pipu//', 'https://home.lan/pipu'],
|
||||
])('%s → %s', (input, expected) => {
|
||||
expect(normalizeServerUrl(input)).toBe(expected);
|
||||
});
|
||||
|
||||
it.each(['', ' ', 'ftp://music.home.lan', 'https://'])('rejects %j', (input) => {
|
||||
expect(normalizeServerUrl(input)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
const info = {
|
||||
name: 'pipu-music',
|
||||
version: '0.1.0',
|
||||
api_version: 'v1',
|
||||
supported_locales: ['ru', 'en'],
|
||||
min_android_version_code: 100,
|
||||
};
|
||||
|
||||
function clientReturning(response: () => Response | Promise<Response>) {
|
||||
return createApiClient({ baseUrl: 'https://music.test', fetch: async () => response() });
|
||||
}
|
||||
|
||||
const json = (body: unknown, status = 200) =>
|
||||
new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } });
|
||||
|
||||
describe('checkServer', () => {
|
||||
it('reports ok for a compatible server', async () => {
|
||||
await expect(checkServer(clientReturning(() => json(info)), 100)).resolves.toEqual({ status: 'ok', info });
|
||||
});
|
||||
|
||||
it('reports unsupported_app when the app is too old', async () => {
|
||||
const res = await checkServer(clientReturning(() => json(info)), 99);
|
||||
expect(res.status).toBe('unsupported_app');
|
||||
});
|
||||
|
||||
it('reports offline on network errors', async () => {
|
||||
const res = await checkServer(
|
||||
clientReturning(() => {
|
||||
throw new TypeError('Failed to fetch');
|
||||
}),
|
||||
);
|
||||
expect(res).toEqual({ status: 'offline', error: 'Failed to fetch' });
|
||||
});
|
||||
|
||||
it('reports offline with the problem code on API errors', async () => {
|
||||
const res = await checkServer(clientReturning(() => json({ status: 500, code: 'common.internal' }, 500)));
|
||||
expect(res).toEqual({ status: 'offline', error: 'common.internal' });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { ApiClient, ServerInfo } from '@pipu/api-client';
|
||||
|
||||
/**
|
||||
* Приводит введённый пользователем адрес сервера к виду `https://host[:port][/path]` без завершающего слеша.
|
||||
* Без схемы подставляется https. Возвращает null, если адрес некорректен.
|
||||
*/
|
||||
export function normalizeServerUrl(input: string): string | null {
|
||||
const raw = input.trim();
|
||||
if (!raw) return null;
|
||||
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw) ? raw : `https://${raw}`;
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(withScheme);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (url.protocol !== 'https:' && url.protocol !== 'http:') return null;
|
||||
if (!url.hostname) return null;
|
||||
const path = url.pathname.replace(/\/+$/, '');
|
||||
return `${url.protocol}//${url.host}${path}`;
|
||||
}
|
||||
|
||||
export type ServerCheck =
|
||||
| { status: 'ok'; info: ServerInfo }
|
||||
| { status: 'unsupported_app'; info: ServerInfo }
|
||||
| { status: 'offline'; error: string };
|
||||
|
||||
/**
|
||||
* Проверяет сервер через GET /api/v1/server-info.
|
||||
* appVersionCode — versionCode Android-клиента; для веба не передаётся.
|
||||
*/
|
||||
export async function checkServer(client: ApiClient, appVersionCode?: number): Promise<ServerCheck> {
|
||||
try {
|
||||
const { data, error } = await client.GET('/api/v1/server-info');
|
||||
if (!data) return { status: 'offline', error: error ? error.code : 'unknown' };
|
||||
if (appVersionCode !== undefined && appVersionCode < data.min_android_version_code) {
|
||||
return { status: 'unsupported_app', info: data };
|
||||
}
|
||||
return { status: 'ok', info: data };
|
||||
} catch (e) {
|
||||
return { status: 'offline', error: e instanceof Error ? e.message : String(e) };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../../tsconfig.base.json", "compilerOptions": { "lib": ["ES2022", "DOM"] }, "include": ["src"] }
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "@pipu/design-tokens",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./tokens.css": "./src/generated/tokens.css"
|
||||
},
|
||||
"scripts": {
|
||||
"generate": "node scripts/build.mjs",
|
||||
"typecheck": "tsc --noEmit"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Генерирует CSS-переменные (веб) и TS-объект (React Native) из tokens.json.
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const t = JSON.parse(readFileSync(join(root, 'tokens.json'), 'utf8'));
|
||||
const out = join(root, 'src', 'generated');
|
||||
mkdirSync(out, { recursive: true });
|
||||
|
||||
const vars = (theme) =>
|
||||
Object.entries({ ...t.color[theme], ...t.effect[theme] })
|
||||
.map(([k, v]) => ` --${k}: ${v};`)
|
||||
.join('\n');
|
||||
const common = [
|
||||
...Object.entries(t.radius).map(([k, v]) => ` --radius-${k}: ${v}px;`),
|
||||
...Object.entries(t.wave).map(([k, v]) => ` --wave-${k}: ${v};`),
|
||||
` --font-display: '${t.font.display}', system-ui, sans-serif;`,
|
||||
` --font-body: '${t.font.body}', system-ui, sans-serif;`,
|
||||
` --font-mono: '${t.font.mono}', ui-monospace, monospace;`,
|
||||
].join('\n');
|
||||
|
||||
const header = '/* Сгенерировано scripts/build.mjs из tokens.json — не редактировать. */\n';
|
||||
const css = `${header}:root {\n${common}\n${vars('dark')}\n}\n
|
||||
@media (prefers-color-scheme: light) {\n :root:not([data-theme='dark']) {\n${vars('light').replace(/^/gm, ' ')}\n }\n}\n
|
||||
:root[data-theme='light'] {\n${vars('light')}\n}\n
|
||||
:root[data-theme='dark'] {\n${vars('dark')}\n}\n`;
|
||||
writeFileSync(join(out, 'tokens.css'), css);
|
||||
|
||||
const ts = `${header}export const tokens = ${JSON.stringify(
|
||||
{ color: t.color, effect: t.effect, wave: t.wave, radius: t.radius, font: t.font },
|
||||
null,
|
||||
2,
|
||||
)} as const;\n`;
|
||||
writeFileSync(join(out, 'tokens.ts'), ts);
|
||||
console.log('design-tokens: generated tokens.css, tokens.ts');
|
||||
@@ -0,0 +1,145 @@
|
||||
/* Сгенерировано scripts/build.mjs из tokens.json — не редактировать. */
|
||||
:root {
|
||||
--radius-sm: 8px;
|
||||
--radius-md: 12px;
|
||||
--radius-lg: 16px;
|
||||
--radius-xl: 24px;
|
||||
--radius-pill: 999px;
|
||||
--wave-color1: #2F80FF;
|
||||
--wave-color2: #7C5CFF;
|
||||
--wave-color3: #35D3FF;
|
||||
--font-display: 'Unbounded', system-ui, sans-serif;
|
||||
--font-body: 'Onest', system-ui, sans-serif;
|
||||
--font-mono: 'JetBrains Mono', ui-monospace, monospace;
|
||||
--bg: #05070D;
|
||||
--bg2: #080B14;
|
||||
--surface: #0B0F1A;
|
||||
--surface2: #121827;
|
||||
--surface3: #1A2236;
|
||||
--elev: #111726;
|
||||
--hover: rgba(120,150,255,.07);
|
||||
--line: rgba(130,160,255,.10);
|
||||
--line2: rgba(130,160,255,.18);
|
||||
--text: #EDF1FF;
|
||||
--text2: #A0ABC6;
|
||||
--text3: #737F9C;
|
||||
--accent: #2F80FF;
|
||||
--accent2: #5E9BFF;
|
||||
--accent-soft: rgba(47,128,255,.15);
|
||||
--violet: #9B7CFF;
|
||||
--violet-soft: rgba(124,92,255,.16);
|
||||
--ok: #2FD39A;
|
||||
--ok-soft: rgba(47,211,154,.14);
|
||||
--warn: #FFB547;
|
||||
--warn-soft: rgba(255,181,71,.14);
|
||||
--danger: #FF5C70;
|
||||
--danger-soft: rgba(255,92,112,.14);
|
||||
--overlay: rgba(3,5,10,.66);
|
||||
--glass: rgba(12,16,28,.78);
|
||||
--surface-a: rgba(11,15,26,.70);
|
||||
--bar-a: rgba(6,9,16,.55);
|
||||
--shadow: 0 24px 64px rgba(0,0,0,.55);
|
||||
--glow: 0 8px 28px rgba(47,128,255,.38);
|
||||
--amb-op: .8;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root:not([data-theme='dark']) {
|
||||
--bg: #F3F5FA;
|
||||
--bg2: #EBEEF5;
|
||||
--surface: #FFFFFF;
|
||||
--surface2: #F0F3F9;
|
||||
--surface3: #E4E9F3;
|
||||
--elev: #FFFFFF;
|
||||
--hover: rgba(30,60,140,.06);
|
||||
--line: rgba(20,35,80,.10);
|
||||
--line2: rgba(20,35,80,.17);
|
||||
--text: #0A0F1E;
|
||||
--text2: #4B5675;
|
||||
--text3: #677290;
|
||||
--accent: #1F6FF2;
|
||||
--accent2: #1F6FF2;
|
||||
--accent-soft: rgba(31,111,242,.10);
|
||||
--violet: #6A47F0;
|
||||
--violet-soft: rgba(106,71,240,.10);
|
||||
--ok: #0E9465;
|
||||
--ok-soft: rgba(14,148,101,.10);
|
||||
--warn: #A86200;
|
||||
--warn-soft: rgba(168,98,0,.10);
|
||||
--danger: #D32F47;
|
||||
--danger-soft: rgba(211,47,71,.09);
|
||||
--overlay: rgba(20,30,60,.32);
|
||||
--glass: rgba(255,255,255,.84);
|
||||
--surface-a: rgba(255,255,255,.74);
|
||||
--bar-a: rgba(255,255,255,.55);
|
||||
--shadow: 0 24px 64px rgba(20,30,60,.18);
|
||||
--glow: 0 8px 24px rgba(31,111,242,.28);
|
||||
--amb-op: .45;
|
||||
}
|
||||
}
|
||||
|
||||
:root[data-theme='light'] {
|
||||
--bg: #F3F5FA;
|
||||
--bg2: #EBEEF5;
|
||||
--surface: #FFFFFF;
|
||||
--surface2: #F0F3F9;
|
||||
--surface3: #E4E9F3;
|
||||
--elev: #FFFFFF;
|
||||
--hover: rgba(30,60,140,.06);
|
||||
--line: rgba(20,35,80,.10);
|
||||
--line2: rgba(20,35,80,.17);
|
||||
--text: #0A0F1E;
|
||||
--text2: #4B5675;
|
||||
--text3: #677290;
|
||||
--accent: #1F6FF2;
|
||||
--accent2: #1F6FF2;
|
||||
--accent-soft: rgba(31,111,242,.10);
|
||||
--violet: #6A47F0;
|
||||
--violet-soft: rgba(106,71,240,.10);
|
||||
--ok: #0E9465;
|
||||
--ok-soft: rgba(14,148,101,.10);
|
||||
--warn: #A86200;
|
||||
--warn-soft: rgba(168,98,0,.10);
|
||||
--danger: #D32F47;
|
||||
--danger-soft: rgba(211,47,71,.09);
|
||||
--overlay: rgba(20,30,60,.32);
|
||||
--glass: rgba(255,255,255,.84);
|
||||
--surface-a: rgba(255,255,255,.74);
|
||||
--bar-a: rgba(255,255,255,.55);
|
||||
--shadow: 0 24px 64px rgba(20,30,60,.18);
|
||||
--glow: 0 8px 24px rgba(31,111,242,.28);
|
||||
--amb-op: .45;
|
||||
}
|
||||
|
||||
:root[data-theme='dark'] {
|
||||
--bg: #05070D;
|
||||
--bg2: #080B14;
|
||||
--surface: #0B0F1A;
|
||||
--surface2: #121827;
|
||||
--surface3: #1A2236;
|
||||
--elev: #111726;
|
||||
--hover: rgba(120,150,255,.07);
|
||||
--line: rgba(130,160,255,.10);
|
||||
--line2: rgba(130,160,255,.18);
|
||||
--text: #EDF1FF;
|
||||
--text2: #A0ABC6;
|
||||
--text3: #737F9C;
|
||||
--accent: #2F80FF;
|
||||
--accent2: #5E9BFF;
|
||||
--accent-soft: rgba(47,128,255,.15);
|
||||
--violet: #9B7CFF;
|
||||
--violet-soft: rgba(124,92,255,.16);
|
||||
--ok: #2FD39A;
|
||||
--ok-soft: rgba(47,211,154,.14);
|
||||
--warn: #FFB547;
|
||||
--warn-soft: rgba(255,181,71,.14);
|
||||
--danger: #FF5C70;
|
||||
--danger-soft: rgba(255,92,112,.14);
|
||||
--overlay: rgba(3,5,10,.66);
|
||||
--glass: rgba(12,16,28,.78);
|
||||
--surface-a: rgba(11,15,26,.70);
|
||||
--bar-a: rgba(6,9,16,.55);
|
||||
--shadow: 0 24px 64px rgba(0,0,0,.55);
|
||||
--glow: 0 8px 28px rgba(47,128,255,.38);
|
||||
--amb-op: .8;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/* Сгенерировано scripts/build.mjs из tokens.json — не редактировать. */
|
||||
export const tokens = {
|
||||
"color": {
|
||||
"dark": {
|
||||
"bg": "#05070D",
|
||||
"bg2": "#080B14",
|
||||
"surface": "#0B0F1A",
|
||||
"surface2": "#121827",
|
||||
"surface3": "#1A2236",
|
||||
"elev": "#111726",
|
||||
"hover": "rgba(120,150,255,.07)",
|
||||
"line": "rgba(130,160,255,.10)",
|
||||
"line2": "rgba(130,160,255,.18)",
|
||||
"text": "#EDF1FF",
|
||||
"text2": "#A0ABC6",
|
||||
"text3": "#737F9C",
|
||||
"accent": "#2F80FF",
|
||||
"accent2": "#5E9BFF",
|
||||
"accent-soft": "rgba(47,128,255,.15)",
|
||||
"violet": "#9B7CFF",
|
||||
"violet-soft": "rgba(124,92,255,.16)",
|
||||
"ok": "#2FD39A",
|
||||
"ok-soft": "rgba(47,211,154,.14)",
|
||||
"warn": "#FFB547",
|
||||
"warn-soft": "rgba(255,181,71,.14)",
|
||||
"danger": "#FF5C70",
|
||||
"danger-soft": "rgba(255,92,112,.14)",
|
||||
"overlay": "rgba(3,5,10,.66)",
|
||||
"glass": "rgba(12,16,28,.78)",
|
||||
"surface-a": "rgba(11,15,26,.70)",
|
||||
"bar-a": "rgba(6,9,16,.55)"
|
||||
},
|
||||
"light": {
|
||||
"bg": "#F3F5FA",
|
||||
"bg2": "#EBEEF5",
|
||||
"surface": "#FFFFFF",
|
||||
"surface2": "#F0F3F9",
|
||||
"surface3": "#E4E9F3",
|
||||
"elev": "#FFFFFF",
|
||||
"hover": "rgba(30,60,140,.06)",
|
||||
"line": "rgba(20,35,80,.10)",
|
||||
"line2": "rgba(20,35,80,.17)",
|
||||
"text": "#0A0F1E",
|
||||
"text2": "#4B5675",
|
||||
"text3": "#677290",
|
||||
"accent": "#1F6FF2",
|
||||
"accent2": "#1F6FF2",
|
||||
"accent-soft": "rgba(31,111,242,.10)",
|
||||
"violet": "#6A47F0",
|
||||
"violet-soft": "rgba(106,71,240,.10)",
|
||||
"ok": "#0E9465",
|
||||
"ok-soft": "rgba(14,148,101,.10)",
|
||||
"warn": "#A86200",
|
||||
"warn-soft": "rgba(168,98,0,.10)",
|
||||
"danger": "#D32F47",
|
||||
"danger-soft": "rgba(211,47,71,.09)",
|
||||
"overlay": "rgba(20,30,60,.32)",
|
||||
"glass": "rgba(255,255,255,.84)",
|
||||
"surface-a": "rgba(255,255,255,.74)",
|
||||
"bar-a": "rgba(255,255,255,.55)"
|
||||
}
|
||||
},
|
||||
"effect": {
|
||||
"dark": {
|
||||
"shadow": "0 24px 64px rgba(0,0,0,.55)",
|
||||
"glow": "0 8px 28px rgba(47,128,255,.38)",
|
||||
"amb-op": ".8"
|
||||
},
|
||||
"light": {
|
||||
"shadow": "0 24px 64px rgba(20,30,60,.18)",
|
||||
"glow": "0 8px 24px rgba(31,111,242,.28)",
|
||||
"amb-op": ".45"
|
||||
}
|
||||
},
|
||||
"wave": {
|
||||
"color1": "#2F80FF",
|
||||
"color2": "#7C5CFF",
|
||||
"color3": "#35D3FF"
|
||||
},
|
||||
"radius": {
|
||||
"sm": 8,
|
||||
"md": 12,
|
||||
"lg": 16,
|
||||
"xl": 24,
|
||||
"pill": 999
|
||||
},
|
||||
"font": {
|
||||
"display": "Unbounded",
|
||||
"body": "Onest",
|
||||
"mono": "JetBrains Mono"
|
||||
}
|
||||
} as const;
|
||||
@@ -0,0 +1,3 @@
|
||||
export { tokens } from './generated/tokens';
|
||||
|
||||
export type ThemeName = 'dark' | 'light';
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"$comment": "Источник истины дизайн-токенов (docs/design.md). После правки: pnpm --filter @pipu/design-tokens generate",
|
||||
"color": {
|
||||
"dark": {
|
||||
"bg": "#05070D", "bg2": "#080B14", "surface": "#0B0F1A", "surface2": "#121827", "surface3": "#1A2236",
|
||||
"elev": "#111726", "hover": "rgba(120,150,255,.07)", "line": "rgba(130,160,255,.10)", "line2": "rgba(130,160,255,.18)",
|
||||
"text": "#EDF1FF", "text2": "#A0ABC6", "text3": "#737F9C",
|
||||
"accent": "#2F80FF", "accent2": "#5E9BFF", "accent-soft": "rgba(47,128,255,.15)",
|
||||
"violet": "#9B7CFF", "violet-soft": "rgba(124,92,255,.16)",
|
||||
"ok": "#2FD39A", "ok-soft": "rgba(47,211,154,.14)", "warn": "#FFB547", "warn-soft": "rgba(255,181,71,.14)",
|
||||
"danger": "#FF5C70", "danger-soft": "rgba(255,92,112,.14)",
|
||||
"overlay": "rgba(3,5,10,.66)", "glass": "rgba(12,16,28,.78)", "surface-a": "rgba(11,15,26,.70)", "bar-a": "rgba(6,9,16,.55)"
|
||||
},
|
||||
"light": {
|
||||
"bg": "#F3F5FA", "bg2": "#EBEEF5", "surface": "#FFFFFF", "surface2": "#F0F3F9", "surface3": "#E4E9F3",
|
||||
"elev": "#FFFFFF", "hover": "rgba(30,60,140,.06)", "line": "rgba(20,35,80,.10)", "line2": "rgba(20,35,80,.17)",
|
||||
"text": "#0A0F1E", "text2": "#4B5675", "text3": "#677290",
|
||||
"accent": "#1F6FF2", "accent2": "#1F6FF2", "accent-soft": "rgba(31,111,242,.10)",
|
||||
"violet": "#6A47F0", "violet-soft": "rgba(106,71,240,.10)",
|
||||
"ok": "#0E9465", "ok-soft": "rgba(14,148,101,.10)", "warn": "#A86200", "warn-soft": "rgba(168,98,0,.10)",
|
||||
"danger": "#D32F47", "danger-soft": "rgba(211,47,71,.09)",
|
||||
"overlay": "rgba(20,30,60,.32)", "glass": "rgba(255,255,255,.84)", "surface-a": "rgba(255,255,255,.74)", "bar-a": "rgba(255,255,255,.55)"
|
||||
}
|
||||
},
|
||||
"effect": {
|
||||
"dark": { "shadow": "0 24px 64px rgba(0,0,0,.55)", "glow": "0 8px 28px rgba(47,128,255,.38)", "amb-op": ".8" },
|
||||
"light": { "shadow": "0 24px 64px rgba(20,30,60,.18)", "glow": "0 8px 24px rgba(31,111,242,.28)", "amb-op": ".45" }
|
||||
},
|
||||
"wave": { "color1": "#2F80FF", "color2": "#7C5CFF", "color3": "#35D3FF" },
|
||||
"radius": { "sm": 8, "md": 12, "lg": 16, "xl": 24, "pill": 999 },
|
||||
"font": { "display": "Unbounded", "body": "Onest", "mono": "JetBrains Mono" }
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../../tsconfig.base.json", "include": ["src"] }
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"app": {
|
||||
"name": "pipu",
|
||||
"tagline": "Your music from your own server"
|
||||
},
|
||||
"server": {
|
||||
"title": "Server",
|
||||
"checking": "Checking the server…",
|
||||
"online": "Server {{version}} is online",
|
||||
"offline": "The server is not responding. Check the address and your network.",
|
||||
"address": "Server address",
|
||||
"check": "Check",
|
||||
"invalid_address": "Enter the server address, e.g. https://music.home.lan",
|
||||
"unsupported_app": "This app version is too old for the server — please update the app"
|
||||
},
|
||||
"language": {
|
||||
"label": "Language",
|
||||
"ru": "Русский",
|
||||
"en": "English"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"app": {
|
||||
"name": "pipu",
|
||||
"tagline": "Ваша музыка с вашего сервера"
|
||||
},
|
||||
"server": {
|
||||
"title": "Сервер",
|
||||
"checking": "Проверяем сервер…",
|
||||
"online": "Сервер {{version}} на связи",
|
||||
"offline": "Сервер не отвечает. Проверьте адрес и сеть.",
|
||||
"address": "Адрес сервера",
|
||||
"check": "Проверить",
|
||||
"invalid_address": "Введите адрес сервера, например https://music.home.lan",
|
||||
"unsupported_app": "Эта версия приложения слишком старая для сервера — обновите приложение"
|
||||
},
|
||||
"language": {
|
||||
"label": "Язык",
|
||||
"ru": "Русский",
|
||||
"en": "English"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@pipu/i18n",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"scripts": {
|
||||
"check": "node scripts/check.mjs",
|
||||
"test": "node scripts/check.mjs",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"i18next": "^25.2.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Проверяет словари: одинаковые ключи во всех языках и совпадение плейсхолдеров {{...}}.
|
||||
import { readdirSync, readFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const dir = join(dirname(fileURLToPath(import.meta.url)), '..', 'locales');
|
||||
const locales = readdirSync(dir);
|
||||
const flat = (obj, prefix = '') =>
|
||||
Object.entries(obj).flatMap(([k, v]) =>
|
||||
typeof v === 'object' ? flat(v, `${prefix}${k}.`) : [[`${prefix}${k}`, String(v)]],
|
||||
);
|
||||
const placeholders = (s) => [...s.matchAll(/\{\{\s*(\w+)\s*\}\}/g)].map((m) => m[1]).sort().join(',');
|
||||
|
||||
const data = {};
|
||||
for (const loc of locales) {
|
||||
for (const file of readdirSync(join(dir, loc))) {
|
||||
const ns = file.replace(/\.json$/, '');
|
||||
for (const [k, v] of flat(JSON.parse(readFileSync(join(dir, loc, file), 'utf8')))) {
|
||||
(data[`${ns}:${k}`] ??= {})[loc] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const errors = [];
|
||||
for (const [key, byLoc] of Object.entries(data)) {
|
||||
for (const loc of locales) {
|
||||
if (!(loc in byLoc)) errors.push(`${loc}: отсутствует ключ ${key}`);
|
||||
}
|
||||
const sets = new Set(Object.values(byLoc).map(placeholders));
|
||||
if (sets.size > 1) errors.push(`${key}: плейсхолдеры различаются между языками`);
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(errors.join('\n'));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`i18n: ${Object.keys(data).length} ключей × ${locales.length} языка — ок`);
|
||||
@@ -0,0 +1,47 @@
|
||||
import i18next, { type i18n as I18n } from 'i18next';
|
||||
|
||||
import enCommon from '../locales/en/common.json';
|
||||
import ruCommon from '../locales/ru/common.json';
|
||||
|
||||
/** Поддерживаемые языки. Новый язык = папка в locales/ + строка здесь. */
|
||||
export const SUPPORTED_LOCALES = ['ru', 'en'] as const;
|
||||
export type Locale = (typeof SUPPORTED_LOCALES)[number];
|
||||
export const DEFAULT_LOCALE: Locale = 'en';
|
||||
|
||||
export const resources = {
|
||||
ru: { common: ruCommon },
|
||||
en: { common: enCommon },
|
||||
} as const;
|
||||
|
||||
declare module 'i18next' {
|
||||
interface CustomTypeOptions {
|
||||
defaultNS: 'common';
|
||||
resources: (typeof resources)['ru'];
|
||||
}
|
||||
}
|
||||
|
||||
/** Выбирает поддерживаемый язык из списка предпочтений (navigator.languages, настройки ОС). */
|
||||
export function pickLocale(preferred: readonly string[]): Locale {
|
||||
for (const tag of preferred) {
|
||||
const base = tag.toLowerCase().split('-')[0];
|
||||
const match = SUPPORTED_LOCALES.find((l) => l === base);
|
||||
if (match) return match;
|
||||
}
|
||||
return DEFAULT_LOCALE;
|
||||
}
|
||||
|
||||
/** Создаёт и инициализирует экземпляр i18next. */
|
||||
export async function createI18n(locale: Locale): Promise<I18n> {
|
||||
const instance = i18next.createInstance();
|
||||
await instance.init({
|
||||
lng: locale,
|
||||
fallbackLng: DEFAULT_LOCALE,
|
||||
supportedLngs: [...SUPPORTED_LOCALES],
|
||||
defaultNS: 'common',
|
||||
ns: ['common'],
|
||||
resources,
|
||||
interpolation: { escapeValue: false },
|
||||
returnNull: false,
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../../tsconfig.base.json", "include": ["src", "locales"] }
|
||||
Reference in new issue
Block a user