@@ -13,6 +13,7 @@ import {
1313import { Linter } from '@nx/eslint' ;
1414import { join } from 'path' ;
1515import { getProjectDir } from '../../utils/normalize' ;
16+ import { langMapper } from './files/lang-mapper' ;
1617import { Schema } from './schema' ;
1718
1819function 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 ,
0 commit comments