fix: generator

This commit is contained in:
thomas
2024-05-13 16:47:42 +02:00
parent 678dd77030
commit 12a25ec230

View File

@@ -6,7 +6,6 @@ import {
import { formatFiles, generateFiles, Tree, updateJson } from '@nx/devkit';
import { Linter } from '@nx/eslint';
import { join } from 'path';
import { getProjectDir } from '../../utils/normalize';
import { langMapper } from './files/lang-mapper';
import { Schema } from './schema';
@@ -40,21 +39,20 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
);
const challengeNumber =
options.challengeNumber ?? challengeNumberJson.total + 1;
const difficulty = options.challengeDifficulty;
const name = options.title.toLowerCase().split(' ').join('-');
const order = challengeNumberJson[difficulty] + 1;
const { appProjectName, appDirectory } = getProjectDir(
name,
`apps/${options.category}`,
);
const appProjectName = `${options.category}-${name}`;
const appDirectory = `apps/${options.category}/${challengeNumber}-${name}`;
await applicationGenerator(tree, {
...options,
name: `${options.category}-${name}`,
directory: `apps/${options.category}/${challengeNumber}-${name}`,
directory: appDirectory,
style: 'scss',
routing: false,
inlineStyle: true,
@@ -146,18 +144,20 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
);
}
const previousChallengeFilePath = findPreviousChallengeFilePath(
tree,
`./docs/src/content/docs/challenges`,
String(challengeNumber - 1),
);
if (!options.challengeNumber) {
const previousChallengeFilePath = findPreviousChallengeFilePath(
tree,
`./docs/src/content/docs/challenges`,
String(Number(challengeNumber) - 1),
);
const previousChallenge = tree.read(previousChallengeFilePath).toString();
const previousChallenge = tree.read(previousChallengeFilePath).toString();
tree.write(
previousChallengeFilePath,
previousChallenge.replace(`badge: New`, ``),
);
tree.write(
previousChallengeFilePath,
previousChallenge.replace(`badge: New`, ``),
);
}
updateJson(tree, challengeNumberPath, (json) => {
json.total += 1;