-
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.
feat: backup old files, write new one
- Loading branch information
Showing
3 changed files
with
68 additions
and
3 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
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,47 @@ | ||
import Foundation | ||
import SwiftSyntax | ||
|
||
|
||
class GeneratePackageFile { | ||
let defaultIndent = 4 | ||
|
||
func create() { | ||
let identiferPattern = IdentifierPatternSyntax(leadingTrivia: .space, | ||
identifier: .identifier("package")) | ||
|
||
let packageExpression = DeclReferenceExprSyntax(baseName: .identifier("Package")) | ||
|
||
let stringSegmentList = StringLiteralSegmentListSyntax(arrayLiteral: | ||
.stringSegment(StringSegmentSyntax(content: .stringSegment("MyPluginName")))) | ||
|
||
let stringLiteralExpr = StringLiteralExprSyntax(openingQuote: .stringQuoteToken(), | ||
segments: stringSegmentList, | ||
closingQuote: .stringQuoteToken()) | ||
|
||
|
||
let firstArg = LabeledExprSyntax(label: .identifier("name"), expression: stringLiteralExpr) | ||
let arguments = LabeledExprListSyntax(arrayLiteral: firstArg) | ||
|
||
let packageFunctionCall = FunctionCallExprSyntax(calledExpression: packageExpression, leftParen: .leftParenToken(), arguments: arguments, rightParen: .rightParenToken(), trailingTrivia: .space) | ||
|
||
let initalizerClause = InitializerClauseSyntax(equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space), | ||
value: packageFunctionCall) | ||
|
||
let patternBinding = PatternBindingSyntax(pattern: identiferPattern, initializer: initalizerClause) | ||
|
||
let indentifierDecl = VariableDeclSyntax(leadingTrivia: .spaces(defaultIndent), | ||
bindingSpecifier: .keyword(.let), | ||
bindings: PatternBindingListSyntax(arrayLiteral: patternBinding), | ||
trailingTrivia: .space) | ||
|
||
let defDecl = DeclSyntax(fromProtocol: indentifierDecl) | ||
|
||
let codeBlock = CodeBlockItemSyntax(item: .decl(defDecl)) | ||
|
||
let codeBlockList = CodeBlockItemListSyntax(arrayLiteral: codeBlock) | ||
|
||
let source = SourceFileSyntax(statements: codeBlockList) | ||
|
||
print(source.description) | ||
} | ||
} |
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