Repository navigation
Expand file tree
/
Copy pathdeploy.php
More file actions
130 lines (107 loc) · 3.38 KB
/
Copy pathdeploy.php
File metadata and controls
130 lines (107 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
// deploy.php
// Read the mode/module name from command-line arguments
$modeOrName = isset($argv[1]) ? trim($argv[1]) : '';
if (empty($modeOrName))
{
echo "Error: Please provide a module name or 'dev'!\n";
echo "Usage: composer deploy [module-name|dev]\n";
echo "Example: composer deploy mod_meinmodul\n";
echo " composer deploy dev\n";
exit(1);
}
// Defining paths
$baseDir = __DIR__;
$distDir = $baseDir . '/dist';
// Check if dev mode
$isDevMode = ($modeOrName === 'dev');
if ($isDevMode)
{
// Dev mode: use root-module folder
$sourceDir = $baseDir . '/root-module';
$moduleName = 'mod_blueprint';
$zipFileName = 'mod_blueprint-dev.zip';
if (!is_dir($sourceDir))
{
echo "Error: root-module folder not found!\n";
exit(1);
}
echo "Dev mode: Packaging original blueprint module...\n";
}
else
{
// Normal mode: use customized folder
$moduleName = $modeOrName;
$sourceDir = $baseDir . '/customized/' . $moduleName;
$zipFileName = $moduleName . '.zip';
if (!is_dir($sourceDir))
{
echo "Error: Module folder not found: customized/" . $moduleName . "\n";
echo "Please run 'composer setup' first and use the correct module name.\n";
exit(1);
}
echo "Production mode: Packaging customized module...\n";
}
$zipFilePath = $distDir . '/' . $zipFileName;
// Create a 'dist' folder if it does not exist
if (!is_dir($distDir))
{
mkdir($distDir, 0755, true);
echo "Created dist folder.\n";
}
// Delete any existing ZIP file, if there is one
if (file_exists($zipFilePath))
{
unlink($zipFilePath);
echo "Removed existing ZIP file.\n";
}
// Create a ZIP archive
$zip = new ZipArchive();
if ($zip->open($zipFilePath, ZipArchive::CREATE) !== true)
{
echo "Error: Could not create ZIP file!\n";
exit(1);
}
// Add files to the ZIP file recursively
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($sourceDir),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $file)
{
if (!$file->isDir())
{
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($sourceDir) + 1);
// Unerwünschte Dateien ausschließen
$excludeFiles = ['composer-setup.php', 'composer.json', 'composer.lock', '.gitignore'];
$excludeFolders = ['vendor', 'node_modules', '.git', '.idea', '.vscode'];
$skip = false;
// Check whether the file should be excluded
if (in_array(basename($file), $excludeFiles))
{
$skip = true;
}
// Check whether the path contains any excluded folders
foreach ($excludeFolders as $folder)
{
if (strpos($relativePath, $folder . '/') === 0 || strpos($relativePath, '/' . $folder . '/') !== false)
{
$skip = true;
break;
}
}
if (!$skip)
{
$zip->addFile($filePath, $relativePath);
echo "Added: " . $relativePath . "\n";
}
}
}
$zip->close();
echo "\n========================================\n";
echo "Deployment completed successfully!\n";
echo "========================================\n";
echo "ZIP file created: dist/" . $zipFileName . "\n";
echo "File size: " . round(filesize($zipFilePath) / 1024, 2) . " KB\n";
echo "========================================\n";