215 lines
7.8 KiB
Python
215 lines
7.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
AI Moji Build System
|
|
FontAwesome風のアイコンフォントパッケージを自動生成
|
|
|
|
使用方法:
|
|
python build.py # 全体ビルド
|
|
python build.py --font-only # フォントのみ生成
|
|
python build.py --css-only # CSSのみ生成
|
|
python build.py --package-only # パッケージングのみ
|
|
python build.py --clean # distディレクトリクリア
|
|
"""
|
|
|
|
import argparse
|
|
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
|
|
# 同じディレクトリの他のモジュールをインポート
|
|
from font_generator import AIMojiFontGenerator
|
|
from css_generator import AIMojiCSSGenerator
|
|
from packager import AIMojiPackager
|
|
|
|
class AIMojiBuildSystem:
|
|
def __init__(self, svg_dir: str = "../../svg", output_dir: str = "../../dist"):
|
|
self.svg_dir = Path(svg_dir)
|
|
self.output_dir = Path(output_dir)
|
|
|
|
# 各コンポーネントの初期化
|
|
self.font_generator = AIMojiFontGenerator(svg_dir, output_dir)
|
|
self.css_generator = AIMojiCSSGenerator(output_dir)
|
|
self.packager = AIMojiPackager(output_dir)
|
|
|
|
def clean_dist(self):
|
|
"""distディレクトリをクリア"""
|
|
if self.output_dir.exists():
|
|
print(f"🗑️ {self.output_dir} をクリア中...")
|
|
shutil.rmtree(self.output_dir)
|
|
print("✅ クリア完了")
|
|
else:
|
|
print("📁 distディレクトリが存在しません")
|
|
|
|
def validate_prerequisites(self) -> bool:
|
|
"""前提条件チェック"""
|
|
errors = []
|
|
|
|
# SVGディレクトリ存在チェック
|
|
if not self.svg_dir.exists():
|
|
errors.append(f"SVGディレクトリが存在しません: {self.svg_dir}")
|
|
|
|
# SVGファイル存在チェック
|
|
svg_files = list(self.svg_dir.glob("*.svg"))
|
|
if not svg_files:
|
|
errors.append(f"SVGファイルが見つかりません: {self.svg_dir}")
|
|
|
|
# Python依存関係チェック
|
|
try:
|
|
import fontforge
|
|
except ImportError:
|
|
errors.append("FontForgeがインストールされていません (pip install fontforge)")
|
|
|
|
if errors:
|
|
print("❌ 前提条件エラー:")
|
|
for error in errors:
|
|
print(f" - {error}")
|
|
return False
|
|
|
|
print("✅ 前提条件チェック: 問題なし")
|
|
print(f"📂 SVGファイル数: {len(svg_files)}")
|
|
return True
|
|
|
|
def build_font(self) -> bool:
|
|
"""フォント生成"""
|
|
try:
|
|
print("\n🔤 === フォント生成フェーズ ===")
|
|
result = self.font_generator.generate()
|
|
return result["success"]
|
|
except Exception as e:
|
|
print(f"❌ フォント生成エラー: {e}")
|
|
return False
|
|
|
|
def build_css(self) -> bool:
|
|
"""CSS/SCSS生成"""
|
|
try:
|
|
print("\n🎨 === CSS/SCSS生成フェーズ ===")
|
|
self.css_generator.generate_all()
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ CSS生成エラー: {e}")
|
|
return False
|
|
|
|
def build_package(self) -> bool:
|
|
"""パッケージング"""
|
|
try:
|
|
print("\n📦 === パッケージングフェーズ ===")
|
|
result = self.packager.package_all()
|
|
return result["is_valid"]
|
|
except Exception as e:
|
|
print(f"❌ パッケージングエラー: {e}")
|
|
return False
|
|
|
|
def build_all(self) -> bool:
|
|
"""全体ビルド"""
|
|
print("🚀 AI Moji アイコンフォント パッケージ生成開始")
|
|
print(f"⏰ 開始時刻: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
print("=" * 60)
|
|
|
|
# 前提条件チェック
|
|
if not self.validate_prerequisites():
|
|
return False
|
|
|
|
# フォント生成
|
|
if not self.build_font():
|
|
return False
|
|
|
|
# CSS生成
|
|
if not self.build_css():
|
|
return False
|
|
|
|
# パッケージング
|
|
if not self.build_package():
|
|
return False
|
|
|
|
print("\n" + "=" * 60)
|
|
print("🎉 AI Moji アイコンフォントパッケージ生成完了!")
|
|
print(f"⏰ 完了時刻: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
print(f"📁 出力ディレクトリ: {self.output_dir.absolute()}")
|
|
print("\n📋 ファイル構成:")
|
|
self.show_output_structure()
|
|
print("\n🚀 npm パッケージとして公開準備完了!")
|
|
print(" cd dist && npm publish")
|
|
|
|
return True
|
|
|
|
def show_output_structure(self):
|
|
"""出力ディレクトリ構造表示"""
|
|
if not self.output_dir.exists():
|
|
print(" (出力ディレクトリが存在しません)")
|
|
return
|
|
|
|
def print_tree(path: Path, prefix: str = ""):
|
|
items = sorted(path.iterdir(), key=lambda x: (x.is_file(), x.name))
|
|
for i, item in enumerate(items):
|
|
is_last = i == len(items) - 1
|
|
current_prefix = "└── " if is_last else "├── "
|
|
print(f" {prefix}{current_prefix}{item.name}")
|
|
|
|
if item.is_dir() and item.name in ["fonts", "css", "scss"]:
|
|
extension = " " if is_last else "│ "
|
|
print_tree(item, prefix + extension)
|
|
|
|
print_tree(self.output_dir)
|
|
|
|
def main():
|
|
"""メイン実行関数"""
|
|
parser = argparse.ArgumentParser(
|
|
description="AI Moji FontAwesome風アイコンフォントパッケージ生成システム",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
使用例:
|
|
python build.py # 全体ビルド
|
|
python build.py --font-only # フォントのみ生成
|
|
python build.py --css-only # CSSのみ生成
|
|
python build.py --package-only # パッケージングのみ
|
|
python build.py --clean # distディレクトリクリア
|
|
"""
|
|
)
|
|
|
|
parser.add_argument("--font-only", action="store_true",
|
|
help="フォントファイルのみ生成")
|
|
parser.add_argument("--css-only", action="store_true",
|
|
help="CSS/SCSSファイルのみ生成")
|
|
parser.add_argument("--package-only", action="store_true",
|
|
help="パッケージングのみ実行")
|
|
parser.add_argument("--clean", action="store_true",
|
|
help="distディレクトリをクリア")
|
|
parser.add_argument("--svg-dir", default="../../svg",
|
|
help="SVGファイルディレクトリ (デフォルト: ../../svg)")
|
|
parser.add_argument("--output-dir", default="../../dist",
|
|
help="出力ディレクトリ (デフォルト: ../../dist)")
|
|
|
|
args = parser.parse_args()
|
|
|
|
# ビルドシステム初期化
|
|
build_system = AIMojiBuildSystem(args.svg_dir, args.output_dir)
|
|
|
|
try:
|
|
# クリーンアップ
|
|
if args.clean:
|
|
build_system.clean_dist()
|
|
return 0
|
|
|
|
# 個別ビルド
|
|
if args.font_only:
|
|
success = build_system.build_font()
|
|
elif args.css_only:
|
|
success = build_system.build_css()
|
|
elif args.package_only:
|
|
success = build_system.build_package()
|
|
else:
|
|
# 全体ビルド
|
|
success = build_system.build_all()
|
|
|
|
return 0 if success else 1
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n⚠️ ビルドが中断されました")
|
|
return 1
|
|
except Exception as e:
|
|
print(f"\n❌ 予期しないエラーが発生しました: {e}")
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
exit(main()) |