#!/bin/bash

# 运行 Rollup 打包
echo "正在打包代码..."
npx rollup -c

# 检查打包是否成功
if [ $? -eq 0 ]; then
    echo "打包成功，正在添加许可证注释..."
    
    # 定义许可证注释
    LICENSE_COMMENT=$(cat << 'EOF'
/**
 * Copyright 2025 王小玗
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
EOF
)

    # 创建临时文件并添加许可证注释
    echo "$LICENSE_COMMENT" > temp_file.js
    cat atal.min.js >> temp_file.js
    
    # 替换原文件
    mv temp_file.js atal.min.js
    
    echo "许可证注释已成功添加到 atal.min.js 文件开头"
else
    echo "打包失败，请检查错误信息"
    exit 1
fi
