-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6d5a6ef
Showing
104 changed files
with
4,314 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "PathKit", | ||
"repositoryURL": "https://github.com/kylef/PathKit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "e2f5be30e4c8f531c9c1e8765aa7b71c0a45d7a0", | ||
"version": "0.9.2" | ||
} | ||
}, | ||
{ | ||
"package": "PromiseKit", | ||
"repositoryURL": "https://github.com/mxcl/PromiseKit", | ||
"state": { | ||
"branch": null, | ||
"revision": "f14f16cc2602afec1030e4f492100d6d43dca544", | ||
"version": "6.13.1" | ||
} | ||
}, | ||
{ | ||
"package": "Rainbow", | ||
"repositoryURL": "https://github.com/onevcat/Rainbow", | ||
"state": { | ||
"branch": null, | ||
"revision": "9c52c1952e9b2305d4507cf473392ac2d7c9b155", | ||
"version": "3.1.5" | ||
} | ||
}, | ||
{ | ||
"package": "Spectre", | ||
"repositoryURL": "https://github.com/kylef/Spectre.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5", | ||
"version": "0.9.0" | ||
} | ||
}, | ||
{ | ||
"package": "Stencil", | ||
"repositoryURL": "https://github.com/kylef/Stencil.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "0e9a78d6584e3812cd9c09494d5c7b483e8f533c", | ||
"version": "0.13.1" | ||
} | ||
}, | ||
{ | ||
"package": "StencilSwiftKit", | ||
"repositoryURL": "https://github.com/SwiftGen/StencilSwiftKit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "dbf02bd6afe71b65ead2bd250aaf974abc688094", | ||
"version": "2.7.2" | ||
} | ||
}, | ||
{ | ||
"package": "SwiftCLI", | ||
"repositoryURL": "https://github.com/jakeheis/SwiftCLI", | ||
"state": { | ||
"branch": null, | ||
"revision": "c72c4564f8c0a24700a59824880536aca45a4cae", | ||
"version": "6.0.1" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// swift-tools-version:5.1 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "AnalyticsGen", | ||
platforms: [ | ||
.macOS(.v10_12) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/jakeheis/SwiftCLI", from: "6.0.0"), | ||
.package(url: "https://github.com/kylef/PathKit.git", from: "0.9.2"), | ||
.package(url: "https://github.com/onevcat/Rainbow", from: "3.0.0"), | ||
.package(url: "https://github.com/mxcl/PromiseKit", from: "6.8.0"), | ||
.package(url: "https://github.com/kylef/Stencil.git", from: "0.13.0"), | ||
.package(url: "https://github.com/SwiftGen/StencilSwiftKit.git", from: "2.7.2") | ||
], | ||
targets: [ | ||
.target( | ||
name: "AnalyticsGen", | ||
dependencies: [ | ||
"AnalyticsGenTools", | ||
"SwiftCLI", | ||
"PathKit", | ||
"Rainbow", | ||
"PromiseKit", | ||
"Stencil", | ||
"StencilSwiftKit" | ||
] | ||
), | ||
.target( | ||
name: "AnalyticsGenTools", | ||
dependencies: ["SwiftCLI", "PathKit"] | ||
), | ||
.testTarget( | ||
name: "AnalyticsGenTests", | ||
dependencies: ["AnalyticsGen"] | ||
) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# AnalyticsGen | ||
|
||
A description of this package. |
44 changes: 44 additions & 0 deletions
44
Sources/AnalyticsGen/Coders/Decodable/DecodableCoder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// DecodableCoder.swift | ||
// AnalyticsGen | ||
// | ||
// Created by Timur Shafigullin on 19/01/2020. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol DecodableCoder { | ||
|
||
// MARK: - Instance Methods | ||
|
||
func encode<T: Encodable>(_ object: T, encoder: JSONEncoder) throws -> [String: Any] | ||
func encode<T: Encodable>(_ array: [T], encoder: JSONEncoder) throws -> [[String: Any]] | ||
|
||
func decode<T: Decodable>(from json: [String: Any], decoder: JSONDecoder) throws -> T | ||
func decode<T: Decodable>(from json: [[String: Any]], decoder: JSONDecoder) throws -> [T] | ||
} | ||
|
||
// MARK: - | ||
|
||
extension DecodableCoder { | ||
|
||
// MARK: - Instance Methods | ||
|
||
func encode<T: Encodable>(_ object: T, encoder: JSONEncoder = JSONEncoder()) throws -> [String: Any] { | ||
return try self.encode(object, encoder: encoder) | ||
} | ||
|
||
func encode<T: Encodable>(_ array: [T], encoder: JSONEncoder = JSONEncoder()) throws -> [[String: Any]] { | ||
return try self.encode(array, encoder: encoder) | ||
} | ||
|
||
// MARK: - | ||
|
||
func decode<T: Decodable>(from json: [String: Any], decoder: JSONDecoder = JSONDecoder()) throws -> T { | ||
return try self.decode(from: json, decoder: decoder) | ||
} | ||
|
||
func decode<T: Decodable>(from json: [[String: Any]], decoder: JSONDecoder = JSONDecoder()) throws -> [T] { | ||
return try self.decode(from: json, decoder: decoder) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
Sources/AnalyticsGen/Coders/Decodable/DefualtDecodableCoder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// DefualtDecodableCoder.swift | ||
// AnalyticsGen | ||
// | ||
// Created by Timur Shafigullin on 19/01/2020. | ||
// | ||
|
||
import Foundation | ||
|
||
final class DefaultDecodableCoder: DecodableCoder { | ||
|
||
// MARK: - DecodableCoder | ||
|
||
func encode<T: Encodable>(_ object: T, encoder: JSONEncoder) throws -> [String: Any] { | ||
let data = try encoder.encode(object) | ||
let object = try JSONSerialization.jsonObject(with: data) | ||
|
||
guard let json = object as? [String: Any] else { | ||
let context = DecodingError.Context( | ||
codingPath: [], | ||
debugDescription: "Deserialized object is not a dictionary" | ||
) | ||
|
||
throw DecodingError.typeMismatch(type(of: object), context) | ||
} | ||
|
||
return json | ||
} | ||
|
||
func encode<T: Encodable>(_ array: [T], encoder: JSONEncoder) throws -> [[String: Any]] { | ||
let data = try encoder.encode(array) | ||
let object = try JSONSerialization.jsonObject(with: data) | ||
|
||
guard let json = object as? [[String: Any]] else { | ||
let context = DecodingError.Context( | ||
codingPath: [], | ||
debugDescription: "Deserialized object is not a array" | ||
) | ||
|
||
throw DecodingError.typeMismatch(type(of: object), context) | ||
} | ||
|
||
return json | ||
} | ||
|
||
// MARK: - | ||
|
||
func decode<T: Decodable>(from json: [String: Any], decoder: JSONDecoder) throws -> T { | ||
let data = try JSONSerialization.data(withJSONObject: json) | ||
|
||
return try decoder.decode(from: data) | ||
} | ||
|
||
func decode<T: Decodable>(from json: [[String: Any]], decoder: JSONDecoder) throws -> [T] { | ||
let data = try JSONSerialization.data(withJSONObject: json) | ||
|
||
return try decoder.decode(from: data) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Sources/AnalyticsGen/Coders/Tracker/DefaultTrackerCoder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// DefaultTrackerCoder.swift | ||
// AnalyticsGen | ||
// | ||
// Created by Timur Shafigullin on 19/01/2020. | ||
// | ||
|
||
import Foundation | ||
|
||
final class DefaultTrackerCoder: TrackerCoder { | ||
|
||
// MARK: - Instance Properties | ||
|
||
let decodableCoder: DecodableCoder | ||
|
||
// MARK: - Initializers | ||
|
||
init(decodableCoder: DecodableCoder) { | ||
self.decodableCoder = decodableCoder | ||
} | ||
|
||
// MARK: - TrackerCoder | ||
|
||
func encode(trackers: [Tracker]) -> [String: Any] { | ||
let trackersJSON = (try? self.decodableCoder.encode(trackers)) ?? [] | ||
|
||
return ["trackers": trackersJSON] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// TrackerCoder.swift | ||
// AnalyticsGen | ||
// | ||
// Created by Timur Shafigullin on 19/01/2020. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol TrackerCoder { | ||
|
||
// MARK: - Instance Methods | ||
|
||
func encode(trackers: [Tracker]) -> [String: Any] | ||
} |
45 changes: 45 additions & 0 deletions
45
Sources/AnalyticsGen/Commands/AsyncExecutableCommand.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// AsyncExecutableCommand.swift | ||
// AnalyticsGen | ||
// | ||
// Created by Timur Shafigullin on 12/01/2020. | ||
// | ||
|
||
import Foundation | ||
import SwiftCLI | ||
import Rainbow | ||
|
||
protocol AsyncExecutableCommand: Command { | ||
|
||
// MARK: - Instance Methods | ||
|
||
func executeAsyncAndExit() throws | ||
|
||
func fail(message: String) -> Never | ||
func succeed(message: String) -> Never | ||
} | ||
|
||
// MARK: - | ||
|
||
extension AsyncExecutableCommand { | ||
|
||
// MARK: - Instance Methods | ||
|
||
func execute() throws { | ||
try self.executeAsyncAndExit() | ||
|
||
RunLoop.main.run() | ||
} | ||
|
||
func fail(message: String) -> Never { | ||
self.stderr <<< message.red | ||
|
||
exit(EXIT_FAILURE) | ||
} | ||
|
||
func succeed(message: String) -> Never { | ||
self.stdout <<< message.green | ||
|
||
exit(EXIT_SUCCESS) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Sources/AnalyticsGen/Commands/GenerationConfigurableCommand.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// GenerationConfigurableCommand.swift | ||
// AnalyticsGen | ||
// | ||
// Created by Timur Shafigullin on 19/01/2020. | ||
// | ||
|
||
import Foundation | ||
import SwiftCLI | ||
|
||
protocol GenerationConfigurableCommand: Command { | ||
|
||
// MARK: - Instance Properties | ||
|
||
var template: Key<String> { get } | ||
var destination: Key<String> { get } | ||
|
||
var generationConfiguration: GenerationConfiguration { get } | ||
} | ||
|
||
// MARK: - | ||
|
||
extension GenerationConfigurableCommand { | ||
|
||
// MARK: - Instance Properties | ||
|
||
var generationConfiguration: GenerationConfiguration { | ||
GenerationConfiguration(template: template.value, templateOptions: nil, destination: self.destination.value) | ||
} | ||
} |
Oops, something went wrong.