Last active
March 21, 2020 20:46
-
-
Save tmotyl/31da3ea208004f91605d5d177c6303dd to your computer and use it in GitHub Desktop.
generate composer.json from modman
This file contains 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 | |
$folderToScan = '.modman/3rdParty'; | |
$directories = scandir($folderToScan); | |
foreach ($directories as $directory) { | |
if ($directory === '.' || $directory === '..' || $directory === '3rdParty') { | |
continue; | |
} | |
if (!file_exists($folderToScan . '/' . $directory . '/modman') | |
|| file_exists($folderToScan . '/' . $directory . '/composer.json') | |
) { | |
continue; | |
} | |
$fn = fopen($folderToScan . '/' . $directory . '/modman', "r"); | |
$composerJson = [ | |
"name" => strtolower($directory), | |
"type" => "magento-module", | |
"version" => "1.0.0", | |
"extra" => [ | |
"map" => [ | |
], | |
], | |
]; | |
$mapping = []; | |
while (!feof($fn)) { | |
$line = trim(fgets($fn)); | |
if ($line) { | |
$matches = []; | |
preg_match('/(.*)[ \t]+(.*)/', $line, $matches); | |
$mapping[] = $matches; | |
$composerJson['extra']['map'][] = [trim($matches[1]), trim($matches[2])]; | |
} | |
} | |
fclose($fn); | |
$content = json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); | |
file_put_contents($folderToScan . '/' . $directory . '/composer.json', $content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment