From 7dd215469001c8e379a83cae7817a728ede15b33 Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 28 Jan 2024 14:31:58 +0100 Subject: [PATCH] fix: generator --- docs/src/content/docs/fr/index.mdx | 2 +- docs/src/content/docs/index.mdx | 2 +- .../generators/challenge/files/lang-mapper.ts | 7 +++ .../cli/src/generators/challenge/generator.ts | 58 ++++++++++++------- libs/cli/src/generators/challenge/schema.json | 7 ++- 5 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 libs/cli/src/generators/challenge/files/lang-mapper.ts diff --git a/docs/src/content/docs/fr/index.mdx b/docs/src/content/docs/fr/index.mdx index 92996fcf4..147d89d38 100644 --- a/docs/src/content/docs/fr/index.mdx +++ b/docs/src/content/docs/fr/index.mdx @@ -15,7 +15,7 @@ hero: icon: right-arrow variant: primary - text: Aller au dernier Challenge - link: /challenges/angular/43-signal-input/ + link: /fr/challenges/angular/43-signal-input/ icon: rocket - text: Donne une étoile link: https://github.com/tomalaforge/angular-challenges diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx index 4cf03a98d..e639a2142 100644 --- a/docs/src/content/docs/index.mdx +++ b/docs/src/content/docs/index.mdx @@ -26,7 +26,7 @@ import MyIcon from '../../components/MyIcon.astro'; - This repository gathers 43 Challenges related to Angular, Nx, RxJS, Ngrx and Typescript. + This repository gathers 43 challenges related to Angular, Nx, RxJS, Ngrx and Typescript. These challenges resolve around real-life issues or specific features to elevate your skills. diff --git a/libs/cli/src/generators/challenge/files/lang-mapper.ts b/libs/cli/src/generators/challenge/files/lang-mapper.ts new file mode 100644 index 000000000..60efe9bf0 --- /dev/null +++ b/libs/cli/src/generators/challenge/files/lang-mapper.ts @@ -0,0 +1,7 @@ +export const langMapper = { + en: 'Challenges', + fr: 'Défis', + es: 'Desafíos', + pt: 'Desafios', + ru: 'Испытания', +}; diff --git a/libs/cli/src/generators/challenge/generator.ts b/libs/cli/src/generators/challenge/generator.ts index c97a70f39..991e89e1c 100644 --- a/libs/cli/src/generators/challenge/generator.ts +++ b/libs/cli/src/generators/challenge/generator.ts @@ -13,6 +13,7 @@ import { import { Linter } from '@nx/eslint'; import { join } from 'path'; import { getProjectDir } from '../../utils/normalize'; +import { langMapper } from './files/lang-mapper'; import { Schema } from './schema'; function findPreviousChallengeFilePath(tree, path, number) { @@ -25,8 +26,7 @@ function findPreviousChallengeFilePath(tree, path, number) { .find((child) => child.startsWith(`${number}-`)); if (matchingChild) { - const fullPath = path + '/' + matchingChild; - return fullPath; + return path + '/' + matchingChild; } for (const child of tree.children(path)) { @@ -49,7 +49,8 @@ export async function challengeGenerator(tree: Tree, options: Schema) { await applicationGenerator(tree, { ...options, - directory: `apps/${options.category}`, + name: `${options.category}-${options.name}`, + directory: `apps/${options.category}/${options.name}`, style: 'scss', routing: false, inlineStyle: true, @@ -61,14 +62,15 @@ export async function challengeGenerator(tree: Tree, options: Schema) { addTailwind: true, standalone: true, skipTests: true, + projectNameAndRootFormat: 'as-provided', }); const challengeNumberPath = 'challenge-number.json'; - const challangeNumberJson = JSON.parse( + const challengeNumberJson = JSON.parse( tree.read(challengeNumberPath).toString(), ); - const challengeNumber = challangeNumberJson.total + 1; - const order = challangeNumberJson[difficulty] + 1; + const challengeNumber = challengeNumberJson.total + 1; + const order = challengeNumberJson[difficulty] + 1; generateFiles(tree, join(__dirname, 'files', 'app'), appDirectory, { tmpl: '', @@ -116,20 +118,36 @@ export async function challengeGenerator(tree: Tree, options: Schema) { tree.write('./README.md', readmeReplace); - const docs = tree.read('./docs/src/content/docs/index.mdx').toString(); - - const regex = new RegExp(`${challengeNumber - 1} Challenges`, 'gi'); - const replaced = docs.replace(regex, `${challengeNumber} Challenges`); - - const linkRegex = new RegExp(`link: \\/challenges\\/(.*?)\n`, 'gi'); - const replacedLink = replaced.replace( - linkRegex, - `link: /challenges/${options.category}/${challengeNumber}-${ - names(options.name).name - }/\n`, - ); - - tree.write('./docs/src/content/docs/index.mdx', replacedLink); + for (const lang of ['en', 'es', 'fr', 'pt', 'ru']) { + const docs = tree + .read(`./docs/src/content/docs/${lang === 'en' ? '' : lang}/index.mdx`) + .toString(); + + const regex = new RegExp( + `${challengeNumber - 1} ${langMapper[lang]}`, + 'gi', + ); + const replaced = docs.replace( + regex, + `${challengeNumber} ${langMapper[lang]}`, + ); + + const linkRegex = new RegExp( + `link: \\/${lang}\\/challenges\\/(.*?)\n`, + 'gi', + ); + const replacedLink = replaced.replace( + linkRegex, + `link: /${lang}/challenges/${options.category}/${challengeNumber}-${ + names(options.name).name + }/\n`, + ); + + tree.write( + `./docs/src/content/docs/${lang === 'en' ? '' : lang}/index.mdx`, + replacedLink, + ); + } const previousChallengeFilePath = findPreviousChallengeFilePath( tree, diff --git a/libs/cli/src/generators/challenge/schema.json b/libs/cli/src/generators/challenge/schema.json index 58b15010f..4f5140211 100644 --- a/libs/cli/src/generators/challenge/schema.json +++ b/libs/cli/src/generators/challenge/schema.json @@ -24,13 +24,16 @@ "$source": "argv", "index": 1 }, - "x-priority": "important" + "x-priority": "important", + "x-prompt": "What should be the title of your challenge?", + "pattern": "^[a-zA-Z].*$" }, "author": { "description": "Your full name", "type": "string", "maxLength": "25", - "x-priority": "important" + "x-priority": "important", + "x-prompt": "Author?" }, "challengeDifficulty": { "description": "The difficulty of the challenge.",