From 40d7a8d960a855c0c9ad466a723ec1b1646d148e Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 22 Sep 2023 21:33:47 +0200 Subject: [PATCH] feat(generator): modify generator to create application --- ...allengeNumber__-__projectName__.md__tmpl__ | 39 +++++++++++ .../app/files/readme/README.md__tmpl__ | 33 ++-------- libs/cli/src/generators/app/generator.ts | 14 ++++ libs/cli/src/generators/app/schema.d.ts | 2 + libs/cli/src/generators/app/schema.json | 66 ++++++++++++++++++- 5 files changed, 126 insertions(+), 28 deletions(-) create mode 100644 libs/cli/src/generators/app/files/docs/__challengeNumber__-__projectName__.md__tmpl__ diff --git a/libs/cli/src/generators/app/files/docs/__challengeNumber__-__projectName__.md__tmpl__ b/libs/cli/src/generators/app/files/docs/__challengeNumber__-__projectName__.md__tmpl__ new file mode 100644 index 0000000..9f6069f --- /dev/null +++ b/libs/cli/src/generators/app/files/docs/__challengeNumber__-__projectName__.md__tmpl__ @@ -0,0 +1,39 @@ +--- +title: <%= difficulty %> <%= title %> +description: Challenge <%= challengeNumber %> is about ... +--- + +:::note +WIP +::: + +
Challenge #<%= challengeNumber %>
+ +## Information + +## Statement + +## Constraints + +--- + +:::note +Start the project by running: `npx nx serve <%= projectName %>`. +::: + +:::tip[Reminder] +Your PR title must start with Answer:<%= challengeNumber %>. +::: + +
+ + ❖ Community Answers + + + ▶︎ Author Answer + +
diff --git a/libs/cli/src/generators/app/files/readme/README.md__tmpl__ b/libs/cli/src/generators/app/files/readme/README.md__tmpl__ index 54f66ad..4305e46 100644 --- a/libs/cli/src/generators/app/files/readme/README.md__tmpl__ +++ b/libs/cli/src/generators/app/files/readme/README.md__tmpl__ @@ -1,32 +1,13 @@ -

<%= title %>

+# <%= title %> > Author: Thomas Laforge - +### Run Application -### Information +```bash +npx nx serve <%= projectName %> +``` -### Statement +### Documentation and Instruction -### Step 1 - -### Step 2 - -### Constraints: - -### Submitting your work - -1. Fork the project -2. clone it -3. npm ci -4. `npx nx serve <%= projectName %>` -5. _...work on it_ -6. Commit your work -7. Submit a PR with a title beginning with **Answer:<%= challengeNumber %>** that I will review and other dev can review. - -<%= projectName %> -<%= projectName %> solution author - - - -_You can ask any question on_ twitter +Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/<%= docRepository %>/<%= challengeNumber %>-<%= projectName %>/). diff --git a/libs/cli/src/generators/app/generator.ts b/libs/cli/src/generators/app/generator.ts index fb60992..0355e5b 100644 --- a/libs/cli/src/generators/app/generator.ts +++ b/libs/cli/src/generators/app/generator.ts @@ -37,8 +37,22 @@ export async function appGenerator(tree: Tree, options: Schema) { projectName: names(options.name).name, title: options.title, challengeNumber: options.challengeNumber, + docRepository: options.docRepository, }); + generateFiles( + tree, + join(__dirname, 'files', 'docs'), + `./docs/src/content/docs/challenges/${options.docRepository}`, + { + tmpl: '', + projectName: names(options.name).name, + title: options.title, + challengeNumber: options.challengeNumber, + difficulty: options.challengeDifficulty, + } + ); + if (options.addTest) { generateFiles(tree, join(__dirname, 'files', 'test'), appDirectory, { tmpl: '', diff --git a/libs/cli/src/generators/app/schema.d.ts b/libs/cli/src/generators/app/schema.d.ts index 08d8403..12df137 100644 --- a/libs/cli/src/generators/app/schema.d.ts +++ b/libs/cli/src/generators/app/schema.d.ts @@ -1,6 +1,8 @@ export interface Schema { title: string; challengeNumber: number; + challengeDifficulty: string; + docRepository: string; name: string; directory?: string; addTest?: boolean; diff --git a/libs/cli/src/generators/app/schema.json b/libs/cli/src/generators/app/schema.json index dd589bd..9340ee4 100644 --- a/libs/cli/src/generators/app/schema.json +++ b/libs/cli/src/generators/app/schema.json @@ -7,7 +7,7 @@ "cli": "nx", "properties": { "name": { - "description": "The name of the application.", + "description": "The name of the application. (should be in camel case)", "type": "string", "$default": { "$source": "argv", @@ -17,7 +17,7 @@ "pattern": "^[a-zA-Z].*$" }, "title": { - "description": "Title of your challenge.", + "description": "Title of your challenge. (use quote to add spaces)", "type": "string", "$default": { "$source": "argv", @@ -34,6 +34,68 @@ }, "x-priority": "important" }, + "challengeDifficulty": { + "description": "The difficulty of the challenge.", + "type": "string", + "x-priority": "important", + "x-prompt": { + "message": "Which category would you like?", + "type": "list", + "items": [ + { + "value": "🟢", + "label": "Easy" + }, + { + "value": "🟠", + "label": "Medium" + }, + { + "value": "🔴", + "label": "Hard" + } + ] + } + }, + "docRepository": { + "type": "string", + "description": "The category of your challenge.", + "x-priority": "important", + "x-prompt": { + "message": "Which category would you like?", + "type": "list", + "items": [ + { + "value": "angular", + "label": "Angular" + }, + { + "value": "angular-performance", + "label": "Angular Performance" + }, + { + "value": "ngrx", + "label": "NgRx" + }, + { + "value": "rxjs", + "label": "RxJs" + }, + { + "value": "nx", + "label": "Nx" + }, + { + "value": "testing", + "label": "Testing" + }, + { + "value": "typescript", + "label": "Typescript" + } + ] + } + }, "directory": { "description": "The directory of the new application.", "type": "string",