From 20a9b843e55eabd58bc59c8cafb16aefa65bae70 Mon Sep 17 00:00:00 2001 From: tomer953 Date: Mon, 2 Oct 2023 21:39:34 +0300 Subject: [PATCH] feat(doc): create challenge generator now support order by difficulty --- challenge-number.json | 5 ++++- .../__challengeNumber__-__projectName__.md__tmpl__ | 2 +- libs/cli/src/generators/challenge/generator.ts | 13 ++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/challenge-number.json b/challenge-number.json index 4fc2198..85b441f 100644 --- a/challenge-number.json +++ b/challenge-number.json @@ -1,3 +1,6 @@ { - "total": 35 + "total": 35, + "🟢": 12, + "🟠": 116, + "🔴": 207 } diff --git a/libs/cli/src/generators/challenge/files/docs/__challengeNumber__-__projectName__.md__tmpl__ b/libs/cli/src/generators/challenge/files/docs/__challengeNumber__-__projectName__.md__tmpl__ index 1bd1882..2d422eb 100644 --- a/libs/cli/src/generators/challenge/files/docs/__challengeNumber__-__projectName__.md__tmpl__ +++ b/libs/cli/src/generators/challenge/files/docs/__challengeNumber__-__projectName__.md__tmpl__ @@ -2,7 +2,7 @@ title: <%= difficulty %> <%= title %> description: Challenge <%= challengeNumber %> is about ... sidebar: - order: <%= challengeNumber %> + order: <%= order %> --- :::note diff --git a/libs/cli/src/generators/challenge/generator.ts b/libs/cli/src/generators/challenge/generator.ts index f5c939f..ce3b5b3 100644 --- a/libs/cli/src/generators/challenge/generator.ts +++ b/libs/cli/src/generators/challenge/generator.ts @@ -20,8 +20,13 @@ import { Schema } from './schema'; export async function challengeGenerator(tree: Tree, options: Schema) { const { appDirectory } = getProjectDir(options.name, options.directory); + const difficulty = options.challengeDifficulty; + + // read json file with the total challanges and display order const challengeNumberPath = 'challenge-number.json'; - const challengeNumber = readJsonFile(challengeNumberPath).total; + const challangeNumberJson = readJsonFile(challengeNumberPath); + const challengeNumber = challangeNumberJson.total; + const order = challangeNumberJson[difficulty] + 1; await applicationGenerator(tree, { ...options, @@ -60,7 +65,8 @@ export async function challengeGenerator(tree: Tree, options: Schema) { projectName: names(options.name).name, title: options.title, challengeNumber, - difficulty: options.challengeDifficulty, + difficulty, + order, } ); @@ -90,7 +96,8 @@ export async function challengeGenerator(tree: Tree, options: Schema) { await writeFile('./docs/src/content/docs/index.mdx', replaced, 'utf-8'); updateJson(tree, challengeNumberPath, (json) => { - json.total = json.total + 1; + json.total += 1; + json[difficulty] += 1; return json; });