Skip to content

Commit

Permalink
always start dagger listen before fluentci repl
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jan 23, 2024
1 parent 8e09629 commit b4094d9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fluentci # Run the pipeline
fluentci --help

Usage: fluentci [pipeline] [jobs...]
Version: 0.11.1
Version: 0.11.2

Description:

Expand Down
3 changes: 1 addition & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ export async function main() {
})
.command("repl", "Start FluentCI REPL")
.arguments("[pipelines...:string]")
.option("--quiet", "Disable verbose output")
.option("--debug", "Enable debug mode")
.option("--debug", "Show more information for debugging")
.action(async function (options, ...pipelines: [string, ...Array<string>]) {
await repl(options, pipelines);
})
Expand Down
43 changes: 11 additions & 32 deletions src/cmd/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
import { BASE_URL } from "../consts.ts";
import { extractVersion, fluentciDirExists } from "../utils.ts";

async function repl(
{ quiet, debug }: { quiet?: boolean; debug?: boolean },
pipelines: string[]
) {
async function repl({ debug }: { debug?: boolean }, pipelines: string[]) {
const isFluentciProject = await fluentciDirExists();
const args = [];
if (isFluentciProject) {
Expand Down Expand Up @@ -52,41 +49,23 @@ async function repl(
}
}

let command = new Deno.Command("dagger", {
const port = Math.floor(Math.random() * (65535 - 1024 + 1)) + 1024;
const dagger = await startDagger(port, debug);
const command = new Deno.Command("deno", {
args: [
"--progress",
"plain",
"run",
"deno",
"repl",
"-A",
"--eval-file=https://cdn.jsdelivr.net/gh/fluentci-io/fluentci@0c8a9aa/src/prelude.ts",
...args,
],
env: {
DAGGER_SESSION_TOKEN: "repl",
DAGGER_SESSION_PORT: port.toString(),
},
stdout: "inherit",
stdin: "inherit",
stderr: "inherit",
});
let dagger: Deno.ChildProcess | undefined;

if (quiet) {
dagger = await startDagger(debug);
command = new Deno.Command("deno", {
args: [
"repl",
"-A",
"--eval-file=https://cdn.jsdelivr.net/gh/fluentci-io/fluentci@0c8a9aa/src/prelude.ts",
...args,
],
env: {
DAGGER_SESSION_TOKEN: "repl",
DAGGER_SESSION_PORT: "8080",
},
stdout: "inherit",
stdin: "inherit",
stderr: "inherit",
});
}

console.log(`
.
Expand All @@ -112,7 +91,7 @@ You can call any ${green("FluentCI Pipeline function")} or any ${green(
Deno.exit(0);
}

async function startDagger(debug?: boolean) {
async function startDagger(port: number, debug?: boolean) {
let ready = false;
const terminalSpinner = new TerminalSpinner({
text: `Starting Dagger API ...`,
Expand All @@ -121,7 +100,7 @@ async function startDagger(debug?: boolean) {
terminalSpinner.start();

const command = new Deno.Command("dagger", {
args: ["listen"],
args: ["listen", "--listen", `127.0.0.1:${port}`],
env: {
DAGGER_SESSION_TOKEN: "repl",
},
Expand All @@ -147,7 +126,7 @@ async function startDagger(debug?: boolean) {
try {
// sleep for 1 second
await new Promise((resolve) => setTimeout(resolve, 1000));
const conn = await Deno.connect({ port: 8080 });
const conn = await Deno.connect({ port });
conn.close();
break;
} catch (_) {
Expand Down
2 changes: 1 addition & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dir } from "../deps.ts";

export const VERSION = "0.11.1";
export const VERSION = "0.11.2";

export const BASE_URL = "https://api.fluentci.io/v1";

Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export async function getDaggerVersion(): Promise<string> {
export async function fluentciDirExists(): Promise<boolean> {
try {
const fluentciDir = await Deno.stat(".fluentci");
await Deno.stat(".fluentci/mod.ts");
return fluentciDir.isDirectory;
} catch (_) {
return false;
Expand Down

0 comments on commit b4094d9

Please sign in to comment.