mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-11 21:33:02 -05:00
docs(docs): writting docs
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [],
|
||||
selector: 'lib-root',
|
||||
template: ``,
|
||||
styles: [''],
|
||||
})
|
||||
export class AppComponent {}
|
||||
@@ -0,0 +1,41 @@
|
||||
---
|
||||
title: <%= difficulty %> <%= title %>
|
||||
description: Challenge <%= challengeNumber %> is about ...
|
||||
sidebar:
|
||||
order: <%= challengeNumber %>
|
||||
---
|
||||
|
||||
:::note
|
||||
WIP: The following documentation need to be written.
|
||||
:::
|
||||
|
||||
<div class="chip">Challenge #<%= challengeNumber %></div>
|
||||
|
||||
## Information
|
||||
|
||||
## Statement
|
||||
|
||||
## Constraints
|
||||
|
||||
---
|
||||
|
||||
:::note
|
||||
Start the project by running: `npx nx serve <%= projectName %>`.
|
||||
:::
|
||||
|
||||
:::tip[Reminder]
|
||||
Your PR title must start with <b>Answer:<%= challengeNumber %></b>.
|
||||
:::
|
||||
|
||||
<div class="article-footer">
|
||||
<a
|
||||
href="https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A<%= challengeNumber %>+label%3Aanswer"
|
||||
alt="<%= title %> community solutions">
|
||||
❖ Community Answers
|
||||
</a>
|
||||
<a
|
||||
href='https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A<%= challengeNumber %>+label%3A"answer+author"'
|
||||
alt="<%= title %> solution author">
|
||||
▶︎ Author Answer
|
||||
</a>
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
# <%= title %>
|
||||
|
||||
> Author: Thomas Laforge
|
||||
|
||||
### Run Application
|
||||
|
||||
```bash
|
||||
npx nx serve <%= projectName %>
|
||||
```
|
||||
|
||||
### Documentation and Instruction
|
||||
|
||||
Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/<%= docRepository %>/<%= challengeNumber %>-<%= projectName %>/).
|
||||
@@ -0,0 +1,8 @@
|
||||
import { render } from '@testing-library/angular';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
describe('AppComponent', () => {
|
||||
test('...', async () => {
|
||||
await render(AppComponent);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,2 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node", "@testing-library/jest-dom"]
|
||||
},
|
||||
"files": ["src/test-setup.ts"],
|
||||
"include": [
|
||||
"jest.config.ts",
|
||||
"src/**/*.test.ts",
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
100
libs/cli/src/generators/challenge/generator.ts
Normal file
100
libs/cli/src/generators/challenge/generator.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import {
|
||||
applicationGenerator,
|
||||
E2eTestRunner,
|
||||
UnitTestRunner,
|
||||
} from '@nx/angular/generators';
|
||||
import {
|
||||
formatFiles,
|
||||
generateFiles,
|
||||
names,
|
||||
readJsonFile,
|
||||
Tree,
|
||||
updateJson,
|
||||
} from '@nx/devkit';
|
||||
import { Linter } from '@nx/linter';
|
||||
import { readFile, writeFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { getProjectDir } from '../../utils/normalize';
|
||||
import { Schema } from './schema';
|
||||
|
||||
export async function challengeGenerator(tree: Tree, options: Schema) {
|
||||
const { appDirectory } = getProjectDir(options.name, options.directory);
|
||||
|
||||
const challengeNumberPath = 'challenge-number.json';
|
||||
const challengeNumber = readJsonFile(challengeNumberPath).total;
|
||||
|
||||
await applicationGenerator(tree, {
|
||||
...options,
|
||||
style: 'scss',
|
||||
routing: false,
|
||||
inlineStyle: true,
|
||||
inlineTemplate: true,
|
||||
prefix: 'app',
|
||||
unitTestRunner: options.addTest ? UnitTestRunner.Jest : UnitTestRunner.None,
|
||||
e2eTestRunner: E2eTestRunner.None,
|
||||
linter: Linter.EsLint,
|
||||
addTailwind: true,
|
||||
standalone: true,
|
||||
skipTests: true,
|
||||
});
|
||||
|
||||
generateFiles(tree, join(__dirname, 'files', 'app'), appDirectory, {
|
||||
tmpl: '',
|
||||
});
|
||||
tree.delete(join(appDirectory, './src/app/nx-welcome.component.ts'));
|
||||
|
||||
generateFiles(tree, join(__dirname, 'files', 'readme'), appDirectory, {
|
||||
tmpl: '',
|
||||
projectName: names(options.name).name,
|
||||
title: options.title,
|
||||
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,
|
||||
difficulty: options.challengeDifficulty,
|
||||
}
|
||||
);
|
||||
|
||||
if (options.addTest) {
|
||||
generateFiles(tree, join(__dirname, 'files', 'test'), appDirectory, {
|
||||
tmpl: '',
|
||||
});
|
||||
}
|
||||
|
||||
const readme = await readFile('./README.md', { encoding: 'utf-8' });
|
||||
|
||||
const readmeRegex = new RegExp(`all ${challengeNumber} challenges`);
|
||||
const readmeReplace = readme.replace(
|
||||
readmeRegex,
|
||||
`all ${challengeNumber + 1} challenges`
|
||||
);
|
||||
|
||||
await writeFile('./README.md', readmeReplace, 'utf-8');
|
||||
|
||||
const docs = await readFile('./docs/src/content/docs/index.mdx', {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
|
||||
const regex = new RegExp(`${challengeNumber} Challenges`, 'gi');
|
||||
const replaced = docs.replace(regex, `${challengeNumber + 1} Challenges`);
|
||||
|
||||
await writeFile('./docs/src/content/docs/index.mdx', replaced, 'utf-8');
|
||||
|
||||
updateJson(tree, challengeNumberPath, (json) => {
|
||||
json.total = json.total + 1;
|
||||
return json;
|
||||
});
|
||||
|
||||
await formatFiles(tree);
|
||||
}
|
||||
|
||||
export default challengeGenerator;
|
||||
10
libs/cli/src/generators/challenge/schema.d.ts
vendored
Normal file
10
libs/cli/src/generators/challenge/schema.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface Schema {
|
||||
title: string;
|
||||
challengeDifficulty: string;
|
||||
docRepository: string;
|
||||
name: string;
|
||||
directory?: string;
|
||||
addTest?: boolean;
|
||||
skipPackageJson?: boolean;
|
||||
rootProject?: boolean;
|
||||
}
|
||||
118
libs/cli/src/generators/challenge/schema.json
Normal file
118
libs/cli/src/generators/challenge/schema.json
Normal file
@@ -0,0 +1,118 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/schema",
|
||||
"$id": "GeneratorNxChallenge",
|
||||
"title": "Creates the setup for a new Angular Challenge.",
|
||||
"description": "Creates the boilerplate for an Angular Challenge.",
|
||||
"type": "object",
|
||||
"cli": "nx",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "The name of the application. (should be in kebab case)",
|
||||
"type": "string",
|
||||
"$default": {
|
||||
"$source": "argv",
|
||||
"index": 0
|
||||
},
|
||||
"x-prompt": "What name would you like to use for the application?",
|
||||
"pattern": "^[a-zA-Z].*$"
|
||||
},
|
||||
"title": {
|
||||
"description": "Title of your challenge. (use quote to add spaces)",
|
||||
"type": "string",
|
||||
"maxLength": "25",
|
||||
"$default": {
|
||||
"$source": "argv",
|
||||
"index": 1
|
||||
},
|
||||
"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",
|
||||
"x-priority": "important"
|
||||
},
|
||||
"addTest": {
|
||||
"description": "add spec files.",
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"alias": "S"
|
||||
},
|
||||
"skipPackageJson": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Do not add dependencies to `package.json`.",
|
||||
"x-priority": "internal"
|
||||
},
|
||||
"rootProject": {
|
||||
"description": "Create an application at the root of the workspace.",
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"hidden": true,
|
||||
"x-priority": "internal"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["name", "title", "challengeDifficulty", "docRepository"]
|
||||
}
|
||||
Reference in New Issue
Block a user