Skip to content

Commit

Permalink
Merge branch 'release/3.0.0-rc.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
hirsch88 committed Dec 18, 2017
2 parents 8ad2e00 + 55addd0 commit 5a78466
Show file tree
Hide file tree
Showing 72 changed files with 1,723 additions and 329 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ DB_DATABASE="my_database"
DB_SYNCHRONIZE=false
DB_LOGGING=false

#
# GraphQL
#
GRAPHQL_ENABLED=true
GRAPHQL_ROUTE="/graphql"
GRAPHQL_EDITOR=true

#
# Swagger
#
Expand Down
15 changes: 8 additions & 7 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ AUTH_ROUTE="http://localhost:3333/tokeninfo"
#
# DATABASE
#
DB_TYPE="mysql"
DB_HOST="localhost"
DB_PORT=3306
DB_USERNAME="root"
DB_PASSWORD=""
DB_DATABASE="my_database"
DB_SYNCHRONIZE=false
DB_TYPE="sqlite"
DB_DATABASE="./mydb.sql"
DB_LOGGING=false

#
# GraphQL
#
GRAPHQL_ENABLED=true
GRAPHQL_ROUTE="/graphql"

#
# Swagger
#
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typings/
# Dist #
dist/
ormconfig.json
tsconfig.build.json

