Skip to content

Commit 7dd2154

Browse files
committed
fix: generator
1 parent 18bb6e5 commit 7dd2154

File tree

5 files changed

+52
-24
lines changed

5 files changed

+52
-24
lines changed

docs/src/content/docs/fr/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ hero:
1515
icon: right-arrow
1616
variant: primary
1717
- text: Aller au dernier Challenge
18-
link: /challenges/angular/43-signal-input/
18+
link: /fr/challenges/angular/43-signal-input/
1919
icon: rocket
2020
- text: Donne une étoile
2121
link: https://github.com/tomalaforge/angular-challenges

docs/src/content/docs/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import MyIcon from '../../components/MyIcon.astro';
2626

2727
<CardGrid>
2828
<Card title="43 Challenges">
29-
This repository gathers 43 Challenges related to <b>Angular</b>, <b>Nx</b>, <b>RxJS</b>, <b>Ngrx</b> and <b>Typescript</b>.
29+
This repository gathers 43 challenges related to <b>Angular</b>, <b>Nx</b>, <b>RxJS</b>, <b>Ngrx</b> and <b>Typescript</b>.
3030
These challenges resolve around real-life issues or specific features to elevate your skills.
3131
</Card>
3232

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const langMapper = {
2+
en: 'Challenges',
3+
fr: 'Défis',
4+
es: 'Desafíos',
5+
pt: 'Desafios',
6+
ru: 'Испытания',
7+
};

libs/cli/src/generators/challenge/generator.ts

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { Linter } from '@nx/eslint';
1414
import { join } from 'path';
1515
import { getProjectDir } from '../../utils/normalize';
16+
import { langMapper } from './files/lang-mapper';
1617
import { Schema } from './schema';
1718

1819
function findPreviousChallengeFilePath(tree, path, number) {
@@ -25,8 +26,7 @@ function findPreviousChallengeFilePath(tree, path, number) {
2526
.find((child) => child.startsWith(`${number}-`));
2627

2728
if (matchingChild) {
28-
const fullPath = path + '/' + matchingChild;
29-
return fullPath;
29+
return path + '/' + matchingChild;
3030
}
3131

3232
for (const child of tree.children(path)) {
@@ -49,7 +49,8 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
4949

5050
await applicationGenerator(tree, {
5151
...options,
52-
directory: `apps/${options.category}`,
52+
name: `${options.category}-${options.name}`,
53+
directory: `apps/${options.category}/${options.name}`,
5354
style: 'scss',
5455
routing: false,
5556
inlineStyle: true,
@@ -61,14 +62,15 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
6162
addTailwind: true,
6263
standalone: true,
6364
skipTests: true,
65+
projectNameAndRootFormat: 'as-provided',
6466
});
6567

6668
const challengeNumberPath = 'challenge-number.json';
67-
const challangeNumberJson = JSON.parse(
69+
const challengeNumberJson = JSON.parse(
6870
tree.read(challengeNumberPath).toString(),
6971
);
70-
const challengeNumber = challangeNumberJson.total + 1;
71-
const order = challangeNumberJson[difficulty] + 1;
72+
const challengeNumber = challengeNumberJson.total + 1;
73+
const order = challengeNumberJson[difficulty] + 1;
7274

7375
generateFiles(tree, join(__dirname, 'files', 'app'), appDirectory, {
7476
tmpl: '',
@@ -116,20 +118,36 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
116118

117119
tree.write('./README.md', readmeReplace);
118120

119-
const docs = tree.read('./docs/src/content/docs/index.mdx').toString();
120-
121-
const regex = new RegExp(`${challengeNumber - 1} Challenges`, 'gi');
122-
const replaced = docs.replace(regex, `${challengeNumber} Challenges`);
123-
124-
const linkRegex = new RegExp(`link: \\/challenges\\/(.*?)\n`, 'gi');
125-
const replacedLink = replaced.replace(
126-
linkRegex,
127-
`link: /challenges/${options.category}/${challengeNumber}-${
128-
names(options.name).name
129-
}/\n`,
130-
);
131-
132-
tree.write('./docs/src/content/docs/index.mdx', replacedLink);
121+
for (const lang of ['en', 'es', 'fr', 'pt', 'ru']) {
122+
const docs = tree
123+
.read(`./docs/src/content/docs/${lang === 'en' ? '' : lang}/index.mdx`)
124+
.toString();
125+
126+
const regex = new RegExp(
127+
`${challengeNumber - 1} ${langMapper[lang]}`,
128+
'gi',
129+
);
130+
const replaced = docs.replace(
131+
regex,
132+
`${challengeNumber} ${langMapper[lang]}`,
133+
);
134+
135+
const linkRegex = new RegExp(
136+
`link: \\/${lang}\\/challenges\\/(.*?)\n`,
137+
'gi',
138+
);
139+
const replacedLink = replaced.replace(
140+
linkRegex,
141+
`link: /${lang}/challenges/${options.category}/${challengeNumber}-${
142+
names(options.name).name
143+
}/\n`,
144+
);
145+
146+
tree.write(
147+
`./docs/src/content/docs/${lang === 'en' ? '' : lang}/index.mdx`,
148+
replacedLink,
149+
);
150+
}
133151

134152
const previousChallengeFilePath = findPreviousChallengeFilePath(
135153
tree,

libs/cli/src/generators/challenge/schema.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
"$source": "argv",
2525
"index": 1
2626
},
27-
"x-priority": "important"
27+
"x-priority": "important",
28+
"x-prompt": "What should be the title of your challenge?",
29+
"pattern": "^[a-zA-Z].*$"
2830
},
2931
"author": {
3032
"description": "Your full name",
3133
"type": "string",
3234
"maxLength": "25",
33-
"x-priority": "important"
35+
"x-priority": "important",
36+
"x-prompt": "Author?"
3437
},
3538
"challengeDifficulty": {
3639
"description": "The difficulty of the challenge.",

0 commit comments

Comments
 (0)