Skip to content

Commit 86a4354

Browse files
authored
[feat]: Makefile, rename to codeedit (#21)
- rename executable to `codeedit`. - fix the version command. - add Makefile in preparation for `Homebrew` formula.
2 parents fbc8d8d + 1da8f1c commit 86a4354

3 files changed

Lines changed: 28 additions & 26 deletions

File tree

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
prefix ?= /usr/local
2+
bindir = $(prefix)/bin
3+
binname = "codeedit"
4+
5+
build:
6+
swift build -c release --disable-sandbox
7+
8+
install: build
9+
install -d "$(bindir)"
10+
install ".build/release/$(binname)" "$(bindir)"
11+
12+
uninstall:
13+
rm -rf "$(bindir)/$(binname)"
14+
15+
clean:
16+
rm -rf .build
17+
18+
.PHONY: build install uninstall clean

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PackageDescription
66
let package = Package(
77
name: "CodeEditCLI",
88
products: [
9-
.executable(name: "codeedit-cli", targets: ["CodeEditCLI"])
9+
.executable(name: "codeedit", targets: ["CodeEditCLI"])
1010
],
1111
dependencies: [
1212
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0")

Sources/CodeEditCLI/Version.swift

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,28 @@ extension CodeEditCLI {
1616
)
1717

1818
func run() throws {
19-
// Run an apple script to find CodeEdit.app
20-
let pathData = try codeEditURLData()
19+
// Print the cli version
20+
print("CodeEditCLI: \t\(CLI_VERSION)")
21+
22+
// File URL of CodeEdit.app
23+
let appURL = URL(fileURLWithPath: "/Applications/CodeEdit.app")
2124

2225
// Check if there is an Info.plist inside CodeEdit.app
2326
// Then get the version number and print it out
2427
//
2528
// This will fail when CodeEdit.app is not installed
26-
if let url = infoPlistUrl(pathData: pathData),
29+
if let url = infoPlistUrl(appURL),
2730
let plist = NSDictionary(contentsOf: url) as? [String: Any],
2831
let version = plist["CFBundleShortVersionString"] as? String {
2932
print("CodeEdit.app: \t\(version)")
3033
} else {
3134
print("CodeEdit.app is not installed.")
3235
}
33-
34-
// Print the cli version
35-
print("CodeEditCLI: \t\(CLI_VERSION)")
36-
}
37-
38-
private func codeEditURLData() throws -> Data {
39-
let task = Process()
40-
let pipe = Pipe()
41-
task.standardOutput = pipe
42-
task.launchPath = "/usr/bin/osascript"
43-
44-
task.arguments = ["-e"]
45-
task.arguments?.append("POSIX path of (path to application \"CodeEdit\")")
46-
47-
try task.run()
48-
49-
return pipe.fileHandleForReading.readDataToEndOfFile()
5036
}
5137

52-
private func infoPlistUrl(pathData: Data) -> URL? {
53-
if let path = String(data: pathData, encoding: .utf8) {
54-
let url = URL(fileURLWithPath: path.trimmingCharacters(in: .whitespacesAndNewlines))
55-
.appendingPathComponent("Contents")
56-
.appendingPathComponent("Info.plist")
38+
private func infoPlistUrl(_ url: URL?) -> URL? {
39+
if let url = url?.appendingPathComponent("Contents")
40+
.appendingPathComponent("Info.plist") {
5741
return url
5842
} else {
5943
return nil

0 commit comments

Comments
 (0)