Skip to content

Commit

Permalink
refactored run cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Nov 19, 2023
1 parent d5f3a76 commit 5fd78f8
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 878 deletions.
26 changes: 10 additions & 16 deletions packages/cli/src/cmds/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import yargs from "yargs";
import fs from "fs";
import { hideBin } from "yargs/helpers";
import { testEffect } from "./runTests";
import { runNetworkCmd } from "./runNetwork";
import { generateConfig } from "../internal/cmdFunctions/initialisation";
import { fetchArtifact } from "../internal/cmdFunctions/fetchArtifact";
import dotenv from "dotenv";
import { Effect, pipe } from "effect";
import { main } from "./main";
import { runNetworkCmdEffect } from "./runNetwork";
dotenv.config();

const defaultConfigFiles = ["./moonwall.config", "./moonwall.config.json"];
Expand Down Expand Up @@ -136,18 +136,14 @@ const cliStart = Effect.try(() => {

async ({ envName, GrepTest }) => {
process.env.MOON_RUN_SCRIPTS = "true";
const effect = Effect.gen(function* (_) {
yield* _(
testEffect(envName, { testNamePattern: GrepTest }).pipe(
Effect.catchTag("TestsFailedError", (error) => {
failedTests = error.fails;
return Effect.succeed(
console.log(`❌ ${error.fails} test file${error.fails !== 1 ? "s" : ""} failed`)
);
})
)
);
});
const effect = testEffect(envName, { testNamePattern: GrepTest }).pipe(
Effect.catchTag("TestsFailedError", (error) => {
failedTests = error.fails;
return Effect.succeed(
console.log(`❌ ${error.fails} test file${error.fails !== 1 ? "s" : ""} failed`)
);
})
);

await Effect.runPromise(effect);

Expand All @@ -174,9 +170,7 @@ const cliStart = Effect.try(() => {
}),
async (argv) => {
process.env.MOON_RUN_SCRIPTS = "true";
const effect = Effect.tryPromise(() => runNetworkCmd(argv as any));

await Effect.runPromiseExit(effect);
await Effect.runPromiseExit(runNetworkCmdEffect(argv as any));
}
)
.help("h")
Expand Down
15 changes: 8 additions & 7 deletions packages/cli/src/cmds/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import { MoonwallConfig } from "@moonwall/types";
import chalk from "chalk";
import clear from "clear";
import colors from "colors";
import { Effect } from "effect";
import fs from "fs";
import inquirer from "inquirer";
import PressToContinuePrompt from "inquirer-press-to-continue";
import fetch from "node-fetch";
import path from "path";
import { SemVer, lt } from "semver";
import pkg from "../../package.json" assert { type: "json" };
import { fetchArtifact, getVersions } from "../internal/cmdFunctions/fetchArtifact";
import { createFolders, generateConfig } from "../internal/cmdFunctions/initialisation";
import { executeScript } from "../internal/launcherCommon";
import { importAsyncConfig } from "../lib/configReader";
import { allReposAsync } from "../lib/repoDefinitions";
import { runNetworkCmd } from "./runNetwork";
import { testCmd } from "./runTests";
import fs from "fs";
import { executeScript } from "../internal/launcherCommon";
import path from "path";
import { runNetworkCmdEffect } from "./runNetwork";
import { testEffect } from "./runTests";

inquirer.registerPrompt("press-to-continue", PressToContinuePrompt);

Expand Down Expand Up @@ -103,15 +104,15 @@ async function mainMenu(config: MoonwallConfig) {
const chosenRunEnv = await chooseRunEnv(config);
process.env.MOON_RUN_SCRIPTS = "true";
if (chosenRunEnv.envName !== "back") {
await runNetworkCmd(chosenRunEnv);
await Effect.runPromise(runNetworkCmdEffect(chosenRunEnv.envName));
}
return false;
}
case "test": {
const chosenTestEnv = await chooseTestEnv(config);
if (chosenTestEnv.envName !== "back") {
process.env.MOON_RUN_SCRIPTS = "true";
await testCmd(chosenTestEnv.envName);
await Effect.runPromise(testEffect(chosenTestEnv.envName));
await inquirer.prompt({
name: "test complete",
type: "press-to-continue",
Expand Down
Loading

0 comments on commit 5fd78f8

Please sign in to comment.