Skip to content
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: add pocketenv web user interface #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"importMap": "import_map.json",
"tasks": {
"dev": "deno run --watch main.ts"
"dev": "deno run -A --unstable --watch main.ts"
}
}
}
31 changes: 30 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ export {
export { generateName } from "https://deno.land/x/[email protected]/mod.ts ";
import * as _ from "https://cdn.skypack.dev/lodash";
export { _ };
export { serve } from "https://deno.land/[email protected]/http/server.ts";
export { createYoga } from "https://esm.sh/[email protected]?external=graphql";
import SchemaBuilder from "https://esm.sh/*@pothos/[email protected]";
export { SchemaBuilder };
5 changes: 5 additions & 0 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"graphql": "https://esm.sh/[email protected]"
}
}
9 changes: 9 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import down from "./src/cmd/down.ts";
import init from "./src/cmd/init.ts";
import list from "./src/cmd/list.ts";
import logs from "./src/cmd/logs.ts";
import server from "./src/cmd/server.ts";
import shell from "./src/cmd/shell.ts";
import up from "./src/cmd/up.ts";
import { VERSION } from "./src/consts.ts";
Expand Down Expand Up @@ -67,6 +68,14 @@ async function main() {
.action(async function () {
await list();
})
.command("server", "Start the Pocketenv server")
.option(
"--port <port:number>",
"Port to start the server on, defaults to 4090"
)
.action(async function (options) {
await server(options);
})
.parse(Deno.args);
}

Expand Down
13 changes: 12 additions & 1 deletion src/cmd/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
async function server({ port: _port }: { port?: number }) {}
import { createYoga } from "../../deps.ts";
import { schema } from "../server/graphql/schema.ts";

function server({ port }: { port?: number }) {
const yoga = createYoga({
schema,
});

console.log(`Server started on http://localhost:${port || 4090} 🚀`);

Deno.serve({ port: port || 4090 }, yoga);
}

export default server;
4 changes: 4 additions & 0 deletions src/server/graphql/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { SchemaBuilder } from "../../../deps.ts";
import { Context } from "./context.ts";

export const builder = new SchemaBuilder<{ Context: Context }>({});
13 changes: 13 additions & 0 deletions src/server/graphql/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Workspace } from "../../type.ts";

export type KV = {
workspace: {
save: (path: string, data: Workspace) => Promise<void>;
get: (path: string) => Promise<Workspace>;
list: () => Promise<Workspace[]>;
};
};

export type Context = {
kv: KV;
};
27 changes: 27 additions & 0 deletions src/server/graphql/objects/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export class Project {
id: string;
name: string;
template: string;
status: string;
containerId: string;
createdAt: string;
updatedAt: string;

constructor({
id,
name,
template,
status,
containerId,
createdAt,
updatedAt,
}: Project) {
this.id = id;
this.name = name;
this.template = template;
this.status = status;
this.containerId = containerId;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}
}
27 changes: 27 additions & 0 deletions src/server/graphql/objects/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export class Template {
id: string;
name: string;
description: string;
logo: string;
readme: string;
repoUrl: string;
packageName: string;

constructor({
id,
name,
description,
logo,
readme,
repoUrl,
packageName,
}: Template) {
this.id = id;
this.name = name;
this.description = description;
this.logo = logo;
this.readme = readme;
this.repoUrl = repoUrl;
this.packageName = packageName;
}
}
18 changes: 18 additions & 0 deletions src/server/graphql/resolvers/projects/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Context } from "../../context.ts";
import { Project } from "../../objects/project.ts";

export async function createProject(
root: any,
args: any,
ctx: Context
): Promise<Project> {
return new Project({
id: "2",
name: "trusting_pasteur",
template: "nix",
status: "Stopped",
containerId: "",
createdAt: "2024-02-11T19:00:00.778Z",
updatedAt: "2024-02-11T19:00:00.778Z",
});
}
47 changes: 47 additions & 0 deletions src/server/graphql/resolvers/projects/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Context } from "../../context.ts";
import { Project } from "../../objects/project.ts";

export async function getProjects(
root: any,
args: any,
ctx: Context
): Promise<Project[]> {
const projects = [
{
id: "1",
name: "confident_dubinsky",
template: "pkgx",
status: "Running",
containerId: "cf9d06c80fec",
createdAt: "2024-02-11T19:00:00.778Z",
updatedAt: "2024-02-11T19:00:00.778Z",
},
{
id: "2",
name: "trusting_pasteur",
template: "nix",
status: "Stopped",
containerId: "",
createdAt: "2024-02-11T19:00:00.778Z",
updatedAt: "2024-02-11T19:00:00.778Z",
},
];
return projects;
}

export async function getProjectDetails(
root: any,
args: any,
ctx: Context
): Promise<Project | null> {
const project = {
id: "1",
name: "confident_dubinsky",
template: "pkgx",
status: "Running",
containerId: "cf9d06c80fec",
createdAt: "2024-02-11T19:00:00.778Z",
updatedAt: "2024-02-11T19:00:00.778Z",
};
return project;
}
64 changes: 64 additions & 0 deletions src/server/graphql/resolvers/templates/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Template } from "../../objects/template.ts";

