-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.php
More file actions
82 lines (72 loc) · 2.06 KB
/
Copy pathbuild.php
File metadata and controls
82 lines (72 loc) · 2.06 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
<?php
$baseDir = dirname(__FILE__);
$sourceDir = $baseDir . '/source';
$buildDir = $baseDir . '/build';
$distDir = $baseDir . '/dist';
$sourceDirs = ['fonts', 'images', 'javascripts', 'stylesheets'];
function printLine($line)
{
echo "\t {$line}\n";
}
function rcopy($src, $dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
rcopy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
printLine('');
printLine('* Building SlatePHP project...');
// Make sure the build dir exists
if (!is_dir($buildDir)) {
try {
mkdir($buildDir, 0755);
} catch(Exception $e) {
echo $e->getMessage();
die;
}
printLine('* Created "build" directory');
} else {
printLine('* "build" directory already exists');
}
// Make sure the dist dir exists
if (!is_dir($distDir)) {
try {
mkdir($distDir, 0755);
} catch(Exception $e) {
echo $e->getMessage();
die;
}
printLine('* Created "dist" directory');
} else {
printLine('* "dist" directory already exists');
}
// Copy over the files from source to dist
printLine('* Copying over assets to build dir');
foreach($sourceDirs as $dir) {
$fromLocation = "$sourceDir/$dir";
$toLocation = "$buildDir/$dir";
rcopy($fromLocation, $toLocation);
}
printLine('* Completed copying over assets to build dir');
// Parse the markdown
printLine('* Processing markdown source files');
exec("php {$sourceDir}/index.php | cat > {$buildDir}/index.html");
printLine('* Completed processing markdown source files');
// Replace the dist files
printLine('* Copying build to dist');
exec("rm -rf {$distDir}/*");
$fromLocation = "$buildDir";
$toLocation = "$distDir";
rcopy($fromLocation, $toLocation);
printLine('* Completed copying build to dist');
// Remove the build dir
exec("rm -fr {$buildDir}");