Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Jul 8, 2024
1 parent 5426083 commit 7e526b2
Showing 1 changed file with 24 additions and 59 deletions.
83 changes: 24 additions & 59 deletions packages/cli/src/cmds/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ inquirer.registerPrompt("press-to-continue", PressToContinuePrompt);

export async function main() {
for (;;) {
const globalConfig = (await configExists())
? await importAsyncConfig()
: undefined;
const globalConfig = (await configExists()) ? await importAsyncConfig() : undefined;
clear();
await printIntro();
if (await mainMenu(globalConfig)) {
Expand All @@ -63,9 +61,7 @@ async function mainMenu(config?: MoonwallConfig) {
{
name: !configPresent
? "1) Initialise: Generate a new Moonwall Config File"
: chalk.dim(
"1) Initialise: ✅ CONFIG ALREADY GENERATED",
),
: chalk.dim("1) Initialise: ✅ CONFIG ALREADY GENERATED"),
value: "init",
},
{
Expand Down Expand Up @@ -120,9 +116,7 @@ async function mainMenu(config?: MoonwallConfig) {
return false;
case "run": {
if (!config) {
throw new Error(
"Config not defined, this is a defect please raise it.",
);
throw new Error("Config not defined, this is a defect please raise it.");
}

const chosenRunEnv = await chooseRunEnv(config);
Expand All @@ -134,9 +128,7 @@ async function mainMenu(config?: MoonwallConfig) {
}
case "test": {
if (!config) {
throw new Error(
"Config not defined, this is a defect please raise it.",
);
throw new Error("Config not defined, this is a defect please raise it.");
}

const chosenTestEnv = await chooseTestEnv(config);
Expand All @@ -148,7 +140,7 @@ async function mainMenu(config?: MoonwallConfig) {
type: "press-to-continue",
anyKey: true,
pressToContinueMessage: `ℹ️ Test run for ${chalk.bgWhiteBright.black(
chosenTestEnv.envName,
chosenTestEnv.envName
)} has been completed. Press any key to continue...\n`,
});
}
Expand All @@ -163,9 +155,7 @@ async function mainMenu(config?: MoonwallConfig) {

case "exec": {
if (!config) {
throw new Error(
"Config not defined, this is a defect please raise it.",
);
throw new Error("Config not defined, this is a defect please raise it.");
}
return await resolveExecChoice(config);
}
Expand All @@ -185,7 +175,7 @@ async function mainMenu(config?: MoonwallConfig) {
type: "press-to-continue",
anyKey: true,
pressToContinueMessage: `ℹ️ Renaming task for ${chalk.bold(
`/${rootDir}`,
`/${rootDir}`
)} has been completed. Press any key to continue...\n`,
});

Expand All @@ -206,7 +196,7 @@ async function resolveExecChoice(config: MoonwallConfig) {
type: "press-to-continue",
anyKey: true,
pressToContinueMessage: `ℹ️ No scriptDir property defined at ${chalk.bgWhiteBright.black(
"moonwall.config.json",
"moonwall.config.json"
)}\n Press any key to continue...\n`,
});
return false;
Expand All @@ -218,7 +208,7 @@ async function resolveExecChoice(config: MoonwallConfig) {
type: "press-to-continue",
anyKey: true,
pressToContinueMessage: `ℹ️ No scriptDir found at at ${chalk.bgWhiteBright.black(
path.join(process.cwd(), scriptDir),
path.join(process.cwd(), scriptDir)
)}\n Press any key to continue...\n`,
});
return false;
Expand All @@ -232,7 +222,7 @@ async function resolveExecChoice(config: MoonwallConfig) {
type: "press-to-continue",
anyKey: true,
pressToContinueMessage: `ℹ️ No scripts found at ${chalk.bgWhiteBright.black(
path.join(process.cwd(), config.scriptsDir || ""),
path.join(process.cwd(), config.scriptsDir || "")
)}\n Press any key to continue...\n`,
});
}
Expand All @@ -245,8 +235,7 @@ async function resolveExecChoice(config: MoonwallConfig) {
for (;;) {
const result = await inquirer.prompt({
name: "selections",
message:
"Select which scripts you'd like to run (press ↩️ with none selected to go 🔙)\n",
message: "Select which scripts you'd like to run (press ↩️ with none selected to go 🔙)\n",
type: "checkbox",
choices,
});
Expand All @@ -269,7 +258,7 @@ async function resolveExecChoice(config: MoonwallConfig) {
const result = await inquirer.prompt({
name: "args",
message: `Enter any arguments for ${chalk.bgWhiteBright.black(
script,
script
)} (press enter for none)`,
type: "input",
});
Expand All @@ -288,9 +277,7 @@ async function resolveExecChoice(config: MoonwallConfig) {
}

async function resolveDownloadChoice() {
const repos = (await configExists())
? await allReposAsync()
: standardRepos();
const repos = (await configExists()) ? await allReposAsync() : standardRepos();
const binList = repos.reduce((acc, curr) => {
acc.push(...curr.binaries.flatMap((bin) => bin.name));
acc.push(new inquirer.Separator());
Expand All @@ -312,20 +299,15 @@ async function resolveDownloadChoice() {

const versions = await getVersions(
firstChoice.artifact,
firstChoice.artifact.includes("runtime"),
firstChoice.artifact.includes("runtime")
);

const chooseversion = await inquirer.prompt({
name: "binVersion",
type: "list",
default: "latest",
message: "Download - which version?",
choices: [
...versions,
new inquirer.Separator(),
"Back",
new inquirer.Separator(),
],
choices: [...versions, new inquirer.Separator(), "Back", new inquirer.Separator()],
});

if (chooseversion.binVersion === "Back") {
Expand All @@ -342,9 +324,9 @@ async function resolveDownloadChoice() {
name: "continue",
type: "confirm",
message: `You are about to download ${chalk.bgWhite.blackBright(
firstChoice.artifact,
firstChoice.artifact
)} v-${chalk.bgWhite.blackBright(chooseversion.binVersion)} to: ${chalk.bgWhite.blackBright(
chooseLocation.path,
chooseLocation.path
)}.\n Would you like to continue? `,
default: true,
});
Expand Down Expand Up @@ -381,7 +363,7 @@ const chooseTestEnv = async (config: MoonwallConfig) => {
new inquirer.Separator(),
{ name: "Back", value: "back" },
new inquirer.Separator(),
] as any),
] as any)
);
const result = await inquirer.prompt({
name: "envName",
Expand All @@ -406,22 +388,16 @@ const chooseRunEnv = async (config: MoonwallConfig) => {
a.description ? `: \t\t${a.description}` : ""
}`;
} else {
result.name = chalk.dim(
`[${a.foundation.type}] ${a.name} NO NETWORK TO RUN`,
);
result.name = chalk.dim(`[${a.foundation.type}] ${a.name} NO NETWORK TO RUN`);
result.disabled = true;
}
return result;
});

const choices = [
...envs
.filter(({ disabled }) => disabled === false)
.sort((a, b) => (a.name > b.name ? 1 : -1)),
...envs.filter(({ disabled }) => disabled === false).sort((a, b) => (a.name > b.name ? 1 : -1)),
new inquirer.Separator(),
...envs
.filter(({ disabled }) => disabled === true)
.sort((a, b) => (a.name > b.name ? 1 : -1)),
...envs.filter(({ disabled }) => disabled === true).sort((a, b) => (a.name > b.name ? 1 : -1)),
new inquirer.Separator(),
{ name: "Back", value: "back" },
new inquirer.Separator(),
Expand Down Expand Up @@ -459,30 +435,19 @@ const printIntro = async () => {
});

if (releases.status !== 200 || releases.data.length === 0) {
throw new Error(
"No releases found for moonsong-labs.moonwall, try again later.",
);
throw new Error("No releases found for moonsong-labs.moonwall, try again later.");
}
const json = releases.data;

remoteVersion =
json
.find((a) => a.tag_name.includes("@moonwall/cli@"))
?.tag_name.split("@")[2] || "unknown";
json.find((a) => a.tag_name.includes("@moonwall/cli@"))?.tag_name.split("@")[2] || "unknown";
} catch (error) {
remoteVersion = "unknown";
console.error(`Fetch Error: ${error}`);
}

cfonts.say("Moonwall", {
gradient: [
"#FF66FF",
"#9966FF",
"#99CCFF",
"#99FFFF",
"#33FFFF",
"#3366FF",
],
gradient: ["#FF66FF", "#9966FF", "#99CCFF", "#99FFFF", "#33FFFF", "#3366FF"],
transitionGradient: true,
lineHeight: 4,
});
Expand Down

0 comments on commit 7e526b2

Please sign in to comment.