forked from davedelong/AOC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·119 lines (87 loc) · 2.56 KB
/
Copy pathsetup
File metadata and controls
executable file
·119 lines (87 loc) · 2.56 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/xcrun --toolchain default swift
import Foundation
let today = Date()
let calendar = Calendar(identifier: .gregorian)
let day = calendar.component(.day, from: today)
let month = calendar.component(.month, from: today)
let year = calendar.component(.year, from: today)
let todayString = "\(month)/\(day)/\(year % 100)"
let u = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
let sources = u.appendingPathComponent("Sources")
let yearFolder = sources.appendingPathComponent("AOC\(year)")
let resourcesFolder = yearFolder.appendingPathComponent("Resources")
print("Creating \(yearFolder.path)")
mkdir(yearFolder)
mkdir(resourcesFolder)
let mainContents = """
//
// AOC\(year).swift
//
//
// Created by Dave DeLong on \(todayString).
//
import Foundation
@_exported import AOCCore
"""
mainContents >> yearFolder.appendingPathComponent("AOC\(year).swift")
for day in 1 ... 25 {
let dayFolder = yearFolder.appendingPathComponent("Day \(day)")
mkdir(dayFolder)
let dayContents = """
//
// Day\(day).swift
// test
//
// Created by Dave DeLong on \(todayString).
// Copyright © \(year) Dave DeLong. All rights reserved.
//
class Day\(day): Day {
override func run() -> (String, String) {
return super.run()
}
override func part1() -> String {
return #function
}
override func part2() -> String {
return #function
}
}
"""
dayContents >> dayFolder.appendingPathComponent("\(year)-Day\(day).swift")
"" >> resourcesFolder.appendingPathComponent("Day\(day).txt")
}
let testFile = u.appendingPathComponent("Tests").appendingPathComponent("AOCTests").appendingPathComponent("Test\(year).swift")
var contents = """
//
// Test\(year).swift
// AOCTests
//
// Created by Dave DeLong on \(todayString).
// Copyright © \(year) Dave DeLong. All rights reserved.
//
import XCTest
@testable import AOC\(year)
class Test\(year): XCTestCase {
"""
for day in 1 ... 25 {
let testContents = """
func testDay\(day)() {
let d = Day\(day)()
let (p1, p2) = d.run()
XCTAssertEqual(p1, "")
XCTAssertEqual(p2, "")
}
"""
contents += testContents
}
contents += """
}
"""
contents >> testFile
func mkdir(_ path: URL) {
try? FileManager.default.createDirectory(at: path, withIntermediateDirectories: true, attributes: nil)
}
infix operator >>
func >> (lhs: String, rhs: URL) {
try! Data(lhs.utf8).write(to: rhs, options: [])
}