Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Environment variable files with local overrides.
/.env*.local

# Superset configuration for agentic tasks.
/.superset/

# Developement logs generated by pm2.
/logs/**/*.log

Expand Down
4 changes: 2 additions & 2 deletions apps/admin/fly.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.

app = "animeaux-admin-3ac2"
primary_region = "ams"
primary_region = "cdg"
kill_signal = "SIGINT"
kill_timeout = "5s"
swap_size_mb = 512
Expand Down Expand Up @@ -36,7 +36,7 @@ swap_size_mb = 512

[[services.http_checks]]
interval = "1m"
timeout = "2s"
timeout = "5s"
grace_period = "1m"
restart_limit = 0
method = "get"
Expand Down
3 changes: 1 addition & 2 deletions apps/admin/scripts/generate-icon-sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { mkdir, readdir, readFile, writeFile } from "node:fs/promises"
import { basename, dirname, join, relative, resolve } from "node:path"
import { fileURLToPath } from "node:url"

import { relativeToCwd, safelyReadFile } from "@animeaux/dev-tools"
import { watch } from "chokidar"
import { parse } from "node-html-parser"

import { relativeToCwd, safelyReadFile } from "./shared.js"

const FILENAME = fileURLToPath(import.meta.url)
const DIRNAME = dirname(FILENAME)
const SCRIPT_NAME = relativeToCwd(FILENAME)
Expand Down
103 changes: 8 additions & 95 deletions apps/admin/scripts/generate-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { mkdir, readFile, writeFile } from "node:fs/promises"
import { dirname, resolve } from "node:path"
import { fileURLToPath } from "node:url"

import {
formatBreakpoints,
formatSpacing,
relativeToCwd,
safelyReadFile,
} from "@animeaux/dev-tools"
import { __unstable__loadDesignSystem as loadDesignSystem } from "@tailwindcss/node"
import { orderBy } from "es-toolkit/array"
import type { __unstable__loadDesignSystem as loadDesignSystemBase } from "tailwindcss"
import invariant from "tiny-invariant"

import { relativeToCwd, safelyReadFile } from "./shared.js"

const FILENAME = fileURLToPath(import.meta.url)
const DIRNAME = dirname(FILENAME)
Expand All @@ -17,14 +19,6 @@ const MAIN_STYLE_FILE = resolve(STYLES_DIRECTORY, "main.css")
const DEST_DIRECTORY = resolve(DIRNAME, "../src/generated")
const DEST_FILE = resolve(DEST_DIRECTORY, "theme.ts")

/**
* Matches values for the `<length>` CSS type.
* We only support unitless `0`, rem and px.
*
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/length
*/
const CSS_LENGTH_REGEXP = /(?<value>-?\d*\.?\d+)(?<unit>.*)/

console.log("Building...")

