From 1efe474541560cd9fb086e25aec0f61897e3c670 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa Date: Thu, 19 Sep 2019 21:34:02 +0200 Subject: [PATCH 01/16] fix: change output folder to see if it fixes coveralls --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 44cca2b..6faa6c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,4 +22,4 @@ script: - xcodebuild -workspace SwiftyJSONAccelerator.xcworkspace -scheme "SwiftyJSONAccelerator" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO test after_success: - - xcov -w SwiftyJSONAccelerator.xcworkspace -s SwiftyJSONAccelerator -o build/xcov --coveralls_service_name travis-ci --coveralls_service_job_id $TRAVIS_JOB_ID + - xcov -w SwiftyJSONAccelerator.xcworkspace -s SwiftyJSONAccelerator xcov_output --coveralls_service_name travis-ci --coveralls_service_job_id $TRAVIS_JOB_ID From 339bd9e5c10aaf42f11d1841283e0363feafe2e1 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa Date: Mon, 23 Sep 2019 21:48:12 +0200 Subject: [PATCH 02/16] feat: add codecov --- .travis.yml | 1 + codecov.yml | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 codecov.yml diff --git a/.travis.yml b/.travis.yml index 6faa6c4..a906f05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,3 +23,4 @@ script: after_success: - xcov -w SwiftyJSONAccelerator.xcworkspace -s SwiftyJSONAccelerator xcov_output --coveralls_service_name travis-ci --coveralls_service_job_id $TRAVIS_JOB_ID + - bash <(curl -s https://codecov.io/bash) -J 'SwiftyJSONAccelerator' diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..0121f92 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,4 @@ +ignore: + - "Pods" + - "SwiftyJSONAccelerator/UI" + - "SwiftyJSONAccelerator/Support" From 94902ef17f602a1ac6bb6fed141f4a26e439ff5b Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa Date: Mon, 23 Sep 2019 22:06:40 +0200 Subject: [PATCH 03/16] fix: add codecov badge --- .xcovignore | 4 ---- Gemfile | 1 - Gemfile.lock | 7 ------- README.md | 2 +- 4 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 .xcovignore diff --git a/.xcovignore b/.xcovignore deleted file mode 100644 index 1e9491b..0000000 --- a/.xcovignore +++ /dev/null @@ -1,4 +0,0 @@ -# Not core code -- Pods -- SwiftyJSONAccelerator/UI -- SwiftyJSONAccelerator/Support diff --git a/Gemfile b/Gemfile index 1d63f75..b4724b2 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,3 @@ source 'https://rubygems.org' gem 'cocoapods' gem 'synx' gem 'xcpretty' -gem 'xcov' diff --git a/Gemfile.lock b/Gemfile.lock index 15962ad..3fd95c4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -202,12 +202,6 @@ GEM claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) nanaimo (~> 0.2.6) - xcov (1.5.1) - fastlane (>= 2.82.0, < 3.0.0) - multipart-post - slack-notifier - terminal-table - xcodeproj xcpretty (0.3.0) rouge (~> 2.0.7) xcpretty-travis-formatter (1.0.0) @@ -219,7 +213,6 @@ PLATFORMS DEPENDENCIES cocoapods synx - xcov xcpretty BUNDLED WITH diff --git a/README.md b/README.md index 053ab70..1952469 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://travis-ci.org/insanoid/SwiftyJSONAccelerator.svg?branch=master)](https://travis-ci.org/insanoid/SwiftyJSONAccelerator) -[![Coverage Status](https://coveralls.io/repos/github/insanoid/SwiftyJSONAccelerator/badge.svg?branch=master)](https://coveralls.io/github/insanoid/SwiftyJSONAccelerator?branch=master) +[![codecov](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator/branch/master/graph/badge.svg)] **Version v2.1 Released! (Swift 5)** From 336aa09a60a0a64f2924d359a6174823fabb7052 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa KM Date: Mon, 23 Sep 2019 22:19:30 +0200 Subject: [PATCH 04/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1952469..014b3a2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://travis-ci.org/insanoid/SwiftyJSONAccelerator.svg?branch=master)](https://travis-ci.org/insanoid/SwiftyJSONAccelerator) -[![codecov](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator/branch/master/graph/badge.svg)] +![codecov](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator/branch/master/graph/badge.svg) **Version v2.1 Released! (Swift 5)** From dc9e8027e92f4f87592d2a71d75a03731726dc67 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa KM Date: Sun, 6 Oct 2019 09:20:33 +0200 Subject: [PATCH 05/16] Feat/generate init function (#108) * Fix coverage-related issues (#105) * fix: change output folder to see if it fixes coveralls * feat: add codecov * fix: add codecov badge * Update README.md * feat: add initializer function to the class declaration * chore: bump the version number * chore: update readme and version --- Core/Generator/FileGeneratorExtension.swift | 11 ++++++ .../ModelComponent.swift | 8 ++++ .../SwiftJSONModelFile.swift | 22 +++++++++-- .../ModelGenerationConfiguration.swift | 3 ++ Core/Generator/MultipleModelGenerator.swift | 6 ++- Core/Template/BaseTemplate.txt | 4 +- README.md | 13 ++++--- .../project.pbxproj | 4 ++ .../Support/AppDelegate.swift | 6 +-- .../Support/Base.lproj/Main.storyboard | 37 ++++++++++++++----- SwiftyJSONAccelerator/Support/Info.plist | 4 +- .../UI/SJEditorViewController.swift | 20 +++++++--- .../ModelGeneratorTests.swift | 33 ++++++++++++++++- 13 files changed, 137 insertions(+), 34 deletions(-) diff --git a/Core/Generator/FileGeneratorExtension.swift b/Core/Generator/FileGeneratorExtension.swift index 393c056..d540ad3 100644 --- a/Core/Generator/FileGeneratorExtension.swift +++ b/Core/Generator/FileGeneratorExtension.swift @@ -33,8 +33,19 @@ extension FileGenerator { if modelFile.type == .classType { content = content.replacingOccurrences(of: "{REQUIRED}", with: "required ") + if modelFile.configuration?.shouldGenerateInitMethod == true { + let assignment = modelFile.component.initialiserFunctionComponent.map { doubleTab + $0.assignmentString }.joined(separator: "\n") + let functionParameters = modelFile.component.initialiserFunctionComponent.map { $0.functionParameter }.joined(separator: ", ") + let initialiserFunctionStatement = "\n\(singleTab)init (\(functionParameters)) {" + content = content.replacingOccurrences(of: "{INITIALIZER_FUNCTION_DECLRATION}", with: initialiserFunctionStatement) + content = content.replacingOccurrences(of: "{INITIALISER_FUNCTION_ASSIGNMENT}", with: assignment) + content = content.replacingOccurrences(of: "{INITIALISER_FUNCTION_END}", with: "\(singleTab)}\n") + } } else { content = content.replacingOccurrences(of: "{REQUIRED}", with: "") + content = content.replacingOccurrences(of: "{INITIALIZER_FUNCTION_DECLRATION}", with: "") + content = content.replacingOccurrences(of: "{INITIALISER_FUNCTION_ASSIGNMENT}", with: "") + content = content.replacingOccurrences(of: "{INITIALISER_FUNCTION_END}", with: "") } return content } diff --git a/Core/Generator/Model-File-Components/ModelComponent.swift b/Core/Generator/Model-File-Components/ModelComponent.swift index 296b7ad..9dc952d 100644 --- a/Core/Generator/Model-File-Components/ModelComponent.swift +++ b/Core/Generator/Model-File-Components/ModelComponent.swift @@ -16,11 +16,19 @@ internal struct ModelComponent { var stringConstants: [String] /// Initialisers for the properties. var initialisers: [String] + // Initialiser function's assignment and function parameters for classes. + var initialiserFunctionComponent: [InitialiserFunctionComponent] /// Initialise a blank model component structure. init() { declarations = [] stringConstants = [] initialisers = [] + initialiserFunctionComponent = [] } } + +internal struct InitialiserFunctionComponent { + var functionParameter: String + var assignmentString: String +} diff --git a/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift b/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift index 85f2fcc..5602d61 100644 --- a/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift +++ b/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift @@ -43,6 +43,7 @@ struct SwiftJSONModelFile: ModelFile { component.stringConstants.append(genStringConstant(property.constantName, property.key)) component.declarations.append(genVariableDeclaration(property.name, type, isArray, isOptional)) component.initialisers.append(genInitializerForVariable(name: property.name, type: property.type, constantName: property.constantName, isOptional: isOptional, isArray: isArray, isObject: isObject)) + component.initialiserFunctionComponent.append(genInitaliserFunctionAssignmentAndParams(property.name, type, isArray, isOptional)) case .nullType: // Currently we do not deal with null values. break @@ -77,6 +78,13 @@ struct SwiftJSONModelFile: ModelFile { return genPrimitiveVariableDeclaration(name, internalType, isOptional) } + func genPrimitiveVariableDeclaration(_ name: String, _ type: String, _ isOptional: Bool) -> String { + if isOptional { + return "var \(name): \(type)?" + } + return "var \(name): \(type)" + } + /// Generate the variable declaration string /// /// - Parameters: @@ -84,11 +92,19 @@ struct SwiftJSONModelFile: ModelFile { /// - type: variable type to use /// - isArray: Is the value an object /// - Returns: A string to use as the declration - func genPrimitiveVariableDeclaration(_ name: String, _ type: String, _ isOptional: Bool) -> String { + func genInitaliserFunctionAssignmentAndParams(_ name: String, _ type: String, _ isArray: Bool, _ isOptional: Bool) -> InitialiserFunctionComponent { + var result = InitialiserFunctionComponent(functionParameter: "", assignmentString: "") + result.assignmentString = "self.\(name) = \(name)" + + var typeString = type + if isArray { + typeString = "[\(typeString)]" + } if isOptional { - return "var \(name): \(type)?" + typeString = "\(typeString)?" } - return "var \(name): \(type)" + result.functionParameter = "\(name): \(typeString)" + return result } func genInitializerForVariable(name: String, type: String, constantName: String, isOptional: Bool, isArray: Bool, isObject _: Bool) -> String { diff --git a/Core/Generator/ModelGenerationConfiguration.swift b/Core/Generator/ModelGenerationConfiguration.swift index 2d4627b..e51e77d 100644 --- a/Core/Generator/ModelGenerationConfiguration.swift +++ b/Core/Generator/ModelGenerationConfiguration.swift @@ -28,6 +28,8 @@ struct ModelGenerationConfiguration { var separateCodingKeys: Bool /// Should header be included. var variablesOptional: Bool + /// Should generate a init method for the class (applicable only to class). + var shouldGenerateInitMethod: Bool mutating func defaultConfig() { variablesOptional = true @@ -37,5 +39,6 @@ struct ModelGenerationConfiguration { prefix = "" filePath = "" baseClassName = "" + shouldGenerateInitMethod = true } } diff --git a/Core/Generator/MultipleModelGenerator.swift b/Core/Generator/MultipleModelGenerator.swift index a580fb3..cbb8f9a 100644 --- a/Core/Generator/MultipleModelGenerator.swift +++ b/Core/Generator/MultipleModelGenerator.swift @@ -149,6 +149,9 @@ struct MultipleModelGenerator { if let type = fromJSON["construct_type"].string, type == "struct" { constructType = ConstructType.structType } + + let initialiserParameter = fromJSON["initaliser_needed"].bool + let initialisersNeeded = initialiserParameter != nil ? initialiserParameter! : true let jsonLibrary = JSONMappingMethod.swiftNormal let config = ModelGenerationConfiguration(filePath: fromJSON["destination_path"].string ?? "", baseClassName: "", @@ -158,7 +161,8 @@ struct MultipleModelGenerator { constructType: constructType, modelMappingLibrary: jsonLibrary, separateCodingKeys: fromJSON["separate_coding_keys"].boolValue, - variablesOptional: fromJSON["variable_option"].boolValue) + variablesOptional: fromJSON["variable_option"].boolValue, + shouldGenerateInitMethod: initialisersNeeded) return config } diff --git a/Core/Template/BaseTemplate.txt b/Core/Template/BaseTemplate.txt index 80b72fa..0763d6a 100644 --- a/Core/Template/BaseTemplate.txt +++ b/Core/Template/BaseTemplate.txt @@ -14,7 +14,9 @@ import Foundation } {DECLARATION} - +{INITIALIZER_FUNCTION_DECLRATION} +{INITIALISER_FUNCTION_ASSIGNMENT} +{INITIALISER_FUNCTION_END} {REQUIRED}init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) {INITIALIZER} diff --git a/README.md b/README.md index 014b3a2..358c9be 100644 --- a/README.md +++ b/README.md @@ -7,20 +7,23 @@ Status](https://travis-ci.org/insanoid/SwiftyJSONAccelerator.svg?branch=master)] ![codecov](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator/branch/master/graph/badge.svg) -**Version v2.1 Released! (Swift 5)** +**Version v2.2** + +- Generate initializer function for classes +- **Application Download:** [Download the .app (v2.2.0)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v2.2.0/SwiftyJSONAccelerator.app.zip) + +**Version v2.1** - Tests are back - major parts of the code is covered. - Multiple file model generator is working again. -**Version v2.0 Released! (Swift 5)** +**Version v2.0 (Swift 5)** - Generates Swift 5 `Codeable` version along with `CodingKeys`. - Allows support to switch between `Optional` and non-optional variations. - Temporarily support for CLI and tests have been removed. - UI now supports Dark mode! -- **Application Download:** [Download the .app (v2.1.0)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v2.1.0/SwiftyJSONAccelerator.app.zip) - ## Installing & Building - **Building:** @@ -30,7 +33,7 @@ Status](https://travis-ci.org/insanoid/SwiftyJSONAccelerator.svg?branch=master)] You will also need to install `SwiftFormat` with `brew install swiftformat` and `SwiftLint` with `brew install swiftlint`. -- **Application Only:** [Download the .app (v2.1.0)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v2.1.0/SwiftyJSONAccelerator.app.zip) +- **Application Only:** [Download the .app (v2.2.0)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v2.2.0/SwiftyJSONAccelerator.app.zip) ## Features diff --git a/SwiftyJSONAccelerator.xcodeproj/project.pbxproj b/SwiftyJSONAccelerator.xcodeproj/project.pbxproj index 06936fc..4497c9c 100644 --- a/SwiftyJSONAccelerator.xcodeproj/project.pbxproj +++ b/SwiftyJSONAccelerator.xcodeproj/project.pbxproj @@ -713,6 +713,7 @@ CODE_SIGN_ENTITLEMENTS = SwiftyJSONAccelerator/Support/SwiftyJSONAccelerator.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 14; DEVELOPMENT_TEAM = UYGU8PDBPS; INFOPLIST_FILE = SwiftyJSONAccelerator/Support/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -720,6 +721,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.11; + MARKETING_VERSION = 2.2; PRODUCT_BUNDLE_IDENTIFIER = com.karthik.SwiftyJSONAccelerator; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -734,6 +736,7 @@ CODE_SIGN_ENTITLEMENTS = SwiftyJSONAccelerator/Support/SwiftyJSONAccelerator.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 14; DEVELOPMENT_TEAM = UYGU8PDBPS; INFOPLIST_FILE = SwiftyJSONAccelerator/Support/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -741,6 +744,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.11; + MARKETING_VERSION = 2.2; PRODUCT_BUNDLE_IDENTIFIER = com.karthik.SwiftyJSONAccelerator; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/SwiftyJSONAccelerator/Support/AppDelegate.swift b/SwiftyJSONAccelerator/Support/AppDelegate.swift index 4398eb3..7d9050b 100644 --- a/SwiftyJSONAccelerator/Support/AppDelegate.swift +++ b/SwiftyJSONAccelerator/Support/AppDelegate.swift @@ -14,9 +14,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele NSUserNotificationCenter.default.delegate = self } - func applicationWillTerminate(_: Notification) { - // Insert code here to tear down your application - } + func applicationWillTerminate(_: Notification) {} func userNotificationCenter(_: NSUserNotificationCenter, shouldPresent _: NSUserNotification) -> Bool { // Since our notification is to be shown when app is in focus, this function always returns true. @@ -27,7 +25,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele guard let pathString = notification.userInfo![Constants.filePathKey] as? String else { return } - // Open the path for the notification. + // Open the path mentioned in the notification. let urlPath = URL(fileURLWithPath: pathString, isDirectory: true) if notification.activationType == .actionButtonClicked { NSWorkspace.shared.activateFileViewerSelecting([urlPath]) diff --git a/SwiftyJSONAccelerator/Support/Base.lproj/Main.storyboard b/SwiftyJSONAccelerator/Support/Base.lproj/Main.storyboard index 557f01d..a7bf716 100644 --- a/SwiftyJSONAccelerator/Support/Base.lproj/Main.storyboard +++ b/SwiftyJSONAccelerator/Support/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -335,9 +335,12 @@ + + + + + @@ -446,25 +460,27 @@ - + + + - - + + @@ -476,6 +492,7 @@ + diff --git a/SwiftyJSONAccelerator/Support/Info.plist b/SwiftyJSONAccelerator/Support/Info.plist index c40dafd..a897098 100644 --- a/SwiftyJSONAccelerator/Support/Info.plist +++ b/SwiftyJSONAccelerator/Support/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.0 + $(MARKETING_VERSION) CFBundleVersion - 13 + $(CURRENT_PROJECT_VERSION) LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/SwiftyJSONAccelerator/UI/SJEditorViewController.swift b/SwiftyJSONAccelerator/UI/SJEditorViewController.swift index f8b5c75..5c1ee1e 100644 --- a/SwiftyJSONAccelerator/UI/SJEditorViewController.swift +++ b/SwiftyJSONAccelerator/UI/SJEditorViewController.swift @@ -20,6 +20,7 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { @IBOutlet var authorNameTextField: NSTextField! @IBOutlet var variablesOptionalCheckbox: NSButton! @IBOutlet var separateCodingKeysCheckbox: NSButton! + @IBOutlet var generateInitialiserFunctionCheckbox: NSButton! @IBOutlet var librarySelector: NSPopUpButton! @IBOutlet var modelTypeSelectorSegment: NSSegmentedControl! @@ -44,6 +45,8 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { modelTypeSelectorSegment.selectSegment(withTag: 0) variablesOptionalCheckbox.state = .on separateCodingKeysCheckbox.state = .on + generateInitialiserFunctionCheckbox.state = .on + generateInitialiserFunctionCheckbox.isEnabled = false } /// Validate and updates the textview @@ -124,9 +127,11 @@ extension SJEditorViewController { } /// When switching between versions of code being generated - @IBAction func librarySwitched(sender: Any) { - if let menu = sender as? NSPopUpButton { - librarySelector.title = menu.selectedItem!.title + @IBAction func modelTypeSwitched(sender _: Any) { + if modelTypeSelectorSegment.selectedSegment == 0 { + generateInitialiserFunctionCheckbox.isEnabled = false + } else { + generateInitialiserFunctionCheckbox.isEnabled = true } } @@ -150,6 +155,7 @@ extension SJEditorViewController { } func notify(fileCount: Int, path: String) { + NSUserNotificationCenter.default.removeAllDeliveredNotifications() let notification = NSUserNotification() notification.identifier = "SwiftyJSONAccelerator-" + UUID().uuidString notification.title = "SwiftyJSONAccelerator" @@ -192,12 +198,13 @@ extension SJEditorViewController { } let parserResponse = JSONHelper.convertToObject(textView?.string) + let generateInitialiserFunction = modelTypeSelectorSegment.selectedSegment == 1 ? generateInitialiserFunctionCheckbox.state == .on : false // Checks for validity of the content, else can cause crashes. if parserResponse.parsedObject != nil { let destinationPath = filePath!.appending("/") - let variablesOptional = variablesOptionalCheckbox.state.rawValue == 1 - let separateCodingKeys = separateCodingKeysCheckbox.state.rawValue == 1 + let variablesOptional = variablesOptionalCheckbox.state == .on + let separateCodingKeys = separateCodingKeysCheckbox.state == .on let constructType = modelTypeSelectorSegment.selectedSegment == 0 ? ConstructType.structType : ConstructType.classType let libraryType = mappingMethodForIndex(librarySelector.indexOfSelectedItem) let configuration = ModelGenerationConfiguration( @@ -209,7 +216,8 @@ extension SJEditorViewController { constructType: constructType, modelMappingLibrary: libraryType, separateCodingKeys: separateCodingKeys, - variablesOptional: variablesOptional + variablesOptional: variablesOptional, + shouldGenerateInitMethod: generateInitialiserFunction ) let modelGenerator = ModelGenerator(JSON(parserResponse.parsedObject!), configuration) let filesGenerated = modelGenerator.generate() diff --git a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift index 37850f7..bbf9851 100644 --- a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift +++ b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift @@ -59,7 +59,8 @@ class ModelGeneratorTests: XCTestCase { constructType: .structType, modelMappingLibrary: library, separateCodingKeys: true, - variablesOptional: optional + variablesOptional: optional, + shouldGenerateInitMethod: true ) } @@ -119,7 +120,8 @@ class ModelGeneratorTests: XCTestCase { authorName: "A3", companyName: "A4", prefix: "A5", constructType: .classType, modelMappingLibrary: .swiftCodeExtended, - separateCodingKeys: true, variablesOptional: true) + separateCodingKeys: true, variablesOptional: true, + shouldGenerateInitMethod: true) XCTAssertEqual(modelConfig.filePath, "A1") XCTAssertEqual(modelConfig.baseClassName, "A2") @@ -157,6 +159,7 @@ class ModelGeneratorTests: XCTestCase { validateDeclarations(filename: file.fileName, declarations: file.component.declarations, optional: optional) validateKeys(filename: file.fileName, stringKeys: file.component.stringConstants) validateInitialiser(filename: file.fileName, initialisers: file.component.initialisers, optional: optional) + validateInitialiserFunctionComponents(filename: file.fileName, initialiserFunctionComponents: file.component.initialiserFunctionComponent, optional: optional) let content = FileGenerator.generateFileContentWith(file, configuration: config) let name = file.fileName let path = "/tmp/sj/" @@ -230,6 +233,32 @@ class ModelGeneratorTests: XCTestCase { } } + func validateInitialiserFunctionComponents(filename: String, initialiserFunctionComponents: [InitialiserFunctionComponent], optional: Bool) { + let possibleAssignmentValues = ["ACBaseClass": ["self.valueOne = valueOne", "self.valueThree = valueThree", "self.valueSeven = valueSeven", "self.valueEight = valueEight", "self.valueFour = valueFour", "self.valueFive = valueFive", "self.valueSix = valueSix", "self.valueTwo = valueTwo"], + "ACValueSeven": ["self.subValueFive = subValueFive", "self.doubleValue = doubleValue", "self.subValueThird = subValueThird", "self.internalProperty = internalProperty", "self.subValueFour = subValueFour"], + "ACSubValueFive": ["self.twoLevelDown = twoLevelDown"], + "ACValueSix": ["self.subValue = subValue", "self.subValueSecond = subValueSecond"]] + + var possibleFunctionParamValues = ["ACBaseClass": ["valueSeven: [ACValueSeven]", "valueThree: Bool", "valueFive: [String]", "valueSix: ACValueSix", "valueEight: Any", "valueTwo: Int", "valueFour: Float", "valueOne: String"], + "ACValueSeven": ["subValueFive: ACSubValueFive", "subValueFour: String", "internalProperty: String", "subValueThird: Float", "doubleValue: Float"], + "ACSubValueFive": ["twoLevelDown: String"], + "ACValueSix": ["subValue: String", "subValueSecond: Bool"]] + + if optional == true { + possibleFunctionParamValues = ["ACBaseClass": ["valueSeven: [ACValueSeven]?", "valueThree: Bool?", "valueFive: [String]?", "valueSix: ACValueSix?", "valueEight: Any?", "valueTwo: Int?", "valueFour: Float?", "valueOne: String?"], + "ACValueSeven": ["subValueFive: ACSubValueFive?", "subValueFour: String?", "internalProperty: String?", "subValueThird: Float?", "doubleValue: Float?"], + "ACSubValueFive": ["twoLevelDown: String?"], + "ACValueSix": ["subValue: String?", "subValueSecond: Bool?"]] + } + + XCTAssertEqual(possibleAssignmentValues[filename]?.count, initialiserFunctionComponents.count) + XCTAssertEqual(possibleFunctionParamValues[filename]?.count, initialiserFunctionComponents.count) + for initialiserFunctionComponent in initialiserFunctionComponents { + XCTAssert(possibleAssignmentValues[filename]!.contains(initialiserFunctionComponent.assignmentString)) + XCTAssert(possibleFunctionParamValues[filename]!.contains(initialiserFunctionComponent.functionParameter)) + } + } + func testClassModelGenerator() { var config = defaultConfiguration(library: .swiftNormal, optional: true) config.constructType = .classType From 0fc9b490a140e2e0e769b40ca07f88bf42549b31 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 20 Oct 2022 01:11:05 +0200 Subject: [PATCH 06/16] build(deps): bump cocoapods from 1.7.5 to 1.10.2 (#127) Bumps [cocoapods](https://github.com/CocoaPods/CocoaPods) from 1.7.5 to 1.10.2. - [Release notes](https://github.com/CocoaPods/CocoaPods/releases) - [Changelog](https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md) - [Commits](https://github.com/CocoaPods/CocoaPods/compare/1.7.5...1.10.2) Signed-off-by: dependabot-preview[bot] Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> --- Gemfile.lock | 197 +++++++++++---------------------------------------- 1 file changed, 42 insertions(+), 155 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3fd95c4..8c1a60d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,28 +1,29 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (3.0.0) - activesupport (4.2.11.1) - i18n (~> 0.7) + CFPropertyList (3.0.3) + activesupport (5.2.6) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.6.0) - public_suffix (>= 2.0.2, < 4.0) + addressable (2.8.0) + public_suffix (>= 2.0.2, < 5.0) + algoliasearch (1.27.5) + httpclient (~> 2.8, >= 2.8.3) + json (>= 1.5.1) atomos (0.1.3) - babosa (1.0.2) claide (1.0.3) clamp (0.6.5) - cocoapods (1.7.5) - activesupport (>= 4.0.2, < 5) + cocoapods (1.10.2) + addressable (~> 2.6) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.7.5) + cocoapods-core (= 1.10.2) cocoapods-deintegrate (>= 1.0.3, < 2.0) - cocoapods-downloader (>= 1.2.2, < 2.0) + cocoapods-downloader (>= 1.4.0, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) - cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.3.1, < 2.0) + cocoapods-trunk (>= 1.4.0, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) escape (~> 0.0.4) @@ -31,181 +32,67 @@ GEM molinillo (~> 0.6.6) nap (~> 1.0) ruby-macho (~> 1.4) - xcodeproj (>= 1.10.0, < 2.0) - cocoapods-core (1.7.5) - activesupport (>= 4.0.2, < 6) + xcodeproj (>= 1.19.0, < 2.0) + cocoapods-core (1.10.2) + activesupport (> 5.0, < 6) + addressable (~> 2.6) + algoliasearch (~> 1.0) + concurrent-ruby (~> 1.1) fuzzy_match (~> 2.0.4) nap (~> 1.0) + netrc (~> 0.11) + public_suffix + typhoeus (~> 1.0) cocoapods-deintegrate (1.0.4) - cocoapods-downloader (1.2.2) + cocoapods-downloader (1.4.0) cocoapods-plugins (1.0.0) nap cocoapods-search (1.0.0) - cocoapods-stats (1.1.0) - cocoapods-trunk (1.3.1) + cocoapods-trunk (1.5.0) nap (>= 0.8, < 2.0) netrc (~> 0.11) - cocoapods-try (1.1.0) - colored (1.2) + cocoapods-try (1.2.0) colored2 (3.1.2) colorize (0.8.1) - commander-fastlane (4.4.6) - highline (~> 1.7.2) - concurrent-ruby (1.1.5) - declarative (0.0.10) - declarative-option (0.1.0) - digest-crc (0.4.1) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) - dotenv (2.7.5) - emoji_regex (1.0.1) + concurrent-ruby (1.1.9) escape (0.0.4) - excon (0.66.0) - faraday (0.15.4) - multipart-post (>= 1.2, < 3) - faraday-cookie_jar (0.0.6) - faraday (>= 0.7.4) - http-cookie (~> 1.0.0) - faraday_middleware (0.13.1) - faraday (>= 0.7.4, < 1.0) - fastimage (2.1.5) - fastlane (2.128.1) - CFPropertyList (>= 2.3, < 4.0.0) - addressable (>= 2.3, < 3.0.0) - babosa (>= 1.0.2, < 2.0.0) - bundler (>= 1.12.0, < 3.0.0) - colored - commander-fastlane (>= 4.4.6, < 5.0.0) - dotenv (>= 2.1.1, < 3.0.0) - emoji_regex (>= 0.1, < 2.0) - excon (>= 0.45.0, < 1.0.0) - faraday (~> 0.9) - faraday-cookie_jar (~> 0.0.6) - faraday_middleware (~> 0.9) - fastimage (>= 2.1.0, < 3.0.0) - gh_inspector (>= 1.1.2, < 2.0.0) - google-api-client (>= 0.21.2, < 0.24.0) - google-cloud-storage (>= 1.15.0, < 2.0.0) - highline (>= 1.7.2, < 2.0.0) - json (< 3.0.0) - jwt (~> 2.1.0) - mini_magick (>= 4.9.4, < 5.0.0) - multi_xml (~> 0.5) - multipart-post (~> 2.0.0) - plist (>= 3.1.0, < 4.0.0) - public_suffix (~> 2.0.0) - rubyzip (>= 1.2.2, < 2.0.0) - security (= 0.1.3) - simctl (~> 1.6.3) - slack-notifier (>= 2.0.0, < 3.0.0) - terminal-notifier (>= 2.0.0, < 3.0.0) - terminal-table (>= 1.4.5, < 2.0.0) - tty-screen (>= 0.6.3, < 1.0.0) - tty-spinner (>= 0.8.0, < 1.0.0) - word_wrap (~> 1.0.0) - xcodeproj (>= 1.8.1, < 2.0.0) - xcpretty (~> 0.3.0) - xcpretty-travis-formatter (>= 0.0.3) + ethon (0.14.0) + ffi (>= 1.15.0) + ffi (1.15.3) fourflusher (2.3.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) - google-api-client (0.23.9) - addressable (~> 2.5, >= 2.5.1) - googleauth (>= 0.5, < 0.7.0) - httpclient (>= 2.8.1, < 3.0) - mime-types (~> 3.0) - representable (~> 3.0) - retriable (>= 2.0, < 4.0) - signet (~> 0.9) - google-cloud-core (1.3.0) - google-cloud-env (~> 1.0) - google-cloud-env (1.2.0) - faraday (~> 0.11) - google-cloud-storage (1.16.0) - digest-crc (~> 0.4) - google-api-client (~> 0.23) - google-cloud-core (~> 1.2) - googleauth (>= 0.6.2, < 0.10.0) - googleauth (0.6.7) - faraday (~> 0.12) - jwt (>= 1.4, < 3.0) - memoist (~> 0.16) - multi_json (~> 1.11) - os (>= 0.9, < 2.0) - signet (~> 0.7) - highline (1.7.10) - http-cookie (1.0.3) - domain_name (~> 0.5) httpclient (2.8.3) - i18n (0.9.5) + i18n (1.8.10) concurrent-ruby (~> 1.0) - json (2.2.0) - jwt (2.1.0) - memoist (0.16.0) - mime-types (3.2.2) - mime-types-data (~> 3.2015) - mime-types-data (3.2019.0331) - mini_magick (4.9.5) - minitest (5.11.3) + json (2.5.1) + minitest (5.14.4) molinillo (0.6.6) - multi_json (1.13.1) - multi_xml (0.6.0) - multipart-post (2.0.0) - nanaimo (0.2.6) + nanaimo (0.3.0) nap (1.1.0) - naturally (2.2.0) netrc (0.11.0) - os (1.0.1) - plist (3.5.0) - public_suffix (2.0.5) - representable (3.0.4) - declarative (< 0.1.0) - declarative-option (< 0.2.0) - uber (< 0.2.0) - retriable (3.1.2) + public_suffix (4.0.6) + rexml (3.2.5) rouge (2.0.7) ruby-macho (1.4.0) - rubyzip (1.2.3) - security (0.1.3) - signet (0.11.0) - addressable (~> 2.3) - faraday (~> 0.9) - jwt (>= 1.5, < 3.0) - multi_json (~> 1.10) - simctl (1.6.5) - CFPropertyList - naturally - slack-notifier (2.3.2) synx (0.2.1) clamp (~> 0.6) colorize (~> 0.7) xcodeproj (~> 1.0) - terminal-notifier (2.0.0) - terminal-table (1.8.0) - unicode-display_width (~> 1.1, >= 1.1.1) thread_safe (0.3.6) - tty-cursor (0.7.0) - tty-screen (0.7.0) - tty-spinner (0.9.1) - tty-cursor (~> 0.7) - tzinfo (1.2.5) + typhoeus (1.4.0) + ethon (>= 0.9.0) + tzinfo (1.2.9) thread_safe (~> 0.1) - uber (0.1.0) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.6) - unicode-display_width (1.6.0) - word_wrap (1.0.0) - xcodeproj (1.12.0) + xcodeproj (1.20.0) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) - nanaimo (~> 0.2.6) + nanaimo (~> 0.3.0) + rexml (~> 3.2.4) xcpretty (0.3.0) rouge (~> 2.0.7) - xcpretty-travis-formatter (1.0.0) - xcpretty (~> 0.2, >= 0.0.7) PLATFORMS ruby From 3489137516f845c6667d03d5f1a0fb4f54a7de72 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 20 Oct 2022 01:11:31 +0200 Subject: [PATCH 07/16] Upgrade to GitHub-native Dependabot (#126) Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> --- .github/dependabot.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..1dbbb9a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: +- package-ecosystem: bundler + directory: "/" + schedule: + interval: daily + time: "04:00" + open-pull-requests-limit: 10 From 084a029d9bf265368b394f2d79c62738a96f0209 Mon Sep 17 00:00:00 2001 From: Konstantinos Chatzigeorgiou Date: Thu, 20 Oct 2022 02:12:24 +0300 Subject: [PATCH 08/16] fix: text color in light mode (#120) --- SwiftyJSONAccelerator/UI/SJTextView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSONAccelerator/UI/SJTextView.swift b/SwiftyJSONAccelerator/UI/SJTextView.swift index 1721b31..0c7f054 100644 --- a/SwiftyJSONAccelerator/UI/SJTextView.swift +++ b/SwiftyJSONAccelerator/UI/SJTextView.swift @@ -26,7 +26,7 @@ class SJTextView: NSTextView { internal func updateFormat() { textStorage?.font = NSFont(name: "Menlo", size: 12) - textColor = NSColor.white + textColor = NSColor.textColor } override func paste(_ sender: Any?) { From 256ac3ed15fc9620c63725d0ace5c078bc8b74f4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 20 Oct 2022 01:15:35 +0200 Subject: [PATCH 09/16] build(deps): bump cocoapods from 1.10.2 to 1.11.3 (#130) Bumps [cocoapods](https://github.com/CocoaPods/CocoaPods) from 1.10.2 to 1.11.3. - [Release notes](https://github.com/CocoaPods/CocoaPods/releases) - [Changelog](https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md) - [Commits](https://github.com/CocoaPods/CocoaPods/compare/1.10.2...1.11.3) --- updated-dependencies: - dependency-name: cocoapods dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 72 +++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8c1a60d..0816e2e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,24 +1,26 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (3.0.3) - activesupport (5.2.6) + CFPropertyList (3.0.5) + rexml + activesupport (6.1.7) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) algoliasearch (1.27.5) httpclient (~> 2.8, >= 2.8.3) json (>= 1.5.1) atomos (0.1.3) - claide (1.0.3) + claide (1.1.0) clamp (0.6.5) - cocoapods (1.10.2) - addressable (~> 2.6) + cocoapods (1.11.3) + addressable (~> 2.8) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.10.2) + cocoapods-core (= 1.11.3) cocoapods-deintegrate (>= 1.0.3, < 2.0) cocoapods-downloader (>= 1.4.0, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) @@ -29,62 +31,61 @@ GEM escape (~> 0.0.4) fourflusher (>= 2.3.0, < 3.0) gh_inspector (~> 1.0) - molinillo (~> 0.6.6) + molinillo (~> 0.8.0) nap (~> 1.0) - ruby-macho (~> 1.4) - xcodeproj (>= 1.19.0, < 2.0) - cocoapods-core (1.10.2) - activesupport (> 5.0, < 6) - addressable (~> 2.6) + ruby-macho (>= 1.0, < 3.0) + xcodeproj (>= 1.21.0, < 2.0) + cocoapods-core (1.11.3) + activesupport (>= 5.0, < 7) + addressable (~> 2.8) algoliasearch (~> 1.0) concurrent-ruby (~> 1.1) fuzzy_match (~> 2.0.4) nap (~> 1.0) netrc (~> 0.11) - public_suffix + public_suffix (~> 4.0) typhoeus (~> 1.0) - cocoapods-deintegrate (1.0.4) - cocoapods-downloader (1.4.0) + cocoapods-deintegrate (1.0.5) + cocoapods-downloader (1.6.3) cocoapods-plugins (1.0.0) nap - cocoapods-search (1.0.0) - cocoapods-trunk (1.5.0) + cocoapods-search (1.0.1) + cocoapods-trunk (1.6.0) nap (>= 0.8, < 2.0) netrc (~> 0.11) cocoapods-try (1.2.0) colored2 (3.1.2) colorize (0.8.1) - concurrent-ruby (1.1.9) + concurrent-ruby (1.1.10) escape (0.0.4) - ethon (0.14.0) + ethon (0.15.0) ffi (>= 1.15.0) - ffi (1.15.3) + ffi (1.15.5) fourflusher (2.3.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) httpclient (2.8.3) - i18n (1.8.10) + i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.5.1) - minitest (5.14.4) - molinillo (0.6.6) + json (2.6.2) + minitest (5.16.3) + molinillo (0.8.0) nanaimo (0.3.0) nap (1.1.0) netrc (0.11.0) - public_suffix (4.0.6) + public_suffix (4.0.7) rexml (3.2.5) rouge (2.0.7) - ruby-macho (1.4.0) + ruby-macho (2.5.1) synx (0.2.1) clamp (~> 0.6) colorize (~> 0.7) xcodeproj (~> 1.0) - thread_safe (0.3.6) typhoeus (1.4.0) ethon (>= 0.9.0) - tzinfo (1.2.9) - thread_safe (~> 0.1) - xcodeproj (1.20.0) + tzinfo (2.0.5) + concurrent-ruby (~> 1.0) + xcodeproj (1.22.0) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) @@ -93,6 +94,7 @@ GEM rexml (~> 3.2.4) xcpretty (0.3.0) rouge (~> 2.0.7) + zeitwerk (2.6.1) PLATFORMS ruby From dacc2f8ded6a55dc763dd52e6fb66a874ae45793 Mon Sep 17 00:00:00 2001 From: cntrump Date: Thu, 20 Oct 2022 07:20:08 +0800 Subject: [PATCH 10/16] feat: update TextColor and BackgroundColor (#124) * Update TextView color and font * Update TextColor and BackgroundColor * improve dark mode checking Co-authored-by: Karthikeya Udupa --- SwiftyJSONAccelerator/UI/SJTextView.swift | 50 ++++++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/SwiftyJSONAccelerator/UI/SJTextView.swift b/SwiftyJSONAccelerator/UI/SJTextView.swift index 0c7f054..1b0a825 100644 --- a/SwiftyJSONAccelerator/UI/SJTextView.swift +++ b/SwiftyJSONAccelerator/UI/SJTextView.swift @@ -8,8 +8,37 @@ import Cocoa +extension NSColor { + + @inline(__always) public convenience init(RGB hex: UInt32, alpha: CGFloat = 1) { + let red = CGFloat((hex & 0xff0000) >> 16) / 255.0 + let green = CGFloat((hex & 0xff00) >> 8) / 255.0 + let blue = CGFloat(hex & 0xff) / 255.0 + + self.init(deviceRed: red, green: green, blue: blue, alpha: alpha) + } +} + +extension NSView { + + @inline(__always) public var isDarkMode: Bool { + if #available(OSX 10.14, *) { + return effectiveAppearance.name == .darkAqua + } + + return false + } +} + /// A textview customization to handle formatting and handling removal of quotes. class SJTextView: NSTextView { + + let lightTextColor = NSColor(RGB: 0x24292d) + let lightBackgroundColor = NSColor(RGB: 0xf6f8fa) + + let darkTextColor = NSColor(RGB: 0xd1d5da) + let darkBackgroundColor = NSColor(RGB: 0x24292d) + override init(frame frameRect: NSRect, textContainer container: NSTextContainer?) { super.init(frame: frameRect, textContainer: container) disableAutoReplacement() @@ -25,8 +54,19 @@ class SJTextView: NSTextView { } internal func updateFormat() { - textStorage?.font = NSFont(name: "Menlo", size: 12) - textColor = NSColor.textColor + textStorage?.font = NSFont(name: "Monaco", size: 12) + + let color = NSColor(RGB: 0x07c160) + insertionPointColor = color + selectedTextAttributes = [.backgroundColor: color.withAlphaComponent(0.2)] + + if isDarkMode { + textColor = darkTextColor + backgroundColor = darkBackgroundColor + } else { + textColor = lightTextColor + backgroundColor = lightBackgroundColor + } } override func paste(_ sender: Any?) { @@ -43,4 +83,10 @@ class SJTextView: NSTextView { isAutomaticDashSubstitutionEnabled = false isAutomaticTextReplacementEnabled = false } + + override func layout() { + super.layout() + + updateFormat() + } } From b583595d7c9f9dbd116d7df3085cc696e4246295 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa Date: Tue, 25 Oct 2022 05:20:24 +0200 Subject: [PATCH 11/16] feat: add Community Standards (#131) * feature: add full community support * chore: add code-of-conduct * chore: fixbranching --- .github/CODE_OF_CONDUCT.md | 74 ++++++++++++++++++++++++++++++++ .github/ISSUE_TEMPLATE.yml | 73 +++++++++++++++++++++++++++++++ .github/contributing.md | 10 +++++ .github/pull_request_template.md | 26 +++++++++++ LICENSE.md | 9 ++++ README.md | 7 ++- 6 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 .github/CODE_OF_CONDUCT.md create mode 100644 .github/ISSUE_TEMPLATE.yml create mode 100644 .github/contributing.md create mode 100644 .github/pull_request_template.md create mode 100644 LICENSE.md diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..86a3913 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +education, socio-economic status, nationality, personal appearance, race, +religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at {{ email }}. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + diff --git a/.github/ISSUE_TEMPLATE.yml b/.github/ISSUE_TEMPLATE.yml new file mode 100644 index 0000000..6eadcb8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.yml @@ -0,0 +1,73 @@ +name: Bug Report +description: File a bug report +title: "[Bug]: " +labels: ["bug", "triage"] +assignees: + - octocat +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! + - type: input + id: contact + attributes: + label: Contact Details + description: How can we get in touch with you if we need more info? + placeholder: ex. email@example.com + validations: + required: false + - type: textarea + id: what-happened + attributes: + label: What happened? + description: Also tell us, what did you expect to happen? + placeholder: Tell us what you see! + value: "A bug happened!" + validations: + required: true + - type: input + id: version + attributes: + label: Version + description: What version of the app are you running? + validations: + required: true + - type: input + id: macOS-version + attributes: + label: macOS Version + description: What version of macOS are you running? + validations: + required: true + - type: dropdown + id: build-it-self + attributes: + label: Did you build the application or download a pre-built version? + multiple: true + options: + - Built it with Xcode / main branch + - Built it with Xcode / dev branch + - Downloaded .app file + - type: dropdown + id: apple-silicon + attributes: + label: Are you using an apple silicon machine (M1-x, M2) + multiple: true + options: + - Yes + - No + - type: textarea + id: logs + attributes: + label: Relevant log output + description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + render: shell + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/insanoid/SwiftyJSONAcceleratorblob/master/.github/CONTRIBUTING.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true diff --git a/.github/contributing.md b/.github/contributing.md new file mode 100644 index 0000000..f7e57d0 --- /dev/null +++ b/.github/contributing.md @@ -0,0 +1,10 @@ +# Contributing Guide +- All improvements are welcome in the form of pull-requests. More so now than before, as I no longer work primarily on swift. Any suggestions regarding code quality of the app, generated code's quality, Swift related improvements and pull requests are all very welcome. +- If you find bugs please raise them as issue tickets with specifics. Bug is when the feature is not working as it was designed or the app is broken. +- If there are interesting use-cases that you would like to have in the application that would be useful for everyone - would be happy to add them to the app, either raise them as pull-requests or if isn't possible for you to build it raise them as feature request for others to contribute. + +- When making any changes please assess them: + - Is this change relevant for you or do others need it as well - adding features that you/your organisation needs sometimes is a niche and can be done in your branched version. Would be happy to consider but I usually merge things which I see as a more broadly used feature. +- When changing existing functionality (e.g., changing generated variables from `var` to `let`) assess if this is an opinion or a standard way +- When contributing please open your pull-requests to `dev` branch as there will be automation built to create releases. +- Please ensure you add tests for new code you write and fix any tests you break. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..27431ea --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,26 @@ +## Proposed changes + +Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. + +## Types of changes + +What types of changes does your code introduce to SwiftyJSONAccelerator? +_Put an `x` in the boxes that apply_ + +- [ ] Bugfix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] Documentation Update (if none of the other choices apply) + +## Checklist + +_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._ + +- [ ] I have read the [CONTRIBUTING](https://github.com/insanoid/SwiftyJSONAccelerator/blob/main/.github/CONTRIBUTING.md) doc +- [ ] Lint and unit tests pass locally with my changes +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] I have added necessary documentation (if appropriate) + +## Further comments + +If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3e9e4b8 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +# MIT License + +## Copyright (c) Karthikeya Udupa ([karthikeyaudupa@gmail.com](mailto:karthikeyaudupa@gmail.com)) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 358c9be..90971ca 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,11 @@ The older version of the project generating older swift code. Please keep in min Any suggestions regarding code quality of the app, generated code's quality, Swift related improvements and pull requests are all very welcome. Please make sure you submit the pull request to the next release branch and not the master branch. +- [Contributing Guidelines](.github/CONTRIBUTING.md) +- [Pull Request Template](.github/PULL_REQUEST_TEMPLATE.md) +- [Issue Template](.github/ISSUE_TEMPLATE.yml) +- [Code of Conduct](.github/CODE_OF_CONDUCT.yml) + ## License -[MIT License](LICENSE) / [Karthikeya Udupa](https://karthikeya.co.uk) +[MIT License](LICENSE.md) / [Karthikeya Udupa](https://karthikeya.co.uk) From 366666bad8bc0ae6193e3227b5eafaffe32c20ce Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa Date: Tue, 25 Oct 2022 08:55:52 +0530 Subject: [PATCH 12/16] fix: update feature request template --- .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From f0c1de39bc2c8dc8594989769c03b4967411ba05 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa Date: Tue, 25 Oct 2022 05:36:31 +0200 Subject: [PATCH 13/16] fix: add new keyword support and fix build (#132) * fix: add all keywords * fix: issue template * fix: lint * chore: update lint command --- .../{ISSUE_TEMPLATE.yml => ISSUE_TEMPLATE} | 0 .github/ISSUE_TEMPLATE/feature_request.md | 20 ---------- Core/Generator/NameGenerator.swift | 39 +++++++++++++++---- .../project.pbxproj | 5 ++- .../ModelGeneratorTests.swift | 4 +- 5 files changed, 36 insertions(+), 32 deletions(-) rename .github/{ISSUE_TEMPLATE.yml => ISSUE_TEMPLATE} (100%) delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE.yml b/.github/ISSUE_TEMPLATE similarity index 100% rename from .github/ISSUE_TEMPLATE.yml rename to .github/ISSUE_TEMPLATE diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index bbcbbe7..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/Core/Generator/NameGenerator.swift b/Core/Generator/NameGenerator.swift index 5739747..5521a93 100644 --- a/Core/Generator/NameGenerator.swift +++ b/Core/Generator/NameGenerator.swift @@ -50,14 +50,37 @@ struct NameGenerator { /// - Parameter currentName: The current name which has to be checked. /// - Returns: New name for the variable. static func replaceKeywords(_ currentName: String) -> String { - let keywordsWithReplacements = [ - "description": "descriptionValue", - "class": "classProperty", - "struct": "structProperty", - "enum": "enumProperty", - "internal": "internalProperty", - "default": "defaultValue", - ] + + /// Swift keywords from https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID413 as of 2020-10-10 + /// Does not include the "sometimes" keywords + /// Thanks to a PR from @TheMadBug. + let swiftKeywords: Set = [ + "associatedtype", "class", "deinit", + "enum", "extension", "fileprivate", + "func", "import", "init", + "inout", "internal", "let", + "open", "operator", "private", + "protocol", "public", "rethrows", + "static", "struct", "subscript", + "typealias", "var", + "break", "case", "continue", + "default", "defer", "do", + "else", "fallthrough", "for", + "guard", "if", "in", + "repeat", "return", "switch", + "where", "while", + "as", "Any", "catch", + "false", "is", "nil", + "super", "self", "Self", + "throw", "throws", "true", + "try" + ] + + var keywordsWithReplacements: [String: String] = [:] + for keyword in swiftKeywords { + keywordsWithReplacements[keyword] = "\(keyword)Value" + } + if let value = keywordsWithReplacements[currentName] { return value } diff --git a/SwiftyJSONAccelerator.xcodeproj/project.pbxproj b/SwiftyJSONAccelerator.xcodeproj/project.pbxproj index 4497c9c..cafcf48 100644 --- a/SwiftyJSONAccelerator.xcodeproj/project.pbxproj +++ b/SwiftyJSONAccelerator.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -442,6 +442,7 @@ }; 935F7E4722F3852E0003F787 /* Swiftlint */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 12; files = ( ); @@ -456,7 +457,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\nswiftlint autocorrect --config .swiftlint.yml\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint lint --autocorrect --config .swiftlint.yml\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; 937D9DF122E8962F00A83D84 /* Swiftformat */ = { isa = PBXShellScriptBuildPhase; diff --git a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift index bbf9851..320def9 100644 --- a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift +++ b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift @@ -39,8 +39,8 @@ class ModelGeneratorTests: XCTestCase { "double_value": Double(5.3), "sub_value_four": "value", "internal": "renamed_value", - "sub_value_five": ["two_level_down": "value"], - ], + "sub_value_five": ["two_level_down": "value"] + ] ], "value_eight": []]) } From d781a58fd61e49abc4f8bfc09b85eaf206fd6e3a Mon Sep 17 00:00:00 2001 From: yonihemi Date: Mon, 31 Oct 2022 01:18:53 +0800 Subject: [PATCH 14/16] feat: add access control selection (#121) --- Core/Constants.swift | 20 +++++ Core/Generator/FileGeneratorExtension.swift | 4 +- Core/Generator/ModalGenerator.swift | 2 +- .../Model-File-Components/ModelFile.swift | 3 + .../SwiftJSONModelFile.swift | 9 +- .../ModelGenerationConfiguration.swift | 3 + Core/Generator/MultipleModelGenerator.swift | 5 ++ Core/Template/BaseTemplate.txt | 4 +- .../Support/Base.lproj/Main.storyboard | 83 ++++++++++++------- .../UI/SJEditorViewController.swift | 14 ++-- .../ModelGeneratorTests.swift | 4 + .../MultipleModelTests/test_config.json | 1 + 12 files changed, 108 insertions(+), 44 deletions(-) diff --git a/Core/Constants.swift b/Core/Constants.swift index f7fa277..d47d820 100644 --- a/Core/Constants.swift +++ b/Core/Constants.swift @@ -29,6 +29,26 @@ enum ConstructType: String { case structType = "struct" } +/// Various types of access control modifiers that can be applied to objects and properties. +enum AccessControl: String, CaseIterable { + case `internal` + case `private` + case `public` + + /// The prefix to be applied to objects and properties' declarations. + var declarationPrefix: String { + switch self { + case .internal: + // The default access control type, no need to explicitly set it + return "" + case .private: + return "private " + case .public: + return "public " + } + } +} + /// JSON mapping options available in the UI /// /// - Swift: Pure Swift 5 Codeable diff --git a/Core/Generator/FileGeneratorExtension.swift b/Core/Generator/FileGeneratorExtension.swift index d540ad3..74e5170 100644 --- a/Core/Generator/FileGeneratorExtension.swift +++ b/Core/Generator/FileGeneratorExtension.swift @@ -12,9 +12,11 @@ extension FileGenerator { static func generateFileContentWith(_ modelFile: ModelFile, configuration: ModelGenerationConfiguration) -> String { var content = try! loadFileWith("BaseTemplate") let singleTab = " ", doubleTab = " " + let accessPrefix = modelFile.accessControl.declarationPrefix content = content.replacingOccurrences(of: "{OBJECT_NAME}", with: modelFile.fileName) content = content.replacingOccurrences(of: "{DATE}", with: todayDateString()) content = content.replacingOccurrences(of: "{OBJECT_KIND}", with: modelFile.type.rawValue) + content = content.replacingOccurrences(of: "{ACCESS_CONTROL}", with: accessPrefix) if let authorName = configuration.authorName { content = content.replacingOccurrences(of: "__NAME__", with: authorName) @@ -36,7 +38,7 @@ extension FileGenerator { if modelFile.configuration?.shouldGenerateInitMethod == true { let assignment = modelFile.component.initialiserFunctionComponent.map { doubleTab + $0.assignmentString }.joined(separator: "\n") let functionParameters = modelFile.component.initialiserFunctionComponent.map { $0.functionParameter }.joined(separator: ", ") - let initialiserFunctionStatement = "\n\(singleTab)init (\(functionParameters)) {" + let initialiserFunctionStatement = "\n\(singleTab)\(accessPrefix)init (\(functionParameters)) {" content = content.replacingOccurrences(of: "{INITIALIZER_FUNCTION_DECLRATION}", with: initialiserFunctionStatement) content = content.replacingOccurrences(of: "{INITIALISER_FUNCTION_ASSIGNMENT}", with: assignment) content = content.replacingOccurrences(of: "{INITIALISER_FUNCTION_END}", with: "\(singleTab)}\n") diff --git a/Core/Generator/ModalGenerator.swift b/Core/Generator/ModalGenerator.swift index 5ba3caa..216c353 100644 --- a/Core/Generator/ModalGenerator.swift +++ b/Core/Generator/ModalGenerator.swift @@ -114,7 +114,7 @@ public struct ModelGenerator { - returns: Notification tht was generated. */ func generateNotificationFor(_ modelFiles: [ModelFile]) -> NSUserNotification { - let notification: NSUserNotification = NSUserNotification() + let notification = NSUserNotification() notification.title = NSLocalizedString("SwiftyJSONAccelerator", comment: "") if !modelFiles.isEmpty { let firstModel = (modelFiles.first)! diff --git a/Core/Generator/Model-File-Components/ModelFile.swift b/Core/Generator/Model-File-Components/ModelFile.swift index 166ea5f..661896b 100644 --- a/Core/Generator/Model-File-Components/ModelFile.swift +++ b/Core/Generator/Model-File-Components/ModelFile.swift @@ -20,6 +20,9 @@ protocol ModelFile { /// Type of the the object, if a structure or a class. var type: ConstructType { get } + /// Type of access control for object and properties. + var accessControl: AccessControl { get } + /// Storage for various components of the model, it is used to store the intermediate data. var component: ModelComponent { get } diff --git a/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift b/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift index 5602d61..7027e1b 100644 --- a/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift +++ b/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift @@ -13,6 +13,7 @@ import SwiftyJSON struct SwiftJSONModelFile: ModelFile { var fileName: String var type: ConstructType + var accessControl: AccessControl var component: ModelComponent var sourceJSON: JSON var configuration: ModelGenerationConfiguration? @@ -24,11 +25,13 @@ struct SwiftJSONModelFile: ModelFile { type = ConstructType.structType component = ModelComponent() sourceJSON = JSON([]) + accessControl = .internal } mutating func setInfo(_ fileName: String, _ configuration: ModelGenerationConfiguration) { self.fileName = fileName type = configuration.constructType + accessControl = configuration.accessControl self.configuration = configuration } @@ -79,10 +82,8 @@ struct SwiftJSONModelFile: ModelFile { } func genPrimitiveVariableDeclaration(_ name: String, _ type: String, _ isOptional: Bool) -> String { - if isOptional { - return "var \(name): \(type)?" - } - return "var \(name): \(type)" + let optionalSuffix = isOptional ? "?" : "" + return "\(accessControl.declarationPrefix)var \(name): \(type)\(optionalSuffix)" } /// Generate the variable declaration string diff --git a/Core/Generator/ModelGenerationConfiguration.swift b/Core/Generator/ModelGenerationConfiguration.swift index e51e77d..5ca862c 100644 --- a/Core/Generator/ModelGenerationConfiguration.swift +++ b/Core/Generator/ModelGenerationConfiguration.swift @@ -22,6 +22,8 @@ struct ModelGenerationConfiguration { var prefix: String? /// Type of the object that have to be generated. var constructType: ConstructType + /// Access control for object and properties. + var accessControl: AccessControl /// Model mapping library to be used. var modelMappingLibrary: JSONMappingMethod /// Separate coding keys into an enum and not use string. @@ -36,6 +38,7 @@ struct ModelGenerationConfiguration { separateCodingKeys = true modelMappingLibrary = .swiftNormal constructType = .classType + accessControl = .internal prefix = "" filePath = "" baseClassName = "" diff --git a/Core/Generator/MultipleModelGenerator.swift b/Core/Generator/MultipleModelGenerator.swift index cbb8f9a..302b027 100644 --- a/Core/Generator/MultipleModelGenerator.swift +++ b/Core/Generator/MultipleModelGenerator.swift @@ -149,6 +149,10 @@ struct MultipleModelGenerator { if let type = fromJSON["construct_type"].string, type == "struct" { constructType = ConstructType.structType } + var accessControl = AccessControl.internal + if let string = fromJSON["access_control"].string, let value = AccessControl(rawValue: string) { + accessControl = value + } let initialiserParameter = fromJSON["initaliser_needed"].bool let initialisersNeeded = initialiserParameter != nil ? initialiserParameter! : true @@ -159,6 +163,7 @@ struct MultipleModelGenerator { companyName: fromJSON["company_name"].string, prefix: fromJSON["prefix"].string, constructType: constructType, + accessControl: accessControl, modelMappingLibrary: jsonLibrary, separateCodingKeys: fromJSON["separate_coding_keys"].boolValue, variablesOptional: fromJSON["variable_option"].boolValue, diff --git a/Core/Template/BaseTemplate.txt b/Core/Template/BaseTemplate.txt index 0763d6a..af1f344 100644 --- a/Core/Template/BaseTemplate.txt +++ b/Core/Template/BaseTemplate.txt @@ -7,7 +7,7 @@ import Foundation -{OBJECT_KIND} {OBJECT_NAME}: Codable { +{ACCESS_CONTROL}{OBJECT_KIND} {OBJECT_NAME}: Codable { enum CodingKeys: String, CodingKey { {STRING_CONSTANT} @@ -17,7 +17,7 @@ import Foundation {INITIALIZER_FUNCTION_DECLRATION} {INITIALISER_FUNCTION_ASSIGNMENT} {INITIALISER_FUNCTION_END} - {REQUIRED}init(from decoder: Decoder) throws { + {ACCESS_CONTROL}{REQUIRED}init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) {INITIALIZER} } diff --git a/SwiftyJSONAccelerator/Support/Base.lproj/Main.storyboard b/SwiftyJSONAccelerator/Support/Base.lproj/Main.storyboard index a7bf716..35304f1 100644 --- a/SwiftyJSONAccelerator/Support/Base.lproj/Main.storyboard +++ b/SwiftyJSONAccelerator/Support/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -238,21 +238,21 @@ - + - + - + - + - + @@ -267,12 +267,12 @@ - + - + @@ -284,7 +284,7 @@ - + @@ -296,7 +296,7 @@ - + @@ -308,7 +308,7 @@ - + @@ -323,7 +323,7 @@ - + @@ -340,7 +340,7 @@ - + @@ -372,10 +372,7 @@ + + + + + + + + + + + + + + + + + + + + + + + - + @@ -460,34 +480,35 @@ + + + - - - + + - + - - + @@ -504,7 +525,7 @@ - + diff --git a/SwiftyJSONAccelerator/UI/SJEditorViewController.swift b/SwiftyJSONAccelerator/UI/SJEditorViewController.swift index 5c1ee1e..8bda0cc 100644 --- a/SwiftyJSONAccelerator/UI/SJEditorViewController.swift +++ b/SwiftyJSONAccelerator/UI/SJEditorViewController.swift @@ -22,6 +22,7 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { @IBOutlet var separateCodingKeysCheckbox: NSButton! @IBOutlet var generateInitialiserFunctionCheckbox: NSButton! @IBOutlet var librarySelector: NSPopUpButton! + @IBOutlet var accessControlSelector: NSPopUpButton! @IBOutlet var modelTypeSelectorSegment: NSSegmentedControl! override func viewDidLoad() { @@ -30,7 +31,7 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { textView.updateFormat() resetView() textView!.lnv_setUpLineNumberView() - + accessControlSelector.addItems(withTitles: AccessControl.allCases.map(\.rawValue)) // Do any additional setup after loading the view. } @@ -42,6 +43,7 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { companyNameTextField.stringValue = "" prefixClassTextField.stringValue = "" librarySelector.selectItem(at: 0) + accessControlSelector.selectItem(at: 0) modelTypeSelectorSegment.selectSegment(withTag: 0) variablesOptionalCheckbox.state = .on separateCodingKeysCheckbox.state = .on @@ -109,12 +111,12 @@ extension SJEditorViewController { notify(fileCount: generatedModelInfo.modelFiles.count, path: generatedModelInfo.configuration.filePath) } catch let error as MultipleModelGeneratorError { - let alert: NSAlert = NSAlert() + let alert = NSAlert() alert.messageText = "Unable to generate the files." alert.informativeText = error.errorMessage() alert.runModal() } catch let error as NSError { - let alert: NSAlert = NSAlert() + let alert = NSAlert() alert.messageText = "Unable to generate the files." alert.informativeText = error.localizedDescription alert.runModal() @@ -206,6 +208,7 @@ extension SJEditorViewController { let variablesOptional = variablesOptionalCheckbox.state == .on let separateCodingKeys = separateCodingKeysCheckbox.state == .on let constructType = modelTypeSelectorSegment.selectedSegment == 0 ? ConstructType.structType : ConstructType.classType + let accessControl = AccessControl.allCases[accessControlSelector.indexOfSelectedItem] let libraryType = mappingMethodForIndex(librarySelector.indexOfSelectedItem) let configuration = ModelGenerationConfiguration( filePath: destinationPath, @@ -214,6 +217,7 @@ extension SJEditorViewController { companyName: companyNameTextField.stringValue, prefix: prefixClassTextField.stringValue, constructType: constructType, + accessControl: accessControl, modelMappingLibrary: libraryType, separateCodingKeys: separateCodingKeys, variablesOptional: variablesOptional, @@ -228,7 +232,7 @@ extension SJEditorViewController { do { try FileGenerator.writeToFileWith(name, content: content, path: path) } catch let error as NSError { - let alert: NSAlert = NSAlert() + let alert = NSAlert() alert.messageText = "Unable to generate the files, please check the contents of the folder." alert.informativeText = error.localizedDescription alert.runModal() @@ -236,7 +240,7 @@ extension SJEditorViewController { } notify(fileCount: filesGenerated.count, path: destinationPath) } else { - let alert: NSAlert = NSAlert() + let alert = NSAlert() alert.messageText = "Unable to save the file check the content." alert.runModal() } diff --git a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift index 320def9..f37febf 100644 --- a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift +++ b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift @@ -57,6 +57,7 @@ class ModelGeneratorTests: XCTestCase { companyName: "Acme Co.", prefix: "AC", constructType: .structType, + accessControl: .internal, modelMappingLibrary: library, separateCodingKeys: true, variablesOptional: optional, @@ -119,6 +120,7 @@ class ModelGeneratorTests: XCTestCase { var modelConfig = ModelGenerationConfiguration(filePath: "A1", baseClassName: "A2", authorName: "A3", companyName: "A4", prefix: "A5", constructType: .classType, + accessControl: .private, modelMappingLibrary: .swiftCodeExtended, separateCodingKeys: true, variablesOptional: true, shouldGenerateInitMethod: true) @@ -129,6 +131,7 @@ class ModelGeneratorTests: XCTestCase { XCTAssertEqual(modelConfig.companyName, "A4") XCTAssertEqual(modelConfig.prefix, "A5") XCTAssertEqual(modelConfig.constructType, .classType) + XCTAssertEqual(modelConfig.accessControl, .private) XCTAssertEqual(modelConfig.modelMappingLibrary, .swiftCodeExtended) XCTAssertEqual(modelConfig.separateCodingKeys, true) XCTAssertEqual(modelConfig.variablesOptional, true) @@ -139,6 +142,7 @@ class ModelGeneratorTests: XCTestCase { XCTAssertEqual(modelConfig.baseClassName, "") XCTAssertEqual(modelConfig.prefix, "") XCTAssertEqual(modelConfig.constructType, .classType) + XCTAssertEqual(modelConfig.accessControl, .internal) XCTAssertEqual(modelConfig.modelMappingLibrary, .swiftNormal) XCTAssertEqual(modelConfig.separateCodingKeys, true) XCTAssertEqual(modelConfig.variablesOptional, true) diff --git a/SwiftyJSONAcceleratorTests/Support Files/MultipleModelTests/test_config.json b/SwiftyJSONAcceleratorTests/Support Files/MultipleModelTests/test_config.json index 63b173f..8263d6d 100644 --- a/SwiftyJSONAcceleratorTests/Support Files/MultipleModelTests/test_config.json +++ b/SwiftyJSONAcceleratorTests/Support Files/MultipleModelTests/test_config.json @@ -3,6 +3,7 @@ "author_name": "John Smith", "company_name": "Acme Inc", "construct_type": "struct", + "access_control": "internal", "prefix": "NS", "json_mapping_method": "swiftCodingVanilla", "variable_option": false, From 9bce1fd93e801c79d45c30fa9bea0851de3701a2 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa Date: Mon, 31 Oct 2022 07:48:13 +0530 Subject: [PATCH 15/16] feat: add release tagging and clean up code (#133) * feat: add release tagging and clean up code * fix: add commitlint and releaserc * chore: add release drafter file --- .commitlintrc.json | 3 ++ .github/release-drafter.yml | 4 ++ .github/workflows/create_release.yml | 44 +++++++++++++++++ .github/workflows/release_drafter.yml | 23 +++++++++ .releaserc | 47 +++++++++++++++++++ Core/Constants.swift | 8 ++-- Core/Generator/FileGeneratorExtension.swift | 2 +- .../SwiftJSONModelFile.swift | 6 ++- Core/Generator/MultipleModelGenerator.swift | 2 +- Core/Generator/NameGenerator.swift | 45 +++++++++--------- Core/Helpers/JSONHelper.swift | 9 ++-- .../project.pbxproj | 6 ++- .../xcschemes/SwiftyJSONAccelerator.xcscheme | 28 +++++------ .../LineNumberRulerView.swift | 5 +- SwiftyJSONAccelerator/UI/SJTextView.swift | 43 ++++++++--------- .../ModelGeneratorTests.swift | 4 +- 16 files changed, 201 insertions(+), 78 deletions(-) create mode 100644 .commitlintrc.json create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/create_release.yml create mode 100644 .github/workflows/release_drafter.yml create mode 100644 .releaserc diff --git a/.commitlintrc.json b/.commitlintrc.json new file mode 100644 index 0000000..c30e5a9 --- /dev/null +++ b/.commitlintrc.json @@ -0,0 +1,3 @@ +{ + "extends": ["@commitlint/config-conventional"] +} diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..27bcee3 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,4 @@ +template: | + ## What’s Changed + + $CHANGES diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml new file mode 100644 index 0000000..0b6c56b --- /dev/null +++ b/.github/workflows/create_release.yml @@ -0,0 +1,44 @@ +name: Create Release + +on: + push: + branches: + - master + +jobs: + # We create a new version if the branch is master. + version_and_publish: + name: Create Release + if: github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + outputs: + release_version: ${{ steps.generate_version.outputs.release_version }} + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + # In future we should run tests to ensure if it's worth making a release. + - name: Install semantic-release + run: | + npm set registry https://registry.npmjs.org/ + sudo npm install -g \ + semantic-release \ + @semantic-release/commit-analyzer \ + @semantic-release/github \ + @semantic-release/exec \ + @semantic-release/release-notes-generator \ + conventional-changelog-conventionalcommits + + - name: Generate version + id: generate_version + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.GH_TOKEN }} + run: | + npx semantic-release --ci + + - name: No Releases Done + if: "!steps.generate_version.outputs.release_version" + run: | + echo "No Release was done either due to wrong commit or no major changes." diff --git a/.github/workflows/release_drafter.yml b/.github/workflows/release_drafter.yml new file mode 100644 index 0000000..db076db --- /dev/null +++ b/.github/workflows/release_drafter.yml @@ -0,0 +1,23 @@ +name: Release Drafter + +on: + push: + # branches to consider in the event; optional, defaults to all + branches: + - dev + pull_request: + types: [opened, reopened, synchronize] + +permissions: + contents: read + +jobs: + update_release_draft: + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..728ed6f --- /dev/null +++ b/.releaserc @@ -0,0 +1,47 @@ +{ + "branches": ["main"], + "tagFormat": "${version}", + "plugins": [ + [ + "@semantic-release/commit-analyzer", { + "preset": "conventionalcommits", + "releaseRules": [ + {"type": "doc", "release": false}, + {"type": "test", "release": false}, + {"type": "chore", "release": "patch"}, + {"type": "devx", "release": false} + ], + "parserOpts": { + "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] + } + } + ], + "@semantic-release/github", + [ + "@semantic-release/exec", { + "publishCmd": "echo \"::set-output name=release_version::${nextRelease.version}\"" + } + ], + [ + "@semantic-release/release-notes-generator", { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + {"type": "feat", "section": "Features"}, + {"type": "fix", "section": "Bug Fixes"}, + {"type": "doc", "section": "Documentation", "hidden": true}, + {"type": "test", "section": "Tests", "hidden": true}, + {"type": "chore", "section": "Chore / Improvements"}, + {"type": "devx", "section": "Improved Developer Experience", "hidden": false} + ] + }, + "parserOpts": { + "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] + }, + "writerOpts": { + "commitsSort": ["subject", "scope"] + } + } + ] + ] +} diff --git a/Core/Constants.swift b/Core/Constants.swift index d47d820..f05003a 100644 --- a/Core/Constants.swift +++ b/Core/Constants.swift @@ -41,10 +41,8 @@ enum AccessControl: String, CaseIterable { case .internal: // The default access control type, no need to explicitly set it return "" - case .private: - return "private " - case .public: - return "public " + default: + return rawValue } } } @@ -76,6 +74,6 @@ enum PropertyType: String { } /// Place to store actual constants that don't fit in classes. -struct Constants { +enum Constants { static let filePathKey: String = "path" } diff --git a/Core/Generator/FileGeneratorExtension.swift b/Core/Generator/FileGeneratorExtension.swift index 74e5170..69d0560 100644 --- a/Core/Generator/FileGeneratorExtension.swift +++ b/Core/Generator/FileGeneratorExtension.swift @@ -61,7 +61,7 @@ extension FileGenerator { - returns: Boolean indicating if the process was successful. */ - internal static func writeToFileWith(_ name: String, content: String, path: String) throws { + static func writeToFileWith(_ name: String, content: String, path: String) throws { let filename = path.appendingFormat("%@", name + ".swift") try FileManager.default.createDirectory(at: URL(fileURLWithPath: path), withIntermediateDirectories: true, diff --git a/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift b/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift index 7027e1b..0532f13 100644 --- a/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift +++ b/Core/Generator/Model-File-Components/SwiftJSONModelFile.swift @@ -83,7 +83,11 @@ struct SwiftJSONModelFile: ModelFile { func genPrimitiveVariableDeclaration(_ name: String, _ type: String, _ isOptional: Bool) -> String { let optionalSuffix = isOptional ? "?" : "" - return "\(accessControl.declarationPrefix)var \(name): \(type)\(optionalSuffix)" + var declrationPrefix = "" + if !accessControl.declarationPrefix.isEmpty { + declrationPrefix = "\(accessControl.declarationPrefix) " + } + return "\(declrationPrefix)var \(name): \(type)\(optionalSuffix)" } /// Generate the variable declaration string diff --git a/Core/Generator/MultipleModelGenerator.swift b/Core/Generator/MultipleModelGenerator.swift index 302b027..d0b74e3 100644 --- a/Core/Generator/MultipleModelGenerator.swift +++ b/Core/Generator/MultipleModelGenerator.swift @@ -51,7 +51,7 @@ enum MultipleModelGeneratorError: Error, Equatable { } /// A structure to generate multiple mdoels from JSON files at once. -struct MultipleModelGenerator { +enum MultipleModelGenerator { /// Generate models for the JSON files in the given path. Use the `.config.json` to load config. /// /// - Parameter forPath: Path with the JSON files. diff --git a/Core/Generator/NameGenerator.swift b/Core/Generator/NameGenerator.swift index 5521a93..7151065 100644 --- a/Core/Generator/NameGenerator.swift +++ b/Core/Generator/NameGenerator.swift @@ -50,37 +50,36 @@ struct NameGenerator { /// - Parameter currentName: The current name which has to be checked. /// - Returns: New name for the variable. static func replaceKeywords(_ currentName: String) -> String { - /// Swift keywords from https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID413 as of 2020-10-10 /// Does not include the "sometimes" keywords /// Thanks to a PR from @TheMadBug. let swiftKeywords: Set = [ - "associatedtype", "class", "deinit", - "enum", "extension", "fileprivate", - "func", "import", "init", - "inout", "internal", "let", - "open", "operator", "private", - "protocol", "public", "rethrows", - "static", "struct", "subscript", - "typealias", "var", - "break", "case", "continue", - "default", "defer", "do", - "else", "fallthrough", "for", - "guard", "if", "in", - "repeat", "return", "switch", - "where", "while", - "as", "Any", "catch", - "false", "is", "nil", - "super", "self", "Self", - "throw", "throws", "true", - "try" - ] - + "associatedtype", "class", "deinit", + "enum", "extension", "fileprivate", + "func", "import", "init", + "inout", "internal", "let", + "open", "operator", "private", + "protocol", "public", "rethrows", + "static", "struct", "subscript", + "typealias", "var", + "break", "case", "continue", + "default", "defer", "do", + "else", "fallthrough", "for", + "guard", "if", "in", + "repeat", "return", "switch", + "where", "while", + "as", "Any", "catch", + "false", "is", "nil", + "super", "self", "Self", + "throw", "throws", "true", + "try", + ] + var keywordsWithReplacements: [String: String] = [:] for keyword in swiftKeywords { keywordsWithReplacements[keyword] = "\(keyword)Value" } - + if let value = keywordsWithReplacements[currentName] { return value } diff --git a/Core/Helpers/JSONHelper.swift b/Core/Helpers/JSONHelper.swift index c29b0b1..fbe4262 100644 --- a/Core/Helpers/JSONHelper.swift +++ b/Core/Helpers/JSONHelper.swift @@ -21,7 +21,7 @@ struct JSONParserResponse { } /// Provide helpers to handle JSON content that the user provided. -struct JSONHelper { +enum JSONHelper { /// Validate if the string that is provided can be converted into a valid JSON. /// /// - Parameter jsonString: Input string that is to be checked as JSON. @@ -77,16 +77,19 @@ struct JSONHelper { /// - Parameter items: An array of JSON items that have to be reduced. /// - Returns: Reduced JSON with the common key/value pairs. static func reduce(_ items: [JSON]) -> JSON { - return items.reduce([:]) { (source, item) -> JSON in + return items.reduce([:]) { source, item -> JSON in var finalObject = source for (key, jsonValue) in item { if let newValue = jsonValue.dictionary { finalObject[key] = reduce([JSON(newValue), finalObject[key]]) } else if let newValue = jsonValue.array, newValue.first != nil && (newValue.first!.dictionary != nil || newValue.first!.array != nil) { finalObject[key] = JSON([reduce(newValue + finalObject[key].arrayValue)]) + // swiftlint:disable all + // swift-format-ignore } else if jsonValue != JSON.null || !finalObject[key].exists() { finalObject[key] = jsonValue } + // swiftlint:enable all } return finalObject } @@ -126,7 +129,7 @@ extension JSON { .cgFloatType, .doubleType: return .float - // Covers any future types for CFNumber. + // Covers any future types for CFNumber. @unknown default: return .float } diff --git a/SwiftyJSONAccelerator.xcodeproj/project.pbxproj b/SwiftyJSONAccelerator.xcodeproj/project.pbxproj index cafcf48..70c88ca 100644 --- a/SwiftyJSONAccelerator.xcodeproj/project.pbxproj +++ b/SwiftyJSONAccelerator.xcodeproj/project.pbxproj @@ -359,7 +359,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1030; - LastUpgradeCheck = 1030; + LastUpgradeCheck = 1340; ORGANIZATIONNAME = "Karthikeya Udupa"; TargetAttributes = { 93E0F10322E859D5008D3B16 = { @@ -617,6 +617,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -678,6 +679,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -712,6 +714,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = SwiftyJSONAccelerator/Support/SwiftyJSONAccelerator.entitlements; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 14; @@ -735,6 +738,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = SwiftyJSONAccelerator/Support/SwiftyJSONAccelerator.entitlements; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 14; diff --git a/SwiftyJSONAccelerator.xcodeproj/xcshareddata/xcschemes/SwiftyJSONAccelerator.xcscheme b/SwiftyJSONAccelerator.xcodeproj/xcshareddata/xcschemes/SwiftyJSONAccelerator.xcscheme index e4bd7c6..ac9a7f2 100644 --- a/SwiftyJSONAccelerator.xcodeproj/xcshareddata/xcschemes/SwiftyJSONAccelerator.xcscheme +++ b/SwiftyJSONAccelerator.xcodeproj/xcshareddata/xcschemes/SwiftyJSONAccelerator.xcscheme @@ -1,6 +1,6 @@ + onlyGenerateCoverageForSpecifiedTargets = "YES"> + + + + - - - - - - - - Void in + let drawLineNumber = { (lineNumberString: String, y: CGFloat) in let attString = NSAttributedString(string: lineNumberString, attributes: lineNumberAttributes) let x = 35 - attString.size().width attString.draw(at: NSPoint(x: x, y: relativePoint.y + y)) diff --git a/SwiftyJSONAccelerator/UI/SJTextView.swift b/SwiftyJSONAccelerator/UI/SJTextView.swift index 1b0a825..946a3ff 100644 --- a/SwiftyJSONAccelerator/UI/SJTextView.swift +++ b/SwiftyJSONAccelerator/UI/SJTextView.swift @@ -8,37 +8,34 @@ import Cocoa -extension NSColor { - - @inline(__always) public convenience init(RGB hex: UInt32, alpha: CGFloat = 1) { - let red = CGFloat((hex & 0xff0000) >> 16) / 255.0 - let green = CGFloat((hex & 0xff00) >> 8) / 255.0 - let blue = CGFloat(hex & 0xff) / 255.0 - +public extension NSColor { + @inline(__always) convenience init(RGB hex: UInt32, alpha: CGFloat = 1) { + let red = CGFloat((hex & 0xFF0000) >> 16) / 255.0 + let green = CGFloat((hex & 0xFF00) >> 8) / 255.0 + let blue = CGFloat(hex & 0xFF) / 255.0 + self.init(deviceRed: red, green: green, blue: blue, alpha: alpha) } } -extension NSView { - - @inline(__always) public var isDarkMode: Bool { +public extension NSView { + @inline(__always) var isDarkMode: Bool { if #available(OSX 10.14, *) { return effectiveAppearance.name == .darkAqua } - + return false } } /// A textview customization to handle formatting and handling removal of quotes. class SJTextView: NSTextView { - - let lightTextColor = NSColor(RGB: 0x24292d) - let lightBackgroundColor = NSColor(RGB: 0xf6f8fa) - - let darkTextColor = NSColor(RGB: 0xd1d5da) - let darkBackgroundColor = NSColor(RGB: 0x24292d) - + let lightTextColor = NSColor(RGB: 0x24292D) + let lightBackgroundColor = NSColor(RGB: 0xF6F8FA) + + let darkTextColor = NSColor(RGB: 0xD1D5DA) + let darkBackgroundColor = NSColor(RGB: 0x24292D) + override init(frame frameRect: NSRect, textContainer container: NSTextContainer?) { super.init(frame: frameRect, textContainer: container) disableAutoReplacement() @@ -55,11 +52,11 @@ class SJTextView: NSTextView { internal func updateFormat() { textStorage?.font = NSFont(name: "Monaco", size: 12) - - let color = NSColor(RGB: 0x07c160) + + let color = NSColor(RGB: 0x07C160) insertionPointColor = color selectedTextAttributes = [.backgroundColor: color.withAlphaComponent(0.2)] - + if isDarkMode { textColor = darkTextColor backgroundColor = darkBackgroundColor @@ -83,10 +80,10 @@ class SJTextView: NSTextView { isAutomaticDashSubstitutionEnabled = false isAutomaticTextReplacementEnabled = false } - + override func layout() { super.layout() - + updateFormat() } } diff --git a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift index f37febf..d1c0694 100644 --- a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift +++ b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift @@ -39,8 +39,8 @@ class ModelGeneratorTests: XCTestCase { "double_value": Double(5.3), "sub_value_four": "value", "internal": "renamed_value", - "sub_value_five": ["two_level_down": "value"] - ] + "sub_value_five": ["two_level_down": "value"], + ], ], "value_eight": []]) } From 86b424395a61db5bcf6c2cafab66b5335ec9d465 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa Date: Mon, 31 Oct 2022 08:01:39 +0530 Subject: [PATCH 16/16] fix: releaserc wrong branch name (#137) --- .releaserc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.releaserc b/.releaserc index 728ed6f..e463cd7 100644 --- a/.releaserc +++ b/.releaserc @@ -1,5 +1,5 @@ { - "branches": ["main"], + "branches": ["master"], "tagFormat": "${version}", "plugins": [ [