-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4395075
Showing
11 changed files
with
1,404 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"es2020": true, | ||
"node": true | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# misc | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"printWidth": 120, | ||
"singleQuote": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# PHP Changelog | ||
|
||
## [Initial Version] - 2023-01-23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# PHP | ||
|
||
Switch PHP version with Homebrew |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"$schema": "https://www.raycast.com/schemas/extension.json", | ||
"name": "php", | ||
"title": "Switch PHP version with Homebrew", | ||
"description": "Switch PHP version with Homebrew", | ||
"icon": "icon.png", | ||
"author": "David", | ||
"owner": "woda", | ||
"license": "MIT", | ||
"commands": [ | ||
{ | ||
"name": "php", | ||
"title": "PHP", | ||
"description": "Switch PHP version with Homebrew", | ||
"mode": "view", | ||
"preferences": [ | ||
{ | ||
"name": "7.4", | ||
"required": false, | ||
"title": "PHP 7.4", | ||
"type": "checkbox", | ||
"description": "PHP 7.4 installed?" | ||
}, | ||
{ | ||
"name": "8.0", | ||
"required": false, | ||
"title": "PHP 8.0", | ||
"type": "checkbox", | ||
"description": "PHP 8.0 installed?" | ||
}, | ||
{ | ||
"name": "8.1", | ||
"required": false, | ||
"title": "PHP 8.1", | ||
"type": "checkbox", | ||
"description": "PHP 8.1 installed?" | ||
}, | ||
{ | ||
"name": "8.2", | ||
"required": false, | ||
"title": "PHP 8.2", | ||
"type": "checkbox", | ||
"description": "PHP 8.2 installed?" | ||
} | ||
] | ||
} | ||
], | ||
"dependencies": { | ||
"@raycast/api": "^1.46.0", | ||
"@raycast/utils": "^1.4.16" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "18.8.3", | ||
"@types/react": "18.0.9", | ||
"@typescript-eslint/eslint-plugin": "^5.0.0", | ||
"@typescript-eslint/parser": "^5.0.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"prettier": "^2.5.1", | ||
"typescript": "^4.4.3" | ||
}, | ||
"scripts": { | ||
"build": "ray build -e dist", | ||
"dev": "ray develop", | ||
"fix-lint": "ray lint --fix", | ||
"lint": "ray lint", | ||
"publish": "ray publish" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { | ||
Action, | ||
ActionPanel, | ||
Clipboard, | ||
Toast, | ||
showToast, | ||
popToRoot, | ||
List, | ||
} from '@raycast/api'; | ||
import { exec } from 'child_process'; | ||
import { useMemo, useState } from 'react'; | ||
import { useExec } from "@raycast/utils"; | ||
|
||
interface Version { | ||
name: string; | ||
value: string; | ||
} | ||
|
||
const phpRegex = new RegExp('^(php[\\s@])'); | ||
const versionRegex = new RegExp('^(\\d+\\.\\d+)'); | ||
|
||
const handleError = async (message: string) => { | ||
await Clipboard.copy(message); | ||
void showToast({ | ||
title: 'Error', | ||
message: 'Message copied to your clipboard', | ||
style: Toast.Style.Failure, | ||
}); | ||
return; | ||
} | ||
|
||
const linkVersion = (version: Version, unlinkVersions: string[]) => { | ||
showToast({ | ||
title: `Linking PHP ${version.name}`, | ||
style: Toast.Style.Animated, | ||
}); | ||
const commands: string[] = []; | ||
unlinkVersions.forEach((v) => { | ||
commands.push(`brew unlink ${v}`); | ||
}); | ||
commands.push(`brew link ${version.value}`); | ||
const command = commands.join(' && '); | ||
exec(command, (error, _stdout, stderr) => { | ||
if (error) { | ||
return handleError(error.message); | ||
} | ||
if (stderr) { | ||
return handleError(stderr); | ||
} | ||
showToast({ | ||
title: `Successfully linked PHP ${version.name}`, | ||
style: Toast.Style.Success, | ||
}).then(() => { | ||
popToRoot(); | ||
});; | ||
}); | ||
} | ||
|
||
export default function Command() { | ||
const { isLoading, data } = useExec('/usr/local/bin/brew', ['list', '--versions']); | ||
const [linkingInProgress, setLinkingInProgress] = useState(false); | ||
const [linkedVersion, setLinkedVersion] = useState(''); | ||
|
||
const versions: Version[] = useMemo(() => { | ||
if (isLoading) { | ||
return []; | ||
} | ||
const newVersions: Version[] = []; | ||
const entries = (data || '').split('\n'); | ||
entries.forEach((entry) => { | ||
if (!phpRegex.test(entry)) { | ||
return; | ||
} | ||
const [name, version] = entry.split(' '); | ||
const simpleVersion = versionRegex.exec(version); | ||
if (!simpleVersion) { | ||
return; | ||
} | ||
newVersions.push({ name: simpleVersion[0], value: name }); | ||
}); | ||
return newVersions; | ||
}, [data, isLoading]); | ||
|
||
return <List | ||
navigationTitle="Link PHP Version" | ||
searchBarPlaceholder="Link PHP Version" | ||
> | ||
{linkingInProgress || versions.length === 0 ? ( | ||
<List.EmptyView | ||
title={linkingInProgress ? `Linking PHP ${linkedVersion}` : 'Loading...'} | ||
icon={{ source: "icon-small.png" }} | ||
/> | ||
) : ( | ||
versions.map((version) => ( | ||
<List.Item | ||
key={version.value} | ||
title={version.name} | ||
actions={ | ||
<ActionPanel> | ||
<Action | ||
title="Link" | ||
onAction={() => { | ||
setLinkingInProgress(true); | ||
setLinkedVersion(version.name); | ||
linkVersion( | ||
version, | ||
versions.reduce( | ||
(acc, v) => { | ||
if (v.value !== version.value) { | ||
acc.push(v.value); | ||
} | ||
return acc; | ||
}, | ||
[] as string[] | ||
) | ||
) | ||
}} /> | ||
</ActionPanel> | ||
} | ||
/> | ||
)) | ||
)} | ||
</List> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"display": "Node 16", | ||
"include": ["src/**/*"], | ||
"compilerOptions": { | ||
"lib": ["es2021"], | ||
"module": "commonjs", | ||
"target": "es2021", | ||
"strict": true, | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react-jsx", | ||
"resolveJsonModule": true | ||
} | ||
} |
Oops, something went wrong.