Public
Script
January 1, 2024
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env -S deno run -A
import type * as sunbeam from "https://deno.land/x/sunbeam/mod.ts";
import * as dates from "npm:date-fns";
const manifest = {
title: "Deno Deploy",
description: "Manage your Deno Deploy projects",
preferences: [
{
name: "token",
label: "Access Token",
type: "text",
},
],
commands: [
{
name: "projects",
title: "List Projects",
mode: "filter",
},
{
name: "dashboard",
title: "Open Dashboard",
mode: "silent",
},
{
name: "deployments",
title: "List Deployments",
hidden: true,
mode: "filter",
params: [{ name: "project", label: "Project", type: "text" }],
},
{
name: "playground",
title: "View Playground",
hidden: true,
mode: "detail",
params: [{ name: "project", label: "Project", type: "text" }],
},
],
} as const satisfies sunbeam.Manifest;
if (Deno.args.length == 0) {
console.log(JSON.stringify(manifest));
Deno.exit(0);
}
const payload: sunbeam.Payload<typeof manifest> = JSON.parse(Deno.args[0]);
const deployToken = payload.preferences.token;
if (!deployToken) {
console.error("Missing deploy token");
Deno.exit(1);
}
// #sunbeam
try {
const res = await run(payload);
if (res) {
console.log(JSON.stringify(res));
}
} catch (e) {
console.error(e);
Deno.exit(1);
}
async function run(payload: sunbeam.Payload<typeof manifest>) {
switch (payload.command) {
case "dashboard": {
await new Deno.Command("sunbeam", {
args: ["open", "https://dash.deno.com"],
}).output();
return;
}
case "projects": {
const resp = await fetchDeployAPI("/projects");
if (resp.status != 200) {
throw new Error("Failed to fetch projects");
}
const projects = await resp.json();
return {
items: projects.map((project: any) => {
const item: sunbeam.ListItem = {
title: project.name,
accessories: [project.type],
actions: [
{
title: "Open Dashboard",
type: "open",
open: {
url: `https://dash.deno.com/projects/${project.id}`,
},
},
],
};
if (project.hasProductionDeployment) {
const domains = project.productionDeployment.deployment.domainMappings;
const domain = domains.length
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
January 1, 2024