Skip to content
Snippets Groups Projects
Commit e256b53a authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Write result into output file

parent 32aa3263
No related branches found
No related tags found
No related merge requests found
......@@ -10,10 +10,11 @@
F6752A4E2683522200CC9A19 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6752A4D2683522200CC9A19 /* main.swift */; };
F6752A592683534800CC9A19 /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = F6752A582683534800CC9A19 /* ArgumentParser */; };
F6752A5C268354B900CC9A19 /* PathKit in Frameworks */ = {isa = PBXBuildFile; productRef = F6752A5B268354B900CC9A19 /* PathKit */; };
F6752A61268357D900CC9A19 /* lib_InternalSwiftSyntaxParser.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F6752A5D2683577D00CC9A19 /* lib_InternalSwiftSyntaxParser.dylib */; };
F6752A62268357D900CC9A19 /* lib_InternalSwiftSyntaxParser.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = F6752A5D2683577D00CC9A19 /* lib_InternalSwiftSyntaxParser.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
F6752A662683599500CC9A19 /* SwiftSyntax in Frameworks */ = {isa = PBXBuildFile; productRef = F6752A652683599500CC9A19 /* SwiftSyntax */; };
F6752A6826835A2F00CC9A19 /* DeclarationCollector.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6752A6726835A2F00CC9A19 /* DeclarationCollector.swift */; };
F6752A6B2683600A00CC9A19 /* Stencil in Frameworks */ = {isa = PBXBuildFile; productRef = F6752A6A2683600A00CC9A19 /* Stencil */; };
F6BC6BA72683649000E4F37D /* lib_InternalSwiftSyntaxParser.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F6BC6BA62683648800E4F37D /* lib_InternalSwiftSyntaxParser.dylib */; };
F6BC6BA82683649000E4F37D /* lib_InternalSwiftSyntaxParser.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = F6BC6BA62683648800E4F37D /* lib_InternalSwiftSyntaxParser.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -32,7 +33,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
F6752A62268357D900CC9A19 /* lib_InternalSwiftSyntaxParser.dylib in Embed Libraries */,
F6BC6BA82683649000E4F37D /* lib_InternalSwiftSyntaxParser.dylib in Embed Libraries */,
);
name = "Embed Libraries";
runOnlyForDeploymentPostprocessing = 0;
......@@ -42,8 +43,9 @@
/* Begin PBXFileReference section */
F6752A4A2683522200CC9A19 /* SwiftMetaModelGenerator */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SwiftMetaModelGenerator; sourceTree = BUILT_PRODUCTS_DIR; };
F6752A4D2683522200CC9A19 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
F6752A5D2683577D00CC9A19 /* lib_InternalSwiftSyntaxParser.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = lib_InternalSwiftSyntaxParser.dylib; path = Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftSyntaxParser.dylib; sourceTree = DEVELOPER_DIR; };
F6752A6726835A2F00CC9A19 /* DeclarationCollector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeclarationCollector.swift; sourceTree = "<group>"; };
F6752A6C2683602800CC9A19 /* meta_model.stencil */ = {isa = PBXFileReference; lastKnownFileType = text; path = meta_model.stencil; sourceTree = "<group>"; };
F6BC6BA62683648800E4F37D /* lib_InternalSwiftSyntaxParser.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = lib_InternalSwiftSyntaxParser.dylib; path = Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftSyntaxParser.dylib; sourceTree = DEVELOPER_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -52,7 +54,8 @@
buildActionMask = 2147483647;
files = (
F6752A5C268354B900CC9A19 /* PathKit in Frameworks */,
F6752A61268357D900CC9A19 /* lib_InternalSwiftSyntaxParser.dylib in Frameworks */,
F6752A6B2683600A00CC9A19 /* Stencil in Frameworks */,
F6BC6BA72683649000E4F37D /* lib_InternalSwiftSyntaxParser.dylib in Frameworks */,
F6752A592683534800CC9A19 /* ArgumentParser in Frameworks */,
F6752A662683599500CC9A19 /* SwiftSyntax in Frameworks */,
);
......@@ -81,7 +84,7 @@
F6752A4C2683522200CC9A19 /* SwiftMetaModelGenerator */ = {
isa = PBXGroup;
children = (
F6752A5D2683577D00CC9A19 /* lib_InternalSwiftSyntaxParser.dylib */,
F6752A6D2683606A00CC9A19 /* templates */,
F6752A4D2683522200CC9A19 /* main.swift */,
F6752A6726835A2F00CC9A19 /* DeclarationCollector.swift */,
);
......@@ -91,10 +94,19 @@
F6752A5E268357A200CC9A19 /* Frameworks */ = {
isa = PBXGroup;
children = (
F6BC6BA62683648800E4F37D /* lib_InternalSwiftSyntaxParser.dylib */,
);
name = Frameworks;
sourceTree = "<group>";
};
F6752A6D2683606A00CC9A19 /* templates */ = {
isa = PBXGroup;
children = (
F6752A6C2683602800CC9A19 /* meta_model.stencil */,
);
path = templates;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
......@@ -116,6 +128,7 @@
F6752A582683534800CC9A19 /* ArgumentParser */,
F6752A5B268354B900CC9A19 /* PathKit */,
F6752A652683599500CC9A19 /* SwiftSyntax */,
F6752A6A2683600A00CC9A19 /* Stencil */,
);
productName = SwiftMetaModelGenerator;
productReference = F6752A4A2683522200CC9A19 /* SwiftMetaModelGenerator */;
......@@ -148,6 +161,7 @@
F6752A572683534800CC9A19 /* XCRemoteSwiftPackageReference "swift-argument-parser" */,
F6752A5A268354B900CC9A19 /* XCRemoteSwiftPackageReference "PathKit" */,
F6752A642683598C00CC9A19 /* XCRemoteSwiftPackageReference "swift-syntax" */,
F6752A692683600A00CC9A19 /* XCRemoteSwiftPackageReference "Stencil" */,
);
productRefGroup = F6752A4B2683522200CC9A19 /* Products */;
projectDirPath = "";
......@@ -356,6 +370,14 @@
minimumVersion = 0.50400.0;
};
};
F6752A692683600A00CC9A19 /* XCRemoteSwiftPackageReference "Stencil" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/kylef/Stencil.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.14.1;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
......@@ -374,6 +396,11 @@
package = F6752A642683598C00CC9A19 /* XCRemoteSwiftPackageReference "swift-syntax" */;
productName = SwiftSyntax;
};
F6752A6A2683600A00CC9A19 /* Stencil */ = {
isa = XCSwiftPackageProductDependency;
package = F6752A692683600A00CC9A19 /* XCRemoteSwiftPackageReference "Stencil" */;
productName = Stencil;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = F6752A422683522200CC9A19 /* Project object */;
......
......@@ -19,6 +19,15 @@
"version": "0.9.2"
}
},
{
"package": "Stencil",
"repositoryURL": "https://github.com/kylef/Stencil.git",
"state": {
"branch": null,
"revision": "973e190edf5d09274e4a6bc2e636c86899ed84c3",
"version": "0.14.1"
}
},
{
"package": "swift-argument-parser",
"repositoryURL": "https://github.com/apple/swift-argument-parser",
......
......@@ -56,7 +56,15 @@
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "/Users/tobias/Documents/Programmieren/Projects/WolfManagement/WolfManagementMobile/WolfManagementMobile/Data/ValueObjects/Protocol/Accident/VOAnimalAccidentProtocol.swift"
argument = "/Users/tobias/Documents/Programmieren/Projects/WolfManagement/WolfManagementMobile/WolfManagementMobile/Data/ValueObjects"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--output"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "/Users/tobias/Documents/Programmieren/Projects/WolfManagement/WolfManagementMobile/WolfManagementMobile/Generated/Metamodel.swift"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
......
......@@ -8,6 +8,7 @@
import Foundation
import ArgumentParser
import SwiftSyntax
import Stencil
import PathKit
struct SwiftMetaModelGenerator: ParsableCommand
......@@ -15,31 +16,40 @@ struct SwiftMetaModelGenerator: ParsableCommand
@Option(name: .shortAndLong, help: "Input file or folder")
var input: String
@Option(name: .shortAndLong, help: "Output file")
var output: String
mutating func run() throws {
let inputPath = Path(input)
let classes: [ClassDeclaration]
if inputPath.isDirectory {
inputPath.iterateChildren().forEach( { processFile(file: $0) })
classes = try inputPath.iterateChildren().flatMap( { try processFile(file: $0) })
} else {
processFile(file: inputPath)
classes = try processFile(file: inputPath)
}
let context = [
"classes": classes
]
let environment = Environment(loader: FileSystemLoader(paths: ["/Users/tobias/Documents/Programmieren/Projects/SwiftMetaModelGenerator/SwiftMetaModelGenerator/templates/"]))
let rendered = try environment.renderTemplate(name: "meta_model.stencil", context: context)
try Path(output).write(rendered)
}
func processFile(file: Path) {
func processFile(file: Path) throws -> [ClassDeclaration] {
if !(file.extension?.lowercased().hasSuffix("swift") ?? false) {
return
return []
}
do {
let content: String = try file.read()
let collector = DeclarationCollector()
let tree = try SyntaxParser.parse(source: content)
collector.walk(tree)
print(collector.classes)
} catch {
print(error)
}
return collector.classes
}
}
......
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
// swiftlint:disable superfluous_disable_command implicit_return
// swiftlint:disable sorted_imports
import Foundation
// swiftlint:disable attributes file_length vertical_whitespace_closing_braces
// swiftlint:disable identifier_name line_length type_body_length
{% for class in classes %}
class {{class.name}}_ {
{% for variable in class.variables %}
static let {{ variable }}: String = "{{ variable }}"
{% endfor %}
}
{% endfor %}
// swiftlint:enable identifier_name line_length type_body_length
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment