Skip to content

Commit

Permalink
update: Drop plugins for SwiftPM (#2649)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Miller <[email protected]>
  • Loading branch information
calvincestari and AnthonyMDev authored Nov 16, 2022
1 parent 4c4edf5 commit 69538a3
Show file tree
Hide file tree
Showing 101 changed files with 107 additions and 845 deletions.
11 changes: 0 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ commands:
working_directory: Tests/CodegenCLITests/pod-install-test/
command: ./Pods/Apollo/apollo-ios-cli generate
name: CocoaPods - CLI Test (generate)
swiftpm_plugin_test:
steps:
- run:
working_directory: Tests/CodegenCLITests/swiftpm-test/
command: swift build
name: SwiftPM - Build package
- run:
working_directory: Tests/CodegenCLITests/swiftpm-test/
command: swift package plugin --allow-writing-to-package-directory apollo-generate --verbose
name: SwiftPM - Plugin Test (generate)
save-xcodebuild-artifacts:
description: Save artifacts logs, crash reports and test results generated by xcodebuild
steps:
Expand Down Expand Up @@ -248,7 +238,6 @@ jobs:
steps:
- common_test_setup
- cocoapods_install_test
- swiftpm_plugin_test

workflows:
version: 2
Expand Down
4 changes: 0 additions & 4 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,6 @@
E6203346284F252A00A291D1 /* MockUnionsFileGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6203345284F252A00A291D1 /* MockUnionsFileGeneratorTests.swift */; };
E6203348284F25DF00A291D1 /* MockUnionsTemplateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6203347284F25DF00A291D1 /* MockUnionsTemplateTests.swift */; };
E623FD2A2797A6F4008B4CED /* InterfaceTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E623FD292797A6F4008B4CED /* InterfaceTemplate.swift */; };
E639F20528F0A8FA00441FF4 /* IgnoredOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E639F20428F0A8FA00441FF4 /* IgnoredOptions.swift */; };
E63F0C0328EE0F2A009069EA /* ApolloCodegenFrontendBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E63F0C0028EE099A009069EA /* ApolloCodegenFrontendBundle.swift */; };
E64F226D28B8B3FE0011292F /* LogLevelSetter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E64F226C28B8B3FE0011292F /* LogLevelSetter.swift */; };
E64F227128B8BEE10011292F /* MockLogLevelSetter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E64F227028B8BEE10011292F /* MockLogLevelSetter.swift */; };
Expand Down Expand Up @@ -1882,7 +1881,6 @@
E6203347284F25DF00A291D1 /* MockUnionsTemplateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUnionsTemplateTests.swift; sourceTree = "<group>"; };
E623FD292797A6F4008B4CED /* InterfaceTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InterfaceTemplate.swift; sourceTree = "<group>"; };
E623FD2B2797A700008B4CED /* InterfaceTemplateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InterfaceTemplateTests.swift; sourceTree = "<group>"; };
E639F20428F0A8FA00441FF4 /* IgnoredOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IgnoredOptions.swift; sourceTree = "<group>"; };
E63F0C0028EE099A009069EA /* ApolloCodegenFrontendBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloCodegenFrontendBundle.swift; sourceTree = "<group>"; };
E64F226C28B8B3FE0011292F /* LogLevelSetter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogLevelSetter.swift; sourceTree = "<group>"; };
E64F227028B8BEE10011292F /* MockLogLevelSetter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockLogLevelSetter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3977,7 +3975,6 @@
isa = PBXGroup;
children = (
E687B3CC28B398E600A9551C /* InputOptions.swift */,
E639F20428F0A8FA00441FF4 /* IgnoredOptions.swift */,
);
path = OptionGroups;
sourceTree = "<group>";
Expand Down Expand Up @@ -5749,7 +5746,6 @@
E687B3E828B398E600A9551C /* SchemaDownloadProvider.swift in Sources */,
E64F226D28B8B3FE0011292F /* LogLevelSetter.swift in Sources */,
E687B3E428B398E600A9551C /* Initialize.swift in Sources */,
E639F20528F0A8FA00441FF4 /* IgnoredOptions.swift in Sources */,
E687B3E128B398E600A9551C /* String+Data.swift in Sources */,
E687B3DD28B398E600A9551C /* InputOptions.swift in Sources */,
E687B3E728B398E600A9551C /* CodegenProvider.swift in Sources */,
Expand Down
37 changes: 5 additions & 32 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ let package = Package(
.library(name: "ApolloWebSocket", targets: ["ApolloWebSocket"]),
.library(name: "ApolloTestSupport", targets: ["ApolloTestSupport"]),
.executable(name: "apollo-ios-cli", targets: ["apollo-ios-cli"]),
.plugin(name: "ApolloCodegenPlugin-Initialize", targets: ["ApolloCodegenPlugin-Initialize"]),
.plugin(name: "ApolloCodegenPlugin-Fetch", targets: ["ApolloCodegenPlugin-Fetch"]),
.plugin(name: "ApolloCodegenPlugin-Generate", targets: ["ApolloCodegenPlugin-Generate"]),
],
dependencies: [
.package(
Expand Down Expand Up @@ -106,40 +103,16 @@ let package = Package(
"Info.plist",
]),
.plugin(
name: "ApolloCodegenPlugin-Initialize",
name: "InstallCLI",
capability: .command(
intent: .custom(
verb: "apollo-initialize-codegen-config",
description: "Initialize a new code generation configuration with defaults."),
verb: "apollo-cli-install",
description: "Installs the Apollo iOS Command line interface."),
permissions: [
.writeToPackageDirectory(reason: "Adds a codegen JSON configuration file.")
.writeToPackageDirectory(reason: "Creates a symbolic link to the CLI executable in your project directory.")
]),
dependencies: [
"apollo-ios-cli"
]),
.plugin(
name: "ApolloCodegenPlugin-Fetch",
capability: .command(
intent: .custom(
verb: "apollo-fetch-schema",
description: "Download a GraphQL schema from the Apollo Registry or via GraphQL introspection."),
permissions: [
.writeToPackageDirectory(reason: "Downloads the GraphQL schema to a file.")
]),
dependencies: [
"apollo-ios-cli"
]),
.plugin(
name: "ApolloCodegenPlugin-Generate",
capability: .command(
intent: .custom(
verb: "apollo-generate",
description: "Generate Swift code for the configured GraphQL schema and operations."),
permissions: [
.writeToPackageDirectory(reason: "Generates Swift files for the schema and operations.")
]),
dependencies: [
"apollo-ios-cli"
]),
])
]
)
22 changes: 0 additions & 22 deletions Plugins/ApolloCodegenPlugin-Fetch/ApolloCodegenPluginFetch.swift

