-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.php
125 lines (109 loc) · 3.19 KB
/
build.php
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
<?php
$target = 'zip';
if (isset($_SERVER['argv'][1])) {
$target = $_SERVER['argv'][1];
}
switch ($target) {
case 'zip':
zip();
break;
case 'translate':
translate();
break;
default:
zip();
break;
}
function translate()
{
shell_exec('find * \( -iname "*.php" -o -iname "*.ihtml" \) | xargs xgettext --from-code=UTF-8 -j --add-location=never --package-name=Opencast --language=PHP -o "locale/en/LC_MESSAGES/aufgaben.po"');
shell_exec('msgfmt "locale/en/LC_MESSAGES/aufgaben.po" --output-file="locale/en/LC_MESSAGES/aufgaben.mo"');
}
/**
* Creates the Stud.IP plugin zip archive.
*/
function zip()
{
$archive = new ZipArchive();
$archive->open('aufgaben.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
addDirectories($archive, [
'assets',
'classes',
'controllers',
'locale',
'migrations',
'models',
'views'
]);
$archive->addFile('README.md');
$archive->addFile('LICENSE');
$archive->addFile('bootstrap.php');
$archive->addFile('AufgabenPlugin.php');
$archive->addFile('plugin.manifest');
$archive->close();
printSuccess('created the Stud.IP plugin zip archive');
}
/**
* Recursively adds a directory tree to a zip archive.
*
* @param ZipArchive $archive The zip archive
* @param string $directory The directory to add
* @param string $ignoredFilesRegex Regular expression that matches
* files which should be ignored
*/
function addDirectory(ZipArchive $archive, $directory, $ignoredFilesRegex = '')
{
$archive->addEmptyDir($directory);
foreach (glob($directory.'/*') as $file) {
if (is_dir($file)) {
addDirectory($archive, $file, $ignoredFilesRegex);
} else {
if ($ignoredFilesRegex === '' || !preg_match($ignoredFilesRegex, $file)) {
$archive->addFile($file);
} else {
printError('ignore '.$file);
}
}
}
}
/**
* Recursively adds directory trees to a zip archive.
*
* @param ZipArchive $archive The zip archive
* @param array $directories The directories to add
* @param string $ignoredFilesRegex Regular expression that matches
* files which should be ignored
*/
function addDirectories(ZipArchive $archive, array $directories, $ignoredFilesRegex = '')
{
foreach ($directories as $directory) {
addDirectory($archive, $directory, $ignoredFilesRegex);
}
}
/**
* Prints a success message to the standard output stream of the console.
*
* @param string $message The message to print
*/
function printSuccess($message)
{
echo "\033[32m".$message."\033[39m".PHP_EOL;
}
/**
* Prints an info message to the standard output stream of the console.
*
* @param string $message The message to print
*/
function printInfo($message)
{
echo $message.PHP_EOL;
}
/**
* Prints an error message to the standard output stream of the console.
*
* @param string $message The message to print
*/
function printError($message)
{
file_put_contents('php://stderr', "\033[31m".$message."\033[39m".PHP_EOL);
}