Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
avishayhajbi committed Jan 13, 2020
1 parent 7005cd2 commit a1090c2
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nestjs/schematics",
"version": "6.8.0",
"description": "Nest - modern, fast, powerful node.js web framework (@schematics)",
"description": "Nest - modern, fast, powerful node.js web framework (@schematics)!",
"main": "dist/index.js",
"files": [
"dist/**/*"
Expand Down
5 changes: 5 additions & 0 deletions src/lib/application/files/ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
12 changes: 6 additions & 6 deletions src/lib/sub-app/files/ts/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { <%= classify(name) || 'App' %>Controller } from './app.controller';
import { <%= classify(name) || 'App' %>Service } from './app.service';

describe('AppController', () => {
let appController: AppController;
let <%= (classify(name) || 'App').toLowerCase() %>Controller: <%= classify(name) || 'App' %>Controller;

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

appController = app.get<AppController>(AppController);
<%= (classify(name) || 'App').toLowerCase() %>Controller = app.get<<%= classify(name) || 'App' %>Controller>(<%= classify(name) || 'App' %>Controller);
});

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

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
export class <%= classify(name) || 'App' %>Controller {
constructor(private readonly <%= (classify(name) || 'App').toLowerCase() %>Service: <%= classify(name) || 'App' %>Service) {}
@Get()
getHello(): string {
return this.appService.getHello();
return this.<%= (classify(name) || 'App').toLowerCase() %>Service.getHello();
}
}
10 changes: 5 additions & 5 deletions src/lib/sub-app/files/ts/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { <%= classify(name) || 'App' %>Controller } from './app.controller';
import { <%= classify(name) || 'App' %>Service } from './app.service';

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
controllers: [<%= classify(name) || 'App' %>Controller],
providers: [<%= classify(name) || 'App' %>Service],
})
export class AppModule {}
export class <%= classify(name) || 'App' %>Module {}
2 changes: 1 addition & 1 deletion src/lib/sub-app/files/ts/src/app.service.ts
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) || 'App' %>Service {
getHello(): string {
return 'Hello World!';
}
Expand Down
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) || 'App' %>Module } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const app = await NestFactory.create(<%= classify(name) || 'App' %>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) || 'App' %>Module } from './../src/app.module';

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

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

app = moduleFixture.createNestApplication();
Expand Down
10 changes: 2 additions & 8 deletions src/lib/sub-app/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
"properties": {
"name": {
"type": "string",
"description": "The name of the application.",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use for the app?"
"description": "The name of the application."
},
"language": {
"type": "string",
Expand All @@ -27,6 +22,5 @@
"format": "path",
"description": "Applications root directory."
}
},
"required": ["name"]
}
}
2 changes: 1 addition & 1 deletion src/lib/sub-app/sub-app.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('SubApp Factory', () => {
'/apps/awesome-project/tslint.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/aaa.module.ts',
'/apps/awesome-project/src/app.service.ts',
'/apps/awesome-project/src/main.ts',
'/apps/awesome-project/test/app.e2e-spec.ts',
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 a1090c2

Please sign in to comment.