-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add beet.contrib.minify_json plugin
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Plugin that minifies json files.""" | ||
|
||
|
||
import json | ||
from typing import Iterator, Union | ||
|
||
from beet import Context, DataPack, JsonFileBase, ResourcePack | ||
|
||
|
||
def beet_default(ctx: Context): | ||
for pack in ctx.packs: | ||
for json_file in find_json_files(pack): | ||
json_file.text = json.dumps(json_file.data, separators=(",", ":")) | ||
|
||
|
||
def find_json_files(pack: Union[ResourcePack, DataPack]) -> Iterator[JsonFileBase]: | ||
for extra_file in pack.extra.values(): | ||
if isinstance(extra_file, JsonFileBase): | ||
yield extra_file | ||
for namespace in pack.values(): | ||
for file_type, container in namespace.items(): | ||
if issubclass(file_type, JsonFileBase): | ||
yield from container.values() # type: ignore |