diff --git a/docs/contributing.rst b/docs/contributing.rst --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -37,10 +37,9 @@ To get started with Kallithea developmen pip install --upgrade pip setuptools pip install --upgrade -e . pip install --upgrade -r dev_requirements.txt - npm install # install dependencies - both tools and data - npm run less # for generating css from less kallithea-cli config-create my.ini kallithea-cli db-create -c my.ini --user=user --email=user@example.com --password=password --repos=/tmp + kallithea-cli front-end-build gearbox serve -c my.ini --reload & firefox http://127.0.0.1:5000/ diff --git a/docs/overview.rst b/docs/overview.rst --- a/docs/overview.rst +++ b/docs/overview.rst @@ -69,11 +69,9 @@ installed. (``pip install kallithea`` from a source tree will do pretty much the same but build the Kallithea package itself locally instead of downloading it.) -.. note:: The front-end code is built with Node. Currently, it must be built - locally after installing Kallithea. Assuming Node and the Node - Package Manager is available, other tools and source code will be - downloaded and installed. The front-end code can then be built from - source locally. +.. note:: Kallithea includes front-end code that needs to be processed first. +The tool npm_ is used to download external dependencies and orchestrate the +processing. The ``npm`` binary must thus be available. Web server @@ -144,3 +142,4 @@ continuous hammering from the internet. .. _WSGI: http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface .. _HAProxy: http://www.haproxy.org/ .. _Varnish: https://www.varnish-cache.org/ +.. _npm: https://www.npmjs.com/ diff --git a/docs/setup.rst b/docs/setup.rst --- a/docs/setup.rst +++ b/docs/setup.rst @@ -5,22 +5,6 @@ Setup ===== -Preparing front-end -------------------- - -Temporarily, in the current Kallithea version, some extra steps are required to -build front-end files: - -Find the right ``kallithea/public/less`` path with:: - - python -c "import os, kallithea; print os.path.join(os.path.dirname(os.path.abspath(kallithea.__file__)), 'public', 'less')" - -Then run:: - - npm install - npm run less - - Setting up Kallithea -------------------- @@ -70,6 +54,10 @@ path to the root). but when trying to do a push it will fail with permission denied errors unless it has write access. +Finally, prepare the front-end by running:: + + kallithea-cli front-end-build + You are now ready to use Kallithea. To run it simply execute:: gearbox serve -c my.ini diff --git a/docs/upgrade.rst b/docs/upgrade.rst --- a/docs/upgrade.rst +++ b/docs/upgrade.rst @@ -86,18 +86,7 @@ If you originally installed from version cd my-kallithea-clone hg pull -u pip install --upgrade -e . - -Temporarily, in the current version, an extra step is required to build -front-end files: - -Find the right ``kallithea/public/less`` path with:: - - python -c "import os, kallithea; print os.path.join(os.path.dirname(os.path.abspath(kallithea.__file__)), 'public', 'less')" - -Then run:: - - npm install - npm run less + kallithea-cli front-end-build 5. Upgrade your configuration diff --git a/docs/usage/customization.rst b/docs/usage/customization.rst --- a/docs/usage/customization.rst +++ b/docs/usage/customization.rst @@ -28,13 +28,10 @@ directory, you can use this file to over you can use this to override ``@kallithea-theme-main-color``, ``@kallithea-logo-url`` or other `Bootstrap variables`_. -After creating the ``theme.less`` file, you need to regenerate the CSS files. -Install npm for your platform and run:: +After creating the ``theme.less`` file, you need to regenerate the CSS files, by +running:: - npm install - npm run less - -in the Kallithea root directory. + kallithea-cli front-end-build --no-install-deps .. _bootstrap 3: https://getbootstrap.com/docs/3.3/ .. _bootstrap variables: https://getbootstrap.com/docs/3.3/customize/#less-variables 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 @@ -20,6 +20,7 @@ import kallithea.bin.kallithea_cli_celer import kallithea.bin.kallithea_cli_config import kallithea.bin.kallithea_cli_db import kallithea.bin.kallithea_cli_extensions +import kallithea.bin.kallithea_cli_front_end import kallithea.bin.kallithea_cli_iis import kallithea.bin.kallithea_cli_index import kallithea.bin.kallithea_cli_ishell diff --git a/kallithea/bin/kallithea_cli_front_end.py b/kallithea/bin/kallithea_cli_front_end.py new file mode 100644 --- /dev/null +++ b/kallithea/bin/kallithea_cli_front_end.py @@ -0,0 +1,50 @@ +# -*- 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 . + +import click +import kallithea.bin.kallithea_cli_base as cli_base + +import os +import subprocess + +import kallithea + +@cli_base.register_command() +@click.option('--install-deps/--no-install-deps', default=True, + help='Skip installation of dependencies, via "npm".') +@click.option('--generate/--no-generate', default=True, + help='Skip generation of front-end files.') +def front_end_build(install_deps, generate): + """Build the front-end. + + Install required dependencies for the front-end and generate the necessary + files. This step is complementary to any 'pip install' step which only + covers Python dependencies. + + The installation of front-end dependencies happens via the tool 'npm' which + is expected to be installed already. + """ + rootdir = os.path.dirname(os.path.dirname(os.path.abspath(kallithea.__file__))) + + if install_deps: + click.echo("Running 'npm install' to install front-end dependencies from package.json") + subprocess.check_call(['npm', 'install'], cwd=rootdir) + + if generate: + click.echo("Generating CSS") + lesscpath = os.path.join(rootdir, 'node_modules', '.bin', 'lessc') + lesspath = os.path.join(rootdir, 'kallithea', 'public', 'less', 'main.less') + csspath = os.path.join(rootdir, 'kallithea', 'public', 'css', 'style.css') + subprocess.check_call([lesscpath, '--relative-urls', '--source-map', + '--source-map-less-inline', lesspath, csspath]) diff --git a/package.json b/package.json --- a/package.json +++ b/package.json @@ -7,8 +7,5 @@ "devDependencies": { "less": "~2.7", "less-plugin-clean-css": "~1.5" - }, - "scripts": { - "less": "lessc --relative-urls --source-map --source-map-less-inline kallithea/public/less/main.less kallithea/public/css/style.css" } }