(args: list[str] | None = None, version: str | None = None)
| 1667 | |
| 1668 | # Now, refactor the main function to use these |
| 1669 | def main(args: list[str] | None = None, version: str | None = None): |
| 1670 | check_ftcli() |
| 1671 | parsed_args = parse_args(args) |
| 1672 | |
| 1673 | font_config = FontConfig(args=parsed_args, version=version) |
| 1674 | build_option = BuildOption(use_hinted=font_config.use_hinted) |
| 1675 | build_option.load_cn_dir_and_suffix(font_config) |
| 1676 | |
| 1677 | if parsed_args.dry: |
| 1678 | font_config.nerd_font["use_font_patcher"] = ( |
| 1679 | build_option.should_use_font_patcher(config=font_config, should_exit=False) |
| 1680 | ) |
| 1681 | if is_ci(): |
| 1682 | print(json.dumps(font_config.__dict__, indent=4)) |
| 1683 | else: |
| 1684 | print("font_config:", json.dumps(font_config.__dict__, indent=4)) |
| 1685 | print("build_option:", json.dumps(build_option.__dict__, indent=4)) |
| 1686 | print("parsed_args:", json.dumps(parsed_args.__dict__, indent=4)) |
| 1687 | return |
| 1688 | |
| 1689 | should_use_cache = parsed_args.cache |
| 1690 | target_styles = ( |
| 1691 | build_option.base_subfamily_list |
| 1692 | if parsed_args.least_styles or font_config.debug |
| 1693 | else None |
| 1694 | ) |
| 1695 | |
| 1696 | if not should_use_cache: |
| 1697 | print("🧹 Clean cache...\n") |
| 1698 | shutil.rmtree(build_option.output_dir, ignore_errors=True) |
| 1699 | shutil.rmtree(build_option.output_woff2, ignore_errors=True) |
| 1700 | |
| 1701 | makedirs(build_option.output_dir, exist_ok=True) |
| 1702 | makedirs(build_option.output_variable, exist_ok=True) |
| 1703 | makedirs(build_option.output_ttf, exist_ok=True) |
| 1704 | makedirs(build_option.output_ttf_hinted, exist_ok=True) |
| 1705 | |
| 1706 | start_time = time.time() |
| 1707 | print( |
| 1708 | f"🚩 Start building {font_config.family_name} {font_config.version_str} ...\n" |
| 1709 | ) |
| 1710 | |
| 1711 | # Build basic fonts if no cache |
| 1712 | if not should_use_cache or not build_option.has_cache: |
| 1713 | build_variable_fonts(font_config, build_option) |
| 1714 | build_base_fonts(font_config, build_option, target_styles) |
| 1715 | |
| 1716 | # Build variants |
| 1717 | build_nerd_fonts(font_config, build_option, target_styles) |
| 1718 | build_chinese_fonts(font_config, build_option, target_styles) |
| 1719 | |
| 1720 | # Write config |
| 1721 | with open( |
| 1722 | joinPaths(build_option.output_dir, "build-config.json"), "w", encoding="utf-8" |
| 1723 | ) as config_file: |
| 1724 | result = { |
| 1725 | "version": FONT_VERSION, |
| 1726 | "family_name": font_config.family_name, |
no test coverage detected