# IDE #
.idea/
Expand All @@ -34,3 +35,4 @@ test/**/*.js
test/**/*.js.map
coverage/
!test/preprocessor.js
mydb.sql
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"typescript.tsdk": "./node_modules/typescript/lib",
"cSpell.enabled": true
"cSpell.enabled": true,
"files.exclude": {
"tsconfig.build.json": true,
"ormconfig.json": true
}
}
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
[Jest](https://facebook.github.io/jest/),
[Swagger](http://swagger.io/),
[validatejs](https://validatejs.org/),
[GraphQL](http://graphql.org/),
[DataLoaders](https://github.com/facebook/dataloader),
by [w3tech](https://github.com/w3tecch)

## Why
Expand All @@ -40,15 +42,13 @@ Try it!! We are happy to hear your feedback or any kind of new features.
- **API Documentation** thanks to [swagger](http://swagger.io/).
- **API Monitoring** thanks to [express-status-monitor](https://github.com/RafalWilinski/express-status-monitor).
- **Integrated Testing Tool** thanks to [Jest](https://facebook.github.io/jest).
- **E2E API Testing** thanks to [supertest](https://github.com/visionmedia/supertest).
- **Basic Security Features** thanks to [Helmet](https://helmetjs.github.io/).
- **Easy event dispatching** thanks to [event-dispatch](https://github.com/pleerock/event-dispatch).
- **Fast Database Building** with simple migration from [TypeORM](https://github.com/typeorm/typeorm).
- **Easy Data Seeding** with our own factories.

### Comming soon

- **Custom Commands** are also available in our setup and really easy to use or even extend.
- **Scaffolding Commands** will speed up your development tremendously as you should focus on business code and not scaffolding.
- **GraphQL** provides as a awesome query language for our api [GraphQL](http://graphql.org/).
- **DataLoaders** helps with performance thanks to caching and batching [DataLoaders](https://github.com/facebook/dataloader).

# Table of Contents

Expand Down Expand Up @@ -96,7 +96,7 @@ Create a new database with the name you have in your `.env`-file.
Then setup your application environment.

```bash
npm start setup
npm run setup
```

> This installs all dependencies with yarn. After that it migrates the database and seeds some test data into it. So after that your development environment is ready to use.
Expand Down Expand Up @@ -128,7 +128,8 @@ All script are defined in the package.json file, but the most important ones are
### Tests

- Run the unit tests using `npm start test` (There is also a vscode task for this called `test`).
- Run the e2e tests using `npm start test:e2e` and don't forget to start your application and your [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server).
- Run the integration tests using `npm start test:integration`.
- Run the e2e tests using `npm start test:e2e`.

### Running in dev mode

Expand Down Expand Up @@ -165,9 +166,11 @@ The swagger and the monitor route can be altered in the `.env` file.
| Route | Description |
| -------------- | ----------- |
| **/api** | Shows us the name, description and the version of the package.json |
| **/graphql** | Route to the graphql editor or your query/mutations requests |
| **/swagger** | This is the Swagger UI with our API documentation |
| **/monitor** | Shows a small monitor page for the server |
| **/api/users** | Example entity endpoint |
| **/api/pets** | Example entity endpoint |

## Project Structure

Expand All @@ -187,6 +190,9 @@ The swagger and the monitor route can be altered in the `.env` file.
| **src/api/services/** | Service layer |
| **src/api/subscribers/** | Event subscribers |
| **src/api/validators/** | Custom validators, which can be used in the request classes |
| **src/api/queries/** | GraphQL queries |
| **src/api/mutations/** | GraphQL mutations |
| **src/api/types/** | GraphQL types |
| **src/api/** swagger.json | Swagger documentation |
| **src/auth/** | Authentication checkers and services |
| **src/core/** | The core features like logger and env variables |
Expand All @@ -199,9 +205,12 @@ The swagger and the monitor route can be altered in the `.env` file.
| **src/types/** *.d.ts | Custom type definitions and files that aren't on DefinitelyTyped |
| **test** | Tests |
| **test/e2e/** *.test.ts | End-2-End tests (like e2e) |
| **test/integration/** *.test.ts | Integration test with SQLite3 |
| **test/unit/** *.test.ts | Unit tests |
| .env.example | Environment configurations |
| .env.test | Test environment configurations |
| ormconfig.json | TypeORM configuration for the database. Used by seeds and the migration. (generated file) |
| mydb.sql | SQLite database for integration tests. Ignored by git and only available after integration tests |

## Logging

Expand Down Expand Up @@ -316,7 +325,7 @@ export class CreateUsers implements SeedsInterface {
public async seed(factory: FactoryInterface): Promise<any> {
await factory
.get(User)
.create(10);
.createMany(10);
}

}
Expand All @@ -330,7 +339,7 @@ export class CreateUsers implements SeedsInterface {
public async seed(factory: FactoryInterface): Promise<any> {
await factory
.get(User, 'admin')
.create(1);
.create();
}

}
Expand All @@ -344,7 +353,7 @@ await factory.get(User)
.each(async (user: User) => {

const pets: Pet[] = await factory.get(Pet)
.create(2);
.createMany(2);

const petIds = pets.map((pet: Pet) => pet.Id);
await user.pets().attach(petIds);
Expand Down Expand Up @@ -377,7 +386,12 @@ npm start db.seed
| [Helmet](https://helmetjs.github.io/) | Helmet helps you secure your Express apps by setting various HTTP headers. It’s not a silver bullet, but it can help! |
| [Auth0 API Documentation](https://auth0.com/docs/api/management/v2) | Authentification service |
| [Jest](http://facebook.github.io/jest/) | Delightful JavaScript Testing Library for unit and e2e tests |
| [supertest](https://github.com/visionmedia/supertest) | Super-agent driven library for testing node.js HTTP servers using a fluent API |
| [nock](https://github.com/node-nock/nock) | HTTP mocking and expectations library |
| [swagger Documentation](http://swagger.io/) | API Tool to describe and document your api. |
| [SQLite Documentation](https://www.sitepoint.com/getting-started-sqlite3-basic-commands/) | Getting Started with SQLite3 – Basic Commands. |
| [GraphQL Documentation](http://graphql.org/graphql-js/) | A query language for your API. |
| [DataLoader Documentation](https://github.com/facebook/dataloader) | DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batching and caching. |
## Related Projects
Expand Down
File renamed without changes.
10 changes: 8 additions & 2 deletions src/lib/ormconfig.ts → commands/ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import * as dotenv from 'dotenv';
dotenv.config();

import * as path from 'path';
import * as Chalk from 'chalk';
import * as jsonfile from 'jsonfile';
import { env } from '../core/env';
import { env } from '../src/core/env';


const content = {
Expand All @@ -23,8 +24,13 @@ const content = {
const filePath = path.join(process.cwd(), 'ormconfig.json');
jsonfile.writeFile(filePath, content, { spaces: 2 }, (err) => {
if (err === null) {
console.log('Successfully generated ormconfig.json form the .env file');
const chalk = Chalk.default;
console.log('👍 ',
chalk.gray.underline('generated:'),
chalk.blue.bold('ormconfig.json')
);
} else {
console.error('Failed to generate the ormconfig.json', err);
process.exit(1);
}
});
24 changes: 24 additions & 0 deletions commands/tsconfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as path from 'path';
import * as Chalk from 'chalk';
import * as jsonfile from 'jsonfile';
import * as tsconfig from '../tsconfig.json';


const content: any = tsconfig;
content.include = [
'src/**/*',
];

const filePath = path.join(process.cwd(), 'tsconfig.build.json');
jsonfile.writeFile(filePath, content, { spaces: 2 }, (err) => {
if (err === null) {
const chalk = Chalk.default;
console.log('👍 ',
chalk.gray.underline('generated:'),
chalk.blue.bold('tsconfig.build.json')
);
} else {
console.error('Failed to generate the otsconfig.build.json', err);
process.exit(1);
}
});
Loading

0 comments on commit 5a78466

Please sign in to comment.