Skip to content

Commit 12a25ec

Browse files
committed
fix: generator
1 parent 678dd77 commit 12a25ec

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
import { formatFiles, generateFiles, Tree, updateJson } from '@nx/devkit';
77
import { Linter } from '@nx/eslint';
88
import { join } from 'path';
9-
import { getProjectDir } from '../../utils/normalize';
109
import { langMapper } from './files/lang-mapper';
1110
import { Schema } from './schema';
1211

@@ -40,21 +39,20 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
4039
);
4140
const challengeNumber =
4241
options.challengeNumber ?? challengeNumberJson.total + 1;
42+
4343
const difficulty = options.challengeDifficulty;
4444

4545
const name = options.title.toLowerCase().split(' ').join('-');
4646

4747
const order = challengeNumberJson[difficulty] + 1;
4848

49-
const { appProjectName, appDirectory } = getProjectDir(
50-
name,
51-
`apps/${options.category}`,
52-
);
49+
const appProjectName = `${options.category}-${name}`;
50+
const appDirectory = `apps/${options.category}/${challengeNumber}-${name}`;
5351

5452
await applicationGenerator(tree, {
5553
...options,
5654
name: `${options.category}-${name}`,
57-
directory: `apps/${options.category}/${challengeNumber}-${name}`,
55+
directory: appDirectory,
5856
style: 'scss',
5957
routing: false,
6058
inlineStyle: true,
@@ -146,18 +144,20 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
146144
);
147145
}
148146

149-
const previousChallengeFilePath = findPreviousChallengeFilePath(
150-
tree,
151-
`./docs/src/content/docs/challenges`,
152-
String(challengeNumber - 1),
153-
);
147+
if (!options.challengeNumber) {
148+
const previousChallengeFilePath = findPreviousChallengeFilePath(
149+
tree,
150+
`./docs/src/content/docs/challenges`,
151+
String(Number(challengeNumber) - 1),
152+
);
154153

155-
const previousChallenge = tree.read(previousChallengeFilePath).toString();
154+
const previousChallenge = tree.read(previousChallengeFilePath).toString();
156155

157-
tree.write(
158-
previousChallengeFilePath,
159-
previousChallenge.replace(`badge: New`, ``),
160-
);
156+
tree.write(
157+
previousChallengeFilePath,
158+
previousChallenge.replace(`badge: New`, ``),
159+
);
160+
}
161161

162162
updateJson(tree, challengeNumberPath, (json) => {
163163
json.total += 1;

0 commit comments

Comments
 (0)