Created
December 21, 2017 12:23
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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