|
6 | 6 | import { formatFiles, generateFiles, Tree, updateJson } from '@nx/devkit'; |
7 | 7 | import { Linter } from '@nx/eslint'; |
8 | 8 | import { join } from 'path'; |
9 | | -import { getProjectDir } from '../../utils/normalize'; |
10 | 9 | import { langMapper } from './files/lang-mapper'; |
11 | 10 | import { Schema } from './schema'; |
12 | 11 |
|
@@ -40,21 +39,20 @@ export async function challengeGenerator(tree: Tree, options: Schema) { |
40 | 39 | ); |
41 | 40 | const challengeNumber = |
42 | 41 | options.challengeNumber ?? challengeNumberJson.total + 1; |
| 42 | + |
43 | 43 | const difficulty = options.challengeDifficulty; |
44 | 44 |
|
45 | 45 | const name = options.title.toLowerCase().split(' ').join('-'); |
46 | 46 |
|
47 | 47 | const order = challengeNumberJson[difficulty] + 1; |
48 | 48 |
|
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}`; |
53 | 51 |
|
54 | 52 | await applicationGenerator(tree, { |
55 | 53 | ...options, |
56 | 54 | name: `${options.category}-${name}`, |
57 | | - directory: `apps/${options.category}/${challengeNumber}-${name}`, |
| 55 | + directory: appDirectory, |
58 | 56 | style: 'scss', |
59 | 57 | routing: false, |
60 | 58 | inlineStyle: true, |
@@ -146,18 +144,20 @@ export async function challengeGenerator(tree: Tree, options: Schema) { |
146 | 144 | ); |
147 | 145 | } |
148 | 146 |
|
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 | + ); |
154 | 153 |
|
155 | | - const previousChallenge = tree.read(previousChallengeFilePath).toString(); |
| 154 | + const previousChallenge = tree.read(previousChallengeFilePath).toString(); |
156 | 155 |
|
157 | | - tree.write( |
158 | | - previousChallengeFilePath, |
159 | | - previousChallenge.replace(`badge: New`, ``), |
160 | | - ); |
| 156 | + tree.write( |
| 157 | + previousChallengeFilePath, |
| 158 | + previousChallenge.replace(`badge: New`, ``), |
| 159 | + ); |
| 160 | + } |
161 | 161 |
|
162 | 162 | updateJson(tree, challengeNumberPath, (json) => { |
163 | 163 | json.total += 1; |
|
0 commit comments