Skip to content

Commit 1fef361

Browse files
examples(@nestjs) babel integration
1 parent cfa3131 commit 1fef361

17 files changed

Lines changed: 271 additions & 89 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# dependencies
2+
/node_modules
3+
4+
# IDE
5+
/.idea
6+
/.awcache
7+
/.vscode
8+
9+
# misc
10+
npm-debug.log
11+
12+
# example
13+
/quick-start
14+
15+
# tests
16+
/test
17+
/coverage
18+
/.nyc_output
19+
20+
# dist
21+
/dist

examples/09-babel-example/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('babel-core/register');
2+
require('babel-polyfill');
3+
require('./src/server');
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"experimentalDecorators": true
5+
},
6+
"exclude": [
7+
"node_modules"
8+
]
9+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "nest-babel-starter",
3+
"version": "1.0.0",
4+
"description": "Nest Babel starter repository",
5+
"license": "MIT",
6+
"scripts": {
7+
"build": "babel src -d dist",
8+
"prestart": "npm run build",
9+
"start": "node index.js",
10+
"start:prod": "node dist/server.js"
11+
},
12+
"dependencies": {
13+
"@nestjs/common": "^4.0.1",
14+
"@nestjs/core": "^4.0.1",
15+
"@nestjs/microservices": "^4.0.1",
16+
"@nestjs/testing": "^4.0.1",
17+
"@nestjs/websockets": "^4.0.1",
18+
"body-parser": "^1.17.2",
19+
"redis": "^2.7.1",
20+
"reflect-metadata": "^0.1.10",
21+
"rxjs": "^5.4.3"
22+
},
23+
"devDependencies": {
24+
"babel-cli": "^6.26.0",
25+
"babel-core": "^6.26.0",
26+
"babel-plugin-transform-decorators-legacy": "^1.3.4",
27+
"babel-polyfill": "^6.26.0",
28+
"babel-preset-es2015": "^6.24.1",
29+
"babel-preset-stage-0": "^6.24.1"
30+
}
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Module } from '@nestjs/common';
2+
import { CatsModule } from './cats/cats.module';
3+
import { CatsController } from './cats/cats.controller';
4+
5+
@Module({
6+
modules: [CatsModule],
7+
})
8+
export class ApplicationModule {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {
2+
Controller,
3+
Get,
4+
Post,
5+
Body,
6+
Bind,
7+
Dependencies,
8+
ReflectMetadata,
9+
Param,
10+
} from '@nestjs/common';
11+
import { CatsService } from './cats.service';
12+
13+
@Controller('cats')
14+
@Dependencies(CatsService)
15+
export class CatsController {
16+
constructor(catsService) {
17+
this.catsService = catsService;
18+
}
19+
20+
@Post()
21+
@Bind(Body())
22+
async create(createCatDto) {
23+
this.catsService.create(createCatDto);
24+
}
25+
26+
@Get()
27+
async findAll() {
28+
return this.catsService.findAll();
29+
}
30+
31+
@Get(':id')
32+
@Bind(Param('id'))
33+
findOne(id) {
34+
// logic
35+
}
36+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Module } from '@nestjs/common';
2+
import { CatsController } from './cats.controller';
3+
import { CatsService } from './cats.service';
4+
5+
@Module({
6+
controllers: [CatsController],
7+
components: [CatsService],
8+
})
9+
export class CatsModule {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Component } from '@nestjs/common';
2+
import { CatsModule } from './cats.module';
3+
4+
@Component()
5+
export class CatsService {
6+
constructor() {
7+
this.cats = [];
8+
}
9+
10+
create(cat) {
11+
this.cats.push(cat);
12+
}
13+
14+
findAll() {
15+
return this.cats;
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require('babel-core/register');
2+
require('babel-polyfill');
3+
4+
import * as bodyParser from 'body-parser';
5+
import { NestFactory } from '@nestjs/core';
6+
import { ApplicationModule } from './modules/app.module';
7+
8+
async function bootstrap() {
9+
const app = await NestFactory.create(ApplicationModule);
10+
await app.listen(3000);
11+
}
12+
bootstrap();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Binds parameters decorators to the method
3+
* Useful when the language doesn't provide a 'Parameter Decorators' feature
4+
* @param {} ...decorators
5+
*/
6+
export function Bind(...decorators) {
7+
return (target: object, key, descriptor) => {
8+
decorators.forEach((fn, index) => fn(target, key, index));
9+
return descriptor;
10+
};
11+
}

0 commit comments

Comments
 (0)