Skip to content

Commit

Permalink
提供构建命令行工具
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Jul 16, 2024
1 parent c7d432d commit 75a2faf
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 76 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.build_www
run: python -m tools.cli --cleanup --font-formats woff2 --html
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ jobs:
release:
permissions:
contents: write
strategy:
matrix:
font-size: [8, 10, 12]
width-mode: [monospaced, proportional]
font-format: [otf, woff2, ttf, bdf, pcf, otc, ttc]
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -21,7 +27,7 @@ jobs:
python -m pip install pip --upgrade
python -m pip install -r requirements.txt
- name: Build
run: python -m tools.build
run: python -m tools.cli --cleanup --font-sizes ${{ matrix.font-size }} --width-modes ${{ matrix.width-mode }} --font-formats ${{ matrix.font-format }} --release
- name: Release
uses: softprops/action-gh-release@v2
with:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Logo 捏他自 [《游戏王》](https://zh.wikipedia.org/wiki/%E9%81%8A%E6%88%B
- [Jinja](https://github.com/pallets/jinja)
- [HTTPX](https://github.com/encode/httpx)
- [Loguru](https://github.com/Delgan/loguru)
- [Cyclopts](https://github.com/BrianPugh/cyclopts)

## 赞助

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ beautifulsoup4==4.12.3
Jinja2==3.1.4
httpx==0.27.0
loguru==0.7.2
cyclopts==2.9.3
45 changes: 6 additions & 39 deletions tools/build.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,12 @@
import itertools
import shutil

from tools import configs
from tools.configs import path_define
from tools.configs.dump import DumpConfig
from tools.configs.fallback import FallbackConfig
from tools.configs.font import FontConfig
from tools.services import update_service, dump_service, publish_service, info_service, template_service, image_service
from tools.services.font_service import DesignContext
from tools import cli


def main():
if path_define.build_dir.exists():
shutil.rmtree(path_define.build_dir)

update_service.setup_ark_pixel_glyphs()

dump_configs = DumpConfig.load()
fallback_configs = FallbackConfig.load()
font_configs = {}

for font_size in configs.font_sizes:
for dump_config in dump_configs[font_size]:
dump_service.dump_font(dump_config)

for fallback_config in fallback_configs[font_size]:
dump_service.apply_fallback(fallback_config)

font_config = FontConfig.load(font_size)
font_configs[font_size] = font_config
design_context = DesignContext.load(font_config)
for width_mode in configs.width_modes:
for font_format in itertools.chain(configs.font_formats, configs.font_collection_formats):
design_context.make_fonts(width_mode, font_format)
publish_service.make_release_zip(font_size, width_mode, font_format)
info_service.make_font_info(design_context, width_mode)
template_service.make_alphabet_html(design_context, width_mode)
template_service.make_demo_html(design_context)
image_service.make_preview_image(font_config)
template_service.make_index_html(font_configs)
template_service.make_playground_html(font_configs)
cli.main(
cleanup=True,
release=True,
all_attachments=True,
)


if __name__ == '__main__':
Expand Down
35 changes: 0 additions & 35 deletions tools/build_www.py

This file was deleted.

99 changes: 99 additions & 0 deletions tools/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import shutil

from cyclopts import App
from loguru import logger

from tools import configs
from tools.configs import path_define, FontSize, WidthMode, FontFormat, FontCollectionFormat
from tools.configs.dump import DumpConfig
from tools.configs.fallback import FallbackConfig
from tools.configs.font import FontConfig
from tools.services import update_service, dump_service, publish_service, info_service, template_service, image_service
from tools.services.font_service import DesignContext

app = App(version=configs.version)


@app.default
def main(
cleanup: bool = False,
font_sizes: list[FontSize] | None = None,
width_modes: list[WidthMode] | None = None,
font_formats: list[FontFormat | FontCollectionFormat] | None = None,
release: bool = False,
all_attachments: bool = False,
font_info: bool = False,
html: bool = False,
image: bool = False,
):
if font_sizes is None:
font_sizes = configs.font_sizes
if width_modes is None:
width_modes = configs.width_modes
if font_formats is None:
font_formats = configs.font_formats + configs.font_collection_formats
if all_attachments:
font_info = True
html = True
image = True

all_font_sizes = set(font_sizes) == set(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'font_info = {font_info}')
print(f'html = {html}')
print(f'image = {image}')
print()

if cleanup and path_define.build_dir.exists():
shutil.rmtree(path_define.build_dir)
logger.info("Delete dir: '{}'", path_define.build_dir)

update_service.setup_ark_pixel_glyphs()

dump_configs = DumpConfig.load()
fallback_configs = FallbackConfig.load()
font_configs = {}
design_contexts = {}
for font_size in font_sizes:
for dump_config in dump_configs[font_size]:
dump_service.dump_font(dump_config)

for fallback_config in fallback_configs[font_size]:
dump_service.apply_fallback(fallback_config)

font_config = FontConfig.load(font_size)
font_configs[font_size] = font_config
design_context = DesignContext.load(font_config)
design_contexts[font_size] = design_context
for width_mode in width_modes:
for font_format in font_formats:
design_context.make_fonts(width_mode, font_format)
if release:
publish_service.make_release_zip(font_size, width_mode, font_format)
if font_info:
info_service.make_font_info(design_context, width_mode)

if html:
for font_size in font_sizes:
design_context = design_contexts[font_size]
for width_mode in width_modes:
template_service.make_alphabet_html(design_context, width_mode)
template_service.make_demo_html(design_context)
if all_font_sizes:
template_service.make_index_html(font_configs)
template_service.make_playground_html(font_configs)

if image:
for font_size in font_sizes:
font_config = font_configs[font_size]
image_service.make_preview_image(font_config)


if __name__ == '__main__':
app()
6 changes: 6 additions & 0 deletions tools/update_docs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from tools import cli
from tools.services import publish_service


def main():
cli.main(
font_formats=[],
font_info=True,
image=True,
)
publish_service.update_docs()


Expand Down

0 comments on commit 75a2faf

Please sign in to comment.