4 // This script reads the project composer.lock file to generate
5 // clear license details for our PHP dependencies.
7 declare(strict_types=1);
8 require "gen-licenses-shared.php";
10 $rootPath = dirname(__DIR__, 2);
11 $outputPath = "{$rootPath}/dev/licensing/js-library-licenses.txt";
12 $outputSeparator = "\n-----------\n";
15 ...glob("{$rootPath}/node_modules/*/package.json"),
16 ...glob("{$rootPath}/node_modules/@*/*/package.json"),
19 $packageOutput = array_map(packageToOutput(...), $packages);
21 $licenseInfo = implode($outputSeparator, $packageOutput) . "\n";
22 file_put_contents($outputPath, $licenseInfo);
24 echo "License information written to {$outputPath}\n";
25 echo implode("\n", getWarnings()) . "\n";
27 function packageToOutput(string $packagePath): string
30 $package = json_decode(file_get_contents($packagePath));
31 $output = ["{$package->name}"];
33 $license = $package->license ?? '';
35 $output[] = "License: {$license}";
37 warn("Package {$package->name}: No license found");
40 $licenseFile = findLicenseFile($package->name, $packagePath);
42 $relLicenseFile = str_replace("{$rootPath}/", '', $licenseFile);
43 $output[] = "License File: {$relLicenseFile}";
44 $copyright = findCopyright($licenseFile);
46 $output[] = "Copyright: {$copyright}";
48 warn("Package {$package->name}: no copyright found in its license");
52 $source = $package->repository->url ?? $package->repository ?? '';
54 $output[] = "Source: {$source}";
57 $link = $package->homepage ?? $source;
59 $output[] = "Link: {$link}";
62 return implode("\n", $output);