feat(doc): create challenge generator now support order by difficulty

This commit is contained in:
tomer953
2023-10-02 21:39:34 +03:00
parent 3dc0cb3317
commit 20a9b843e5
3 changed files with 15 additions and 5 deletions

View File

@@ -1,3 +1,6 @@
{ {
"total": 35 "total": 35,
"🟢": 12,
"🟠": 116,
"🔴": 207
} }

View File

@@ -2,7 +2,7 @@
title: <%= difficulty %> <%= title %> title: <%= difficulty %> <%= title %>
description: Challenge <%= challengeNumber %> is about ... description: Challenge <%= challengeNumber %> is about ...
sidebar: sidebar:
order: <%= challengeNumber %> order: <%= order %>
--- ---
:::note :::note

View File

@@ -20,8 +20,13 @@ import { Schema } from './schema';
export async function challengeGenerator(tree: Tree, options: Schema) { export async function challengeGenerator(tree: Tree, options: Schema) {
const { appDirectory } = getProjectDir(options.name, options.directory); 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 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, { await applicationGenerator(tree, {
...options, ...options,
@@ -60,7 +65,8 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
projectName: names(options.name).name, projectName: names(options.name).name,
title: options.title, title: options.title,
challengeNumber, 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'); await writeFile('./docs/src/content/docs/index.mdx', replaced, 'utf-8');
updateJson(tree, challengeNumberPath, (json) => { updateJson(tree, challengeNumberPath, (json) => {
json.total = json.total + 1; json.total += 1;
json[difficulty] += 1;
return json; return json;
}); });