const mainCss = await readFile(MAIN_STYLE_FILE, "utf-8")
Expand All @@ -40,11 +34,11 @@ const design = (await loadDesignSystem(mainCss, {
await mkdir(DEST_DIRECTORY, { recursive: true })

const content = `// This file is generated by ${SCRIPT_NAME}
${getBreakpoints()}
${formatBreakpoints(design.theme.namespace("--breakpoint"))}

${getColors()}

${getSpacing()}
${formatSpacing(design.theme.namespace("--spacing"))}
`

const currentContent = await safelyReadFile(DEST_FILE)
Expand All @@ -59,36 +53,6 @@ if (currentContent === content) {
await writeFile(DEST_FILE, content)
console.info(`Built theme (${relativeToCwd(DEST_FILE)})`)

function getBreakpoints() {
const breakpoints = design.theme.namespace("--breakpoint")

const sortedEntries = orderBy(
Array.from(breakpoints.entries())
// `null` is used as key for a property with the namespace's name (e.g.
// `--breakpoint: <value>`).
// For breakpoints this shouldn't happen.
.filter((entry): entry is [string, string] => entry[0] != null)
.map(
([breakpoint, length]) =>
[breakpoint, getLengthValuePx(length)] as const,
),
[([_breakpoint, valuePx]) => valuePx],
["desc"],
)

return `export type Breakpoint = typeof Breakpoint.names[number]

export namespace Breakpoint {
/** Breakpoint names sorted by descending value. */
export const names = ${JSON.stringify(
sortedEntries.map(([breakpoint]) => breakpoint),
)} as const

/** Breakpoint values in pixels. */
export const value = ${JSON.stringify(Object.fromEntries(sortedEntries), null, 2)} as const
}`
}

function getColors() {
const colors = design.theme.namespace("--color")

Expand All @@ -97,54 +61,3 @@ function getColors() {
export const white = ${JSON.stringify(colors.get("white"))}
}`
}

function getSpacing() {
const spacings = design.theme.namespace("--spacing")

// A property with the namespace's name has `null` as key. (e.g.
// `--spacing: <value>`).
const spacing = spacings.get(null)

invariant(spacing != null, "A `--spacing` definition is missing in the theme")

return `export namespace Spacing {
export const unitPx = ${getLengthValuePx(spacing)}
}`
}

/**
* Returns the given CSS length in pixels.
*
* @param length expressed with the `<length>` CSS type.
* @returns The value in pixels
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/length
*/
function getLengthValuePx(length: string) {
length = length.trim()

const match = length.match(CSS_LENGTH_REGEXP)

if (match == null || match?.groups?.value == null) {
throw new Error(`Invalid CSS length from theme: "${length}"`)
}

const value = Number(match.groups.value)

// The unit is optional when the value is `0`.
// See https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/length#syntax
const unit = match.groups.unit || "px"

switch (unit) {
case "px": {
return value
}

case "rem": {
return 16 * value
}

default: {
throw new Error(`Unsupported length unit: "${unit}" in "${length}"`)
}
}
}
14 changes: 4 additions & 10 deletions apps/show/fly.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.

app = "animeaux-show-3ac2"
primary_region = "ams"
primary_region = "cdg"
kill_signal = "SIGINT"
kill_timeout = "5s"

Expand Down Expand Up @@ -33,16 +33,10 @@ kill_timeout = "5s"
hard_limit = 100
soft_limit = 80

[[services.tcp_checks]]
interval = "15s"
timeout = "2s"
grace_period = "1s"
restart_limit = 0

[[services.http_checks]]
interval = "10s"
timeout = "2s"
grace_period = "5s"
interval = "1m"
timeout = "5s"
grace_period = "1m"
restart_limit = 0
method = "get"
path = "/healthcheck"
Expand Down
7 changes: 5 additions & 2 deletions apps/show/scripts/generate-icon-sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { mkdir, readdir, readFile, writeFile } from "node:fs/promises"
import { basename, dirname, join, relative, resolve } from "node:path"
import { fileURLToPath } from "node:url"

import {
oneAtTheTime,
relativeToCwd,
safelyReadFile,
} from "@animeaux/dev-tools"
import { watch } from "chokidar"
import { parse } from "node-html-parser"

import { oneAtTheTime, relativeToCwd, safelyReadFile } from "./shared.js"

const FILENAME = fileURLToPath(import.meta.url)
const DIRNAME = dirname(FILENAME)
const SCRIPT_NAME = relativeToCwd(FILENAME)
Expand Down
7 changes: 5 additions & 2 deletions apps/show/scripts/generate-pictogram-sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { mkdir, readdir, readFile, writeFile } from "node:fs/promises"
import { basename, dirname, join, relative, resolve } from "node:path"
import { fileURLToPath } from "node:url"

import {
oneAtTheTime,
relativeToCwd,
safelyReadFile,
} from "@animeaux/dev-tools"
import { watch } from "chokidar"
import { parse } from "node-html-parser"

import { oneAtTheTime, relativeToCwd, safelyReadFile } from "./shared.js"

const FILENAME = fileURLToPath(import.meta.url)
const DIRNAME = dirname(FILENAME)
const SCRIPT_NAME = relativeToCwd(FILENAME)
Expand Down
105 changes: 9 additions & 96 deletions apps/show/scripts/generate-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { mkdir, readFile, writeFile } from "node:fs/promises"
import { dirname, resolve } from "node:path"
import { fileURLToPath } from "node:url"

import {
formatBreakpoints,
formatSpacing,
relativeToCwd,
safelyReadFile,
} from "@animeaux/dev-tools"
import { __unstable__loadDesignSystem as loadDesignSystem } from "@tailwindcss/node"
import { formatHex } from "culori"
import { orderBy } from "es-toolkit/array"
import type { __unstable__loadDesignSystem as loadDesignSystemBase } from "tailwindcss"
import invariant from "tiny-invariant"

import { relativeToCwd, safelyReadFile } from "./shared.js"

const FILENAME = fileURLToPath(import.meta.url)
const DIRNAME = dirname(FILENAME)
const SCRIPT_NAME = relativeToCwd(FILENAME)
Expand Down Expand Up @@ -37,13 +40,13 @@ const design = (await loadDesignSystem(mainCss, {
await mkdir(DEST_DIRECTORY, { recursive: true })

const content = `// This file is generated by ${SCRIPT_NAME}
${getBreakpoints()}
${formatBreakpoints(design.theme.namespace("--breakpoint"))}

${getFonts()}

${getColors()}

${getSpacing()}
${formatSpacing(design.theme.namespace("--spacing"))}
`

const currentContent = await safelyReadFile(DEST_FILE)
Expand All @@ -58,36 +61,6 @@ if (currentContent === content) {
await writeFile(DEST_FILE, content)
console.info(`Built theme (${relativeToCwd(DEST_FILE)})`)

function getBreakpoints() {
const breakpoints = design.theme.namespace("--breakpoint")

const sortedEntries = orderBy(
Array.from(breakpoints.entries())
// `null` is used as key for a property with the namespace's name (e.g.
// `--breakpoint: <value>`).
// For breakpoints this shouldn't happen.
.filter((entry): entry is [string, string] => entry[0] != null)
.map(
([breakpoint, length]) =>
[breakpoint, getLengthValuePx(length)] as const,
),
[([_breakpoint, valuePx]) => valuePx],
["desc"],
)

return `export type Breakpoint = typeof Breakpoint.names[number]

export namespace Breakpoint {
/** Breakpoint names sorted by descending value. */
export const names = ${JSON.stringify(
sortedEntries.map(([breakpoint]) => breakpoint),
)} as const

/** Breakpoint values in pixels. */
export const value = ${JSON.stringify(Object.fromEntries(sortedEntries), null, 2)} as const
}`
}

function getColors() {
const colors = design.theme.namespace("--color")

Expand Down Expand Up @@ -121,7 +94,7 @@ function getFonts() {
export const sans = ${JSON.stringify(sans, null, 2)} as const

export const serif = ${JSON.stringify(serif, null, 2)} as const

export const all = [sans, serif]
}`
}
Expand Down Expand Up @@ -206,63 +179,3 @@ function parseFontFamily(

return { name, fallbacks, variants }
}

function getSpacing() {
const spacings = design.theme.namespace("--spacing")

// A property with the namespace's name has `null` as key. (e.g.
// `--spacing: <value>`).
const spacing = spacings.get(null)

invariant(spacing != null, "A `--spacing` definition is missing in the theme")

return `export namespace Spacing {
export const unitPx = ${getLengthValuePx(spacing)}
}`
}

/**
* Returns the given CSS length in pixels.
*
* @param length expressed with the `<length>` CSS type.
* @returns The value in pixels
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/length
*/
function getLengthValuePx(length: string) {
length = length.trim()

/**
* Matches values for the `<length>` CSS type.
* We only support unitless `0`, rem and px.
*
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/length
*/
const CSS_LENGTH_REGEXP = /(?<value>-?\d*\.?\d+)(?<unit>.*)/

const match = length.match(CSS_LENGTH_REGEXP)

invariant(
match?.groups?.value != null,
`Invalid CSS length from theme: "${length}"`,
)

const value = Number(match.groups.value)

// The unit is optional when the value is `0`.
// See https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/length#syntax
const unit = match.groups.unit || "px"

switch (unit) {
case "px": {
return value
}

case "rem": {
return 16 * value
}

default: {
throw new Error(`Unsupported length unit: "${unit}" in "${length}"`)
}
}
}
Loading
Loading