This file was deleted.

4 changes: 0 additions & 4 deletions Plugins/ApolloCodegenPlugin-Fetch/Symbolic Links/README.md

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions Plugins/ApolloCodegenPlugin-Generate/Symbolic Links/README.md

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

37 changes: 37 additions & 0 deletions Plugins/InstallCLI/InstallCLIPluginCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Foundation
import PackagePlugin

@main
struct InstallCLIPluginCommand: CommandPlugin {

func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws {
let pathToCLI = try context.tool(named: "apollo-ios-cli").path
try createSymbolicLink(from: pathToCLI, to: context.package.directory)
}

func createSymbolicLink(from: PackagePlugin.Path, to: PackagePlugin.Path) throws {
let task = Process()
task.standardInput = nil
task.environment = ProcessInfo.processInfo.environment
task.arguments = ["-c", "ln -f -s \(from.string) \(to.string)"]
task.executableURL = URL(fileURLWithPath: "/bin/zsh")
try task.run()
task.waitUntilExit()
}

}

#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin

extension InstallCLIPluginCommand: XcodeCommandPlugin {

/// 👇 This entry point is called when operating on an Xcode project.
func performCommand(context: XcodePluginContext, arguments: [String]) throws {
print("Installing Apollo CLI Plugin to Xcode project \(context.xcodeProject.displayName)")
let pathToCLI = try context.tool(named: "apollo-ios-cli").path
try createSymbolicLink(from: pathToCLI, to: context.xcodeProject.directory)
}

}
#endif
18 changes: 0 additions & 18 deletions Plugins/SharedPackageFiles/CodegenCommand.swift

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion Sources/CodegenCLI/Commands/FetchSchema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public struct FetchSchema: ParsableCommand {
)

@OptionGroup var inputs: InputOptions
@OptionGroup var ignored: IgnoredOptions

// MARK: - Implementation

Expand Down
1 change: 0 additions & 1 deletion Sources/CodegenCLI/Commands/Generate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public struct Generate: ParsableCommand {
)

@OptionGroup var inputs: InputOptions
@OptionGroup var ignored: IgnoredOptions

@Flag(
name: .shortAndLong,
Expand Down
2 changes: 0 additions & 2 deletions Sources/CodegenCLI/Commands/Initialize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public struct Initialize: ParsableCommand {
abstract: "Initialize a new configuration with defaults."
)

@OptionGroup var ignored: IgnoredOptions

@Option(
name: [.long, .customShort("n")],
help: "Name used to scope the generated schema type files."
Expand Down
19 changes: 0 additions & 19 deletions Sources/CodegenCLI/OptionGroups/IgnoredOptions.swift

This file was deleted.

19 changes: 19 additions & 0 deletions docs/shared/spm-install-cli.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The Apollo iOS SPM package includes the Codegen CLI as an executable target. This ensures you always have a valid CLI version for your Apollo iOS version.

To simplify accessing the Codegen CLI, you can run the included `InstallCLI` SPM plugin.

This plugin builds the CLI and creates a symbolic link to the executable in your project root.

When using a `Package.swift` file, install the CLI by running:

```bash
swift package --allow-writing-to-package-directory apollo-cli-install
```

When using Swift packages through Xcode, right-click on your project in the Xcode file explorer and at the bottom of the menu you will find the `InstallCLI` plugin command. Clicking on this will present a dialog asking for permission for the plugin to write to your project directory.

<img class="screenshot" src="../source/screenshot/apollo-xcode-plugin.png" alt="Where to find the SPM plugin commands in Xcode" />

After running the installation plugin, a symbolic link to the Codegen CLI named `apollo-ios-cli` is located in your project root folder. You can now run the CLI from the command line with `./apollo-ios-cli`.

> **Note:** Because the `apollo-ios-cli` in your project root is only a symbolic link, it will only work if the compiled CLI exectuable exists. This is generally located in your Xcode Derived Data or the `.build` folder. If these are cleared, you can run the install plugin again to re-build the CLI executable.
Loading

0 comments on commit 69538a3

Please sign in to comment.