Created
August 19, 2022 02:41
-
-
Save johnlindquist/1ecd76684a229ba5e5a92d65887abd15 to your computer and use it in GitHub Desktop.
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
// Name: Netlify | |
// Sponsor: Diamond | |
// Logo: /Users/johnlindquist/.kit/logos/netlify/netlify-dark.svg | |
// color-primary-dark:0, 140, 107 | |
// color-secondary-dark:0, 0, 0 | |
// color-primary-light:21, 250, 194 | |
// color-secondary-light:255, 255, 255 | |
// Index: -2 | |
import "@johnlindquist/kit" | |
let { NetlifyAPI } = await npm("netlify") | |
let NETLIFY_TOKEN = await env("NETLIFY_TOKEN") | |
let client = new NetlifyAPI(NETLIFY_TOKEN) | |
let { Octokit } = await npm("@octokit/rest") | |
let octokit = new Octokit({ | |
auth: await env("GITHUB_NETLIFY_REPOS"), | |
}) | |
let owner = "netlify" | |
let repo = "templates" | |
onTab("About", async () => { | |
await div(md(`## Netlify | |
Netlify is a great company | |
`)) | |
}) | |
onTab("Sites", async () => { | |
setLoading(true) | |
let admin_url = await arg("Select a site", async () => { | |
let sites = await client.listSites() | |
return sites.map(({ name, url, admin_url }) => { | |
return { | |
name, | |
description: url, | |
value: admin_url, | |
} | |
}) | |
}) | |
await exec(`open '${admin_url}'`) | |
}) | |
onTab("Create", async () => { | |
setLoading(true) | |
let url = await arg("Select a template", async () => { | |
let response = await octokit.rest.repos.getContent({ | |
owner, | |
repo, | |
path: "/src/site/template", | |
}) | |
let choices = response.data.map( | |
({ name, download_url }) => { | |
return { | |
name, | |
value: download_url, | |
} | |
} | |
) | |
return choices | |
}) | |
let response = await get(url) | |
let repository = response.data | |
.match(/(?<=repo:).*/)?.[0] | |
?.trim() | |
let stack = response.data | |
.match(/(?<=stack:).*/)?.[0] | |
?.trim() | |
let data = _.pickBy( | |
{ | |
repository, | |
stack, | |
}, | |
(k, v) => v | |
) | |
let params = new URLSearchParams(data) | |
await exec( | |
`open 'https://app.netlify.com/start/deploy?${params.toString()}'` | |
) | |
}) | |
onTab("CLI", async () => { | |
let yn = await arg("Open CLI", ["yes", "no"]) | |
if (yn) { | |
setBounds({ height: 480 }) | |
await term({ | |
command: `netlify`, | |
footer: `Netlify CLI`, | |
}) | |
} | |
}) | |
onTab("Build", async () => { | |
await arg("Deployments", [ | |
{ | |
name: "Deployments Name", | |
description: "Description", | |
}, | |
]) | |
}) | |
onTab("Domains", async () => { | |
await arg("Analytics", [ | |
{ | |
name: "Analytics Name", | |
description: "Description", | |
}, | |
]) | |
}) | |
onTab("Members", async () => { | |
await arg("Settings", [ | |
{ | |
name: "Settings Name", | |
description: "Description", | |
}, | |
]) | |
}) | |
onTab("Settings", async () => { | |
await arg("Settings", [ | |
{ | |
name: "Settings Name", | |
description: "Description", | |
}, | |
]) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment