yx_icon_fonts_flutter/generate.sh

158 lines
3.4 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# YX Icon Fonts 生成脚本
# 用于生成图标数据和示例文件
set -e # 遇到错误时退出
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 打印带颜色的消息
print_info() {
echo -e "${BLUE} $1${NC}"
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
# 检查 Dart 是否安装
check_dart() {
if ! command -v dart &> /dev/null; then
print_error "Dart 未安装或不在 PATH 中"
exit 1
fi
}
# 检查必要文件是否存在
check_files() {
if [ ! -f "iconfont.json" ]; then
print_error "找不到 iconfont.json 文件"
exit 1
fi
if [ ! -f "scripts/generate_icons.dart" ]; then
print_error "找不到 scripts/generate_icons.dart 文件"
exit 1
fi
if [ ! -f "scripts/generate_example.dart" ]; then
print_error "找不到 scripts/generate_example.dart 文件"
exit 1
fi
if [ ! -f "scripts/generate_wrapper.dart" ]; then
print_error "找不到 scripts/generate_wrapper.dart 文件"
exit 1
fi
}
# 生成图标数据
generate_icons() {
print_info "正在生成图标数据..."
dart scripts/generate_icons.dart
print_success "图标数据生成完成"
}
# 生成示例文件
generate_example() {
print_info "正在生成示例文件..."
dart scripts/generate_example.dart
print_success "示例文件生成完成"
}
# 生成外部封装文件
generate_wrapper() {
print_info "正在生成外部封装文件..."
dart scripts/generate_wrapper.dart
print_success "外部封装文件生成完成"
}
# 生成所有文件
generate_all() {
print_info "开始生成所有文件..."
echo
generate_icons
echo
generate_wrapper
echo
generate_example
echo
print_success "所有文件生成完成!"
}
# 显示帮助信息
show_help() {
echo "YX Icon Fonts 生成脚本"
echo
echo "用法: $0 [选项]"
echo
echo "选项:"
echo " icons 只生成图标数据 (lib/src/yx_icon_fonts_data.dart)"
echo " wrapper 只生成外部封装文件 (generate/icons.dart)"
echo " example 只生成示例文件 (example/lib/icons.dart)"
echo " all 生成所有文件 (默认)"
echo " help 显示此帮助信息"
echo
echo "示例:"
echo " $0 # 生成所有文件"
echo " $0 icons # 只生成图标数据"
echo " $0 wrapper # 只生成外部封装文件"
echo " $0 example # 只生成示例文件"
echo
}
# 主函数
main() {
local action=${1:-all}
case $action in
"icons")
check_dart
check_files
generate_icons
;;
"wrapper")
check_dart
check_files
generate_wrapper
;;
"example")
check_dart
check_files
generate_example
;;
"all")
check_dart
check_files
generate_all
;;
"help"|"-h"|"--help")
show_help
;;
*)
print_error "未知选项: $action"
echo
show_help
exit 1
;;
esac
}
# 运行主函数
main "$@"