changeset 7461:96b53ab02c2a

front-end: use license-checker to generate information about code used to build the front-end
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 25 Dec 2018 20:23:42 +0100
parents 7ec976c8c198
children 585dee5eb4bb
files kallithea/bin/kallithea_cli_front_end.py kallithea/front-end/package.json kallithea/templates/about.html
diffstat 3 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/bin/kallithea_cli_front_end.py	Mon Dec 10 22:35:29 2018 +0100
+++ b/kallithea/bin/kallithea_cli_front_end.py	Tue Dec 25 20:23:42 2018 +0100
@@ -17,6 +17,7 @@
 
 import os
 import subprocess
+import json
 
 import kallithea
 
@@ -60,3 +61,23 @@
         subprocess.check_call([lesscpath, '--relative-urls', '--source-map',
                 '--source-map-less-inline', lesspath, csspath],
                 cwd=front_end_dir)
+
+        click.echo("Generating LICENSES.txt")
+        check_licensing_json_path = os.path.join(tmp_dir, 'licensing.json')
+        licensing_txt_path = os.path.join(public_dir, 'LICENSES.txt')
+        subprocess.check_call([
+            os.path.join(front_end_dir, 'node_modules', '.bin', 'license-checker'),
+            '--json',
+            '--out', check_licensing_json_path,
+            ], cwd=front_end_dir)
+        with open(check_licensing_json_path) as jsonfile:
+            rows = json.loads(jsonfile.read())
+            with open(licensing_txt_path, 'w') as out:
+                out.write("The Kallithea front-end was built using the following Node modules:\n\n")
+                for name_version, values in sorted(rows.items()):
+                    name, version = name_version.rsplit('@', 1)
+                    line = "%s from https://www.npmjs.com/package/%s/v/%s\n  License: %s\n  Repository: %s\n" % (
+                        name_version, name, version, values['licenses'], values.get('repository', '-'))
+                    if values.get('copyright'):
+                        line += "  Copyright: %s\n" % (values['copyright'])
+                    out.write(line + '\n')
--- a/kallithea/front-end/package.json	Mon Dec 10 22:35:29 2018 +0100
+++ b/kallithea/front-end/package.json	Tue Dec 25 20:23:42 2018 +0100
@@ -6,6 +6,7 @@
   },
   "devDependencies": {
     "less": "~2.7",
-    "less-plugin-clean-css": "~1.5"
+    "less-plugin-clean-css": "~1.5",
+    "license-checker": "24.1.0"
   }
 }
--- a/kallithea/templates/about.html	Mon Dec 10 22:35:29 2018 +0100
+++ b/kallithea/templates/about.html	Tue Dec 25 20:23:42 2018 +0100
@@ -158,12 +158,17 @@
   </ul>
 
   <p>The above are the copyright holders who have submitted direct
-  contributions to the Kallithea repository.  In
-  the <a href="https://kallithea-scm.org/repos/kallithea">Kallithea source
-  code</a>, there is
-  a <a href="https://kallithea-scm.org/repos/kallithea/files/tip/LICENSE.md">list
+  contributions to the Kallithea repository.</p>
+
+  <p>In the <a href="https://kallithea-scm.org/repos/kallithea">Kallithea
+  source code</a>, there is a
+  <a href="https://kallithea-scm.org/repos/kallithea/files/tip/LICENSE.md">list
   of third-party libraries and code that Kallithea incorporates</a>.</p>
 
+  <p>The front-end contains a <a href="${h.url('/LICENSES.txt')}">list of
+  software that is used to build the front-end</a> but isn't distributed as a
+  part of Kallithea.</p>
+
   </div>
 </div>