Skip to content

Instantly share code, notes, and snippets.

@manuelkiessling
Created December 21, 2017 12:23
Show Gist options
  • Save manuelkiessling/d7b12c0f7a260496fdae24f9abc648d5 to your computer and use it in GitHub Desktop.
Save manuelkiessling/d7b12c0f7a260496fdae24f9abc648d5 to your computer and use it in GitHub Desktop.
Generate manifest.json file with hashes of all asset files in a folder, recursively
#!/usr/bin/env php
<?php
$path = realpath(__DIR__ . '/../web/assets');
$obsoletePrefix = realpath(__DIR__ . '/../web/') . '/';
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::KEY_AS_PATHNAME | RecursiveDirectoryIterator::FOLLOW_SYMLINKS));
$hashes = [];
foreach ($objects as $name => $object) {
if (is_file($name)) {
$hashes[str_replace($obsoletePrefix, '', $name)] = str_replace($obsoletePrefix, '', $name) . '?contentHash=' . md5_file($name);
}
}
echo json_encode($hashes, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment