Skip to content

Commit 7e4ee1f

Browse files
committed
#8 release first version of the component
1 parent ec2f63c commit 7e4ee1f

File tree

12 files changed

+805
-2
lines changed

12 files changed

+805
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/*
22
vendor/*
3+
dist/*
34
composer.lock
45
cypress.config.mjs

RoboFile.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
/**
4+
* This is project's console commands configuration for Robo task runner.
5+
*
6+
* Download robo.phar from http://robo.li/robo.phar and type in the root of the repo: $ php robo.phar
7+
* Or do: $ composer update, and afterwards you will be able to execute robo like $ php vendor/bin/robo
8+
*
9+
* @package Joomla.Site
10+
* @subpackage RoboFile
11+
*
12+
* @copyright Copyright (C) 2005 - 2025 Open Source Matters, Inc. All rights reserved.
13+
* @license GNU General Public License version 2 or later; see LICENSE.txt
14+
*/
15+
16+
use Joomla\Jorobo\Tasks\Tasks as loadReleaseTasks;
17+
use Joomla\Jorobo\Tasks\CopyrightHeader;
18+
use Joomla\Jorobo\Tasks\Build;
19+
use Joomla\Jorobo\Tasks\BumpVersion;
20+
use Joomla\Jorobo\Tasks\Map;
21+
use Robo\Tasks;
22+
23+
require_once 'vendor/autoload.php';
24+
25+
if (!defined('JPATH_BASE')) {
26+
define('JPATH_BASE', __DIR__);
27+
}
28+
29+
/**
30+
* Modern php task runner for Joomla! Browser Automated Tests execution
31+
*
32+
* @package RoboFile
33+
*
34+
* @since 1.0
35+
*/
36+
class RoboFile extends Tasks
37+
{
38+
// Load tasks from composer, see composer.json
39+
use loadReleaseTasks;
40+
41+
/**
42+
* Constructor
43+
*/
44+
public function __construct()
45+
{
46+
// Set default timezone (so no warnings are generated if it is not set)
47+
date_default_timezone_set('UTC');
48+
}
49+
50+
/**
51+
* Build the joomla extension package
52+
*
53+
* @param array $params Additional params
54+
*
55+
* @return void
56+
*/
57+
public function build($params = ['dev' => false])
58+
{
59+
if (!file_exists('jorobo.ini')) {
60+
$this->_copy('jorobo.dist.ini', 'jorobo.ini');
61+
}
62+
63+
$this->task(Build::class, $params)->run();
64+
}
65+
66+
/**
67+
* Update copyright headers for this project. (Set the text up in the jorobo.ini)
68+
*
69+
* @return void
70+
*/
71+
public function headers()
72+
{
73+
if (!file_exists('jorobo.ini')) {
74+
$this->_copy('jorobo.dist.ini', 'jorobo.ini');
75+
}
76+
77+
$this->task(CopyrightHeader::class)->run();
78+
}
79+
80+
/**
81+
* Update Version __DEPLOY_VERSION__ in Component. (Set the version up in the jorobo.ini)
82+
*
83+
* @return void
84+
*/
85+
public function bump()
86+
{
87+
$this->task(BumpVersion::class)->run();
88+
}
89+
90+
/**
91+
* Map into Joomla installation.
92+
*
93+
* @param String $target The target joomla instance
94+
*
95+
* @return void
96+
* @since __DEPLOY_VERSION__
97+
*
98+
*/
99+
public function map($target)
100+
{
101+
$this->task(Map::class, $target)->run();
102+
}
103+
}

