feat(variants): copy per-client assets (fonts/css/images) automatically in build.php
The definitions dir (private variants repo) now has a standard layout per client: <client>.json + <client>/files/... + <client>/css/variant.css. build.php copies <client>/ into the generated theme folder, so a client-specific font or css is part of the variant by default. README updated accordingly. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
d22abc8745
commit
dd8714b6a0
1 changed files with 49 additions and 4 deletions
|
|
@ -28,6 +28,12 @@
|
|||
* point this script at that folder via the optional second argument or the
|
||||
* RESPONDAGE_VARIANTS_DIR environment variable.
|
||||
*
|
||||
* Standard layout in that definitions dir per client:
|
||||
* <variantName>.json house-style option values + fontOptions + files_add
|
||||
* <variantName>/files/... client assets (logos, fonts in files/fonts/)
|
||||
* <variantName>/css/... client css (e.g. css/variant.css with @font-face)
|
||||
* The <variantName>/ folder is copied into the generated theme automatically.
|
||||
*
|
||||
* Example:
|
||||
* php variants/build.php <client> /path/to/private-variants
|
||||
*
|
||||
|
|
@ -103,6 +109,28 @@ function setMetadata(DOMXPath $xpath, DOMDocument $doc, string $tag, string $val
|
|||
$node->textContent = $value;
|
||||
}
|
||||
|
||||
/** Recursively copy a directory (used for the variant's own assets). */
|
||||
function copyDirRecursive(string $src, string $dst): void
|
||||
{
|
||||
if (!is_dir($dst)) {
|
||||
mkdir($dst, 0775, true);
|
||||
}
|
||||
$dir = opendir($src);
|
||||
while (($entry = readdir($dir)) !== false) {
|
||||
if ($entry === '.' || $entry === '..') {
|
||||
continue;
|
||||
}
|
||||
$s = $src . DIRECTORY_SEPARATOR . $entry;
|
||||
$d = $dst . DIRECTORY_SEPARATOR . $entry;
|
||||
if (is_dir($s)) {
|
||||
copyDirRecursive($s, $d);
|
||||
} else {
|
||||
copy($s, $d);
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
setMetadata($xpath, $doc, 'name', $definition['name'] ?? $variantName);
|
||||
setMetadata($xpath, $doc, 'title', $definition['title'] ?? ucfirst($variantName));
|
||||
if (isset($definition['description'])) {
|
||||
|
|
@ -221,6 +249,17 @@ if (!is_dir($variantDir . DIRECTORY_SEPARATOR . 'files')) {
|
|||
$out = $variantDir . DIRECTORY_SEPARATOR . 'config.xml';
|
||||
$doc->save($out);
|
||||
|
||||
// --- copy the variant's own assets (fonts, css, images) from the definitions dir ---
|
||||
// Standard layout in the private variants repo: <definitionsDir>/<variantName>/
|
||||
// with e.g. files/fonts/*.woff2, files/*.png, css/variant.css. Everything in that
|
||||
// folder is copied into the generated theme, so a client-specific font or css is
|
||||
// part of the variant by default (no manual copying needed).
|
||||
$variantAssets = rtrim($definitionsDir, '/\\') . DIRECTORY_SEPARATOR . $variantName;
|
||||
if (is_dir($variantAssets)) {
|
||||
copyDirRecursive($variantAssets, $variantDir);
|
||||
echo "Copied variant assets: $variantAssets -> $variantDir\n";
|
||||
}
|
||||
|
||||
echo "Variant '$variantName' built: $out\n";
|
||||
echo 'Options overridden: ' . (empty($definition['options']) ? '(none)' : implode(', ', array_keys($definition['options']))) . "\n";
|
||||
echo "Remember: upload the folder to upload/themes/survey/ and reset the theme in LimeSurvey.\n";
|
||||
|
|
|
|||
Loading…
Reference in a new issue