From b945521dbf4481f37f9fe7e778f9f051173c9830 Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 18 Oct 2023 11:01:17 +0200 Subject: [PATCH] fix(generator): fix generator --- .../challenge/files/readme/README.md__tmpl__ | 2 +- libs/cli/src/generators/challenge/generator.ts | 10 +++++----- libs/cli/src/generators/challenge/schema.d.ts | 3 +-- libs/cli/src/generators/challenge/schema.json | 15 ++------------- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/libs/cli/src/generators/challenge/files/readme/README.md__tmpl__ b/libs/cli/src/generators/challenge/files/readme/README.md__tmpl__ index 1491c3d..14eba7a 100644 --- a/libs/cli/src/generators/challenge/files/readme/README.md__tmpl__ +++ b/libs/cli/src/generators/challenge/files/readme/README.md__tmpl__ @@ -10,4 +10,4 @@ npx nx serve <%= appProjectName %> ### Documentation and Instruction -Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/<%= docRepository %>/<%= challengeNumber %>-<%= projectName %>/). +Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/<%= category %>/<%= challengeNumber %>-<%= projectName %>/). diff --git a/libs/cli/src/generators/challenge/generator.ts b/libs/cli/src/generators/challenge/generator.ts index bd09979..9747969 100644 --- a/libs/cli/src/generators/challenge/generator.ts +++ b/libs/cli/src/generators/challenge/generator.ts @@ -43,12 +43,11 @@ function findPreviousChallengeFilePath(tree, path, number) { export async function challengeGenerator(tree: Tree, options: Schema) { const { appProjectName, appDirectory } = getProjectDir( options.name, - options.directory + `apps/${options.category}` ); const difficulty = options.challengeDifficulty; - // read json file with the total challanges and display order const challengeNumberPath = 'challenge-number.json'; const challangeNumberJson = readJsonFile(challengeNumberPath); const challengeNumber = challangeNumberJson.total + 1; @@ -56,6 +55,7 @@ export async function challengeGenerator(tree: Tree, options: Schema) { await applicationGenerator(tree, { ...options, + directory: `apps/${options.category}`, style: 'scss', routing: false, inlineStyle: true, @@ -80,13 +80,13 @@ export async function challengeGenerator(tree: Tree, options: Schema) { appProjectName, title: options.title, challengeNumber, - docRepository: options.docRepository, + category: options.category, }); generateFiles( tree, join(__dirname, 'files', 'docs'), - `./docs/src/content/docs/challenges/${options.docRepository}`, + `./docs/src/content/docs/challenges/${options.category}`, { tmpl: '', projectName: names(options.name).name, @@ -123,7 +123,7 @@ export async function challengeGenerator(tree: Tree, options: Schema) { const linkRegex = new RegExp(`link: \\/challenges\\/(.*?)\n`, 'gi'); const replacedLink = replaced.replace( linkRegex, - `link: /challenges/${options.docRepository}/${challengeNumber}-${ + `link: /challenges/${options.category}/${challengeNumber}-${ names(options.name).name }/\n` ); diff --git a/libs/cli/src/generators/challenge/schema.d.ts b/libs/cli/src/generators/challenge/schema.d.ts index 67b0636..6549276 100644 --- a/libs/cli/src/generators/challenge/schema.d.ts +++ b/libs/cli/src/generators/challenge/schema.d.ts @@ -2,9 +2,8 @@ export interface Schema { title: string; author: string; challengeDifficulty: string; - docRepository: string; + category: string; name: string; - directory?: string; addTest?: boolean; skipPackageJson?: boolean; rootProject?: boolean; diff --git a/libs/cli/src/generators/challenge/schema.json b/libs/cli/src/generators/challenge/schema.json index b1078e3..58b1501 100644 --- a/libs/cli/src/generators/challenge/schema.json +++ b/libs/cli/src/generators/challenge/schema.json @@ -55,7 +55,7 @@ ] } }, - "docRepository": { + "category": { "type": "string", "description": "The category of your challenge.", "x-priority": "important", @@ -94,11 +94,6 @@ ] } }, - "directory": { - "description": "The directory of the new application.", - "type": "string", - "x-priority": "important" - }, "addTest": { "description": "add spec files.", "type": "boolean", @@ -120,11 +115,5 @@ } }, "additionalProperties": false, - "required": [ - "name", - "title", - "author", - "challengeDifficulty", - "docRepository" - ] + "required": ["name", "title", "author", "challengeDifficulty", "category"] }