Skip to content

Commit

Permalink
#2: Support multiple buld target on deli.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
kawoou committed Aug 31, 2018
1 parent ff0fb54 commit 55585b1
Show file tree
Hide file tree
Showing 19 changed files with 527 additions and 401 deletions.
93 changes: 57 additions & 36 deletions Binary/Sources/Deli/Command/BuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,81 @@ struct BuildCommand: CommandProtocol {
func run(_ options: BuildOptions) -> Result<(), CommandError> {
Logger.isVerbose = options.isVerbose

let configure: Configuration
let configuration = Configuration()
let configure: Config
if let project = options.project {
guard let config = Configuration(projectPath: project, scheme: options.scheme, output: options.output) else {
guard let config = configuration.getConfig(project: project, scheme: options.scheme, output: options.output) else {
return .failure(.failedToLoadConfigFile)
}
configure = config
} else {
guard options.scheme == nil, options.output == nil else {
return .failure(.mustBeUsedWithProjectArguments)
}
guard let config = Configuration(path: options.configFile) else {
guard let config = configuration.getConfig(configPath: options.configFile) else {
return .failure(.failedToLoadConfigFile)
}
configure = config
}

let sourceFiles = configure.getSourceList()
.filter { $0.contains(".swift") }
guard configure.target.count > 0 else {
Logger.log(.warn("No targets are active.", nil))
return .success(())
}
for target in configure.target {
guard let info = configure.config[target] else {
Logger.log(.warn("Target not found: `\(target)`", nil))
continue
}

Logger.log(.info("Set Target `\(target)`"))
let outputFile = configuration.getOutputPath(info: info)
let sourceFiles = configuration.getSourceList(info: info)
if sourceFiles.count == 0 {
Logger.log(.warn("No source files for processing.", nil))
}
Logger.log(.debug("Source files:"))
for source in sourceFiles {
Logger.log(.debug(" - \(source)"))
}

let parser = Parser([
ComponentParser(),
ConfigurationParser(),
AutowiredParser(),
LazyAutowiredParser(),
AutowiredFactoryParser(),
LazyAutowiredFactoryParser(),
InjectParser()
])
let corrector = Corrector([
QualifierCorrector(parser: parser),
ScopeCorrector(parser: parser),
NotImplementCorrector(parser: parser)
])
let validator = Validator([
FactoryReferenceValidator(parser: parser),
CircularDependencyValidator(parser: parser)
])
let parser = Parser([
ComponentParser(),
ConfigurationParser(),
AutowiredParser(),
LazyAutowiredParser(),
AutowiredFactoryParser(),
LazyAutowiredFactoryParser(),
InjectParser()
])
let corrector = Corrector([
QualifierCorrector(parser: parser),
ScopeCorrector(parser: parser),
NotImplementCorrector(parser: parser)
])
let validator = Validator([
FactoryReferenceValidator(parser: parser),
CircularDependencyValidator(parser: parser)
])

do {
let results = try validator.run(
try corrector.run(
try parser.run(sourceFiles)
do {
let results = try validator.run(
try corrector.run(
try parser.run(sourceFiles)
)
)
)
let outputData = try SourceGenerator(results: results).generate()
let url = URL(fileURLWithPath: configure.outputPath)
try? FileManager.default.removeItem(at: url)
try outputData.write(to: url, atomically: false, encoding: .utf8)
let outputData = try SourceGenerator(results: results).generate()
let url = URL(fileURLWithPath: outputFile)
try? FileManager.default.removeItem(at: url)
try outputData.write(to: url, atomically: false, encoding: .utf8)

Logger.log(.info("Generate file. \(configure.outputPath)"))
} catch let error {
return .failure(.runner(error))
}
Logger.log(.info("Generate file: \(outputFile)"))
} catch let error {
return .failure(.runner(error))
}

Logger.log(.newLine)
}
return .success(())
}
}
Expand Down
130 changes: 74 additions & 56 deletions Binary/Sources/Deli/Command/GenerateCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,77 +13,95 @@ struct GenerateCommand: CommandProtocol {

func run(_ options: GenerateOptions) -> Result<(), CommandError> {
Logger.isVerbose = options.isVerbose

let configure: Configuration

let configuration = Configuration()
let configure: Config
if let project = options.project {
guard let config = Configuration(projectPath: project, scheme: options.scheme, output: nil) else {
guard let config = configuration.getConfig(project: project, scheme: options.scheme, output: nil) else {
return .failure(.failedToLoadConfigFile)
}
configure = config
} else {
guard options.scheme == nil else {
return .failure(.mustBeUsedWithProjectArguments)
}
guard let config = Configuration(path: options.configFile) else {
guard let config = configuration.getConfig(configPath: options.configFile) else {
return .failure(.failedToLoadConfigFile)
}
configure = config
}

let sourceFiles = configure.getSourceList()
.filter { $0.contains(".swift") }
guard configure.target.count > 0 else {
Logger.log(.warn("No targets are active.", nil))
return .success(())
}
for target in configure.target {
guard let info = configure.config[target] else {
Logger.log(.warn("Target not found: `\(target)`", nil))
continue
}

Logger.log(.info("Set Target `\(target)`"))
let sourceFiles = configuration.getSourceList(info: info)
if sourceFiles.count == 0 {
Logger.log(.warn("Empty source files.", nil))
}
Logger.log(.debug("Source files:"))
for source in sourceFiles {
Logger.log(.debug(" - \(source)"))
}

let parser = Parser([
ComponentParser(),
ConfigurationParser(),
AutowiredParser(),
LazyAutowiredParser(),
AutowiredFactoryParser(),
LazyAutowiredFactoryParser(),
InjectParser()
])
let corrector = Corrector([
QualifierCorrector(parser: parser),
ScopeCorrector(parser: parser),
NotImplementCorrector(parser: parser)
])
let validator = Validator([
FactoryReferenceValidator(parser: parser),
CircularDependencyValidator(parser: parser)
])
let parser = Parser([
ComponentParser(),
ConfigurationParser(),
AutowiredParser(),
LazyAutowiredParser(),
AutowiredFactoryParser(),
LazyAutowiredFactoryParser(),
InjectParser()
])
let corrector = Corrector([
QualifierCorrector(parser: parser),
ScopeCorrector(parser: parser),
NotImplementCorrector(parser: parser)
])
let validator = Validator([
FactoryReferenceValidator(parser: parser),
CircularDependencyValidator(parser: parser)
])

do {
let results = try validator.run(
try corrector.run(
try parser.run(sourceFiles)
do {
let results = try validator.run(
try corrector.run(
try parser.run(sourceFiles)
)
)
)

let outputData: String
switch options.type {
case "graph", "html":
outputData = try GraphGenerator(results: results).generate()
case "code", "swift":
outputData = try SourceGenerator(results: results).generate()
case "raw":
outputData = try RawGenerator(results: results).generate()
default:
throw CommandError.unacceptableType
}

if let path = options.outputFile {
let url = URL(fileURLWithPath: path)
try? FileManager.default.removeItem(at: url)
try outputData.write(to: url, atomically: false, encoding: .utf8)

Logger.log(.info("Generate file. \(path)"))
} else {
print(outputData)
let outputData: String
switch options.type {
case "graph", "html":
outputData = try GraphGenerator(results: results).generate()
case "code", "swift":
outputData = try SourceGenerator(results: results).generate()
case "raw":
outputData = try RawGenerator(results: results).generate()
default:
throw CommandError.unacceptableType
}

if let path = options.output {
let url = URL(fileURLWithPath: path)
try? FileManager.default.removeItem(at: url)
try outputData.write(to: url, atomically: false, encoding: .utf8)

Logger.log(.info("Generate file: \(path)"))
} else {
print(outputData)
}
} catch let error {
return .failure(.runner(error))
}
} catch let error {
return .failure(.runner(error))
}

return .success(())
}
}
Expand All @@ -93,12 +111,12 @@ struct GenerateOptions: OptionsProtocol {
let isVerbose: Bool
let project: String?
let scheme: String?
let outputFile: String?
let output: String?
let type: String

static func create(configFile: String?) -> (_ isVerbose: Bool) -> (_ project: String?) -> (_ scheme: String?) -> (_ outputFile: String?) -> (_ type: String) -> GenerateOptions {
return { isVerbose in { project in { scheme in { outputFile in { type in
self.init(configFile: configFile, isVerbose: isVerbose, project: project, scheme: scheme, outputFile: outputFile, type: type)
static func create(configFile: String?) -> (_ isVerbose: Bool) -> (_ project: String?) -> (_ scheme: String?) -> (_ output: String?) -> (_ type: String) -> GenerateOptions {
return { isVerbose in { project in { scheme in { output in { type in
self.init(configFile: configFile, isVerbose: isVerbose, project: project, scheme: scheme, output: output, type: type)
}}}}}
}

Expand Down
2 changes: 1 addition & 1 deletion Binary/Sources/Deli/Command/UpgradeCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct UpgradeCommand: CommandProtocol {
guard let latestVersion = VersionManager.shared.getLatestVersion() else {
return .failure(.notFoundLatestVersion)
}
guard latestVersion != "v\(Version.current.value)" else {
if latestVersion == "v\(Version.current.value)" {
Logger.log(.info("No need to upgrade."))
return .success(())
}
Expand Down
82 changes: 50 additions & 32 deletions Binary/Sources/Deli/Command/ValidateCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,74 @@ struct ValidateCommand: CommandProtocol {
func run(_ options: ValidateOptions) -> Result<(), CommandError> {
Logger.isVerbose = options.isVerbose

let configure: Configuration
let configuration = Configuration()
let configure: Config
if let project = options.project {
guard let config = Configuration(projectPath: project, scheme: options.scheme, output: nil) else {
guard let config = configuration.getConfig(project: project, scheme: options.scheme, output: nil) else {
return .failure(.failedToLoadConfigFile)
}
configure = config
} else {
guard options.scheme == nil else {
return .failure(.mustBeUsedWithProjectArguments)
}
guard let config = Configuration(path: options.configFile) else {
guard let config = configuration.getConfig(configPath: options.configFile) else {
return .failure(.failedToLoadConfigFile)
}
configure = config
}

let sourceFiles = configure.getSourceList()
.filter { $0.contains(".swift") }
guard configure.target.count > 0 else {
Logger.log(.warn("No targets are active.", nil))
return .success(())
}
for target in configure.target {
guard let info = configure.config[target] else {
Logger.log(.warn("Target not found: `\(target)`", nil))
continue
}

Logger.log(.info("Set Target `\(target)`"))
let sourceFiles = configuration.getSourceList(info: info)
if sourceFiles.count == 0 {
Logger.log(.warn("No source files for processing.", nil))
}
Logger.log(.debug("Source files:"))
for source in sourceFiles {
Logger.log(.debug(" - \(source)"))
}

let parser = Parser([
ComponentParser(),
ConfigurationParser(),
AutowiredParser(),
LazyAutowiredParser(),
AutowiredFactoryParser(),
LazyAutowiredFactoryParser(),
InjectParser()
])
let corrector = Corrector([
QualifierCorrector(parser: parser),
ScopeCorrector(parser: parser),
NotImplementCorrector(parser: parser)
])
let validator = Validator([
FactoryReferenceValidator(parser: parser),
CircularDependencyValidator(parser: parser)
])
let parser = Parser([
ComponentParser(),
ConfigurationParser(),
AutowiredParser(),
LazyAutowiredParser(),
AutowiredFactoryParser(),
LazyAutowiredFactoryParser(),
InjectParser()
])
let corrector = Corrector([
QualifierCorrector(parser: parser),
ScopeCorrector(parser: parser),
NotImplementCorrector(parser: parser)
])
let validator = Validator([
FactoryReferenceValidator(parser: parser),
CircularDependencyValidator(parser: parser)
])

do {
_ = try validator.run(
try corrector.run(
try parser.run(sourceFiles)
do {
_ = try validator.run(
try corrector.run(
try parser.run(sourceFiles)
)
)
)

Logger.log(.info("Validate success."))
} catch let error {
return .failure(.runner(error))
Logger.log(.info("Validate success."))
} catch let error {
return .failure(.runner(error))
}
}

return .success(())
}
}
Expand Down
Loading

0 comments on commit 55585b1

Please sign in to comment.