-
Notifications
You must be signed in to change notification settings - Fork 2
DEX-292 Add dummy comments to source code #232
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
Open
shivkeshmadasu-skyflow
wants to merge
6
commits into
main
Choose a base branch
from
DEX-292
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a78492d
DEX-292 Add dummy comments to source code
ShivkeshMadasu 147806f
DEX-292 add custom script and comments for SDK references.
yaswanth-pula-skyflow c83e284
DEX-292 Update sdk refernce script.
yaswanth-pula-skyflow c025768
DEX-292 feat: added comments to iOS SDK
kamal-skyflow 8a76c17
DEX-292 chore: made suggested changes
kamal-skyflow 748607f
DEX-292 chore: made few changes
kamal-skyflow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,200 @@ | ||
| import Foundation | ||
|
|
||
| func processMarkdownFiles(at directoryPath: String, fileNamesToDelete: [String]) { | ||
| let fileManager = FileManager.default | ||
| let directoryURL = URL(fileURLWithPath: directoryPath) | ||
|
|
||
| // Check if directory exists | ||
| if !fileManager.fileExists(atPath: directoryPath) { | ||
| print("Directory does not exist: \(directoryPath)") | ||
| return | ||
| } | ||
|
|
||
| do { | ||
| let fileURLs = try fileManager.contentsOfDirectory(at: directoryURL, includingPropertiesForKeys: nil) | ||
|
|
||
| for fileName in fileNamesToDelete { | ||
| let filesToDelete = fileURLs.filter { $0.pathExtension == "md" && $0.lastPathComponent == fileName } | ||
|
|
||
| for fileURL in filesToDelete { | ||
| try fileManager.removeItem(at: fileURL) | ||
| } | ||
| } | ||
|
|
||
| let filesToProcess = try fileManager.contentsOfDirectory(at: directoryURL, includingPropertiesForKeys: nil) | ||
|
|
||
| for fileURL in filesToProcess { | ||
| convertParamsToTable(at: fileURL) | ||
| } | ||
|
|
||
| } catch { | ||
| print("Error while processing files: \(error.localizedDescription)") | ||
| } | ||
| } | ||
|
|
||
| // Function to read markdown file, convert params to table, and update markdown | ||
| func convertParamsToTable(at fileURL: URL) { | ||
| guard var markdown = try? String(contentsOf: fileURL) else { | ||
| print("Failed to read markdown file: \(fileURL.path)") | ||
| return | ||
| } | ||
|
|
||
| markdown = extractHeadings(from: markdown) | ||
|
|
||
| // Array to store the updated lines of markdown | ||
| var updatedMarkdownLines: [String] = [] | ||
|
|
||
| // Flag to indicate if a parameter list is being processed | ||
| var isProcessingParameters = false | ||
|
|
||
| // Array to store the lines of the current parameter list | ||
| var parameterList: [String] = [] | ||
|
|
||
| var emptyLineCount = 0 | ||
|
|
||
| updatedMarkdownLines.append("{% env enable=\"iosSdkRef\" %}") | ||
| updatedMarkdownLines.append("") | ||
|
|
||
| // Iterate over each line in the markdown | ||
| for line in markdown.components(separatedBy: .newlines) { | ||
| let startsWithParameters = line.range( | ||
| of: #"^#{2,4}\s*Parameters"#, | ||
| options: .regularExpression | ||
| ) != nil | ||
| if startsWithParameters { | ||
| // Start of a new parameter list | ||
| isProcessingParameters = true | ||
| } else if isProcessingParameters && emptyLineCount == 2{ | ||
| // End of the current parameter list | ||
|
|
||
| // Convert parameters list to a table | ||
| updatedMarkdownLines.append("") | ||
| let parameterTable = convertToTable(parameterList) | ||
| updatedMarkdownLines.append(contentsOf: parameterTable) | ||
| updatedMarkdownLines.append("") | ||
|
|
||
| // Reset the parameter list | ||
| parameterList = [] | ||
| isProcessingParameters = false | ||
| emptyLineCount = 0 | ||
| } | ||
|
|
||
| // Append the line to the updated markdown | ||
| if isProcessingParameters && !startsWithParameters{ | ||
| if(line.isEmpty) | ||
| { | ||
| emptyLineCount = emptyLineCount + 1 | ||
| } | ||
| parameterList.append(line) | ||
| } else { | ||
| if(line.starts(with: "``` swift")) | ||
| { | ||
| updatedMarkdownLines.append(line.replacingOccurrences(of: " ", with: "")) | ||
| } | ||
| else { | ||
| updatedMarkdownLines.append(line) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if isProcessingParameters && emptyLineCount == 2{ | ||
| // For parameter list at the end of file | ||
|
|
||
| // Convert parameters list to a table | ||
| updatedMarkdownLines.append("") | ||
| let parameterTable = convertToTable(parameterList) | ||
|
|
||
| updatedMarkdownLines.append(contentsOf: parameterTable) | ||
| updatedMarkdownLines.append("") | ||
|
|
||
| // Reset the parameter list | ||
| parameterList = [] | ||
| isProcessingParameters = false | ||
| emptyLineCount = 0 | ||
| } | ||
|
|
||
| updatedMarkdownLines.append("{% /env %}") | ||
| updatedMarkdownLines.append("") | ||
| // Join the updated markdown lines | ||
| let updatedMarkdown = updatedMarkdownLines.joined(separator: "\n") | ||
|
|
||
| // print("Updated markdown: \(updatedMarkdown)") | ||
| // Write the updated markdown back to the file | ||
| do { | ||
| try updatedMarkdown.write(to: fileURL, atomically: true, encoding: .utf8) | ||
| print("Updated markdown written to: \(fileURL.path)") | ||
| } catch { | ||
| print("Error writing updated markdown: \(error)") | ||
| } | ||
| } | ||
|
|
||
| // Function to convert parameters to a table | ||
| func convertToTable(_ parameters: [String]) -> [String] { | ||
| var table: [String] = [] | ||
| table.append("| Name | Description |") | ||
| table.append("| ---- | ----------- |") | ||
| for line in parameters { | ||
| if(!line.isEmpty) | ||
| { | ||
| let arr = line.split(separator: ":") | ||
| let name = arr[0].split(separator: "-")[1].trimmingCharacters(in: .whitespaces) | ||
| let description = arr[1].trimmingCharacters(in: .whitespaces) | ||
| table.append("| \(name) | \(description) |") | ||
| } | ||
| } | ||
| return table | ||
| } | ||
|
|
||
| func extractHeadings(from markdown: String) -> String { | ||
| var modifiedMarkdown = "" | ||
|
|
||
| let lines = markdown.components(separatedBy: .newlines) | ||
| var isInsideCodeBlock = false | ||
|
|
||
| for line in lines { | ||
| if line.starts(with: "```") { | ||
| isInsideCodeBlock.toggle() | ||
| } | ||
|
|
||
| if isInsideCodeBlock || !line.starts(with: "###") { | ||
| modifiedMarkdown += line + "\n" | ||
| } else if let methodName = extractMethodName(from: line) { | ||
| let hashes = line.components(separatedBy: " ")[0] | ||
| modifiedMarkdown += "\(hashes) \(methodName)\n" | ||
| } | ||
| } | ||
|
|
||
| return modifiedMarkdown | ||
| } | ||
|
|
||
| func extractMethodName(from line: String) -> String? { | ||
| let components = line.components(separatedBy: " ") | ||
| guard components.count > 1 else { | ||
| return nil | ||
| } | ||
|
|
||
| let methodName = components[1] | ||
| let sanitizedMethodName = sanitizeMethodName(methodName) | ||
| return sanitizedMethodName | ||
| } | ||
|
|
||
| func sanitizeMethodName(_ methodName: String) -> String { | ||
| let pattern = "\\([^()]*\\)" | ||
| let regex = try! NSRegularExpression(pattern: pattern, options: []) | ||
| let range = NSRange(location: 0, length: methodName.utf16.count) | ||
|
|
||
| var sanitizedMethodName = regex.stringByReplacingMatches( | ||
| in: methodName, | ||
| options: [], | ||
| range: range, | ||
| withTemplate: "()" | ||
| ) | ||
| sanitizedMethodName = sanitizedMethodName.replacingOccurrences(of: "`", with: "") | ||
| // print("heading: \(sanitizedMethodName)") | ||
| return sanitizedMethodName | ||
| } | ||
| // Usage example | ||
| let path = "docs/markdown" | ||
| let filesToDelete = ["_Footer.md", "_Sidebar.md", "ContainerOptions.md", "Callback.md", "TokenProvider.md", "Label.md", "UILabel.md", "SkyflowLabelView.md", "Home.md", "RevealOptions.md", "FormatLabel.md"] | ||
|
|
||
| processMarkdownFiles(at: path, fileNamesToDelete: filesToDelete) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| import Foundation | ||
|
|
||
| /// Supported environments. | ||
| public enum Env { | ||
| case DEV | ||
| case PROD | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.