build.php

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
<?php
2+
/**
3+
* Build script for Component Migration Manager
4+
*
5+
* @package CCM
6+
* @author Reem
7+
* @copyright 2025 Reem
8+
* @license GNU General Public License version 2 or later
9+
*/
10+
11+
class ComponentBuilder
12+
{
13+
private $version = '1.0.0';
14+
private $packageName = 'com_ccm';
15+
private $buildDir = 'dist';
16+
private $sourceDir = 'src';
17+
18+
public function __construct()
19+
{
20+
echo "Component Migration Manager Build Script\n";
21+
echo "========================================\n";
22+
}
23+
24+
public function build()
25+
{
26+
// Create build directory
27+
$this->createBuildDir();
28+
29+
// Copy component files
30+
$this->copyComponentFiles();
31+
32+
// Process version replacement
33+
$this->replaceVersions();
34+
35+
// Create ZIP package
36+
$this->createPackage();
37+
38+
echo "\nBuild completed successfully!\n";
39+
echo "Package: {$this->buildDir}/{$this->packageName}-{$this->version}.zip\n";
40+
}
41+
42+
private function createBuildDir()
43+
{
44+
$buildPath = "{$this->buildDir}/{$this->packageName}-{$this->version}";
45+
46+
if (is_dir($buildPath)) {
47+
$this->deleteDirectory($buildPath);
48+
}
49+
50+
if (!is_dir($this->buildDir)) {
51+
mkdir($this->buildDir, 0755, true);
52+
}
53+
54+
mkdir($buildPath, 0755, true);
55+
56+
echo "Created build directory: $buildPath\n";
57+
}
58+
59+
private function copyComponentFiles()
60+
{
61+
$buildPath = "{$this->buildDir}/{$this->packageName}-{$this->version}";
62+
63+
// Copy component manifest file (rename to ccm.xml for component)
64+
if (file_exists('component_manifest.xml')) {
65+
copy('component_manifest.xml', "$buildPath/ccm.xml");
66+
echo "Copied component manifest as ccm.xml\n";
67+
} elseif (file_exists('manifest.xml')) {
68+
copy('manifest.xml', "$buildPath/manifest.xml");
69+
echo "Copied manifest.xml\n";
70+
}
71+
72+
// Copy package script if it exists
73+
if (file_exists('script.php')) {
74+
copy('script.php', "$buildPath/script.php");
75+
echo "Copied script.php\n";
76+
}
77+
78+
// Copy administrator component
79+
$adminSource = "{$this->sourceDir}/administrator/components/com_ccm";
80+
$adminDest = "$buildPath/administrator/components/com_ccm";
81+
82+
if (is_dir($adminSource)) {
83+
$this->copyDirectory($adminSource, $adminDest);
84+
echo "Copied administrator component\n";
85+
}
86+
87+
// Copy site component if it exists
88+
$siteSource = "{$this->sourceDir}/components/com_ccm";
89+
$siteDest = "$buildPath/components/com_ccm";
90+
91+
if (is_dir($siteSource)) {
92+
$this->copyDirectory($siteSource, $siteDest);
93+
echo "Copied site component\n";
94+
}
95+
96+
// Copy media files if they exist
97+
$mediaSource = "{$this->sourceDir}/media/com_ccm";
98+
$mediaDest = "$buildPath/media/com_ccm";
99+
100+
if (is_dir($mediaSource)) {
101+
$this->copyDirectory($mediaSource, $mediaDest);
102+
echo "Copied media files\n";
103+
}
104+
105+
// Copy language files
106+
$this->copyLanguageFiles($buildPath);
107+
}
108+
109+
private function copyLanguageFiles($buildPath)
110+
{
111+
// Administrator language files
112+
$adminLangSource = "{$this->sourceDir}/administrator/language";
113+
$adminLangDest = "$buildPath/administrator/language";
114+
115+
if (is_dir($adminLangSource)) {
116+
$this->copyDirectory($adminLangSource, $adminLangDest);
117+
echo "Copied administrator language files\n";
118+
}
119+
120+
// Site language files
121+
$siteLangSource = "{$this->sourceDir}/language";
122+
$siteLangDest = "$buildPath/language";
123+
124+
if (is_dir($siteLangSource)) {
125+
$this->copyDirectory($siteLangSource, $siteLangDest);
126+
echo "Copied site language files\n";
127+
}
128+
}
129+
130+
private function replaceVersions()
131+
{
132+
$buildPath = "{$this->buildDir}/{$this->packageName}-{$this->version}";
133+
134+
// Find all PHP and XML files and replace version placeholders
135+
$iterator = new RecursiveIteratorIterator(
136+
new RecursiveDirectoryIterator($buildPath),
137+
RecursiveIteratorIterator::LEAVES_ONLY
138+
);
139+
140+
foreach ($iterator as $file) {
141+
if ($file->isFile() && preg_match('/\.(php|xml)$/', $file->getFilename())) {
142+
$content = file_get_contents($file->getPathname());
143+
$content = str_replace('__DEPLOY_VERSION__', $this->version, $content);
144+
file_put_contents($file->getPathname(), $content);
145+
}
146+
}
147+
148+
echo "Replaced version placeholders\n";
149+
}
150+
151+
private function createPackage()
152+
{
153+
$buildPath = "{$this->buildDir}/{$this->packageName}-{$this->version}";
154+
$zipFile = "{$this->buildDir}/{$this->packageName}-{$this->version}.zip";
155+
156+
// Remove existing zip file if it exists
157+
if (file_exists($zipFile)) {
158+
unlink($zipFile);
159+
}
160+
161+
// Use system zip command
162+
$command = "cd '$buildPath' && zip -r '../{$this->packageName}-{$this->version}.zip' . -x '*.DS_Store' '*.git*'";
163+
$result = exec($command, $output, $returnCode);
164+
165+
if ($returnCode !== 0) {
166+
throw new Exception("Failed to create ZIP package. Command: $command");
167+
}
168+
169+
echo "Created ZIP package: $zipFile\n";
170+
}
171+
172+
private function copyDirectory($source, $dest)
173+
{
174+
if (!is_dir($dest)) {
175+
mkdir($dest, 0755, true);
176+
}
177+
178+
$iterator = new RecursiveIteratorIterator(
179+
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
180+
RecursiveIteratorIterator::SELF_FIRST
181+
);
182+
183+
foreach ($iterator as $item) {
184+
$relativePath = substr($item->getPathname(), strlen($source) + 1);
185+
$destPath = $dest . DIRECTORY_SEPARATOR . $relativePath;
186+
187+
if ($item->isDir()) {
188+
if (!is_dir($destPath)) {
189+
mkdir($destPath, 0755, true);
190+
}
191+
} else {
192+
copy($item, $destPath);
193+
}
194+
}
195+
}
196+
197+
private function deleteDirectory($dir)
198+
{
199+
if (!is_dir($dir)) {
200+
return;
201+
}
202+
203+
$iterator = new RecursiveIteratorIterator(
204+
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
205+
RecursiveIteratorIterator::CHILD_FIRST
206+
);
207+
208+
foreach ($iterator as $file) {
209+
if ($file->isDir()) {
210+
rmdir($file->getPathname());
211+
} else {
212+
unlink($file->getPathname());
213+
}
214+
}
215+
216+
rmdir($dir);
217+
}
218+
}
219+
220+
// Run the build
221+
try {
222+
$builder = new ComponentBuilder();
223+
$builder->build();
224+
} catch (Exception $e) {
225+
echo "Build failed: " . $e->getMessage() . "\n";
226+
exit(1);
227+
}

0 commit comments

Comments
 (0)