Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move most stuff to a lib #40

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- stage: Continuous Integration
name: SwiftPM macOS
os: osx
osx_image: xcode10.3
osx_image: xcode11
script:
- swift test --parallel
- stage: Continuous Integration
Expand All @@ -21,15 +21,15 @@ jobs:
sudo: required
install:
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
- swiftenv install 5.0
- swiftenv local 5.0
- swiftenv install 5.1
- swiftenv local 5.1
- swift --version
script:
- swift test --parallel
- stage: Continuous Integration
name: Code Coverage (Xcode 10.3)
name: Code Coverage (Xcode 11)
os: osx
osx_image: xcode10.3
osx_image: xcode11
script:
- swift package generate-xcodeproj --enable-code-coverage
- xcodebuild -scheme SourceDocs-Package test
Expand All @@ -38,15 +38,15 @@ jobs:
- stage: Continuous Integration
name: Installation with Homebrew (macOS)
os: osx
osx_image: xcode10.3
osx_image: xcode11
script:
- brew update
- brew install sourcedocs
- sourcedocs version
- stage: Continuous Integration
name: Installation from Source (macOS)
os: osx
osx_image: xcode10.3
osx_image: xcode11
script:
- git clone --depth 1 https://github.com/eneko/SourceDocs.git
- cd SourceDocs
Expand Down
8 changes: 5 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let package = Package(
name: "SourceDocs",
products: [
.executable(name: "sourcedocs", targets: ["SourceDocs"]),
.library(name: "SourceDocsLib", targets: ["SourceDocsLib"])
],
dependencies: [
.package(url: "https://github.com/jpsim/SourceKitten.git", from: "0.26.0"),
Expand All @@ -15,15 +16,16 @@ let package = Package(
.package(url: "https://github.com/eneko/System.git", from: "0.2.0")
],
targets: [
.target(name: "SourceDocs", dependencies: [
.target(name: "SourceDocsLib", dependencies: [
"SourceKittenFramework",
"MarkdownGenerator",
"Rainbow",
"Commandant",
"Curry"
]),
]),
.target(name: "SourceDocs", dependencies: ["SourceDocsLib"]),
.testTarget(name: "BehavioralTests", dependencies: ["System"]),
.testTarget(name: "UnitTests", dependencies: ["SourceDocs"]),
.testTarget(name: "UnitTests", dependencies: ["SourceDocsLib"]),
.target(name: "SourceDocsDemo", dependencies: []),
]
)
1 change: 1 addition & 0 deletions Sources/SourceDocs/main.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import SourceDocsLib

SourceDocs().run()
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

enum AccessLevel: String, CaseIterable {
public enum AccessLevel: String, CaseIterable {
case `private`
case `fileprivate`
case `internal`
Expand Down Expand Up @@ -48,11 +48,11 @@ enum AccessLevel: String, CaseIterable {
}

extension AccessLevel: Comparable, Equatable {
static func < (lhs: AccessLevel, rhs: AccessLevel) -> Bool {
public static func < (lhs: AccessLevel, rhs: AccessLevel) -> Bool {
return lhs.priority < rhs.priority
}

static func == (lhs: AccessLevel, rhs: AccessLevel) -> Bool {
public static func == (lhs: AccessLevel, rhs: AccessLevel) -> Bool {
return lhs.priority == rhs.priority
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,14 @@ class MarkdownIndex {
}
return Array(groupedByType.values)
}

internal func reset() {
self.structs = []
self.classes = []
self.extensions = []
self.enums = []
self.protocols = []
self.typealiases = []
self.methods = []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ import Foundation
import Commandant
import Rainbow

struct SourceDocs {
static let version = "0.6.1"
static let defaultOutputPath = "Documentation/Reference"
static let defaultLinkEnding = ".md"
static let defaultLinkBeginning = ""
public struct SourceDocs {
public static let version = "0.6.1"
public static let defaultOutputPath = "Documentation/Reference"
public static let defaultLinkEnding = ".md"
public static let defaultLinkBeginning = ""

func run() {
public init() {}

public func run(arguments: [String] = CommandLine.arguments) {
let registry = CommandRegistry<SourceDocsError>()
registry.register(CleanCommand())
registry.register(GenerateCommand())
registry.register(VersionCommand())
registry.register(HelpCommand(registry: registry))

registry.main(defaultVerb: "help") { error in
registry.main(arguments: arguments, defaultVerb: "help") { error in
fputs("\(error.localizedDescription)\n)".red, stderr)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import Foundation

enum SourceDocsError: Error {
public enum SourceDocsError: Error {
case internalError(message: String)
}

extension SourceDocsError: LocalizedError {
var errorDescription: String? {
public var errorDescription: String? {
switch self {
case let .internalError(message):
return message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@ import Commandant
import Curry
import Rainbow

struct CleanCommandOptions: OptionsProtocol {
public struct CleanCommandOptions: OptionsProtocol {
let outputFolder: String

static func evaluate(_ mode: CommandMode) -> Result<CleanCommandOptions, CommandantError<SourceDocsError>> {
/// Initializer for options for the Clean command.
///
/// - Parameter outputFolder: Output directory (defaults to "Documentation/Reference").
public init(outputFolder: String = SourceDocs.defaultOutputPath) {
self.outputFolder = outputFolder
}

public static func evaluate(_ mode: CommandMode) -> Result<CleanCommandOptions, CommandantError<SourceDocsError>> {
return curry(self.init)
<*> mode <| Option(key: "output-folder", defaultValue: SourceDocs.defaultOutputPath,
usage: "Output directory (defaults to \(SourceDocs.defaultOutputPath)).")
}
}

struct CleanCommand: CommandProtocol {
typealias Options = CleanCommandOptions
public struct CleanCommand: CommandProtocol {
public typealias Options = CleanCommandOptions

let verb = "clean"
let function = "Delete the output folder and quit."
public let verb = "clean"
public let function = "Delete the output folder and quit."

func run(_ options: CleanCommandOptions) -> Result<(), SourceDocsError> {
public func run(_ options: CleanCommandOptions) -> Result<(), SourceDocsError> {
do {
try CleanCommand.removeReferenceDocs(docsPath: options.outputFolder)
return Result.success(())
Expand All @@ -35,7 +42,7 @@ struct CleanCommand: CommandProtocol {
}
}

static func removeReferenceDocs(docsPath: String) throws {
public static func removeReferenceDocs(docsPath: String) throws {
var isDir: ObjCBool = false
if FileManager.default.fileExists(atPath: docsPath, isDirectory: &isDir) {
fputs("Removing reference documentation at '\(docsPath)'...".green, stdout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Rainbow
import Curry
import SourceKittenFramework

struct GenerateCommandOptions: OptionsProtocol {
public struct GenerateCommandOptions: OptionsProtocol {
let spmModule: String?
let moduleName: String?
let linkBeginningText: String
Expand All @@ -24,8 +24,50 @@ struct GenerateCommandOptions: OptionsProtocol {
let collapsibleBlocks: Bool
let tableOfContents: Bool
let xcodeArguments: [String]

/// Initializer for options object for the Generate command
///
/// - Parameters:
/// - spmModule: Generate documentation for Swift Package Manager module.
/// - moduleName: Generate documentation for a Swift module.
/// - linkBeginningText: The text to begin links with. Defaults to an empty string.
/// - linkEndingText: The text to end links with. Defaults to .md.
/// - inputFolder: Path to the input directory (defaults to the current directory).
/// - outputFolder: Output directory (defaults to "Documentation/Reference").
/// - minimumAccessLevel: The minimum access level to generate documentation. Defaults to public.
/// - includeModuleNameInPath: Include the module name as part of the output folder path. Defaults to false.
/// - clean: Delete output folder before generating documentation. Defaults to false.
/// - collapsibleBlocks: Put methods, properties and enum cases inside collapsible blocks. Defaults to false.
/// - tableOfContents: Generate a table of contents with properties and methods for each type. Defaults to false.
/// - xcodeArguments: Array of `String` arguments to pass to xcodebuild. Defaults to an empty array.
public init(spmModule: String? = nil,
moduleName: String? = nil,
linkBeginningText: String = SourceDocs.defaultLinkBeginning,
linkEndingText: String = SourceDocs.defaultLinkEnding,
inputFolder: String = FileManager.default.currentDirectoryPath,
outputFolder: String = SourceDocs.defaultOutputPath,
minimumAccessLevel: String = AccessLevel.public.rawValue,
includeModuleNameInPath: Bool = false,
clean: Bool = false,
collapsibleBlocks: Bool = false,
tableOfContents: Bool = false,
xcodeArguments: [String] = []) {
self.spmModule = spmModule
self.moduleName = moduleName
self.linkBeginningText = linkBeginningText
self.linkEndingText = linkEndingText
self.inputFolder = inputFolder
self.outputFolder = outputFolder
self.minimumAccessLevel = minimumAccessLevel
self.includeModuleNameInPath = includeModuleNameInPath
self.clean = clean
self.collapsibleBlocks = collapsibleBlocks
self.tableOfContents = tableOfContents
self.xcodeArguments = xcodeArguments
}


static func evaluate(_ mode: CommandMode) -> Result<GenerateCommandOptions, CommandantError<SourceDocsError>> {
public static func evaluate(_ mode: CommandMode) -> Result<GenerateCommandOptions, CommandantError<SourceDocsError>> {
return curry(self.init)
<*> mode <| Option(key: "spm-module", defaultValue: nil,
usage: "Generate documentation for Swift Package Manager module.")
Expand Down Expand Up @@ -57,13 +99,19 @@ struct GenerateCommandOptions: OptionsProtocol {
}
}

struct GenerateCommand: CommandProtocol {
typealias Options = GenerateCommandOptions
public struct GenerateCommand: CommandProtocol {
public typealias Options = GenerateCommandOptions

let verb = "generate"
let function = "Generates the Markdown documentation"
public let verb = "generate"
public let function = "Generates the Markdown documentation"

public init() {}

func run(_ options: GenerateCommandOptions) -> Result<(), SourceDocsError> {
public func run(_ options: GenerateCommandOptions) -> Result<(), SourceDocsError> {
defer {
// Reset the markdown index in case multiple libs are having things generated
MarkdownIndex.shared.reset()
}
do {
if let module = options.spmModule {
let docs = try parseSPMModule(moduleName: module)
Expand Down Expand Up @@ -156,5 +204,4 @@ struct GenerateCommand: CommandProtocol {
process(dictionaries: substructure, options: options)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import Commandant
import Rainbow

/// Type that encapsulates the configuration and evaluation of the `version` subcommand.
struct VersionCommand: CommandProtocol {
let verb = "version"
let function = "Display the current version of SourceDocs"
public struct VersionCommand: CommandProtocol {
public let verb = "version"
public let function = "Display the current version of SourceDocs"

public init() {}

func run(_ options: NoOptions<SourceDocsError>) -> Result<(), SourceDocsError> {
public func run(_ options: NoOptions<SourceDocsError>) -> Result<(), SourceDocsError> {
fputs("SourceDocs v\(SourceDocs.version)\n".cyan, stdout)
return .success(())
}
Expand Down
7 changes: 3 additions & 4 deletions Tests/UnitTests/AccessLevelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
//

import XCTest
// import SourceDocs
import SourceDocsLib

class AccessLevelTests: XCTestCase {

func testPriority() {
// let levels = AccessLevel.allCases
// XCTAssertEqual(levels.count, 5)
let levels = AccessLevel.allCases
XCTAssertEqual(levels.count, 5)
}

}