Skip to content

Commit

Permalink
调整 cli 命令参数
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Nov 8, 2024
1 parent 680d33c commit 63de435
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
python -m pip install pip --upgrade
python -m pip install -r requirements.txt
- name: Build
run: python -m tools.cli --cleanup --font-formats woff2 --html
run: python -m tools.cli --cleanup --font-formats woff2 --attachments html
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
python -m pip install pip --upgrade
python -m pip install -r requirements.txt
- name: Build
run: python -m tools.cli --cleanup --font-sizes ${{ matrix.font-size }} --width-modes ${{ matrix.width-mode }} --font-formats ${{ matrix.font-format }} --release
run: python -m tools.cli --cleanup --font-sizes ${{ matrix.font-size }} --width-modes ${{ matrix.width-mode }} --font-formats ${{ matrix.font-format }} --attachments release
- name: Release
uses: softprops/action-gh-release@v2
with:
Expand Down
3 changes: 1 addition & 2 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
def main():
cli.main(
cleanup=True,
release=True,
all_attachments=True,
attachments={'all'},
)


Expand Down
60 changes: 33 additions & 27 deletions tools/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import shutil
from typing import Literal

from cyclopts import App
from loguru import logger

from tools import configs
from tools.configs import path_define, FontSize, WidthMode, FontFormat
from tools.configs import path_define, FontSize, WidthMode, FontFormat, Attachment
from tools.configs.dump import DumpConfig
from tools.configs.fallback import FallbackConfig
from tools.configs.font import FontConfig
Expand All @@ -17,38 +18,37 @@
@app.default
def main(
cleanup: bool = False,
font_sizes: list[FontSize] | None = None,
width_modes: list[WidthMode] | None = None,
font_formats: list[FontFormat] | None = None,
all_attachments: bool = False,
release: bool = False,
info: bool = False,
html: bool = False,
image: bool = False,
font_sizes: set[FontSize] | None = None,
width_modes: set[WidthMode] | None = None,
font_formats: set[FontFormat] | None = None,
attachments: set[Attachment | Literal['all']] | None = None,
):
if font_sizes is None:
font_sizes = configs.font_sizes
else:
font_sizes = sorted(font_sizes, key=lambda x: configs.font_sizes.index(x))
if width_modes is None:
width_modes = configs.width_modes
else:
width_modes = sorted(width_modes, key=lambda x: configs.width_modes.index(x))
if font_formats is None:
font_formats = configs.font_formats
if all_attachments:
release = True
info = True
html = True
image = True

all_font_sizes = set(font_sizes) == set(configs.font_sizes)
else:
font_formats = sorted(font_formats, key=lambda x: configs.font_formats.index(x))
if attachments is None:
attachments = []
elif 'all' in attachments:
attachments = configs.attachments
else:
attachments = sorted(attachments, key=lambda x: configs.attachments.index(x))
all_font_sizes = font_sizes == configs.font_sizes

print()
print(f'cleanup = {cleanup}')
print(f'font_sizes = {repr(font_sizes)}')
print(f'width_modes = {repr(width_modes)}')
print(f'font_formats = {repr(font_formats)}')
print(f'release = {release}')
print(f'info = {info}')
print(f'html = {html}')
print(f'image = {image}')
print(f'font_sizes = {font_sizes}')
print(f'width_modes = {width_modes}')
print(f'font_formats = {font_formats}')
print(f'attachments = {attachments}')
print()

if cleanup and path_define.build_dir.exists():
Expand Down Expand Up @@ -76,19 +76,25 @@ def main(
for font_format in font_formats:
design_context.make_fonts(width_mode, font_format)

if release:
if 'release' in attachments:
for font_size in font_sizes:
for width_mode in width_modes:
for font_format in font_formats:
publish_service.make_release_zip(font_size, width_mode, font_format)

if info:
if 'info' in attachments:
for font_size in font_sizes:
design_context = design_contexts[font_size]
for width_mode in width_modes:
info_service.make_info(design_context, width_mode)

if html:
if 'alphabet' in attachments:
for font_size in font_sizes:
design_context = design_contexts[font_size]
for width_mode in width_modes:
info_service.make_alphabet_txt(design_context, width_mode)

if 'html' in attachments:
for font_size in font_sizes:
design_context = design_contexts[font_size]
for width_mode in width_modes:
Expand All @@ -98,7 +104,7 @@ def main(
template_service.make_index_html(font_configs)
template_service.make_playground_html(font_configs)

if image:
if 'image' in attachments:
for font_size in font_sizes:
font_config = font_configs[font_size]
image_service.make_preview_image(font_config)
Expand Down
9 changes: 9 additions & 0 deletions tools/configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@

font_collection_formats = ['otc', 'ttc']

type Attachment = Literal[
'release',
'info',
'alphabet',
'html',
'image',
]
attachments = list[Attachment](get_args(Attachment.__value__))

license_configs = {
8: [
'misaki',
Expand Down
9 changes: 9 additions & 0 deletions tools/services/info_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,12 @@ def make_info(design_context: DesignContext, width_mode: WidthMode):
file.write('\n')
_write_locale_chr_count_infos_table(file, _get_ksx1001_chr_count_infos(alphabet))
logger.info("Make info: '{}'", file_path)


def make_alphabet_txt(design_context: DesignContext, width_mode: WidthMode):
alphabet = sorted(design_context.get_alphabet(width_mode))

path_define.outputs_dir.mkdir(parents=True, exist_ok=True)
file_path = path_define.outputs_dir.joinpath(f'alphabet-{design_context.font_size}px-{width_mode}.txt')
file_path.write_text(''.join(alphabet), 'utf-8')
logger.info("Make alphabet txt: '{}'", file_path)
5 changes: 2 additions & 3 deletions tools/update_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

def main():
cli.main(
font_formats=[],
info=True,
image=True,
font_formats=set(),
attachments={'info', 'image'},
)
publish_service.update_docs()

Expand Down

0 comments on commit 63de435

Please sign in to comment.