Files
@ cc2c473abc5f
Branch filter:
Location: kallithea/kallithea/bin/kallithea_cli_front_end.py
cc2c473abc5f
5.6 KiB
text/x-python
front-end: Use DataTables from node_modules and stop bundling it
There is no minimized version in the npm package. For now, we just use the raw
one. We can minimize later.
There is no minimized version in the npm package. For now, we just use the raw
one. We can minimize later.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | # -*- 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 kallithea.bin.kallithea_cli_base as cli_base
import os
import shutil
import subprocess
import json
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.
"""
front_end_dir = os.path.abspath(os.path.join(kallithea.__file__, '..', 'front-end'))
public_dir = os.path.abspath(os.path.join(kallithea.__file__, '..', 'public'))
if install_deps:
click.echo("Running 'npm install' to install front-end dependencies from package.json")
subprocess.check_call(['npm', 'install'], cwd=front_end_dir)
if generate:
tmp_dir = os.path.join(front_end_dir, 'tmp')
if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir)
click.echo("Building CSS styling based on Bootstrap")
with open(os.path.join(tmp_dir, 'pygments.css'), 'w') as f:
subprocess.check_call(['pygmentize',
'-S', 'default',
'-f', 'html',
'-a', '.code-highlight'],
stdout=f)
lesscpath = os.path.join(front_end_dir, 'node_modules', '.bin', 'lessc')
lesspath = os.path.join(public_dir, 'less', 'main.less')
csspath = os.path.join(public_dir, 'css', 'style.css')
subprocess.check_call([lesscpath, '--relative-urls', '--source-map',
'--source-map-less-inline', lesspath, csspath],
cwd=front_end_dir)
click.echo("Preparing Bootstrap JS")
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'bootstrap', 'dist', 'js', 'bootstrap.js'), os.path.join(public_dir, 'js', 'bootstrap.js'))
click.echo("Preparing jQuery JS with Flot")
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'jquery', 'dist', 'jquery.min.js'), os.path.join(public_dir, 'js', 'jquery.min.js'))
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'jquery.flot', 'jquery.flot.js'), os.path.join(public_dir, 'js', 'jquery.flot.js'))
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'jquery.flot', 'jquery.flot.selection.js'), os.path.join(public_dir, 'js', 'jquery.flot.selection.js'))
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'jquery.flot', 'jquery.flot.time.js'), os.path.join(public_dir, 'js', 'jquery.flot.time.js'))
click.echo("Preparing DataTables JS")
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'datatables.net', 'js', 'jquery.dataTables.js'), os.path.join(public_dir, 'js', 'jquery.dataTables.js'))
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'datatables.net-bs', 'js', 'dataTables.bootstrap.js'), os.path.join(public_dir, 'js', 'dataTables.bootstrap.js'))
click.echo("Preparing Select2 JS")
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'select2', 'select2.js'), os.path.join(public_dir, 'js', 'select2.js'))
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'select2', 'select2.png'), os.path.join(public_dir, 'css', 'select2.png'))
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'select2', 'select2x2.png'), os.path.join(public_dir, 'css', 'select2x2.png'))
shutil.copy(os.path.join(front_end_dir, 'node_modules', 'select2', 'select2-spinner.gif'), os.path.join(public_dir, 'css', 'select2-spinner.gif'))
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')
|