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