[PATCH 2 of 3 PoC] cli: add commands to handle front-end generation

Thomas De Schampheleire patrickdepinguin at gmail.com
Mon Sep 24 20:45:23 UTC 2018


# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
# Date 1537814676 -7200
#      Mon Sep 24 20:44:36 2018 +0200
# Node ID b807b1e90e61d2c8c16c5e3ec5978ef7dd7a2d31
# Parent  dd4da443ed94fd93ca09d5f5fd9cf1b2c72b3cc4
cli: add commands to handle front-end generation

diff --git a/kallithea/bin/kallithea_cli.py b/kallithea/bin/kallithea_cli.py
--- a/kallithea/bin/kallithea_cli.py
+++ b/kallithea/bin/kallithea_cli.py
@@ -14,7 +14,11 @@
 
 import click
 
+from kallithea.bin.kallithea_cli_frontend import frontend
+
 @click.group()
 def cli():
     """Various commands to set up a Kallithea instance."""
     pass
+
+cli.add_command(frontend)
diff --git a/kallithea/bin/kallithea_cli_frontend.py b/kallithea/bin/kallithea_cli_frontend.py
new file mode 100644
--- /dev/null
+++ b/kallithea/bin/kallithea_cli_frontend.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import click
+import os
+import subprocess
+
+import kallithea
+
+rootdir = os.path.dirname(os.path.dirname(os.path.abspath(kallithea.__file__)))
+
+ at click.group(name='front-end')
+def frontend():
+    pass
+
+ at frontend.command(name='install-deps')
+def install_deps():
+    """Install required dependencies"""
+    click.echo("Running 'npm install' to install front-end dependencies from package.json\n")
+    subprocess.check_call(['npm', 'install'], cwd=rootdir)
+
+ at frontend.command(name='generate-css')
+def generate_css():
+    """Generate CSS files"""
+    click.echo("\nGenerating pygments.css")
+    with open(os.path.join(rootdir, 'kallithea', 'public', 'css', 'pygments.css'), 'w') as f:
+        subprocess.check_call(['pygmentize',
+                '-S', 'default',
+                '-f', 'html',
+                '-a', '.code-highlight'],
+                stdout=f)
+
+    click.echo("\nRunning 'npm run less' to generate CSS from LESS")
+    subprocess.check_call(['npm', 'run', 'less'], cwd=rootdir)
+
+ at frontend.command()
+ at click.pass_context
+def create(ctx):
+    """Create the front-end completely"""
+    ctx.invoke(install_deps)
+    ctx.invoke(generate_css)


More information about the kallithea-general mailing list