refactor(server-styles): unify render from templates by JSON.stringify

Also, include filename prefix to theming config in meta data.

Signed-off-by: Grigorii K. Shartsev <[email protected]>
This commit is contained in:
Grigorii K. Shartsev committed 2026-07-08 14:58:00 +02:00
1 parent 7dfea8e4de
commit df3aa7dde9
3 files changed
+18 -15

No files matched your search

+1
View File
@@ -15,6 +15,7 @@ export default [
ignores: [
'src/shared/renderer/assets/**/*',
'scripts/nextcloud-app-host/templates/**/*',
'resources/server-global-styles/**/*',
],
},
{
@@ -33,7 +33,7 @@ export async function extractNextcloudStyles({
const versionRef = tag || branch
const versionRefType = tag ? 'tag' : 'branch'
const CONTAINER = `nextcloud-app-host-styles-${versionRef.replace(/[^a-z0-9-_]/ig, '_')}`
const THEMING_CONFIGS = themingConfigs.map((themingConfig) => ({
themingConfigs = themingConfigs.map((themingConfig) => ({
...themingConfig,
// Filename prefix
prefix: themingConfig.name ? `${themingConfig.name}.` : '',
@@ -59,13 +59,13 @@ export async function extractNextcloudStyles({
})
const { version, versionstring: versionString } = await $`docker exec ${CONTAINER} curl -sk https://localhost:443/status.php`.json()
const versionMajor = version.split('.')[0]
const versionMajor = +version.split('.')[0]
const versionCommitHash = (await $`docker exec ${CONTAINER} git -C /var/www/nextcloud rev-parse --short HEAD`.text()).trim()
echo(chalk.yellow(`Nextcloud Server ${versionString} is ready`))
// --- PREPARING DEST -------------------------------------------------------------------------------------------------
const OUTPUT = join(dest, versionMajor)
const OUTPUT = join(dest, versionMajor.toString())
await rm(OUTPUT, { recursive: true, force: true })
await mkdir(OUTPUT, { recursive: true })
@@ -92,7 +92,7 @@ export async function extractNextcloudStyles({
// To prevent server cache
const v = Date.now()
for (const { name, prefix, primaryColor, backgroundColor } of THEMING_CONFIGS) {
for (const { name, prefix, primaryColor, backgroundColor } of themingConfigs) {
echo(chalk.gray(`- Theming configuration "${name || 'default'}" (primaryColor=${primaryColor || 'default'}, backgroundColor=${backgroundColor || 'default'}) ...`))
// Setting theming
@@ -145,24 +145,26 @@ export async function extractNextcloudStyles({
await dockerCp(CONTAINER, '/var/www/nextcloud/', 'apps/theming/REUSE.toml', true) // Added in Nextcloud 32
// Additional REUSE for dynamic styles
await render('REUSE.template.toml', 'apps/theming/theme/REUSE.toml', {
files: JSON.stringify(await glob('*.css', { cwd: 'apps/theming/theme' })),
files: await glob('*.css', { cwd: 'apps/theming/theme' }),
})
// Re-exports entrypoints
await render('index.template.css', 'index.css')
await render('server.template.css', 'server.css')
await Promise.all(THEMING_CONFIGS.map(async ({ prefix }) => {
await Promise.all(themingConfigs.map(async ({ prefix }) => {
await render('theming.template.css', `${prefix}theming.css`, { prefix })
}))
await render('meta.template.js', 'meta.js', {
// Meta-data
const meta = {
versionRef,
versionRefType,
versionMajor,
version,
versionString,
versionCommitHash,
themingConfigs: '[' + themingConfigs.map(({ name, primaryColor, backgroundColor }) => `{ name: '${name}', primaryColor: '${primaryColor}', backgroundColor: '${backgroundColor}' }`).join(', ') + ']',
})
themingConfigs,
}
await render('meta.template.js', 'meta.js', meta)
// --- STOPPING THE SERVER --------------------------------------------------------------------------------------------
@@ -211,7 +213,7 @@ async function render(templateName, dist, data = {}) {
const templatePath = join(import.meta.dirname, 'templates', templateName)
const template = await readFile(templatePath, 'utf-8')
const rendered = template.replace(/\{\{(\w+)\}\}/g, (_, key) => replacements[key] || '')
const rendered = template.replace(/\{\{(\w+)\}\}/g, (_, key) => replacements[key] ? JSON.stringify(replacements[key]) : '')
await writeFile(dist, rendered, 'utf-8')
if ($.verbose) {
echo(` ${chalk.green('render')} ${dist}`)
@@ -4,17 +4,17 @@
*/
/** Git ref the styles are extracted from: version tag (e.g. "v34.0.0rc1") or branch name (e.g. "master") */
export const versionRef = '{{versionRef}}'
export const versionRef = {{versionRef}}
/** Version git reference type used on styles extracting: "tag" or "branch" */
export const versionRefType = '{{versionRefType}}'
export const versionRefType = {{versionRefType}}
/** Version major number, e.g. 34 */
export const versionMajor = {{versionMajor}}
/** Version from $OC_Version, e.g. "34.0.0.5" */
export const version = '{{version}}'
export const version = {{version}}
/** Version from $OC_VersionString, e.g. "34.0.0 RC 1" */
export const versionString = '{{versionString}}'
export const versionString = {{versionString}}
/** Commit hash, e.g. "a1b2c3d" */
export const versionCommitHash = '{{versionCommitHash}}'
export const versionCommitHash = {{versionCommitHash}}
/** Available theming configurations */
export const themingConfigs = {{themingConfigs}}