mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 04:43:03 -05:00
fix: generator
This commit is contained in:
7
libs/cli/src/generators/challenge/files/lang-mapper.ts
Normal file
7
libs/cli/src/generators/challenge/files/lang-mapper.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export const langMapper = {
|
||||
en: 'Challenges',
|
||||
fr: 'Défis',
|
||||
es: 'Desafíos',
|
||||
pt: 'Desafios',
|
||||
ru: 'Испытания',
|
||||
};
|
||||
@@ -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();
|
||||
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} Challenges`, 'gi');
|
||||
const replaced = docs.replace(regex, `${challengeNumber} Challenges`);
|
||||
const regex = new RegExp(
|
||||
`${challengeNumber - 1} ${langMapper[lang]}`,
|
||||
'gi',
|
||||
);
|
||||
const replaced = docs.replace(
|
||||
regex,
|
||||
`${challengeNumber} ${langMapper[lang]}`,
|
||||
);
|
||||
|
||||
const linkRegex = new RegExp(`link: \\/challenges\\/(.*?)\n`, 'gi');
|
||||
const replacedLink = replaced.replace(
|
||||
linkRegex,
|
||||
`link: /challenges/${options.category}/${challengeNumber}-${
|
||||
names(options.name).name
|
||||
}/\n`,
|
||||
);
|
||||
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/index.mdx', replacedLink);
|
||||
tree.write(
|
||||
`./docs/src/content/docs/${lang === 'en' ? '' : lang}/index.mdx`,
|
||||
replacedLink,
|
||||
);
|
||||
}
|
||||
|
||||
const previousChallengeFilePath = findPreviousChallengeFilePath(
|
||||
tree,
|
||||
|
||||
@@ -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.",
|
||||
|
||||
Reference in New Issue
Block a user