mirror of
https://github.com/StikDebug/StikJIT.git
synced 2026-10-15 20:10:31 +00:00
feat: restructure StikJIT integration workflow
This commit is contained in:
parent
dce417d893
commit
640fac91de
14 changed files with 853 additions and 118 deletions
|
|
@ -3,8 +3,25 @@ import Foundation
|
|||
enum BundledScript {
|
||||
|
||||
static func source(for script: StikJIT.Script) throws -> String {
|
||||
if case .custom(let url) = script {
|
||||
guard url.isFileURL else {
|
||||
throw StikJITError.customScript("expected a file URL")
|
||||
}
|
||||
do {
|
||||
let source = try String(contentsOf: url, encoding: .utf8)
|
||||
guard !source.isEmpty else {
|
||||
throw StikJITError.customScript("the file at \(url.path) is empty")
|
||||
}
|
||||
return source
|
||||
} catch let error as StikJITError {
|
||||
throw error
|
||||
} catch {
|
||||
throw StikJITError.customScript("could not read \(url.path): \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
let bundle = Bundle(for: BundleToken.self)
|
||||
guard let url = bundle.url(forResource: script.resourceName, withExtension: "js"),
|
||||
guard let url = bundle.url(forResource: script.name, withExtension: "js"),
|
||||
let source = try? String(contentsOf: url, encoding: .utf8),
|
||||
!source.isEmpty else {
|
||||
throw StikJITError.scriptUnavailable
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue