这里是一个简单的Swift脚本,用于辅助carthage copy-frameworks命令:
import Foundation
let fileManager = FileManager.default
let carthageBuildPath = "/Users/username/Carthage/Build"
let carthageCachePath = "/Users/username/Library/Caches/org.carthage.CarthageKit"
let projectPath = "/Users/username/ProjectFolder"
// 1. 删除过期的构建
let carthageBuildFiles = try fileManager.contentsOfDirectory(atPath: carthageBuildPath)
for file in carthageBuildFiles {
let fullPath = carthageBuildPath + "/" + file
if fileManager.fileExists(atPath: fullPath) {
do {
let attributes = try fileManager.attributesOfItem(atPath: fullPath)
let modifiedDate = attributes[.modificationDate] as! Date
let daysAgo = Date().timeIntervalSince(modifiedDate) / (24 * 60 * 60)
if daysAgo > 7 { // 过期超过7天
try fileManager.removeItem(atPath: fullPath)
}
} catch {
print(error)
}
}
}
// 2. 复制框架
let carthageCacheFiles = try fileManager.contentsOfDirectory(atPath: carthageCachePath)
for file in carthageCacheFiles {
if file.hasSuffix(".framework.zip") || file.hasSuffix(".dSYM.zip") {
let fullPath = carthageCachePath + "/" + file
let destination = projectPath + "/Carthage/Build/" + file
do {
try fileManager.copyItem(atPath: fullPath, toPath: destination)
} catch {
print(error)
}
}
}
// 3. 解压缩框架
let carthageBuildFiles = try fileManager.contentsOfDirectory(atPath: carthageBuildPath)
for file in carthageBuildFiles {
if file.hasSuffix(".framework.zip") {
let fullPath = carthageBuildPath + "/" + file
let destination = carthageBuildPath + "/" + file.replacingOccurrences(of: ".zip", with: "")
do {
try fileManager.unzipItem(at: URL(fileURLWithPath: fullPath), to: URL(fileURLWithPath: destination))
} catch {
print(error)
}
}
}
这个脚本会自动完成以下三个步骤:
1. 删除Carthage/Build文件夹过期的构建产物(超过7天)
2. 从Carthage/Library/Caches文件夹复制.framework.zip和.dSYM.zip文件到Carthage/Build文件夹
3. 解压Build文件夹中的.framework.zip文件这样,您就无需手动运行carthage copy-frameworks命令,该脚本会自动完成framework的管理和同步。
© 版权声明
本文刊载的所有内容,包括文字、图片、音频、视频、软件、程序、以及网页版式设计等部门来源于互联网,版权均归原作者所有!本网站提供的内容服务于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯本网站及相关权利人的合法权利。
联系信息:邮箱aoxolcom@163.com或见网站底部。
联系信息:邮箱aoxolcom@163.com或见网站底部。
THE END
















请登录后发表评论
注册
社交帐号登录