You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.5 KiB
71 lines
2.5 KiB
#!/usr/bin/env php |
|
<?php |
|
/** |
|
* Fix importmap.php by removing 'version' from entries that have 'path' |
|
* Symfony importmap entries cannot have both 'path' and 'version' |
|
*/ |
|
|
|
$importmapFile = __DIR__ . '/../importmap.php'; |
|
if (!file_exists($importmapFile)) { |
|
fwrite(STDERR, "Error: importmap.php not found\n"); |
|
exit(1); |
|
} |
|
|
|
$map = require $importmapFile; |
|
$updated = false; |
|
|
|
foreach ($map as $name => &$config) { |
|
if (isset($config['path']) && isset($config['version'])) { |
|
unset($config['version']); |
|
$updated = true; |
|
echo "Removed version from: $name\n"; |
|
} |
|
} |
|
|
|
if ($updated) { |
|
$content = "<?php\n\n"; |
|
$content .= "/**\n"; |
|
$content .= " * Returns the importmap for this application.\n"; |
|
$content .= " *\n"; |
|
$content .= " * - \"path\" is a path inside the asset mapper system. Use the\n"; |
|
$content .= " * \"debug:asset-map\" command to see the full list of paths.\n"; |
|
$content .= " *\n"; |
|
$content .= " * - \"entrypoint\" (JavaScript only) set to true for any module that will\n"; |
|
$content .= " * be used as an \"entrypoint\" (and passed to the importmap() Twig function).\n"; |
|
$content .= " *\n"; |
|
$content .= " * The \"importmap:require\" command can be used to add new entries to this file.\n"; |
|
$content .= " *\n"; |
|
$content .= " * This file is auto-generated from npm packages. Run scripts/npm-to-importmap.php to update.\n"; |
|
$content .= " */\n"; |
|
$content .= "return [\n"; |
|
|
|
foreach ($map as $name => $config) { |
|
$nameEscaped = str_replace("'", "\\'", $name); |
|
$content .= " '$nameEscaped' => [\n"; |
|
|
|
if (isset($config['path'])) { |
|
$pathEscaped = str_replace("'", "\\'", $config['path']); |
|
$content .= " 'path' => '$pathEscaped',\n"; |
|
} |
|
if (isset($config['version'])) { |
|
$versionEscaped = str_replace("'", "\\'", $config['version']); |
|
$content .= " 'version' => '$versionEscaped',\n"; |
|
} |
|
if (isset($config['type'])) { |
|
$typeEscaped = str_replace("'", "\\'", $config['type']); |
|
$content .= " 'type' => '$typeEscaped',\n"; |
|
} |
|
if (isset($config['entrypoint'])) { |
|
$content .= " 'entrypoint' => " . ($config['entrypoint'] ? 'true' : 'false') . ",\n"; |
|
} |
|
|
|
$content .= " ],\n"; |
|
} |
|
|
|
$content .= "];\n"; |
|
|
|
file_put_contents($importmapFile, $content); |
|
echo "\n✓ Updated importmap.php\n"; |
|
} else { |
|
echo "No changes needed - all entries are correct\n"; |
|
} |