Created
October 12, 2017 04:33
-
-
Save luke-denton-aligent/2f0e4a507f6ec8900a724965e4208401 to your computer and use it in GitHub Desktop.
A file to process 2 lists, removing the entries from the first list that occur in the second list, and creating a txt file with the resultant list
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
<?php | |
$listOfFiles = 'assets_js.txt'; | |
$listOfCheckoutFiles = 'assets_checkout_files.txt'; | |
$outputOfNonCheckoutFiles = 'assets_non-checkout_files.txt'; | |
$files = file($listOfFiles, FILE_IGNORE_NEW_LINES); | |
$checkoutFiles = file($listOfCheckoutFiles , FILE_IGNORE_NEW_LINES); | |
$nonCheckoutFiles = []; | |
// Loop all JS files that exist within Magento | |
foreach ($files as $file) { | |
$inArray = false; | |
// Check if the file being looped is a checkout file | |
foreach ($checkoutFiles as $checkoutFile) { | |
if (strstr($file, $checkoutFile)) { | |
$inArray = true; | |
} | |
} | |
// Only keep files that aren't used in checkout | |
if (!$inArray) { | |
// Remove the "{frontend|adminhtml}/{Vendor}/{ThemeName}/{locale}/" section from the names | |
$pattern = "~([a-zA-Z]*/){3}([a-zA-Z_]*/)~"; | |
$nonCheckoutFiles[] = preg_replace($pattern, "", $file);; | |
} | |
} | |
// Remove duplicate entries | |
$cleanedNonCheckoutFiles = array_unique($nonCheckoutFiles); | |
// Create file with appropriate XML elements | |
foreach ($cleanedNonCheckoutFiles as $file) { | |
// Example of following replace: Magento_Theme/menu.min.js => Magento_Theme::menu.min.js | |
$filename = preg_replace('~([A-Z][a-zA-Z]*_[A-Z][a-zA-Z]*)/~', '${1}::', $file); | |
$string = '<item type="file">' . $filename . '</item>'.PHP_EOL; | |
file_put_contents($outputOfNonCheckoutFiles, $string , FILE_APPEND | LOCK_EX); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment