forked from exercism/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.swift
72 lines (64 loc) · 2.39 KB
/
Package.swift
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// swift-tools-version:5.3
import PackageDescription
import Foundation
extension String {
var pascalCased: String {
let items = self.components(separatedBy: "-")
return items.reduce("", { $0 + $1.capitalized })
}
}
let currentDirectory = FileManager.default.currentDirectoryPath
let configPath = currentDirectory + "/config.json"
var conceptExercises = [String]()
var practiceExercises = [String]()
if
let jsonData = try? Data(contentsOf: URL(fileURLWithPath: configPath), options: Data.ReadingOptions.mappedIfSafe),
let json = try? JSONSerialization.jsonObject(with: jsonData, options: []),
let jsonDict = json as? [String: Any],
let exercisesDict = jsonDict["exercises"] as? [String: Any],
let conceptExercisesDict = exercisesDict["concept"] as? [[String: Any]],
let conceptExerciseSlugs = conceptExercisesDict.map({ $0["slug"] }) as? [String],
let practiceExercisesDict = exercisesDict["practice"] as? [[String: Any]],
let practiceExerciseSlugs = practiceExercisesDict.map({ $0["slug"] }) as? [String] {
conceptExercises += conceptExerciseSlugs
practiceExercises += practiceExerciseSlugs
} else {
print("Could not parse config.json at \(configPath)")
}
let conceptExerciseTargets: [Target] = conceptExercises.flatMap {
return [
.target(
name:"\($0.pascalCased)",
path:"./exercises/concept/\($0)/.meta/Sources"),
.testTarget(
name:"\($0.pascalCased)Tests",
dependencies: [
.target(name:"\($0.pascalCased)")
],
path:"./exercises/concept/\($0)/Tests",
exclude: ["LinuxMain.swift"])
]
}
let practiceExerciseTargets: [Target] = practiceExercises.flatMap {
return [
.target(
name:"\($0.pascalCased)",
path:"./exercises/practice/\($0)/.meta/Sources"),
.testTarget(
name:"\($0.pascalCased)Tests",
dependencies: [
.target(name:"\($0.pascalCased)")
],
path:"./exercises/practice/\($0)/Tests")
]
}
let allTargets = conceptExerciseTargets + practiceExerciseTargets
let package = Package(
name: "xswift",
products: [
.library(
name: "xswift",
targets: allTargets.filter { $0.type == .regular }.map { $0.name })
],
targets: allTargets
)