]> BookStack Code Mirror - bookstack/blob - dev/licensing/gen-js-licenses
Merge pull request #5626 from BookStackApp/rubentalstra-development
[bookstack] / dev / licensing / gen-js-licenses
1 #!/usr/bin/env php
2 <?php
3
4 // This script reads the project composer.lock file to generate
5 // clear license details for our PHP dependencies.
6
7 declare(strict_types=1);
8 require "gen-licenses-shared.php";
9
10 $rootPath = dirname(__DIR__, 2);
11 $outputPath = "{$rootPath}/dev/licensing/js-library-licenses.txt";
12 $outputSeparator = "\n-----------\n";
13
14 $packages = [
15     ...glob("{$rootPath}/node_modules/*/package.json"),
16     ...glob("{$rootPath}/node_modules/@*/*/package.json"),
17 ];
18
19 $packageOutput = array_map(packageToOutput(...), $packages);
20
21 $licenseInfo = implode($outputSeparator, $packageOutput) . "\n";
22 file_put_contents($outputPath, $licenseInfo);
23
24 echo "License information written to {$outputPath}\n";
25 echo implode("\n", getWarnings()) . "\n";
26
27 function packageToOutput(string $packagePath): string
28 {
29     global $rootPath;
30     $package = json_decode(file_get_contents($packagePath));
31     $output = ["{$package->name}"];
32
33     $license = $package->license ?? '';
34     if ($license) {
35         $output[] = "License: {$license}";
36     } else {
37         warn("Package {$package->name}: No license found");
38     }
39
40     $licenseFile = findLicenseFile($package->name, $packagePath);
41     if ($licenseFile) {
42         $relLicenseFile = str_replace("{$rootPath}/", '', $licenseFile);
43         $output[] = "License File: {$relLicenseFile}";
44         $copyright = findCopyright($licenseFile);
45         if ($copyright) {
46             $output[] = "Copyright: {$copyright}";
47         } else {
48             warn("Package {$package->name}: no copyright found in its license");
49         }
50     }
51
52     $source = $package->repository->url ?? $package->repository ?? '';
53     if ($source) {
54         $output[] = "Source: {$source}";
55     }
56
57     $link = $package->homepage ?? $source;
58     if ($link) {
59         $output[] = "Link: {$link}";
60     }
61
62     return implode("\n", $output);
63 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.