Skip to content

Commit

Permalink
Merge branch 'auto-create-monorepo-name-convention' of https://github…
Browse files Browse the repository at this point in the history
….com/SSCIsrael/schematics into SSCIsrael-auto-create-monorepo-name-convention
  • Loading branch information
kamilmysliwiec committed Nov 4, 2020
2 parents 230152e + 9771379 commit 18f835a
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 62 deletions.
1 change: 1 addition & 0 deletions src/lib/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const DEFAULT_VERSION = '0.0.1';
export const DEFAULT_PATH_NAME = 'src';
export const DEFAULT_LIB_PATH = 'libs';
export const DEFAULT_APPS_PATH = 'apps';
export const DEFAULT_APP_NAME = 'app';
export const DEFAULT_DIR_ENTRY_APP = 'main';
export const TEST_ENV = 'test';
export const PROJECT_TYPE = {
Expand Down
22 changes: 22 additions & 0 deletions src/lib/sub-app/files/ts/src/__name__.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { <%= classify(name) %>Controller } from './<%= name %>.controller';
import { <%= classify(name) %>Service } from './<%= name %>.service';

describe('AppController', () => {
let <%= camelize(name) %>Controller: <%= classify(name) %>Controller;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [<%= classify(name) %>Controller],
providers: [<%= classify(name) %>Service],
}).compile();

<%= camelize(name) %>Controller = app.get<<%= classify(name) %>Controller>(<%= classify(name) %>Controller);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(<%= camelize(name) %>Controller.getHello()).toBe('Hello World!');
});
});
});
12 changes: 12 additions & 0 deletions src/lib/sub-app/files/ts/src/__name__.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { <%= classify(name) %>Service } from './<%= name %>.service';

@Controller()
export class <%= classify(name) %>Controller {
constructor(private readonly <%= camelize(name) %>Service: <%= classify(name) %>Service) {}

@Get()
getHello(): string {
return this.<%= camelize(name) %>Service.getHello();
}
}
10 changes: 10 additions & 0 deletions src/lib/sub-app/files/ts/src/__name__.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { <%= classify(name) %>Controller } from './<%= name %>.controller';
import { <%= classify(name) %>Service } from './<%= name %>.service';

@Module({
imports: [],
controllers: [<%= classify(name) %>Controller],
providers: [<%= classify(name) %>Service],
})
export class <%= classify(name) %>Module {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
export class <%= classify(name)%>Service {
getHello(): string {
return 'Hello World!';
}
Expand Down
22 changes: 0 additions & 22 deletions src/lib/sub-app/files/ts/src/app.controller.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/lib/sub-app/files/ts/src/app.controller.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/lib/sub-app/files/ts/src/app.module.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/lib/sub-app/files/ts/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { <%= classify(name) %>Module } from './<%= name %>.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const app = await NestFactory.create(<%= classify(name) %>Module);
await app.listen(3000);
}
bootstrap();
4 changes: 2 additions & 2 deletions src/lib/sub-app/files/ts/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
import { <%= classify(name)%>Module } from './../src/<%= classify(name)%>.module';

describe('AppController (e2e)', () => {
let app;

beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
imports: [<%= classify(name)%>Module],
}).compile();

app = moduleFixture.createNestApplication();
Expand Down
3 changes: 1 addition & 2 deletions src/lib/sub-app/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@
"format": "path",
"description": "Applications root directory."
}
},
"required": ["name"]
}
}
16 changes: 8 additions & 8 deletions src/lib/sub-app/sub-app.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('SubApp Factory', () => {
'/nest-cli.json',
'/apps/nestjs-schematics/tsconfig.app.json',
'/apps/project/tsconfig.app.json',
'/apps/project/src/app.controller.spec.ts',
'/apps/project/src/app.controller.ts',
'/apps/project/src/app.module.ts',
'/apps/project/src/app.service.ts',
'/apps/project/src/main.ts',
'/apps/project/src/project.controller.spec.ts',
'/apps/project/src/project.controller.ts',
'/apps/project/src/project.module.ts',
'/apps/project/src/project.service.ts',
'/apps/project/test/app.e2e-spec.ts',
'/apps/project/test/jest-e2e.json',
]);
Expand All @@ -39,11 +39,11 @@ describe('SubApp Factory', () => {
'/nest-cli.json',
'/apps/nestjs-schematics/tsconfig.app.json',
'/apps/awesome-project/tsconfig.app.json',
'/apps/awesome-project/src/app.controller.spec.ts',
'/apps/awesome-project/src/app.controller.ts',
'/apps/awesome-project/src/app.module.ts',
'/apps/awesome-project/src/app.service.ts',
'/apps/awesome-project/src/main.ts',
'/apps/awesome-project/src/awesome-project.controller.spec.ts',
'/apps/awesome-project/src/awesome-project.controller.ts',
'/apps/awesome-project/src/awesome-project.module.ts',
'/apps/awesome-project/src/awesome-project.service.ts',
'/apps/awesome-project/test/app.e2e-spec.ts',
'/apps/awesome-project/test/jest-e2e.json',
]);
Expand Down
5 changes: 2 additions & 3 deletions src/lib/sub-app/sub-app.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@angular-devkit/schematics';
import * as fse from 'fs-extra';
import {
DEFAULT_APP_NAME,
DEFAULT_APPS_PATH,
DEFAULT_DIR_ENTRY_APP,
DEFAULT_LANGUAGE,
Expand Down Expand Up @@ -82,7 +83,7 @@ function transform(options: SubAppOptions): SubAppOptions {
options.rootDir !== undefined ? options.rootDir : DEFAULT_APPS_PATH;

if (!target.name) {
throw new SchematicsException('Option (name) is required.');
target.name = DEFAULT_APP_NAME;
}
target.language = !!target.language ? target.language : DEFAULT_LANGUAGE;
target.name = strings.dasherize(target.name);
Expand Down Expand Up @@ -343,7 +344,6 @@ function updateMainAppOptions(

function generateWorkspace(options: SubAppOptions, appName: string): Source {
const path = join(options.path as Path, appName);

return apply(url(join('./workspace' as Path, options.language)), [
template({
...strings,
Expand All @@ -356,7 +356,6 @@ function generateWorkspace(options: SubAppOptions, appName: string): Source {

function generate(options: SubAppOptions): Source {
const path = join(options.path as Path, options.name);

return apply(url(join('./files' as Path, options.language)), [
template({
...strings,
Expand Down

0 comments on commit 18f835a

Please sign in to comment.