Skip to content

Commit

Permalink
Squashed 'apollo-ios/' changes from 74e71b8..f806167
Browse files Browse the repository at this point in the history
f806167 InstallCLI Plugin Updates (#132)

git-subtree-dir: apollo-ios
git-subtree-split: f806167
  • Loading branch information
gh-action-runner authored and gh-action-runner committed Jan 12, 2024
1 parent 3d9a500 commit 2613e40
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
Binary file removed CLI/apollo-ios-cli.tar.gz
Binary file not shown.
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -63,7 +63,8 @@ let package = Package(
verb: "apollo-cli-install",
description: "Installs the Apollo iOS Command line interface."),
permissions: [
.writeToPackageDirectory(reason: "Creates a symbolic link to the CLI executable in your project directory."),
.writeToPackageDirectory(reason: "Downloads and unzips the CLI executable into your project directory."),
.allowNetworkConnections(scope: .all(ports: []), reason: "Downloads the Apollo iOS CLI executable from the GitHub Release.")
]),
dependencies: [],
path: "Plugins/InstallCLI"
Expand Down
37 changes: 10 additions & 27 deletions Plugins/InstallCLI/InstallCLIPluginCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,17 @@ import PackagePlugin
struct InstallCLIPluginCommand: CommandPlugin {

func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws {
var apolloDirectoryPath: Path? = nil
let dependencies = context.package.dependencies
dependencies.forEach { dep in
try dependencies.forEach { dep in
if dep.package.displayName == "Apollo" {
apolloDirectoryPath = dep.package.directory
let process = Process()
let path = try context.tool(named: "sh").path
process.executableURL = URL(fileURLWithPath: path.string)
process.arguments = ["\(dep.package.directory)/scripts/download-cli.sh", context.package.directory.string]
try process.run()
process.waitUntilExit()
}
}

guard let apolloPath = apolloDirectoryPath else {
fatalError("No Apollo dependency directory path")
}

let process = Process()
let tarPath = try context.tool(named: "tar").path
process.executableURL = URL(fileURLWithPath: tarPath.string)
process.arguments = ["-xvf", "\(apolloPath)/CLI/apollo-ios-cli.tar.gz"]
try process.run()
process.waitUntilExit()
}

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()
}

}
Expand All @@ -47,9 +30,9 @@ extension InstallCLIPluginCommand: XcodeCommandPlugin {
print("Installing Apollo CLI Plugin to Xcode project \(context.xcodeProject.displayName)")
let apolloPath = "\(context.pluginWorkDirectory)/../../checkouts/apollo-ios"
let process = Process()
let tarPath = try context.tool(named: "tar").path
process.executableURL = URL(fileURLWithPath: tarPath.string)
process.arguments = ["-xvf", "\(apolloPath)/CLI/apollo-ios-cli.tar.gz"]
let path = try context.tool(named: "sh").path
process.executableURL = URL(fileURLWithPath: path.string)
process.arguments = ["\(apolloPath)/scripts/download-cli.sh", context.xcodeProject.directory.string]
try process.run()
process.waitUntilExit()
}
Expand Down
19 changes: 19 additions & 0 deletions scripts/download-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# This script is intended for use only with the "InstallCLI" SPM plugin provided by Apollo iOS

directory=$(dirname "$0")
projectDir="$1"

if [ -z "$projectDir" ];
then
echo "Missing project directory path." >&2
exit 1
fi

APOLLO_VERSION=$(sh "$directory/get-version.sh")
DOWNLOAD_URL="https://www.github.com/apollographql/apollo-ios/releases/download/$APOLLO_VERSION/apollo-ios-cli.tar.gz"
FILE_PATH="$projectDir/apollo-ios-cli.tar.gz"
curl -L "$DOWNLOAD_URL" -s -o "$FILE_PATH"
tar -xvf "$FILE_PATH"
rm -f "$FILE_PATH"
2 changes: 1 addition & 1 deletion scripts/get-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
directory=$(dirname "$0")
source "$directory/version-constants.sh"

constantsFile=$(cat $directory/../$APOLLO_CONSTANTS_FILE)
constantsFile=$(cat "$directory/../$APOLLO_CONSTANTS_FILE")
currentVersion=$(echo $constantsFile | sed 's/^.*ApolloVersion: String = "\([^"]*\).*/\1/')
echo $currentVersion

0 comments on commit 2613e40

Please sign in to comment.