-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from stateful/deep-deno
Works end-to-end, more work to do
- Loading branch information
Showing
15 changed files
with
445 additions
and
5 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
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,82 @@ | ||
import { LitElement, css, html } from 'lit' | ||
import { customElement, property } from 'lit/decorators.js' | ||
|
||
import { Deployment, Project } from '../../utils/deno/api_types' | ||
|
||
@customElement('deno-output') | ||
export class DenoOutput extends LitElement { | ||
// Define scoped styles right with your component, in plain CSS | ||
static styles = css` | ||
:host { | ||
display: block; | ||
font-family: Arial | ||
} | ||
section { | ||
padding: 10px; | ||
border: 1px solid #444; | ||
border-radius: 5px; | ||
display: flex; | ||
flex-direction: row; | ||
gap: 50px; | ||
align-items: flex-start; | ||
} | ||
img { | ||
width: 100px; | ||
padding: 20px; | ||
} | ||
h4 { | ||
margin-bottom: 0; | ||
} | ||
` | ||
|
||
// Declare reactive properties | ||
@property({ type: Object }) | ||
content?: any | ||
|
||
// Render the UI as a function of component state | ||
render() { | ||
if (!this.content) { | ||
return html`⚠️ Ups! Something went wrong displaying the result!` | ||
} | ||
|
||
const deployed: boolean = this.content.deployed | ||
const project: Project = this.content.project | ||
const deployments: Deployment[] = this.content.deployments | ||
|
||
if (!project.name || (deployments ?? []).length < 0) { | ||
return html`Deploying to Deno...` | ||
} | ||
|
||
const deployment = deployments[0] | ||
const len = deployments.length | ||
const more = len > 1 ? deployments.slice(1, len-1) : [] | ||
|
||
return html`<section> | ||
<img src="https://www.svgrepo.com/show/378789/deno.svg"> | ||
<div> | ||
<h4>Deployment</h4> | ||
${deployed ? html` | ||
<vscode-link href="https://${deployment.domainMappings[0].domain}"> | ||
${deployment.domainMappings[0].domain} | ||
</vscode-link> | ||
` : html`Pending` } | ||
<h4>Project</h4> | ||
<vscode-link href="https://dash.deno.com/projects/${project.name}/deployments">${project.name}</vscode-link> | ||
</div> | ||
<div> | ||
<h4>Created At</h4> | ||
${deployed ? (new Date(deployment.createdAt)).toString() : 'Pending' } | ||
<h4>Status</h4> | ||
${deployed ? | ||
html`Ready <button>🚀 Promote to Prod</button>` | ||
: 'Deploying'} | ||
</div> | ||
${more.forEach(m => { | ||
return html`<div>${m.domainMappings[0].domain}</div>` | ||
})} | ||
</section>` | ||
} | ||
} |
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
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
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
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,12 @@ | ||
import { ExtensionContext, NotebookCellExecution, TextDocument } from "vscode" | ||
|
||
import { bash } from './task' | ||
import { deploy } from "./deno/deploy" | ||
|
||
export async function deno ( | ||
context: ExtensionContext, | ||
exec: NotebookCellExecution, | ||
doc: TextDocument | ||
): Promise<boolean> { | ||
return Promise.all([bash(context, exec, doc), deploy(exec)]).then(([a, b]) => a && b) | ||
} |
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 { NotebookCellOutput, NotebookCellOutputItem, NotebookCellExecution, window } from 'vscode' | ||
|
||
import { OutputType } from '../../../constants' | ||
import type { CellOutput } from '../../../types' | ||
import { ENV_STORE } from '../../constants' | ||
import { API } from '../../../utils/deno/api' | ||
|
||
export async function deploy ( | ||
exec: NotebookCellExecution, | ||
// doc: TextDocument, | ||
// argv: any | ||
): Promise<boolean> { | ||
let token = ENV_STORE.get('DENO_ACCESS_TOKEN') | ||
|
||
try { | ||
if (!token) { | ||
token = await window.showInputBox({ | ||
title: 'Deno Access Token', | ||
prompt: 'Please enter a valid access token to run a Deno deployment.' | ||
}) | ||
} | ||
|
||
if (!token) { | ||
throw new Error('No token supplied') | ||
} | ||
|
||
const start = new Date() | ||
|
||
const denoAPI = API.fromToken(token) | ||
const projects = await denoAPI.getProjects() | ||
|
||
if ((projects ?? []).length < 1) { | ||
throw new Error('No deno projects available') | ||
} | ||
|
||
let deployed = false | ||
let iteration = 0 | ||
let created = start | ||
while (created <= start && iteration < 30) { | ||
const deployments = await denoAPI.getDeployments(projects![0].id) | ||
if ((deployments || []).length > 0) { | ||
created = new Date(deployments![0].createdAt) ?? start | ||
} | ||
|
||
deployed = created > start | ||
exec.replaceOutput(new NotebookCellOutput([ | ||
NotebookCellOutputItem.json(<CellOutput>{ | ||
type: OutputType.deno, | ||
output: { project: projects![0], deployments, deployed }, | ||
}, OutputType.deno), | ||
], { deno: { deploy: true } })) | ||
|
||
// keep going slower after 20 loops | ||
const timeout = 1000 + Math.max(0, iteration - 20) * 1000 | ||
await new Promise<void>(resolve => { setTimeout(() => { resolve() }, timeout) }) | ||
|
||
iteration++ | ||
} | ||
if (!deployed) { | ||
exec.replaceOutput(new NotebookCellOutput([ | ||
NotebookCellOutputItem.json(<CellOutput>{ | ||
type: 'error', | ||
output: 'Timed out' | ||
}, OutputType.deno) | ||
])) | ||
} | ||
} catch (err: any) { | ||
exec.replaceOutput(new NotebookCellOutput([ | ||
NotebookCellOutputItem.json(<CellOutput>{ | ||
type: 'error', | ||
output: err.message | ||
}, OutputType.deno) | ||
])) | ||
return false | ||
} | ||
|
||
return 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 @@ | ||
export * from './deploy' |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { sh, bash } from './task' | ||
import { vercel } from './vercel' | ||
import { deno } from './deno' | ||
import { html } from './html' | ||
import { js, jsx, ts, tsx } from './script' | ||
|
||
export default { sh, bash, vercel, html, js, jsx, ts, tsx } | ||
export default { sh, bash, vercel, html, js, jsx, ts, tsx, deno } |
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
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
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
Oops, something went wrong.