export const templates: Template[] = [
{
id: "1",
name: "Devbox",
description:
"A ready-to-use development environment with devbox already installed.",
logo: "https://cdn.jsdelivr.net/gh/fluent-ci-templates/.github@main/assets/devbox_logo_dark.png",
readme: "https://cdn.jsdelivr.net/gh/pocketenv-io/devbox@main/README.md",
repoUrl: "https://github.com/pocketenv-io/devbox",
packageName: "devbox",
},
{
id: "2",
name: "Devenv",
description:
"A ready-to-use development environment with devenv already installed.",
logo: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIALUAwAMBIgACEQEDEQH/xAAcAAEAAgIDAQAAAAAAAAAAAAAABgcEBQECCAP/xABAEAABAgIECQgIBgIDAAAAAAAAAQMCBQQGBxEXMTZVdJOxstMSITU3VHJz0RMUFjJRkZLhUlNWlKHSFUEiI0L/xAAZAQEAAwEBAAAAAAAAAAAAAAAAAgMEAQX/xAAgEQEAAgIBBQEBAAAAAAAAAAAAAQIDETISExQxYQRR/9oADAMBAAIRAxEAPwC8QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVZXe0OeyWs9IlUqo0ujbZghi5VIbjWJb0v8A9RoaTCnXDscl1LvEMG0brFmHgt7ppTVjxVtXcqL3mJ1CUYU64djkupd4gwp1w7HJdS7xCLgn2KI92yUYU64djkupd4h86Ra1W2jMxPOUKTLDAl6ojLvEI2YU56MpHcOWw0iNuxktt6coD8VJoNHfiREidahjVExXql59zDk3Q9B0dvdQzDG0AAAAAAAAAAAAAAAAAAAAACg7RusWYeC3umlN1aN1izDwW900puw8IZcnIABagGFOejKR3DNMKc9GUjuEb8Zdr7el5N0PQdHb3UMww5N0PQdHb3UMw85sAAAAAAAAAAAAAAAAAAAAAFB2jdYsw8FvdNKbe0t5pm0SYK65DAnomveW7/yaD16idpa+o3YZjohmycmQDH9eonaWvqHr1E7S19RZuENMgwpz0ZSO4fX16idpa+ow5tS6NHLn4YH21VYcSRIctMdMu19vT0m6HoOjt7qGYYcm6HoOjt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idZqgyyscFBhpVMmDC0JtG24qM5BCqonxvhU0mB2TZ7n2va4ZY4OxMx6c1CuMDsmz3Pte1wxgdk2e59r2uGWODvVb+moVxgdk2e59r2uGMDsmz3Pte1wyxwOq39OmAAEXQAAAAAAAAAAAAAAAAAAAAAAAAAAAAB//Z",
readme: "https://cdn.jsdelivr.net/gh/pocketenv-io/devenv@main/README.md",
repoUrl: "https://github.com/pocketenv-io/devenv",
packageName: "devenv",
},
{
id: "3",
name: "Flox",
description:
"A ready-to-use development environment with flox already installed.",
logo: "https://cdn.jsdelivr.net/gh/fluent-ci-templates/.github@main/assets/flox.svg",
readme: "https://cdn.jsdelivr.net/gh/pocketenv-io/flox@main/README.md",
repoUrl: "https://github.com/pocketenv-io/flox",
packageName: "flox",
},
{
id: "4",
name: "Homebrew",
description:
"A ready-to-use development environment with homebrew already installed.",
logo: "https://upload.wikimedia.org/wikipedia/commons/9/95/Brew_logo.svg",
readme: "https://cdn.jsdelivr.net/gh/pocketenv-io/homebrew@main/README.md",
repoUrl: "https://github.com/pocketenv-io/homebrew",
packageName: "homebrew",
},
{
id: "5",
name: "Pkgx",
description:
"A ready-to-use development environment with pkgx already installed.",
logo: "https://avatars.githubusercontent.com/u/140643783?s=200&v=4",
readme: "https://cdn.jsdelivr.net/gh/pocketenv-io/pkgx@main/README.md",
repoUrl: "https://github.com/pocketenv-io/pkgx",
packageName: "pkgx",
},
{
id: "6",
name: "Nix",
description:
"A ready-to-use development environment with nix already installed.",
logo: "https://upload.wikimedia.org/wikipedia/commons/2/28/Nix_snowflake.svg",
readme: "https://cdn.jsdelivr.net/gh/pocketenv-io/nix@main/README.md",
repoUrl: "https://github.com/pocketenv-io/nix",
packageName: "nix",
},
];
20 changes: 20 additions & 0 deletions src/server/graphql/resolvers/templates/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Context } from "../../context.ts";
import { Template } from "../../objects/template.ts";
import { templates } from "./mocks.ts";

export async function getTemplates(
root: any,
args: any,
ctx: Context
): Promise<Template[]> {
return templates;
}

export async function getTemplateDetails(
root: any,
args: any,
ctx: Context
): Promise<Template | null> {
const template = templates.find((template) => template.id === args.id);
return template!;
}
Loading
Loading