Files
carmanagement/apps/api/src/services/platformContentService.ts
T
root 7ff2dbb139
Build & Deploy / Build & Push Docker Image (push) Successful in 2m55s
Test / Type Check (all packages) (push) Successful in 54s
Build & Deploy / Deploy to VPS (push) Successful in 4s
Test / API Unit Tests (push) Failing after 48s
Test / Homepage Unit Tests (push) Successful in 43s
Test / Storefront Unit Tests (push) Failing after 40s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Failing after 42s
Test / API Integration Tests (push) Successful in 1m0s
chore: wire Carplace into dev and production stacks
2026-07-02 18:15:42 -04:00

48 lines
1.4 KiB
TypeScript

import { mkdir, readFile, writeFile } from 'fs/promises'
import path from 'path'
import {
cloneCarplaceHomepageContent,
type CarplaceHomepageConfig,
} from '@rentaldrivego/types'
function resolveContentPath() {
const cwd = process.cwd()
const appScoped = path.resolve(cwd, 'src/data/platform-content.json')
const repoScoped = path.resolve(cwd, 'apps/api/src/data/platform-content.json')
return cwd.includes('/apps/api') ? appScoped : repoScoped
}
const platformContentPath = resolveContentPath()
type PlatformContentFile = {
carplaceHomepage?: CarplaceHomepageConfig
}
async function readPlatformContentFile(): Promise<PlatformContentFile> {
try {
const raw = await readFile(platformContentPath, 'utf8')
return JSON.parse(raw) as PlatformContentFile
} catch {
return {}
}
}
async function writePlatformContentFile(content: PlatformContentFile) {
await mkdir(path.dirname(platformContentPath), { recursive: true })
await writeFile(platformContentPath, JSON.stringify(content, null, 2))
}
export async function getCarplaceHomepageContent() {
const content = await readPlatformContentFile()
return content.carplaceHomepage ?? cloneCarplaceHomepageContent()
}
export async function saveCarplaceHomepageContent(homepage: CarplaceHomepageConfig) {
const content = await readPlatformContentFile()
await writePlatformContentFile({
...content,
carplaceHomepage: homepage,
})
return homepage
}