Jacob Swain

Jacob Swain

// Name: Heroku Status
// Description: Displays the status of Heroku apps
// Author: Jacob Swain
// Twitter: @jacobswain
import "@johnlindquist/kit";
const Heroku = await npm("heroku-client");
let token = await env("HEROKU_API_TOKEN");
const heroku = new Heroku({ token });
const preview = ({ name, stack, web_url, git_url, updated_at, status }) =>
md(`
## ${name}
- Updated: ${updated_at}
- Status: ${status}
- Stack: ${stack}
### Links
${git_url ? `- [git](${git_url})` : ""}
${web_url ? `- [web](${web_url})` : ""}
`);
const byDateDesc = (a, b) => {
if (a.created_at < b.created_at) {
return 1;
}
if (a.created_at > b.created_at) {
return -1;
}
return 0;
};
const apps = await heroku.get("/apps").then((apps) =>
apps.map(({ id, name, web_url, git_url, updated_at }) => ({
name,
description: web_url,
value: `https://dashboard.heroku.com/apps/${name}`,
preview: async () => {
const setups = await heroku
.get(`/apps/${id}/builds`)
.then((builds) => builds.sort(byDateDesc));
if (!setups || !setups.length) return md(`No builds found`);
return preview({ ...setups[0], name, web_url, git_url });
},
}))
);
let url = await arg("Select Heroku App:", apps);
await $`open ${url}`;
// Menu: NPM Search
// Description: Search NPM for packages
// Author: Jacob A. Swain
// Twitter: @jacobswain
// Email: jacobswain@gmail.com
import "@johnlindquist/kit";
const baseUrl = "https://www.npmjs.com/search/suggestions?q=";
const toData = (res) => res.data;
const term = await arg("Package name:");
let preview = async ({ name, description, version, links }) =>
await md(`
## ${name}
- Description: ${description}
- Version: ${version}
#### Links
${links.npm ? `- [npm](${links.npm})` : ""}
${links.repository ? `- [repository](${links.repository})` : ""}
${links.repository ? `- [homepage](${links.homepage})` : ""}
`);
const results = await get(`${baseUrl}${term}`)
.then(toData)
.then((results) =>
results.map(({ name, description, version, links }) => ({
name,
description,
value: links.npm,
preview: async () => preview({ name, description, version, links }),
}))
);
let url = await arg("Select package:", results);
await $`open ${url}`;