diff --git a/packages/schematics/src/generators/application/schema.d.ts b/packages/schematics/src/generators/application/schema.d.ts index ed3d0c7b..41cc904e 100644 --- a/packages/schematics/src/generators/application/schema.d.ts +++ b/packages/schematics/src/generators/application/schema.d.ts @@ -1,3 +1,3 @@ export interface ApplicationGeneratorSchema { - projectName: string; + name: string; } diff --git a/packages/schematics/src/generators/auth-jwt/files/src/app/core/auth/controllers/auth.controller.spec.ts.template b/packages/schematics/src/generators/auth-jwt/files/src/app/core/auth/controllers/auth.controller.spec.ts.template index abbbf3de..5d827f5b 100644 --- a/packages/schematics/src/generators/auth-jwt/files/src/app/core/auth/controllers/auth.controller.spec.ts.template +++ b/packages/schematics/src/generators/auth-jwt/files/src/app/core/auth/controllers/auth.controller.spec.ts.template @@ -1,5 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { AuthServiceMock } from '../../../test/auth/auth.service.mock'; +import { AuthServiceMock } from '../../../../../test/auth/auth.service.mock'; import { AuthService } from '../services/auth.service'; import { AuthController } from './auth.controller'; import { PassportModule } from '@nestjs/passport'; diff --git a/packages/schematics/src/generators/auth-jwt/files/src/app/core/user/model/entities/user.entity.ts.template b/packages/schematics/src/generators/auth-jwt/files/src/app/core/user/model/entities/user.entity.ts.template index e85abe08..de8bfeb3 100644 --- a/packages/schematics/src/generators/auth-jwt/files/src/app/core/user/model/entities/user.entity.ts.template +++ b/packages/schematics/src/generators/auth-jwt/files/src/app/core/user/model/entities/user.entity.ts.template @@ -1,6 +1,6 @@ import { Exclude } from 'class-transformer'; import { Column, Entity } from 'typeorm'; -import { BaseEntity } from '../../../../../../init-typeorm/files/src/app/shared/model/entities/base.entity'; +import { BaseEntity } from '../../../../shared/model/entities/base.entity'; import { roles } from '../../../auth/model/roles.enum'; @Entity() diff --git a/packages/schematics/src/generators/auth-jwt/generator.spec.ts b/packages/schematics/src/generators/auth-jwt/generator.spec.ts index 34a4c74c..42c2df56 100644 --- a/packages/schematics/src/generators/auth-jwt/generator.spec.ts +++ b/packages/schematics/src/generators/auth-jwt/generator.spec.ts @@ -25,7 +25,10 @@ describe('auth-jwt generator', () => { expect(fileContent).toMatch(/"devDependencies": {(.|\n)*"@types\/passport-jwt":/g); expect(fileContent).toMatch(/"devDependencies": {(.|\n)*"@types\/bcrypt":/g); expect(fileContent).toMatch(/"devDependencies": {(.|\n)*"@types\/lodash":/g); + expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@nestjs\/jwt":/g); + expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@nestjs\/typeorm":/g); expect(fileContent).toMatch(/"dependencies": {(.|\n)*"bcrypt":/g); + expect(fileContent).toMatch(/"dependencies": {(.|\n)*"typeorm":/g); expect(fileContent).toMatch(/"dependencies": {(.|\n)*"passport":/g); expect(fileContent).toMatch(/"dependencies": {(.|\n)*"passport-jwt":/g); expect(fileContent).toMatch(/"dependencies": {(.|\n)*"lodash":/g); diff --git a/packages/schematics/src/generators/auth-jwt/generator.ts b/packages/schematics/src/generators/auth-jwt/generator.ts index ed2f271e..b32ec735 100644 --- a/packages/schematics/src/generators/auth-jwt/generator.ts +++ b/packages/schematics/src/generators/auth-jwt/generator.ts @@ -23,7 +23,7 @@ export async function authJwtGenerator(tree: Tree, options: AuthJwtGeneratorSche [packagesVersion['bcrypt'].name]: packagesVersion['bcrypt'].version, [packagesVersion['nestjsTypeorm'].name]: packagesVersion['nestjsTypeorm'].version, [packagesVersion['nestjsPassport'].name]: packagesVersion['nestjsPassport'].version, - [packagesVersion['nestjsSwagger'].name]: packagesVersion['nestjsSwagger'].version, + [packagesVersion['nestjsJwt'].name]: packagesVersion['nestjsJwt'].version, [packagesVersion['lodash'].name]: packagesVersion['lodash'].version, [packagesVersion['passport'].name]: packagesVersion['passport'].version, [packagesVersion['passportJwt'].name]: packagesVersion['passportJwt'].version, diff --git a/packages/schematics/src/generators/convict/schema.json b/packages/schematics/src/generators/convict/schema.json index a5b4c99f..fdb81406 100644 --- a/packages/schematics/src/generators/convict/schema.json +++ b/packages/schematics/src/generators/convict/schema.json @@ -3,5 +3,16 @@ "$id": "ConvictConfigSchematic", "title": "Convict Configuration Schema", "type": "object", - "properties": {} + "properties": { + "projectName": { + "type": "string", + "description": "", + "$default": { + "$source": "argv", + "index": 0 + }, + "x-prompt": "In which project would you like to add convict configuration?" + } + }, + "required": ["projectName"] } diff --git a/packages/schematics/src/generators/entity/generator.spec.ts b/packages/schematics/src/generators/entity/generator.spec.ts index f05bc02a..df0d325d 100644 --- a/packages/schematics/src/generators/entity/generator.spec.ts +++ b/packages/schematics/src/generators/entity/generator.spec.ts @@ -27,7 +27,6 @@ describe('entity generator', () => { it('should add dependencies to package.json', async () => { const fileContent = tree.read('package.json')?.toString('utf-8'); expect(fileContent).toMatch(/"dependencies": {(.|\n)*"typeorm":/g); - expect(fileContent).toMatch(/"dependencies": {(.|\n)*"mysql2":/g); expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@nestjs\/typeorm":/g); }); diff --git a/packages/schematics/src/generators/entity/generator.ts b/packages/schematics/src/generators/entity/generator.ts index 72f906e7..ddddea9c 100644 --- a/packages/schematics/src/generators/entity/generator.ts +++ b/packages/schematics/src/generators/entity/generator.ts @@ -19,7 +19,6 @@ export async function entityGenerator(tree: Tree, options: EntityGeneratorSchema { [packagesVersion['typeorm'].name]: packagesVersion['typeorm'].version, [packagesVersion['nestjsTypeorm'].name]: packagesVersion['nestjsTypeorm'].version, - [packagesVersion['mysql2'].name]: packagesVersion['mysql2'].version, }, {}, ); diff --git a/packages/schematics/src/generators/mailer/configvalues.ts b/packages/schematics/src/generators/mailer/configvalues.ts index 287002f4..2974f37c 100644 --- a/packages/schematics/src/generators/mailer/configvalues.ts +++ b/packages/schematics/src/generators/mailer/configvalues.ts @@ -33,6 +33,20 @@ export const mailerValuesFromConfig = `{ }`; export const mailerConfigType = `{ + mailOptions: { + host: string; + port: number; + secure: boolean; + tlsRejectUnauthorized: boolean; + }; + emailFrom: string; + hbsOptions: { + templatesDir: string; + partialsDir: string; + }; + }`; + +export const mailerConfigFile = `{ mailOptions: { host: { doc: 'Mail server host URL', diff --git a/packages/schematics/src/generators/mailer/generator.spec.ts b/packages/schematics/src/generators/mailer/generator.spec.ts index 9aad09e2..0c287867 100644 --- a/packages/schematics/src/generators/mailer/generator.spec.ts +++ b/packages/schematics/src/generators/mailer/generator.spec.ts @@ -3,6 +3,7 @@ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import applicationGenerator from '../application/generator'; import { mailerGenerator } from './generator'; import { MailerGeneratorSchema } from './schema'; +import convictGenerator from '../convict/generator'; describe('mailer generator', () => { let tree: Tree; @@ -15,7 +16,6 @@ describe('mailer generator', () => { projectNameAndRootFormat: 'as-provided', directory: 'apps/test', }); - await mailerGenerator(tree, options); jest.clearAllMocks(); }, 60000); @@ -23,17 +23,58 @@ describe('mailer generator', () => { const config = readProjectConfiguration(tree, 'test'); expect(config).toBeDefined(); }); - it('should add dependencies to package.json', async () => { - const fileContent = tree.read('package.json')?.toString('utf-8'); - expect(fileContent).toMatch(/"dependencies": {(.|\n)*"handlebars":/g); - expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@devon4ts\/mailer":/g); + + describe('mailer generator without convict', () => { + beforeAll(async () => { + await mailerGenerator(tree, options); + }, 60000); + + it('should add dependencies to package.json', async () => { + const fileContent = tree.read('package.json')?.toString('utf-8'); + expect(fileContent).toMatch(/"dependencies": {(.|\n)*"handlebars":/g); + expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@devon4ts\/mailer":/g); + }); + + it('should add MailerModule to core.module', async () => { + const fileContent = tree + .read(`./packages/schematics/apps/${options.projectName}/src/app/core/core.module.ts`) + ?.toString('utf-8'); + + expect(fileContent).toContain('MailerModule'); + }); }); - it('should add MailerModule to core.module', async () => { - const fileContent = tree - .read(`./packages/schematics/apps/${options.projectName}/src/app/core/core.module.ts`) - ?.toString('utf-8'); + describe('mailer generator with convict', () => { + beforeAll(async () => { + await convictGenerator(tree, options); + await mailerGenerator(tree, options); + }, 60000); - expect(fileContent).toContain('MailerModule'); + it('should add dependencies to package.json', async () => { + const fileContent = tree.read('package.json')?.toString('utf-8'); + expect(fileContent).toMatch(/"dependencies": {(.|\n)*"handlebars":/g); + expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@devon4ts\/mailer":/g); + }); + + it('should add MailerModule to core.module', async () => { + const fileContent = tree + .read(`./packages/schematics/apps/${options.projectName}/src/app/core/core.module.ts`) + ?.toString('utf-8'); + expect(fileContent).toContain('MailerModule'); + }); + + it('should add mailer configuration src/app/shared/app-config.ts', async () => { + const fileContent = tree + .read(`./packages/schematics/apps/${options.projectName}/src/app/shared/app-config.ts`) + ?.toString('utf-8'); + expect(fileContent).toContain('mailer'); + }); + + it('should add mailer configuration src/config.ts', async () => { + const fileContent = tree + .read(`./packages/schematics/apps/${options.projectName}/src/config.ts`) + ?.toString('utf-8'); + expect(fileContent).toContain('mailer'); + }); }); }); diff --git a/packages/schematics/src/generators/mailer/generator.ts b/packages/schematics/src/generators/mailer/generator.ts index 2304c7c0..6f816ef6 100644 --- a/packages/schematics/src/generators/mailer/generator.ts +++ b/packages/schematics/src/generators/mailer/generator.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import { ASTFileBuilder } from '../../utils/ast-file-builder'; import { existsConvictConfig } from '../../utils/tree-utils'; import { packagesVersion } from '../packagesVersion'; -import { defaultMailerValues, mailerConfigType, mailerValuesFromConfig } from './configvalues'; +import { defaultMailerValues, mailerConfigType, mailerConfigFile, mailerValuesFromConfig } from './configvalues'; import { MailerGeneratorSchema } from './schema'; export async function mailerGenerator(tree: Tree, options: MailerGeneratorSchema): Promise<() => void> { @@ -68,13 +68,19 @@ function addMailerToProject(tree: Tree, projectRoot: string): Tree { } addMailerToCoreModule(tree, true, projectRoot); - const typesFile = `${projectRoot}/config.ts`; - const typesFileContent = new ASTFileBuilder(tree.read(typesFile)!.toString('utf-8')) - .addPropertyToObjectLiteralParam('config', 0, 'mailer', mailerConfigType) + // Add properties to config type file + const configTypeFile = `${projectRoot}/app/shared/app-config.ts`; + const configTypeFileContent = new ASTFileBuilder(tree.read(configTypeFile)!.toString('utf-8')) + .addPropToInterface('AppConfig', 'mailer', mailerConfigType) .build(); + tree.write(configTypeFile, configTypeFileContent); - tree.write(typesFile, typesFileContent); - + // Add properties to config file + const configFile = `${projectRoot}/config.ts`; + const configFileContent = new ASTFileBuilder(tree.read(configFile)!.toString('utf-8')) + .addPropertyToObjectLiteralParam('config', 0, 'mailer', mailerConfigFile) + .build(); + tree.write(configFile, configFileContent); return tree; } diff --git a/packages/schematics/src/generators/swagger/schema.json b/packages/schematics/src/generators/swagger/schema.json index 7e426f97..3a61ebeb 100644 --- a/packages/schematics/src/generators/swagger/schema.json +++ b/packages/schematics/src/generators/swagger/schema.json @@ -4,7 +4,7 @@ "title": "Swagger Schema", "type": "object", "properties": { - "project": { + "projectName": { "type": "string", "description": "Target application where Swagger config is going to be created.", "$default": { @@ -14,5 +14,5 @@ "x-prompt": "What application would you like to modify?" } }, - "required": ["project"] + "required": ["projectName"] }