fix: generator

This commit is contained in:
thomas
2024-05-11 21:41:13 +02:00
parent 001d35731a
commit 4eb6f64f16
46 changed files with 63 additions and 72 deletions

View File

@@ -5,7 +5,7 @@
### Run Application ### Run Application
```bash ```bash
npx nx serve nx-static-dynamic-import npx nx serve nx-static-vs-dynamic-import
``` ```
### Documentation and Instruction ### Documentation and Instruction

View File

@@ -1,27 +1,27 @@
{ {
"name": "nx-static-dynamic-import", "name": "nx-static-vs-dynamic-import",
"$schema": "../../../node_modules/nx/schemas/project-schema.json", "$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application", "projectType": "application",
"prefix": "app", "prefix": "app",
"sourceRoot": "apps/nx/static-dynamic-import/src", "sourceRoot": "apps/nx/42-static-vs-dynamic-import/src",
"tags": [], "tags": [],
"targets": { "targets": {
"build": { "build": {
"executor": "@angular-devkit/build-angular:application", "executor": "@angular-devkit/build-angular:application",
"outputs": ["{options.outputPath}"], "outputs": ["{options.outputPath}"],
"options": { "options": {
"outputPath": "dist/apps/nx/static-dynamic-import", "outputPath": "dist/apps/nx/42-static-vs-dynamic-import",
"index": "apps/nx/static-dynamic-import/src/index.html", "index": "apps/nx/42-static-vs-dynamic-import/src/index.html",
"browser": "apps/nx/static-dynamic-import/src/main.ts", "browser": "apps/nx/42-static-vs-dynamic-import/src/main.ts",
"polyfills": ["zone.js"], "polyfills": ["zone.js"],
"tsConfig": "apps/nx/static-dynamic-import/tsconfig.app.json", "tsConfig": "apps/nx/42-static-vs-dynamic-import/tsconfig.app.json",
"inlineStyleLanguage": "scss", "inlineStyleLanguage": "scss",
"assets": [ "assets": [
"apps/nx/static-dynamic-import/src/favicon.ico", "apps/nx/42-static-vs-dynamic-import/src/favicon.ico",
"apps/nx/static-dynamic-import/src/assets" "apps/nx/42-static-vs-dynamic-import/src/assets"
], ],
"styles": [ "styles": [
"apps/nx/static-dynamic-import/src/styles.scss", "apps/nx/42-static-vs-dynamic-import/src/styles.scss",
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css" "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
], ],
"scripts": [] "scripts": []
@@ -55,10 +55,10 @@
"executor": "@angular-devkit/build-angular:dev-server", "executor": "@angular-devkit/build-angular:dev-server",
"configurations": { "configurations": {
"production": { "production": {
"buildTarget": "nx-static-dynamic-import:build:production" "buildTarget": "nx-static-vs-dynamic-import:build:production"
}, },
"development": { "development": {
"buildTarget": "nx-static-dynamic-import:build:development" "buildTarget": "nx-static-vs-dynamic-import:build:development"
} }
}, },
"defaultConfiguration": "development" "defaultConfiguration": "development"
@@ -66,7 +66,7 @@
"extract-i18n": { "extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n", "executor": "@angular-devkit/build-angular:extract-i18n",
"options": { "options": {
"buildTarget": "nx-static-dynamic-import:build" "buildTarget": "nx-static-vs-dynamic-import:build"
} }
}, },
"lint": { "lint": {

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -5,9 +5,9 @@
### Run Application ### Run Application
```bash ```bash
npx nx serve typescript-overload` npx nx serve typescript-function-overload`
``` ```
### Documentation and Instruction ### Documentation and Instruction
Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/typescript/15-typescript-overload-fn/). Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/typescript/15-typescript-function-overload-fn/).

View File

@@ -1,25 +1,25 @@
{ {
"name": "typescript-overload", "name": "typescript-function-overload",
"$schema": "../../../node_modules/nx/schemas/project-schema.json", "$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application", "projectType": "application",
"sourceRoot": "apps/typescript/overload/src", "sourceRoot": "apps/typescript/15-function-overload/src",
"prefix": "app", "prefix": "app",
"targets": { "targets": {
"build": { "build": {
"executor": "@angular-devkit/build-angular:browser", "executor": "@angular-devkit/build-angular:browser",
"outputs": ["{options.outputPath}"], "outputs": ["{options.outputPath}"],
"options": { "options": {
"outputPath": "dist/apps/typescript/overload", "outputPath": "dist/apps/typescript/15-function-overload",
"index": "apps/typescript/overload/src/index.html", "index": "apps/typescript/15-function-overload/src/index.html",
"main": "apps/typescript/overload/src/main.ts", "main": "apps/typescript/15-function-overload/src/main.ts",
"polyfills": ["zone.js"], "polyfills": ["zone.js"],
"tsConfig": "apps/typescript/overload/tsconfig.app.json", "tsConfig": "apps/typescript/15-function-overload/tsconfig.app.json",
"inlineStyleLanguage": "scss", "inlineStyleLanguage": "scss",
"assets": [ "assets": [
"apps/typescript/overload/src/favicon.ico", "apps/typescript/15-function-overload/src/favicon.ico",
"apps/typescript/overload/src/assets" "apps/typescript/15-function-overload/src/assets"
], ],
"styles": ["apps/typescript/overload/src/styles.scss"], "styles": ["apps/typescript/15-function-overload/src/styles.scss"],
"scripts": [] "scripts": []
}, },
"configurations": { "configurations": {
@@ -53,10 +53,10 @@
"executor": "@angular-devkit/build-angular:dev-server", "executor": "@angular-devkit/build-angular:dev-server",
"configurations": { "configurations": {
"production": { "production": {
"buildTarget": "typescript-overload:build:production" "buildTarget": "typescript-function-overload:build:production"
}, },
"development": { "development": {
"buildTarget": "typescript-overload:build:development" "buildTarget": "typescript-function-overload:build:development"
} }
}, },
"defaultConfiguration": "development" "defaultConfiguration": "development"
@@ -64,7 +64,7 @@
"extract-i18n": { "extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n", "executor": "@angular-devkit/build-angular:extract-i18n",
"options": { "options": {
"buildTarget": "typescript-overload:build" "buildTarget": "typescript-function-overload:build"
} }
}, },
"lint": { "lint": {

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -3,24 +3,24 @@
"$schema": "../../../node_modules/nx/schemas/project-schema.json", "$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application", "projectType": "application",
"prefix": "app", "prefix": "app",
"sourceRoot": "apps/typescript/enums-vs-union-types/src", "sourceRoot": "apps/typescript/47-enums-vs-union-types/src",
"tags": [], "tags": [],
"targets": { "targets": {
"build": { "build": {
"executor": "@angular-devkit/build-angular:application", "executor": "@angular-devkit/build-angular:application",
"outputs": ["{options.outputPath}"], "outputs": ["{options.outputPath}"],
"options": { "options": {
"outputPath": "dist/apps/typescript/enums-vs-union-types", "outputPath": "dist/apps/typescript/47-enums-vs-union-types",
"index": "apps/typescript/enums-vs-union-types/src/index.html", "index": "apps/typescript/47-enums-vs-union-types/src/index.html",
"browser": "apps/typescript/enums-vs-union-types/src/main.ts", "browser": "apps/typescript/47-enums-vs-union-types/src/main.ts",
"polyfills": ["zone.js"], "polyfills": ["zone.js"],
"tsConfig": "apps/typescript/enums-vs-union-types/tsconfig.app.json", "tsConfig": "apps/typescript/47-enums-vs-union-types/tsconfig.app.json",
"inlineStyleLanguage": "scss", "inlineStyleLanguage": "scss",
"assets": [ "assets": [
"apps/typescript/enums-vs-union-types/src/favicon.ico", "apps/typescript/47-enums-vs-union-types/src/favicon.ico",
"apps/typescript/enums-vs-union-types/src/assets" "apps/typescript/47-enums-vs-union-types/src/assets"
], ],
"styles": ["apps/typescript/enums-vs-union-types/src/styles.scss"], "styles": ["apps/typescript/47-enums-vs-union-types/src/styles.scss"],
"scripts": [] "scripts": []
}, },
"configurations": { "configurations": {

View File

@@ -41,16 +41,16 @@ enum Direction {
`, `,
styles: ` styles: `
section { section {
@apply flex flex-col mx-auto my-5 w-fit gap-2 items-center; @apply mx-auto my-5 flex w-fit flex-col items-center gap-2;
> div { > div {
@apply flex w-fit gap-5; @apply flex w-fit gap-5;
} }
} }
button { button {
@apply rounded-md border px-4 py-2; @apply rounded-md border px-4 py-2;
} }
`, `,
}) })
export class AppComponent { export class AppComponent {

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -8,23 +8,23 @@
"noImplicitOverride": true, "noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true, "noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true, "noImplicitReturns": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true
}, },
"files": [], "files": [],
"include": [], "include": [],
"references": [ "references": [
{ {
"path": "./tsconfig.app.json", "path": "./tsconfig.app.json"
}, },
{ {
"path": "./tsconfig.editor.json", "path": "./tsconfig.editor.json"
}, }
], ],
"extends": "../../../tsconfig.base.json", "extends": "../../../tsconfig.base.json",
"angularCompilerOptions": { "angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false, "enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true, "strictInjectionParameters": true,
"strictInputAccessModifiers": true, "strictInputAccessModifiers": true,
"strictTemplates": true, "strictTemplates": true
}, }
} }

View File

@@ -5,7 +5,7 @@ author: thomas-laforge
contributors: contributors:
- tomalaforge - tomalaforge
challengeNumber: 42 challengeNumber: 42
command: nx-static-dynamic-import command: nx-static-vs-dynamic-import
sidebar: sidebar:
order: 15 order: 15
--- ---

View File

@@ -5,7 +5,7 @@ author: thomas-laforge
contributors: contributors:
- tomalaforge - tomalaforge
challengeNumber: 15 challengeNumber: 15
command: typescript-overload command: typescript-function-overload
blogLink: https://medium.com/ngconf/function-overloading-in-typescript-8236706b2c05 blogLink: https://medium.com/ngconf/function-overloading-in-typescript-8236706b2c05
sidebar: sidebar:
order: 115 order: 115

View File

@@ -40,17 +40,26 @@ function findPreviousChallengeFilePath(tree, path, number) {
} }
export async function challengeGenerator(tree: Tree, options: Schema) { export async function challengeGenerator(tree: Tree, options: Schema) {
const challengeNumberPath = 'challenge-number.json';
const challengeNumberJson = JSON.parse(
tree.read(challengeNumberPath).toString(),
);
const challengeNumber = challengeNumberJson.total + 1;
const difficulty = options.challengeDifficulty;
const name = options.title.toLowerCase().split(' ').join('-');
const order = challengeNumberJson[difficulty] + 1;
const { appProjectName, appDirectory } = getProjectDir( const { appProjectName, appDirectory } = getProjectDir(
options.name, name,
`apps/${options.category}`, `apps/${options.category}`,
); );
const difficulty = options.challengeDifficulty;
await applicationGenerator(tree, { await applicationGenerator(tree, {
...options, ...options,
name: `${options.category}-${options.name}`, name: `${options.category}-${name}`,
directory: `apps/${options.category}/${options.name}`, directory: `apps/${options.category}/${challengeNumber}-${name}`,
style: 'scss', style: 'scss',
routing: false, routing: false,
inlineStyle: true, inlineStyle: true,
@@ -65,13 +74,6 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
projectNameAndRootFormat: 'as-provided', projectNameAndRootFormat: 'as-provided',
}); });
const challengeNumberPath = 'challenge-number.json';
const challengeNumberJson = JSON.parse(
tree.read(challengeNumberPath).toString(),
);
const challengeNumber = challengeNumberJson.total + 1;
const order = challengeNumberJson[difficulty] + 1;
generateFiles(tree, join(__dirname, 'files', 'app'), appDirectory, { generateFiles(tree, join(__dirname, 'files', 'app'), appDirectory, {
tmpl: '', tmpl: '',
}); });
@@ -79,7 +81,7 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
generateFiles(tree, join(__dirname, 'files', 'readme'), appDirectory, { generateFiles(tree, join(__dirname, 'files', 'readme'), appDirectory, {
tmpl: '', tmpl: '',
projectName: names(options.name).name, projectName: names(name).name,
appProjectName, appProjectName,
title: options.title, title: options.title,
challengeNumber, challengeNumber,
@@ -92,7 +94,7 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
`./docs/src/content/docs/challenges/${options.category}`, `./docs/src/content/docs/challenges/${options.category}`,
{ {
tmpl: '', tmpl: '',
projectName: names(options.name).name, projectName: names(name).name,
appProjectName, appProjectName,
author: options.author, author: options.author,
title: options.title, title: options.title,
@@ -141,7 +143,7 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
const replacedLink = replaced.replace( const replacedLink = replaced.replace(
linkRegex, linkRegex,
`link: /${lang}/challenges/${options.category}/${challengeNumber}-${ `link: /${lang}/challenges/${options.category}/${challengeNumber}-${
names(options.name).name names(name).name
}/\n`, }/\n`,
); );

View File

@@ -3,7 +3,6 @@ export interface Schema {
author: string; author: string;
challengeDifficulty: string; challengeDifficulty: string;
category: string; category: string;
name: string;
addTest?: boolean; addTest?: boolean;
skipPackageJson?: boolean; skipPackageJson?: boolean;
rootProject?: boolean; rootProject?: boolean;

View File

@@ -6,16 +6,6 @@
"type": "object", "type": "object",
"cli": "nx", "cli": "nx",
"properties": { "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": { "title": {
"description": "Title of your challenge.", "description": "Title of your challenge.",
"type": "string", "type": "string",