-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: vercast 1.0.0 #18
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"printWidth": 120, | ||
"singleQuote": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# vercast | ||
|
||
🚥 View your vercel deployments with raycast | ||
|
||
![example img](example.png) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "vercast", | ||
"title": "vercast", | ||
"description": "View your vercel deployments", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vercel is written in uppercase afaik, can you update? |
||
"icon": "vercel-icon.png", | ||
"author": "matt", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add this field to the manifest: |
||
"commands": [ | ||
{ | ||
"name": "index", | ||
"title": "vercast", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As command title, I'd suggest something like: Search Vercel Deployments |
||
"subtitle": "", | ||
"description": "View your vercel deployments", | ||
"mode": "view", | ||
"preferences": [ | ||
{ | ||
"name": "token", | ||
"type": "password", | ||
"required": true, | ||
"title": "Token", | ||
"description": "Account Token", | ||
"link": "https://vercel.com/account/tokens" | ||
} | ||
] | ||
} | ||
], | ||
"dependencies": { | ||
"@raycast/api": "^0.1.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be updated to: |
||
"dayjs": "^1.10.7", | ||
"node-fetch": "^2.6.1", | ||
"use-interval": "^1.3.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unfortunately not compatible with the react peer dependency that comes with our API. Also see my main review comment on this. |
||
}, | ||
"devDependencies": { | ||
"@types/node": "^16.4.3", | ||
"@types/node-fetch": "^2.5.12", | ||
"@types/react": "^17.0.15", | ||
"@typescript-eslint/eslint-plugin": "^4.28.5", | ||
"@typescript-eslint/parser": "^4.28.5", | ||
"eslint": "^7.31.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"typescript": "^4.3.5" | ||
}, | ||
"scripts": { | ||
"build": "ray build -e dist", | ||
"dev": "ray develop" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { render, ActionPanel, Color, Icon, List, OpenInBrowserAction } from "@raycast/api"; | ||
import { useEffect, useState } from "react"; | ||
import useInterval from "use-interval"; | ||
import { Deployment, DeploymentState, fetchDeployments, fetchUsername } from "./vercel"; | ||
|
||
render(<Main />); | ||
|
||
function Main(): JSX.Element { | ||
const [username, setUsername] = useState(""); | ||
const [deployments, setDeployments] = useState<Deployment[]>(); | ||
|
||
useEffect(() => { | ||
const call = async () => setUsername(await fetchUsername()); | ||
if (username === "") { | ||
call(); | ||
} | ||
}); | ||
useEffect(() => { | ||
const call = async () => setDeployments(await fetchDeployments(username)); | ||
if (!deployments) { | ||
call(); | ||
} | ||
}); | ||
|
||
useInterval(async () => { | ||
setDeployments(await fetchDeployments(username)); | ||
}, 1000); | ||
|
||
return ( | ||
<List isLoading={!deployments}> | ||
{deployments?.map((d) => { | ||
let iconSource = Icon.Globe; | ||
let iconTintColor = Color.PrimaryText; | ||
switch (d.state) { | ||
case DeploymentState.ready: | ||
iconSource = Icon.Checkmark; | ||
iconTintColor = Color.Green; | ||
break; | ||
case DeploymentState.deploying: | ||
iconSource = Icon.Hammer; | ||
iconTintColor = Color.Yellow; | ||
break; | ||
case DeploymentState.failed: | ||
iconSource = Icon.XmarkCircle; | ||
iconTintColor = Color.Red; | ||
break; | ||
} | ||
return ( | ||
<List.Item | ||
key={d.id} | ||
id={d.id} | ||
title={d.project} | ||
accessoryTitle={d.time} | ||
icon={{ tintColor: iconTintColor, source: iconSource }} | ||
actions={ | ||
<ActionPanel> | ||
<OpenInBrowserAction url={d.url} /> | ||
</ActionPanel> | ||
} | ||
/> | ||
); | ||
})} | ||
</List> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { preferences, showToast, ToastStyle } from "@raycast/api"; | ||
import fetch, { Headers } from "node-fetch"; | ||
import dayjs from "dayjs"; | ||
import relativeTime from "dayjs/plugin/relativeTime"; | ||
|
||
const headers = new Headers({ | ||
Authorization: "Bearer " + preferences.token.value, | ||
}); | ||
const apiURL = "https://api.vercel.com/"; | ||
|
||
export enum DeploymentState { | ||
ready, | ||
failed, | ||
deploying, | ||
} | ||
|
||
export interface Deployment { | ||
project: string; | ||
state: DeploymentState; | ||
time: string; | ||
id: string; | ||
url: string; | ||
} | ||
|
||
export async function fetchUsername(): Promise<string> { | ||
try { | ||
const response = await fetch(apiURL + "www/user", { | ||
method: "get", | ||
headers: headers, | ||
}); | ||
const json = await response.json(); | ||
return json.user.username; | ||
} catch (err) { | ||
console.error(err); | ||
showToast(ToastStyle.Failure, "Failed to fetch username"); | ||
} | ||
return Promise.resolve(""); | ||
} | ||
|
||
export async function fetchDeployments(username: string): Promise<Deployment[]> { | ||
dayjs.extend(relativeTime); | ||
|
||
try { | ||
const response = await fetch(apiURL + "v8/projects", { | ||
method: "get", | ||
headers: headers, | ||
}); | ||
const json = await response.json(); | ||
const deployments: Deployment[] = []; | ||
for (const project of json.projects) { | ||
for (const deployment of project.latestDeployments) { | ||
if (deployment.creator.username === username) { | ||
let state: DeploymentState; | ||
switch (deployment.readyState.toUpperCase()) { | ||
case "READY": | ||
state = DeploymentState.ready; | ||
break; | ||
case "BUILDING": | ||
case "QUEUED": | ||
state = DeploymentState.deploying; | ||
break; | ||
default: | ||
state = DeploymentState.failed; | ||
break; | ||
} | ||
deployments.push({ | ||
project: project.name, | ||
state: state, | ||
time: dayjs(deployment.createdAt).fromNow(), | ||
id: deployment.id, | ||
url: `https://vercel.com/${username}/${project.name}/${deployment.id.replace("dpl_", "")}`, | ||
}); | ||
break; | ||
} | ||
} | ||
} | ||
return deployments; | ||
} catch (err) { | ||
console.error(err); | ||
showToast(ToastStyle.Failure, "Failed to fetch deployments"); | ||
} | ||
return Promise.resolve([]); | ||
} |
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" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend to use uppercase for the title: Vercast