Skip to content

Commit

Permalink
feat: add typescript SDK ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Mar 17, 2024
1 parent ff10090 commit d489338
Show file tree
Hide file tree
Showing 49 changed files with 6,903 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FluentCI Engine is a programmable CI/CD engine that is designed to be simple, fl
- [x] No containerization or virtualization
- [x] Built-in support for Nix, Pkgx, Devbox, Flox and Devenv
- [ ] Cache support
- [ ] SDK for writing pipelines in TypeScript
- [x] SDK for writing pipelines in TypeScript, see [@fluentci/sdk](./sdk/typescript)
- [x] GraphQL API

## 🚀 Quick Start
Expand Down
3 changes: 3 additions & 0 deletions codegen/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deno.enable": true
}
5 changes: 5 additions & 0 deletions codegen/demo/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tasks": {
"dev": "deno run --watch main.ts"
}
}
62 changes: 62 additions & 0 deletions codegen/demo/deno.lock

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

5 changes: 5 additions & 0 deletions codegen/demo/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { gql } from "npm:[email protected]";
export { gql };
export { ClientError, GraphQLClient } from "npm:[email protected]";
import * as env from "jsr:@tsirysndr/[email protected]";
export { env };
81 changes: 81 additions & 0 deletions codegen/demo/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { dag } from "./sdk/client.gen.ts";

async function main() {
Deno.env.set("FLUENTCI_SESSION_PORT", "6880");
Deno.env.set("FLUENTCI_SESSION_TOKEN", "token");

const demo = await dag
.pipeline("demo")
.withWorkdir("./")
.withExec(["echo", "hello"])
.withExec(["echo", "hello world"])
.withExec(["echo", "hello again"])
.stdout();

console.log(demo);

const nix = await dag
.pipeline("nix-demo")
.nix()
.withWorkdir("./nix-demo")
.withExec(["nix", "--version"])
.withExec(["which", "deno"])
.stdout();

console.log(nix);

const devbox = await dag
.pipeline("devbox-demo")
.devbox()
.withWorkdir("./devbox-demo")
.withExec(["devbox", "version"])
.withExec(["which", "jq"])
.stdout();

console.log(devbox);

const flox = await dag
.pipeline("flox-demo")
.flox()
.withWorkdir("./flox-demo")
.withExec(["flox", "--version"])
.withExec(["which", "jq"])
.stdout();

console.log(flox);

const pkgx = await dag
.pipeline("pkgx-demo")
.pkgx()
.withWorkdir("./pkgx-demo")
.withExec(["pkgx", "--version"])
.withExec(["which", "deno"])
.stdout();

console.log(pkgx);

const git = await dag
.git("https://github.com/tsirysndr/me")
.branch("main")
.tree()
.withExec(["pwd"])
.stdout();
console.log(git);

const gitEntries = await dag
.git("https://github.com/tsirysndr/me")
.branch("main")
.tree()
.entries();

console.log(gitEntries);

const dir = await dag.directory(".").entries();

console.log(dir);
}

// Learn more at https://deno.land/manual/examples/module_metadata#concepts
if (import.meta.main) {
await main();
}
31 changes: 31 additions & 0 deletions codegen/demo/sdk/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createGQLClient } from "./client.ts";
import { Context } from "./context.ts";
import { env } from "../deps.ts";

/**
* @hidden
*
* Initialize a default client context from environment.
*/
export function initDefaultContext(): Context {
let ctx = new Context();

// Prefer FLUENTCI_SESSION_PORT if set
const daggerSessionPort = env.get("FLUENTCI_SESSION_PORT");
if (daggerSessionPort) {
const sessionToken = env.get("FLUENTCI_SESSION_TOKEN");
if (!sessionToken) {
throw new Error(
"FLUENTCI_SESSION_TOKEN must be set when using FLUENTCI_SESSION_PORT"
);
}

ctx = new Context({
client: createGQLClient(Number(daggerSessionPort), sessionToken),
});
} else {
throw new Error("FLUENTCI_SESSION_PORT must be set");
}

return ctx;
}
Loading

0 comments on commit d489338

Please sign in to comment.