Skip to content

Commit

Permalink
detect xcode
Browse files Browse the repository at this point in the history
  • Loading branch information
tonka3000 committed Feb 1, 2024
1 parent 667a7ff commit 2a3ed9e
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 27 deletions.
133 changes: 110 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
"@typescript-eslint/parser": "^5.21.0",
"@vscode/test-cli": "^0.0.4",
"@vscode/test-electron": "^2.3.9",
"@types/which": "^3.0.3",
"eslint": "^8.14.0",
"glob": "^8.0.1",
"mocha": "^9.2.2",
Expand All @@ -438,6 +439,7 @@
"dependencies": {
"edit-json-file": "^1.7.0",
"json-to-ast": "^2.1.0",
"node-fetch": "^3.3.2"
"node-fetch": "^3.3.2",
"which": "^4.0.0"
}
}
36 changes: 33 additions & 3 deletions src/commands/swiftSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ import * as vscode from "vscode";
import { fileExists, showTextDocumentAtPosition } from "../utils";
import path = require("path");
import { readManifestFile } from "../manifest";
import which = require("which");

const raycastSwiftUrl = "https://github.com/raycast/extensions-swift-tools";

async function isXcodeInstalled() {
const resolved = await which("xcode-select", { nothrow: true });
return resolved ? true : false;
}

async function openXcodeInAppStore() {
await vscode.env.openExternal(vscode.Uri.parse("https://apps.apple.com/app/xcode/id497799835"));
}

function commentify(lines: string[]) {
return lines.map((c) => `//${c.length > 0 ? " " : ""}${c}`).join("\n");
}
Expand Down Expand Up @@ -52,10 +62,11 @@ let package = Package(
"",
"Example TypeScript file src/mycommand.tsx :",
"",
'import { hello } from "swift:../swift" // relative path to the swift directory from the workspace root',
'import { hello, helloName } from "swift:../swift" // relative path to the swift directory from the workspace root',
"",
"async function exampleFunction() {",
" await hello();",
' await helloName("Michael");',
"}",
];

Expand Down Expand Up @@ -90,6 +101,10 @@ import RaycastSwiftMacros
"Hello from Swift"
}
@raycast func helloName(name:String) -> String{
"Hello \(name)"
}
${commentify(example)}
${commentify(warning)}
Expand All @@ -109,8 +124,8 @@ export async function addSwiftSupportCmd(manager: ExtensionManager) {
throw new Error("No active workspace");
}
const swiftRootFolder = path.join(ws.uri.fsPath, "swift");
if (await fileExists(swiftRootFolder)) {
throw new Error("Swift folder already exists");
if (await fileExists(path.join(swiftRootFolder, "Package.swift"))) {
throw new Error("Swift Support already exist");
}
const swiftFilename = await addSwiftSupport(manager, swiftRootFolder);
showTextDocumentAtPosition(vscode.Uri.file(swiftFilename));
Expand All @@ -119,4 +134,19 @@ export async function addSwiftSupportCmd(manager: ExtensionManager) {
vscode.env.openExternal(vscode.Uri.parse(raycastSwiftUrl));
}
});
const xcodeInstalled = await isXcodeInstalled();
if (!xcodeInstalled) {
vscode.window
.showWarningMessage(
"You need to install Xcode because it is required for Swift for Raycast",
...["More Info", "AppStore"],
)
.then((selected) => {
if (selected === "More Info") {
vscode.env.openExternal(vscode.Uri.parse(raycastSwiftUrl + "#requirements"));
} else if (selected === "AppStore") {
openXcodeInAppStore();
}
});
}
}

0 comments on commit 2a3ed9e

Please sign in to comment.