Skip to content

Commit

Permalink
Add filtering and ordering to list of demos
Browse files Browse the repository at this point in the history
  • Loading branch information
dolanmiu committed Jun 14, 2023
1 parent 6288bb0 commit 9aba21e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const dir = "./demo";
const fileNames = fs.readdirSync(dir);

const keys = fileNames.map((f) => path.parse(f).name);
const getFileNumber = (file: string): number => {
const nameParts = file.split("-");
const firstPart = nameParts[0];

return Number(firstPart);
};

const demoFiles = keys.filter((file) => !isNaN(getFileNumber(file))).sort((a, b) => getFileNumber(a) - getFileNumber(b));

const answers = await inquirer.prompt<Answers>([
{
Expand All @@ -26,7 +34,7 @@ const answers = await inquirer.prompt<Answers>([
type: "list",
name: "demoFile",
message: "What demo do you wish to run?",
choices: keys,
choices: demoFiles,
filter: (input) => parseInt(input.split("-")[0]),
when: (answers) => answers.type === "list",
},
Expand Down

0 comments on commit 9aba21e

Please sign in to comment.