Skip to content

Commit

Permalink
Minify content published to API (qmk#20285)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored and coquizen committed Mar 30, 2023
1 parent 4d574f2 commit 2d75d77
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/python/qmk/cli/generate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from qmk.datetime import current_datetime
from qmk.info import info_json
from qmk.json_encoders import InfoJSONEncoder
from qmk.json_schema import json_load
from qmk.keymap import list_keymaps
from qmk.keyboard import find_readme, list_keyboards
Expand Down Expand Up @@ -43,14 +42,14 @@ def _resolve_keycode_specs(output_folder):
overall = load_spec(version)

output_file = output_folder / f'constants/keycodes_{version}.json'
output_file.write_text(json.dumps(overall), encoding='utf-8')
output_file.write_text(json.dumps(overall, separators=(',', ':')), encoding='utf-8')

for lang in list_languages():
for version in list_versions(lang):
overall = load_spec(version, lang)

output_file = output_folder / f'constants/keycodes_{lang}_{version}.json'
output_file.write_text(json.dumps(overall, indent=4), encoding='utf-8')
output_file.write_text(json.dumps(overall, separators=(',', ':')), encoding='utf-8')

# Purge files consumed by 'load_spec'
shutil.rmtree(output_folder / 'constants/keycodes/')
Expand All @@ -64,7 +63,7 @@ def _filtered_copy(src, dst):
data = json_load(src)

dst = dst.with_suffix('.json')
dst.write_text(json.dumps(data), encoding='utf-8')
dst.write_text(json.dumps(data, separators=(',', ':')), encoding='utf-8')
return dst

return shutil.copy2(src, dst)
Expand Down Expand Up @@ -130,7 +129,7 @@ def generate_api(cli):
}

keyboard_dir.mkdir(parents=True, exist_ok=True)
keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_json}})
keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_json}}, separators=(',', ':'))
if not cli.args.dry_run:
keyboard_info.write_text(keyboard_json, encoding='utf-8')
cli.log.debug('Wrote file %s', keyboard_info)
Expand All @@ -144,7 +143,7 @@ def generate_api(cli):
keymap_hjson = kb_json['keymaps'][keymap]['path']
keymap_json = v1_dir / keymap_hjson
keymap_json.parent.mkdir(parents=True, exist_ok=True)
keymap_json.write_text(json.dumps(json_load(Path(keymap_hjson))), encoding='utf-8')
keymap_json.write_text(json.dumps(json_load(Path(keymap_hjson)), separators=(',', ':')), encoding='utf-8')
cli.log.debug('Wrote keymap %s', keymap_json)

if 'usb' in kb_json:
Expand Down Expand Up @@ -173,12 +172,12 @@ def generate_api(cli):
_resolve_keycode_specs(v1_dir)

# Write the global JSON files
keyboard_all_json = json.dumps({'last_updated': current_datetime(), 'keyboards': kb_all}, cls=InfoJSONEncoder)
usb_json = json.dumps({'last_updated': current_datetime(), 'usb': usb_list}, cls=InfoJSONEncoder)
keyboard_list_json = json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, cls=InfoJSONEncoder)
keyboard_aliases_json = json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, cls=InfoJSONEncoder)
keyboard_metadata_json = json.dumps(keyboard_metadata, cls=InfoJSONEncoder)
constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)})
keyboard_all_json = json.dumps({'last_updated': current_datetime(), 'keyboards': kb_all}, separators=(',', ':'))
usb_json = json.dumps({'last_updated': current_datetime(), 'usb': usb_list}, separators=(',', ':'))
keyboard_list_json = json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, separators=(',', ':'))
keyboard_aliases_json = json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, separators=(',', ':'))
keyboard_metadata_json = json.dumps(keyboard_metadata, separators=(',', ':'))
constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}, separators=(',', ':'))

if not cli.args.dry_run:
keyboard_all_file.write_text(keyboard_all_json, encoding='utf-8')
Expand Down

0 comments on commit 2d75d77

Please sign in to comment.