Skip to content

Commit

Permalink
enhance dev menu options
Browse files Browse the repository at this point in the history
  • Loading branch information
TimurRin committed Jun 25, 2024
1 parent eae844c commit f613f67
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 87 deletions.
10 changes: 5 additions & 5 deletions anca.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"project-type": "app",
"changelog": "keepachangelog.com",
"cinnabar-meta": true,
"ignore": {

},
"git-ignore": "cinnabar",
"license": true,
"nodejs": "cinnabar",
"nodejs-eslint": "cinnabar",
"nodejs-prettier": "cinnabar",
"readme": "cinnabar"
"readme": "cinnabar",
"type": "app"
}
158 changes: 76 additions & 82 deletions src/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ function getDevelopmentDisplayName(development: AncaDevelopmentState): string {
async function getDevelopmentStatus(development: AncaDevelopmentState) {
const exists = await checkExistence(development.fullPath);
if (!exists) {
return [pc.bgRed("not presented locally")];
return [pc.bgRed("remote")];
}

const hasAncaJson =
(await checkExistence(development.fullPath)) &&
(await checkExistence(path.join(development.fullPath, "anca.json")));

const statuses = [];

const gitExists = await checkForGit(development.fullPath);
Expand All @@ -146,133 +150,128 @@ async function getDevelopmentStatus(development: AncaDevelopmentState) {
);

if (statusSummary.files.length > 0) {
statuses.push(pc.bgCyan("edited"));
statuses.push(pc.bgMagenta("edited"));
}
} else {
statuses.push("non-git");
}

// if (development.convention != null) {
// const scriptDirectory = path.dirname(new URL(import.meta.url).pathname);
// const conventionPath = path.resolve(
// path.join(
// scriptDirectory,
// "..",
// "conventions",
// development.convention + ".js",
// ),
// );
// if (fs.existsSync(conventionPath)) {
// const { checkConventionAdherence } = await import(conventionPath);
// if (
// !(await checkConventionAdherence(
// development,
// path.dirname(conventionPath),
// ))
// ) {
// statuses.push("convention-broke");
// }
// }
// }
if (!hasAncaJson) {
statuses.push(pc.bgCyan("non-anca"));
}

return statuses;
}

/**
*
*
* @param development
*/
async function getDevelopmentActions(
development: AncaDevelopmentState,
previousMenu: () => Promise<void>,
) {
const exists = await checkExistence(development.fullPath);
if (!exists) {
return [
{
action: async () => {
await syncDevelopment(development, false, false, true);
await showDevelopmentAction(development, previousMenu);
},
label: "Clone",
},
];
}

const hasAncaJson =
(await checkExistence(development.fullPath)) &&
(await checkExistence(path.join(development.fullPath, "anca.json")));

const actions = [];

if (!hasAncaJson) {
actions.push({
action: placeholderOptions,
label: "Create anca.json",
});
}

return actions;
}

/**
*
*/
async function placeholderOptions() {
const options = [
{ label: "Shrek", name: "shrek" },
{ label: "Fiona", name: "fiona" },
{ label: "Donkey", name: "donkey" },
];
const choice = await promptOptions("Play as:", options);
const choice = await promptOptions("[SHREK CHARACTERS]", options);
console.log(`You chose: ${choice.label}`);
showMainMenu();
}

/**
*
* @param development
*/
async function showAllProjects() {
const options = [{ action: showDevelopmentsMenu, label: "Back" }];

const state = getState();

for (const development of state.developments) {
options.push({
action: placeholderOptions,
label: `${getDevelopmentDisplayName(development)} (${(await getDevelopmentStatus(development)).join(", ")})`,
});
}

await promptMenu("Select a project:", options);
async function showDevelopmentAction(
development: AncaDevelopmentState,
previousMenu: () => Promise<void>,
) {
const actions = [{ action: previousMenu, label: "Back" }];

actions.push(...(await getDevelopmentActions(development, previousMenu)));

await promptMenu(
`\n[${development.data.name.toUpperCase()} at ${development.data.folder.toUpperCase()}]`,
actions,
);
}

/**
*
*/
async function showNotHavingAncaJson() {
async function showAllDevelopments() {
const options = [{ action: showDevelopmentsMenu, label: "Back" }];

const state = getState();

for (const development of state.developments) {
if (
(await checkExistence(development.fullPath)) &&
!(await checkExistence(path.join(development.fullPath, "anca.json")))
) {
options.push({
action: placeholderOptions,
label: getDevelopmentDisplayName(development),
});
}
options.push({
action: async () => {
showDevelopmentAction(development, showAllDevelopments);
},
label: `${getDevelopmentDisplayName(development)} (${(await getDevelopmentStatus(development)).join(", ")})`,
});
}

await promptMenu("Select to create anca.json:", options);
await promptMenu("[ALL DEVELOPMENTS]", options);
}

/**
*
*/
async function showPresentedLocally() {
async function showLocalDevelopments() {
const options = [{ action: showDevelopmentsMenu, label: "Back" }];

const state = getState();

for (const development of state.developments) {
if (await checkExistence(development.fullPath)) {
options.push({
action: placeholderOptions,
label: `${getDevelopmentDisplayName(development)} (${(await getDevelopmentStatus(development)).join(", ")})`,
});
}
}

await promptMenu("Select:", options);
}

/**
*
*/
async function showNotPresentedLocally() {
const options = [{ action: showDevelopmentsMenu, label: "Back" }];

const state = getState();

for (const development of state.developments) {
if (!(await checkExistence(development.fullPath))) {
options.push({
action: async () => {
await syncDevelopment(development, false, false, true);
showDevelopmentAction(development, showLocalDevelopments);
},
label: getDevelopmentDisplayName(development),
label: `${getDevelopmentDisplayName(development)} (${(await getDevelopmentStatus(development)).join(", ")})`,
});
}
}

await promptMenu("Select to clone:", options);
await promptMenu("[LOCAL DEVELOPMENTS]", options);
}

/**
Expand All @@ -282,10 +281,8 @@ async function showDevelopmentsMenu() {
await promptMenu("\n[DEVELOPMENTS]", [
{ action: showMainMenu, label: "Back" },
{ action: placeholderOptions, label: "List of issues" },
{ action: showNotHavingAncaJson, label: "List of not having anca.json" },
{ action: showPresentedLocally, label: "List of presented locally" },
{ action: showNotPresentedLocally, label: "List of not presented locally" },
{ action: showAllProjects, label: "List of all projects" },
{ action: showLocalDevelopments, label: "List of local developments" },
{ action: showAllDevelopments, label: "List of all developments" },
]);
}

Expand All @@ -301,10 +298,7 @@ export async function showMainMenu() {
label: "Quit",
},
{
action: async () => {
console.log("Deployments selected");
showMainMenu();
},
action: placeholderOptions,
label: "Deployments",
},
{ action: showDevelopmentsMenu, label: "Developments" },
Expand Down

0 comments on commit f613f67

Please sign in to comment.