forked from raycast/extensions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: cratecast 1.0.0 Signed-off-by: Matt Gleich <[email protected]> * feat: update cratecast Signed-off-by: Matt Gleich <[email protected]>
- Loading branch information
Showing
10 changed files
with
195 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,14 @@ | ||
{ | ||
"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,2 @@ | ||
node_modules/ | ||
.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 @@ | ||
trailingComma: 'es5' | ||
tabWidth: 2 | ||
semi: false | ||
singleQuote: true |
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,8 @@ | ||
# cratecast | ||
|
||
[](https://github.com/gleich/cratecast/actions/workflows/lint.yml) | ||
[](https://github.com/gleich/cratecast/actions/workflows/build.yml) | ||
|
||
📦 crates.io from raycast | ||
|
||
 |
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,39 @@ | ||
{ | ||
"name": "cratecast", | ||
"title": "crates.io Search", | ||
"description": "Explore crates.io", | ||
"icon": "icon.png", | ||
"author": "matt", | ||
"license": "MIT", | ||
"commands": [ | ||
{ | ||
"name": "index", | ||
"title": "crates.io Search", | ||
"subtitle": "crates.io", | ||
"description": "Search for crates on crates.io", | ||
"mode": "view" | ||
} | ||
], | ||
"dependencies": { | ||
"@raycast/api": "^1.25.0", | ||
"node-fetch": "^3.0.0", | ||
"use-debounce": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "~16.10.0", | ||
"@types/react": "^17.0.28", | ||
"@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.4.1", | ||
"react-devtools": "^4.19.2", | ||
"typescript": "^4.4.3" | ||
}, | ||
"scripts": { | ||
"build": "ray build -e dist", | ||
"dev": "ray develop", | ||
"format": "prettier -w .", | ||
"format::check": "prettier --check ." | ||
} | ||
} |
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,34 @@ | ||
import fetch from 'node-fetch' | ||
|
||
export interface Crate { | ||
name: string | ||
version: string | ||
downloads: number | ||
documentationURL?: string | ||
homepageURL?: string | ||
repositoryURL?: string | ||
} | ||
|
||
export async function getCrates(search: string): Promise<Crate[]> { | ||
if (search === '') { | ||
return [] | ||
} | ||
const response = await fetch( | ||
'https://crates.io/api/v1/crates?page=1&per_page=100&q=' + | ||
encodeURIComponent(search) | ||
) | ||
const json = await response.json() | ||
|
||
const crates: Crate[] = [] | ||
for (const crate of Object(json).crates) { | ||
crates.push({ | ||
name: crate.name, | ||
version: crate.max_version, | ||
downloads: crate.downloads, | ||
documentationURL: crate.documentation, | ||
homepageURL: crate.homepage, | ||
repositoryURL: crate.repository, | ||
}) | ||
} | ||
return crates | ||
} |
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,78 @@ | ||
import { | ||
ActionPanel, | ||
CopyToClipboardAction, | ||
Icon, | ||
List, | ||
OpenInBrowserAction, | ||
render, | ||
} from '@raycast/api' | ||
import { randomUUID } from 'crypto' | ||
import { useState } from 'react' | ||
import { Crate, getCrates } from './api' | ||
import { useDebouncedCallback } from 'use-debounce' | ||
|
||
render(<Main />) | ||
|
||
function Main(): JSX.Element { | ||
const [crates, setCrates] = useState<Crate[]>([]) | ||
const [loading, setLoading] = useState(false) | ||
const debounced = useDebouncedCallback(async (v) => { | ||
setLoading(true) | ||
setCrates(await getCrates(v)) | ||
setLoading(false) | ||
}, 500) | ||
|
||
return ( | ||
<List | ||
isLoading={loading} | ||
onSearchTextChange={(v) => debounced(v)} | ||
searchBarPlaceholder="Search for a crate..." | ||
> | ||
{crates.map((c) => { | ||
const id = c.name + randomUUID() | ||
return ( | ||
<List.Item | ||
id={id} | ||
key={id} | ||
title={c.name} | ||
subtitle={c.version} | ||
accessoryTitle={c.downloads.toLocaleString()} | ||
accessoryIcon={Icon.Download} | ||
actions={ | ||
<ActionPanel> | ||
<CopyToClipboardAction | ||
content={`${c.name} = "${c.version}"`} | ||
title="Copy Dependency Line" | ||
/> | ||
{c.documentationURL ? ( | ||
<OpenInBrowserAction | ||
url={c.documentationURL} | ||
title="Open Crate Documentation" | ||
/> | ||
) : ( | ||
<></> | ||
)} | ||
{c.homepageURL ? ( | ||
<OpenInBrowserAction | ||
url={c.homepageURL} | ||
title="Open Homepage" | ||
/> | ||
) : ( | ||
<></> | ||
)} | ||
{c.repositoryURL ? ( | ||
<OpenInBrowserAction | ||
url={c.repositoryURL} | ||
title="Open Repository" | ||
/> | ||
) : ( | ||
<></> | ||
)} | ||
</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,16 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"display": "Node 16", | ||
"include": ["src/**/*"], | ||
"compilerOptions": { | ||
"lib": ["es2020"], | ||
"module": "commonjs", | ||
"target": "es2020", | ||
"strict": true, | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react-jsx" | ||
} | ||
} |