Page MenuHomePhabricator
Paste P9485

RL hashed module names test script
ActivePublic

Authored by hoo on Oct 27 2019, 8:33 AM.
Tags
None
Referenced Files
F30900442: raw.txt
Oct 27 2019, 8:33 AM
Subscribers
None
#!/bin/env php
<?php
$fileName = $argv[1];
$origStartup = file_get_contents( $fileName );
$start = 'mw.loader.register([';
$end = ']);';
$moduleSectionStart = strpos( $origStartup, $start ) + strlen( $start ) - 1;
$moduleSectionEnd = strpos( $origStartup, $end, $moduleSectionStart + 1 ) + 1;
$preModuleSection = substr( $origStartup, 0, $moduleSectionStart );
$moduleSection = substr( $origStartup, $moduleSectionStart, ( $moduleSectionEnd - $moduleSectionStart ) );
$postModuleSection = substr( $origStartup, $moduleSectionEnd );
$modules = json_decode( $moduleSection );
$moduleSection = json_encode( $modules );
$hashedModules = [];
foreach ( $modules as $module ) {
$hashedModules[] = [ substr( md5( $module[0] ), 0, 5), array_slice( $module, 1 ) ];
}
$hashedModuleSection = json_encode( $hashedModules );
file_put_contents( $fileName . '-no-new-lines', $preModuleSection . $moduleSection . $postModuleSection );
file_put_contents( $fileName . '-no-new-lines-hashed-module-names', $preModuleSection . $hashedModuleSection . $postModuleSection );