bundle svg
This commit is contained in:
@@ -201,7 +201,48 @@ def should_exclude_file(file_path: Path, source_dir: Path, exclude_patterns: Lis
|
||||
|
||||
return False
|
||||
|
||||
def copy_source_files(source_dir: Path, dest_dir: Path, exclude_patterns: List[str], exclude_files: List[str] = None, minify: bool = True):
|
||||
def _format_version_tuple(version_tuple: tuple) -> str:
|
||||
"""Format version tuple for insertion into bl_info."""
|
||||
return "(" + ", ".join(str(part) for part in version_tuple) + ")"
|
||||
|
||||
|
||||
def _edition_version_tuple(version: str, version_type: str) -> tuple:
|
||||
"""Return edition-specific version tuple."""
|
||||
try:
|
||||
major_str, minor_str, patch_str = version.split(".", 2)
|
||||
major, minor, patch = int(major_str), int(minor_str), int(patch_str)
|
||||
except ValueError:
|
||||
# Fallback if version string unexpected
|
||||
return (1, 0, 0) if version_type == "free" else (1, 0, 1)
|
||||
|
||||
if version_type == "full":
|
||||
return (major, minor, patch + 1)
|
||||
return (major, minor, patch)
|
||||
|
||||
|
||||
def _apply_edition_overrides(rel_path: Path, source_code: str, version_type: str, version: str) -> str:
|
||||
"""Inject edition-specific metadata into copied source files."""
|
||||
if rel_path.as_posix() == "__init__.py":
|
||||
edition_name = "Text Texture Generator (Pro)" if version_type == "full" else "Text Texture Generator (Free)"
|
||||
target_version_tuple = _edition_version_tuple(version, version_type)
|
||||
|
||||
source_code = re.sub(
|
||||
r'"name":\s*"Text Texture Generator\s*\([^"]*\)"',
|
||||
f'"name": "{edition_name}"',
|
||||
source_code,
|
||||
count=1
|
||||
)
|
||||
|
||||
source_code = re.sub(
|
||||
r'"version":\s*\([^\)]+\)',
|
||||
f'"version": {_format_version_tuple(target_version_tuple)}',
|
||||
source_code,
|
||||
count=1
|
||||
)
|
||||
return source_code
|
||||
|
||||
|
||||
def copy_source_files(source_dir: Path, dest_dir: Path, exclude_patterns: List[str], exclude_files: List[str] = None, minify: bool = True, version_type: str = "free", version: str = "1.0.0"):
|
||||
"""Copy source files to destination, excluding specified patterns and files."""
|
||||
if exclude_files is None:
|
||||
exclude_files = []
|
||||
@@ -232,17 +273,25 @@ def copy_source_files(source_dir: Path, dest_dir: Path, exclude_patterns: List[s
|
||||
# Read, minify, and write Python files
|
||||
try:
|
||||
source_code = item.read_text(encoding='utf-8')
|
||||
source_code = _apply_edition_overrides(rel_path, source_code, version_type, version)
|
||||
minified_code = minify_python_code(source_code)
|
||||
dest_file.write_text(minified_code, encoding='utf-8')
|
||||
print(f" Copied (minified): {rel_path}")
|
||||
except Exception as e:
|
||||
# If minification fails, fall back to regular copy
|
||||
print(f" Warning: Could not minify {rel_path}, copying as-is: {e}")
|
||||
shutil.copy2(item, dest_file)
|
||||
source_code = item.read_text(encoding='utf-8')
|
||||
source_code = _apply_edition_overrides(rel_path, source_code, version_type, version)
|
||||
dest_file.write_text(source_code, encoding='utf-8')
|
||||
print(f" Copied: {rel_path}")
|
||||
else:
|
||||
# Copy non-Python files or when minification is disabled
|
||||
shutil.copy2(item, dest_file)
|
||||
if item.suffix == '.py':
|
||||
source_code = item.read_text(encoding='utf-8')
|
||||
source_code = _apply_edition_overrides(rel_path, source_code, version_type, version)
|
||||
dest_file.write_text(source_code, encoding='utf-8')
|
||||
else:
|
||||
shutil.copy2(item, dest_file)
|
||||
print(f" Copied: {rel_path}")
|
||||
copied_count += 1
|
||||
|
||||
@@ -360,7 +409,7 @@ def build_addon(version_type: str, version: Optional[str] = None, output_dir: Op
|
||||
|
||||
# Copy source files to temp directory with version-specific exclusions
|
||||
build_temp_dir = temp_dir / f"{config['project']['id']}_{version_type}"
|
||||
copy_source_files(source_dir, build_temp_dir, exclude_patterns, exclude_files, minify)
|
||||
copy_source_files(source_dir, build_temp_dir, exclude_patterns, exclude_files, minify, version_type=version_type, version=version)
|
||||
|
||||
# Create output filename
|
||||
version_suffix = f"_{version_type}" if version_type == "free" else ""
|
||||
|
||||
Reference in New Issue
Block a user