diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..60acd69 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,24 @@ +name: Release Cap2SPM + +on: + push: + tags: + '*.*.*' + +jobs: + release: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: swift-actions/setup-swift@v1 + with: + swift-version: "5.9" + - name: Build for Release + run: swift build -c release --arch arm64 --arch x86_64 --product cap2spm + - name: Zip Executable + run: zip cap2spm-${{ github.ref_name }}.zip .build/apple/Products/Release/cap2spm + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + files: cap2spm-${{ github.ref_name }}.zip + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..259fa94 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,11 @@ +# Contributor Code of Conduct + +As contributors and maintainers of the Capacitor project, we pledge to respect everyone who contributes by posting issues, updating documentation, submitting pull requests, providing feedback in comments, and any other activities. + +Communication through any of Capacitor's channels (GitHub, Slack, Forum, IRC, mailing lists, Twitter, etc.) must be constructive and never resort to personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. + +We promise to extend courtesy and respect to everyone involved in this project regardless of gender, gender identity, sexual orientation, disability, age, race, ethnicity, religion, or level of experience. We expect anyone contributing to the Capacitor project to do the same. + +If any member of the community violates this code of conduct, the maintainers of the Capacitor project may take action, removing issues, comments, and PRs or blocking accounts as deemed appropriate. + +If you are subject to or witness unacceptable behavior, or have any other concerns, please email us at [hi@ionicframework.com](mailto:hi@ionicframework.com). diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0832358 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023-present Drifty Co. + +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/Sources/cap2spm.swift b/Sources/cap2spm.swift index 762e49b..3eaa14c 100644 --- a/Sources/cap2spm.swift +++ b/Sources/cap2spm.swift @@ -1,9 +1,3 @@ -// The Swift Programming Language -// https://docs.swift.org/swift-book -// -// Swift Argument Parser -// https://swiftpackageindex.com/apple/swift-argument-parser/documentation - import Foundation import SwiftParser import SwiftSyntax @@ -48,25 +42,30 @@ struct Cap2SPM: ParsableCommand { swiftFileURL = try capacitorPluginPackage.findSwiftPluginFile(from: mFileURL) } - let source = try String(contentsOf: swiftFileURL, encoding: .utf8) - let sourceFile = Parser.parse(source: source) - guard let capPlugin = capacitorPluginPackage.oldPlugin?.capacitorPlugin else { return } - let incremented = AddPluginToClass(with: capPlugin).visit(sourceFile) + try modifySwiftFile(at: swiftFileURL, plugin: capPlugin) + + try fileBackup(at: mFileURL) + try fileBackup(at: hFileURL) + } + + private func fileBackup(at fileURL: URL) throws { + let fileBackupURL = fileURL.appendingPathExtension("old") + print("Moving \(fileURL.path()) to \(fileBackupURL.path())") + try FileManager.default.moveItem(at: fileURL, to: fileBackupURL) + } + + private func modifySwiftFile(at fileURL: URL, plugin: CapacitorPluginSyntax) throws { + let source = try String(contentsOf: fileURL, encoding: .utf8) + let sourceFile = Parser.parse(source: source) - let mFileBackup = mFileURL.appendingPathExtension("old") - let hFileBackup = hFileURL.appendingPathExtension("old") - let swiftFileBackup = swiftFileURL.appendingPathExtension("old") + let incremented = AddPluginToClass(with: plugin).visit(sourceFile) + + try fileBackup(at: fileURL) - try FileManager.default.moveItem(at: mFileURL, to: mFileBackup) - try FileManager.default.moveItem(at: hFileURL, to: hFileBackup) - try FileManager.default.moveItem(at: swiftFileURL, to: swiftFileBackup) - var outputString: String = "" incremented.write(to: &outputString) - try outputString.write(to: swiftFileURL, atomically: true, encoding: .utf8) + try outputString.write(to: fileURL, atomically: true, encoding: .utf8) } } - -