From ff7815929ecf748d8473b63f203c3a7093669818 Mon Sep 17 00:00:00 2001 From: Brent Cordis <994259+bcordis@users.noreply.github.com> Date: Sat, 9 May 2026 17:24:06 -0500 Subject: [PATCH] chore: migrate to cwm-build-tools v0.5.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drops the project-side build/build-package.php in favor of the generic cwm-build binary introduced in cwm-build-tools v0.5.0-alpha (issue Joomla-Bible-Study/cwm-build-tools#5). Bumps to v0.5.1-alpha for the ensure-minified gate fix surfaced during this migration. Behavior parity verified end-to-end: Legacy: 89 files, 215 KB cwm-build: 89 files, 215 KB diff -r between unzipped contents: identical (file list AND every file's bytes) Changes: composer.json - cwm/build-tools: ^0.4@alpha -> ^0.5@alpha - "build:package": "php build/build-package.php" -> "cwm-build" - "build:package:verbose": "php build/build-package.php --verbose" -> "cwm-build -v" - dropped "package": "cwm-package" — single-extension lib doesn't need a multi-extension package wrapper, and on v0.5+ that script would fail without a `package:` block cwm-build.config.json - build.command kept as "npm run build && cwm-build" so the release pipeline keeps auto-running npm build, exactly as before - new build.* fields: outputDir, outputName ({version} substituted), manifest, scriptFile, sources[] (src/sql/language/media — same prefixes as legacy), excludes[] (.git/.DS_Store/.idea/node_modules/.php-cs-fixer.cache — same list, contains-mode default), preBuild (mode: ensure-minified, dirs: media/.../js + css — same gate semantics as legacy) build/build-package.php - deleted (190 lines) composer.lock - cwm/build-tools v0.4.0-alpha -> v0.5.1-alpha The release pipeline is unchanged for downstream callers — cwm-release keeps reading build.command. Direct `composer build:package` users get identical zips. No manifest changes required. Refs Joomla-Bible-Study/cwm-build-tools#5 (per-consumer migration). Co-Authored-By: Claude Opus 4.7 (1M context) --- build/build-package.php | 190 ---------------------------------------- composer.json | 7 +- composer.lock | 40 +++++++-- cwm-build.config.json | 19 +++- 4 files changed, 52 insertions(+), 204 deletions(-) delete mode 100644 build/build-package.php diff --git a/build/build-package.php b/build/build-package.php deleted file mode 100644 index ffe155b..0000000 --- a/build/build-package.php +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env php -getMessage() . "\n"; - exit(1); -} - -function build(bool $verbose = false): void -{ - // Read version from library manifest - $manifestXml = simplexml_load_file(BASE_DIR . '/cwmscripture.xml'); - - if (!$manifestXml) { - throw new \RuntimeException('Could not parse cwmscripture.xml'); - } - - $version = (string) $manifestXml->version; - echo "Building lib_cwmscripture v$version\n\n"; - - $distDir = BASE_DIR . '/build/dist'; - - if (is_dir($distDir)) { - exec('rm -rf ' . escapeshellarg($distDir)); - } - - mkdir($distDir, 0777, true); - - // Verify minified assets exist - $jsDir = BASE_DIR . '/media/lib_cwmscripture/js'; - $cssDir = BASE_DIR . '/media/lib_cwmscripture/css'; - - $missingMin = false; - - foreach (glob($jsDir . '/*.js') as $jsFile) { - if (str_ends_with($jsFile, '.min.js')) { - continue; - } - - $minFile = str_replace('.js', '.min.js', $jsFile); - - if (!file_exists($minFile)) { - echo "WARNING: Missing minified file: " . basename($minFile) . "\n"; - $missingMin = true; - } - } - - foreach (glob($cssDir . '/*.css') as $cssFile) { - if (str_ends_with($cssFile, '.min.css')) { - continue; - } - - $minFile = str_replace('.css', '.min.css', $cssFile); - - if (!file_exists($minFile)) { - echo "WARNING: Missing minified file: " . basename($minFile) . "\n"; - $missingMin = true; - } - } - - if ($missingMin) { - echo "\nRun 'npm run build' first to generate minified assets.\n"; - exit(1); - } - - // Create library ZIP - $zipPath = $distDir . '/lib_cwmscripture-' . $version . '.zip'; - echo "Creating lib_cwmscripture-$version.zip...\n"; - - $zip = new ZipArchive(); - - if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) { - throw new \RuntimeException('Could not create ' . $zipPath); - } - - // Add manifest (goes in root of ZIP for Joomla to find it) - $zip->addFile(BASE_DIR . '/cwmscripture.xml', 'cwmscripture.xml'); - - if ($verbose) { - echo " + cwmscripture.xml\n"; - } - - // Add install script if present - if (file_exists(BASE_DIR . '/script.php')) { - $zip->addFile(BASE_DIR . '/script.php', 'script.php'); - - if ($verbose) { - echo " + script.php\n"; - } - } - - // Add library source files (src/, sql/, language/) - addDirectoryToZip($zip, BASE_DIR . '/src', 'lib_cwmscripture/src', $verbose); - addDirectoryToZip($zip, BASE_DIR . '/sql', 'lib_cwmscripture/sql', $verbose); - addDirectoryToZip($zip, BASE_DIR . '/language', 'lib_cwmscripture/language', $verbose); - - // Add media files (js, css, joomla.asset.json) - addDirectoryToZip($zip, BASE_DIR . '/media/lib_cwmscripture', 'media/lib_cwmscripture', $verbose); - - $fileCount = $zip->numFiles; - $zip->close(); - - $sizeKb = round(filesize($zipPath) / 1024); - echo "\nPackage built: $zipPath\n"; - echo " Files: $fileCount\n"; - echo " Size: {$sizeKb} KB\n"; -} - -/** - * Recursively add a directory's contents to a ZipArchive. - * - * @param ZipArchive $zip The ZIP archive - * @param string $sourcePath Absolute path to source directory - * @param string $zipPrefix Path prefix inside the ZIP - * @param bool $verbose Whether to print each file - */ -function addDirectoryToZip(ZipArchive $zip, string $sourcePath, string $zipPrefix, bool $verbose): void -{ - if (!is_dir($sourcePath)) { - echo " SKIP: $sourcePath (not found)\n"; - - return; - } - - $excludeNames = [ - '.git', '.DS_Store', '.idea', 'node_modules', '.php-cs-fixer.cache', - ]; - - $iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($sourcePath, FilesystemIterator::SKIP_DOTS), - RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($iterator as $file) { - if ($file->isDir()) { - continue; - } - - $filePath = $file->getRealPath(); - $relativePath = substr($filePath, \strlen(realpath($sourcePath)) + 1); - - // Check excludes - $skip = false; - - foreach ($excludeNames as $exclude) { - if (str_contains($relativePath, $exclude)) { - $skip = true; - break; - } - } - - if ($skip) { - continue; - } - - $zipPath = $zipPrefix . '/' . $relativePath; - - if ($verbose) { - echo " + $zipPath\n"; - } - - $zip->addFile($filePath, $zipPath); - } -} diff --git a/composer.json b/composer.json index 0ca40d3..b3a35b3 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "ext-mbstring": "*" }, "require-dev": { - "cwm/build-tools": "^0.4@alpha", + "cwm/build-tools": "^0.5@alpha", "friendsofphp/php-cs-fixer": "^3.0", "phpunit/phpunit": "^11.0" }, @@ -52,11 +52,10 @@ "lint:fix": "php-cs-fixer fix", "test": "phpunit", "test:unit": "phpunit --testsuite unit", - "build:package": "php build/build-package.php", - "build:package:verbose": "php build/build-package.php --verbose", + "build:package": "cwm-build", + "build:package:verbose": "cwm-build -v", "release": "cwm-release", "bump-version": "cwm-bump", - "package": "cwm-package", "ars-publish": "cwm-ars-publish", "ars-list": "cwm-ars-list", "changelog": "cwm-changelog", diff --git a/composer.lock b/composer.lock index b8c52b6..08a9599 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bf612cc94594bcb38ff0961108683d1d", + "content-hash": "7976ea13fccbc712c3f29a2bc1f7da99", "packages": [], "packages-dev": [ { @@ -295,16 +295,16 @@ }, { "name": "cwm/build-tools", - "version": "v0.4.0-alpha", + "version": "v0.5.1-alpha", "source": { "type": "git", "url": "https://github.com/Joomla-Bible-Study/cwm-build-tools.git", - "reference": "70b7c726f2132258309f977c92160a46df074860" + "reference": "2b3fcc3bb740cc90ee9ac3160cc173ec5bb63ce4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Joomla-Bible-Study/cwm-build-tools/zipball/70b7c726f2132258309f977c92160a46df074860", - "reference": "70b7c726f2132258309f977c92160a46df074860", + "url": "https://api.github.com/repos/Joomla-Bible-Study/cwm-build-tools/zipball/2b3fcc3bb740cc90ee9ac3160cc173ec5bb63ce4", + "reference": "2b3fcc3bb740cc90ee9ac3160cc173ec5bb63ce4", "shasum": "" }, "require": { @@ -320,6 +320,7 @@ "bin": [ "bin/cwm-release", "bin/cwm-bump", + "bin/cwm-build", "bin/cwm-package", "bin/cwm-sync-configs", "bin/cwm-sync-languages", @@ -327,6 +328,7 @@ "bin/cwm-ars-list", "bin/cwm-ars-create-stream", "bin/cwm-changelog", + "bin/cwm-article", "bin/cwm-init", "bin/cwm-setup", "bin/cwm-link", @@ -334,7 +336,8 @@ "bin/cwm-clean", "bin/cwm-verify", "bin/cwm-joomla-install", - "bin/cwm-joomla-latest" + "bin/cwm-joomla-latest", + "bin/cwm-joomla-cms-deps" ], "type": "library", "autoload": { @@ -347,6 +350,27 @@ "CWM\\BuildTools\\Tests\\": "tests/" } }, + "archive": { + "exclude": [ + "/.github", + "/.gitattributes", + "/.gitignore", + "/.idea", + "/.php-cs-fixer.cache", + "/.phpunit.cache", + "/.phpunit.result.cache", + "/CLAUDE.md", + "/phpunit.xml", + "/phpunit.xml.dist", + "/tests", + "/workflows" + ] + }, + "scripts": { + "test": [ + "phpunit" + ] + }, "license": [ "GPL-2.0-or-later" ], @@ -365,10 +389,10 @@ "release" ], "support": { - "source": "https://github.com/Joomla-Bible-Study/cwm-build-tools/tree/v0.4.0-alpha", + "source": "https://github.com/Joomla-Bible-Study/cwm-build-tools/tree/v0.5.1-alpha", "issues": "https://github.com/Joomla-Bible-Study/cwm-build-tools/issues" }, - "time": "2026-05-07T20:27:34+00:00" + "time": "2026-05-09T22:17:44+00:00" }, { "name": "ergebnis/agent-detector", diff --git a/cwm-build.config.json b/cwm-build.config.json index 91c7f70..f7c27b5 100644 --- a/cwm-build.config.json +++ b/cwm-build.config.json @@ -9,8 +9,23 @@ ] }, "build": { - "command": "npm run build && php build/build-package.php", - "outputGlob": "build/dist/lib_cwmscripture-*.zip" + "command": "npm run build && cwm-build", + "outputGlob": "build/dist/lib_cwmscripture-*.zip", + "outputDir": "build/dist", + "outputName": "lib_cwmscripture-{version}.zip", + "manifest": "cwmscripture.xml", + "scriptFile": "script.php", + "sources": [ + { "from": "src", "to": "lib_cwmscripture/src" }, + { "from": "sql", "to": "lib_cwmscripture/sql" }, + { "from": "language", "to": "lib_cwmscripture/language" }, + { "from": "media/lib_cwmscripture", "to": "media/lib_cwmscripture" } + ], + "excludes": [".git", ".DS_Store", ".idea", "node_modules", ".php-cs-fixer.cache"], + "preBuild": { + "mode": "ensure-minified", + "dirs": ["media/lib_cwmscripture/js", "media/lib_cwmscripture/css"] + } }, "ars": { "endpoint": "https://www.christianwebministries.org",