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.
53 lines
1.6 KiB
53 lines
1.6 KiB
#!/usr/bin/env php |
|
<?php |
|
/** |
|
* Generate package.json from importmap.php |
|
* Extracts all packages with versions and creates a package.json file |
|
*/ |
|
|
|
$importmapFile = __DIR__ . '/../importmap.php'; |
|
if (!file_exists($importmapFile)) { |
|
fwrite(STDERR, "Error: importmap.php not found\n"); |
|
exit(1); |
|
} |
|
|
|
$map = require $importmapFile; |
|
$packages = []; |
|
|
|
foreach ($map as $name => $config) { |
|
// Only process entries with version but no path (need to be downloaded) |
|
if (isset($config['version']) && !isset($config['path'])) { |
|
// Extract package name (handle scoped packages and subpaths) |
|
$parts = explode('/', $name); |
|
if ($name[0] === '@') { |
|
// Scoped package: @noble/curves/secp256k1 -> @noble/curves |
|
$packageName = $parts[0] . '/' . $parts[1]; |
|
} else { |
|
// Regular package: quill/dist/quill.core.css -> quill |
|
$packageName = $parts[0]; |
|
} |
|
|
|
// Keep the highest version if there are multiple entries for the same package |
|
if (!isset($packages[$packageName]) || version_compare($packages[$packageName], $config['version'], '<')) { |
|
$packages[$packageName] = $config['version']; |
|
} |
|
} |
|
} |
|
|
|
// Build package.json structure |
|
$packageJson = [ |
|
'name' => 'newsroom', |
|
'version' => '1.0.0', |
|
'description' => 'Importmap packages for Symfony Asset Mapper', |
|
'private' => true, |
|
'dependencies' => [] |
|
]; |
|
|
|
// Sort packages for consistent output |
|
ksort($packages); |
|
|
|
foreach ($packages as $name => $version) { |
|
$packageJson['dependencies'][$name] = '^' . $version; |
|
} |
|
|
|
echo json_encode($packageJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
|
|