-
Notifications
You must be signed in to change notification settings - Fork 26
/
make.php
92 lines (69 loc) · 2.54 KB
/
make.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
#!/opt/local/bin/php
<?php
header('Content-Type: text/plain');
// Make the final vanilla2export.php file from the other sources.
$path = dirname(__FILE__) . '/vanilla2export.php';
if (file_exists($path)) {
$r = unlink($path);
if (!$r) {
echo "Could not delete $path.\n";
die();
}
}
// Open the file.
echo "Opening $path\n";
$fp = fopen($path, 'w');
fwrite($fp, "<?php /* This file was automatically generated by make.php. DO NOT EDIT. */ ?>\n\n");
addFile($fp, 'index.php');
fclose($fp);
echo "Make Complete.\n";
/// Functions ///
function addFile($fp, $filename) {
// Recursively build file
$contents = getFile($filename);
// Include individual software porters (undo MAKESKIP)
$paths = glob('packages/*.php');
$exporters = '';
foreach ($paths as $path) {
$exporters .= getFile($path);
}
$contents = str_replace('// [EXPORTERS]', ' ?>' . $exporters . '<?php ', $contents);
// Write the all-in-one file
fwrite($fp, $contents);
}
function getFile($filename, $endPhp = false) {
$path = dirname(__FILE__) . '/' . $filename;
echo "Including file $path\n";
$contents = file_get_contents($path);
// MAKESKIP
$contents = preg_replace('#MAKESKIPSTART(.*)MAKESKIPEND#s', '[EXPORTERS]', $contents);
// Inline any stylesheet includes.
$contents = preg_replace_callback('#<link.+?href=[\'"](.*?)[\'"].*?/>#i', 'replaceStyleCallback', $contents);
// Inline any script includes.
$contents = preg_replace_callback('#<script.+?src=[\'"](.*?)[\'"].*?></script>#i', 'replaceScriptCallback', $contents);
// Inline any includes.
$contents = preg_replace_callback('/include_once [\'"](.*?)[\'"]\;/', 'replaceIncludeCallback', $contents);
// End and begin the php context.
if ($endPhp) {
$contents = "\n/* Contents included from $filename */\n?>" . $contents . "<?php\n";
}
return $contents;
}
function replaceIncludeCallback($matches) {
$path = $matches[1];
$contents = getFile($path, true);
$result = $contents;
return $result;
}
function replaceStyleCallback($matches) {
$path = $matches[1];
$contents = file_get_contents(dirname(__FILE__) . '/' . $path);
$result = "<!-- Contents included from $path -->\n<style>\n" . $contents . "\n</style>";
return $result;
}
function replaceScriptCallback($matches) {
$path = $matches[1];
$contents = file_get_contents(dirname(__FILE__) . '/' . $path);
$result = "<!-- Contents included from $path -->\n<script>\n" . $contents . "\n</script>";
return $result;
}