-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate_resources
More file actions
executable file
·59 lines (43 loc) · 1.18 KB
/
generate_resources
File metadata and controls
executable file
·59 lines (43 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env swift
import Foundation
let fileManager = FileManager.default
let stdlibPath = "pkl/stdlib"
if !fileManager.fileExists(atPath: stdlibPath) {
print(
"""
Error: stdlib not found.
Init and update git submodules:
git submodule init
git submodule update
""")
exit(EXIT_FAILURE)
}
var str =
"""
// This file is auto-generated. Do not edit directly.
public enum Resources {
public static let stdlib: [String: String] = [
"""
let enumerator = fileManager.enumerator(atPath: stdlibPath)
while let element = enumerator?.nextObject() as? String {
if element.hasSuffix(".pkl") {
let value = try String(contentsOfFile: "\(stdlibPath)/\(element)")
.replacingOccurrences(of: "\\", with: "\\\\")
.replacingOccurrences(of: "\"\"\"", with: "\\\"\\\"\\\"")
.replacingOccurrences(of: "\n", with: "\n ")
str +=
"""
"\(element)":
\"\"\"
\(value)
\"\"\",\n\n
"""
}
}
str.removeLast(1)
str +=
"""
]
}
"""
try str.write(toFile: "Sources/pkl-lsp/Resources.swift", atomically: true, encoding: .utf8)