Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: Makefile, rename to codeedit #21

Merged
merged 4 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
prefix ?= /usr/local
bindir = $(prefix)/bin
binname = "codeedit"

build:
swift build -c release --disable-sandbox

install: build
install -d "$(bindir)"
install ".build/release/$(binname)" "$(bindir)"

uninstall:
rm -rf "$(bindir)/$(binname)"

clean:
rm -rf .build

.PHONY: build install uninstall clean
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "CodeEditCLI",
products: [
.executable(name: "codeedit-cli", targets: ["CodeEditCLI"])
.executable(name: "codeedit", targets: ["CodeEditCLI"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0")
Expand Down
34 changes: 9 additions & 25 deletions Sources/CodeEditCLI/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,28 @@ extension CodeEditCLI {
)

func run() throws {
// Run an apple script to find CodeEdit.app
let pathData = try codeEditURLData()
// Print the cli version
print("CodeEditCLI: \t\(CLI_VERSION)")

// File URL of CodeEdit.app
let appURL = URL(fileURLWithPath: "/Applications/CodeEdit.app")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to use the bundle identifier, because not everyone installs in /Applications.

        guard let appURL = NSWorkspace.shared.urlForApplication(
            withBundleIdentifier: "austincondiff.CodeEdit"
        ) else { return }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!


// Check if there is an Info.plist inside CodeEdit.app
// Then get the version number and print it out
//
// This will fail when CodeEdit.app is not installed
if let url = infoPlistUrl(pathData: pathData),
if let url = infoPlistUrl(appURL),
let plist = NSDictionary(contentsOf: url) as? [String: Any],
let version = plist["CFBundleShortVersionString"] as? String {
print("CodeEdit.app: \t\(version)")
} else {
print("CodeEdit.app is not installed.")
}

// Print the cli version
print("CodeEditCLI: \t\(CLI_VERSION)")
}

private func codeEditURLData() throws -> Data {
let task = Process()
let pipe = Pipe()
task.standardOutput = pipe
task.launchPath = "/usr/bin/osascript"

task.arguments = ["-e"]
task.arguments?.append("POSIX path of (path to application \"CodeEdit\")")

try task.run()

return pipe.fileHandleForReading.readDataToEndOfFile()
}

private func infoPlistUrl(pathData: Data) -> URL? {
if let path = String(data: pathData, encoding: .utf8) {
let url = URL(fileURLWithPath: path.trimmingCharacters(in: .whitespacesAndNewlines))
.appendingPathComponent("Contents")
.appendingPathComponent("Info.plist")
private func infoPlistUrl(_ url: URL?) -> URL? {
if let url = url?.appendingPathComponent("Contents")
.appendingPathComponent("Info.plist") {
return url
} else {
return nil
Expand Down