Permalink
Find file
e113e6f Jun 1, 2011
77 lines (63 sloc) 2.08 KB
<?php
// NOTES:
// - php must be in your path
// - git must be in your path if you want to use 'update'
function addFiles(&$files, $pattern, $autoversion = false) {
$abspath = dirname(__FILE__).'/web';
$abspathLen = strlen($abspath)+1;
$filesToAdd = glob($abspath.'/'.$pattern);
foreach($filesToAdd as $filename) {
$newfilename = $filename;
$path = pathinfo($filename);
if($autoversion) {
$ver = '..'.filemtime($filename).'.';
$newfilename = $path['dirname'].'/'.$path['filename'].$ver.$path['extension'];
}
array_push($files, substr($newfilename, $abspathLen));
}
}
$debug = false;
$debugString = '';
if($argc > 1) {
// Check for debugging mode
if(in_array('debug', $argv)) {
$debug = true;
$debugString = 'debug';
}
}
// Always build manifest
$files = array();
array_push($files, '# Version '.time());
addFiles($files, '*.html');
addFiles($files, 'favicon.ico');
addFiles($files, 'apple-touch-icon.png');
addFiles($files, 'apple-touch-icon-precomposed.png');
addFiles($files, 'css/style.css', true);
addFiles($files, 'js/*.js', true);
addFiles($files, 'images/*');
addFiles($files, 'about/*.html');
addFiles($files, 'about/*.png');
//array_push($files, "\nFALLBACK:");
//array_push($files, '/ offline.html');
array_push($files, "\nNETWORK:");
//array_push($files, 'api/');
//array_push($files, 'google-analytics.com/ga.js');
array_push($files, '*');
$manifestFile = fopen('web/cache.manifest', 'wb');
if($manifestFile) {
fputs($manifestFile, "CACHE MANIFEST\n");
foreach($files as $filename) {
fputs($manifestFile, $filename."\n");
}
fclose($manifestFile);
echo "Manifest file created.\n";
} else {
echo "Error opening Manifest file.\n";
}
// Always rebuild index
shell_exec('php web/index-src.php '.$debugString.' > web/index.html');
echo "index.html rebuilt.\n";
shell_exec('php web/index-src.php '.$debugString.' desktop > web/d.html');
echo "d.html rebuilt.\n";
shell_exec('php web/index-src.php '.$debugString.' mobile > web/m.html');
echo "m.html rebuilt.\n";