Skip to content

Commit 613b1f8

Browse files
author
hirsch88
committed
Add nps and update dependencies
1 parent c44c110 commit 613b1f8

14 files changed

+1604
-1075
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Try it!! We are happy to hear your feedback or any kind of new features.
2727

2828
## Features
2929
- **Beautiful Syntax** thanks to the awesome annotations from [Inversify Express Utils](https://github.com/inversify/inversify-express-utils).
30-
- **Easy API Testing** with included black-box testing.
30+
- **Easy API Testing** with included e2e testing.
3131
- **Dependency Injection** done with the nice framework from [Inversify](http://inversify.io/).
3232
- **Fast Database Building** with simple migration and seeding from [Knex](http://knexjs.org/).
3333
- **Simplified Database Query** with the ORM of [Knex](http://knexjs.org/) called [Bookshelf](http://bookshelfjs.org/).
@@ -153,7 +153,7 @@ All script are defined in the package.json file, but the most important ones are
153153

154154
### Tests
155155
* Run the unit tests using `npm test` (There is also a vscode task for this called `test`).
156-
* Run the black-box tests using `npm run test:black-box` and don't forget to start your application and your [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server).
156+
* Run the e2e tests using `npm run test:e2e` and don't forget to start your application and your [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server).
157157

158158
### Running in dev mode
159159
* Run `npm run serve` to start nodemon with ts-node, to serve the app.
@@ -241,7 +241,7 @@ The route prefix is `/api` by default, but you can change this in the .env file.
241241
| **src/public/** | Static assets (fonts, css, js, img). |
242242
| **src/types/** *.d.ts | Custom type definitions and files that aren't on DefinitelyTyped |
243243
| **test** | Tests |
244-
| **test/black-box/** *.test.ts | Black-Box tests (like e2e) |
244+
| **test/e2e/** *.test.ts | End-2-End tests (like e2e) |
245245
| **test/unit/** *.test.ts | Unit tests |
246246
| .env.example | Environment configurations |
247247
| knexfile.ts | This file is used for the migrations and seed task of knex |
@@ -250,7 +250,7 @@ The route prefix is `/api` by default, but you can change this in the .env file.
250250
* [Microsoft/TypeScript-Node-Starter](https://github.com/Microsoft/TypeScript-Node-Starter) - A starter template for TypeScript and Node with a detailed README describing how to use the two together.
251251
* [express-graphql-typescript-boilerplate](https://github.com/w3tecch/express-graphql-typescript-boilerplate) - A starter kit for building amazing GraphQL API's with TypeScript and express by @w3tecch
252252
* [aurelia-typescript-boilerplate](https://github.com/w3tecch/aurelia-typescript-boilerplate) - An Aurelia starter kit with TypeScript
253-
* [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server) - Useful for black-box testing or faking an oAuth server
253+
* [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server) - Useful for e2e testing or faking an oAuth server
254254

255255
## Documentations of our main dependencies
256256
* [Express](https://expressjs.com/)

package-scripts.js

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
const { series, crossEnv, concurrent, rimraf, runInNewWindow } = require('nps-utils');
2+
3+
module.exports = {
4+
scripts: {
5+
/**
6+
* Starts the builded app from the dist directory
7+
*/
8+
start: {
9+
script: 'node dist/app.js'
10+
},
11+
/**
12+
* Serves the current app and watches for changes to restart it
13+
*/
14+
serve: {
15+
script: series(
16+
'nps banner.serve',
17+
'\"./node_modules/.bin/nodemon\" --watch src --watch .env'
18+
)
19+
},
20+
/**
21+
* Setup's the development environment and the database
22+
*/
23+
setup: {
24+
script: series(
25+
'yarn install',
26+
'nps db.migrate',
27+
'nps db.seed'
28+
)
29+
},
30+
/**
31+
* Builds the app into the dist directory
32+
*/
33+
build: {
34+
script: series(
35+
'nps banner.build',
36+
'nps lint',
37+
'nps clean.dist',
38+
'nps transpile',
39+
'nps copy'
40+
)
41+
},
42+
/**
43+
* These run various kinds of tests. Default is unit.
44+
*/
45+
test: {
46+
default: 'nps test.unit',
47+
unit: {
48+
default: {
49+
script: series(
50+
'nps banner.test',
51+
'nps test.unit.pretest',
52+
'nps test.unit.run'
53+
)
54+
},
55+
pretest: {
56+
script: './node_modules/.bin/tslint -c ./tslint.json -t stylish "./test/unit/**/*.ts"'
57+
},
58+
run: {
59+
script: './node_modules/.bin/cross-env NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=unit'
60+
},
61+
verbose: {
62+
script: 'nps "test --verbose"'
63+
},
64+
coverage: {
65+
script: 'nps "test --coverage"'
66+
},
67+
},
68+
e2e: {
69+
default: {
70+
script: series(
71+
'nps banner.test',
72+
'nps test.e2e.pretest',
73+
runInNewWindow(series('nps build', 'nps start')),
74+
'nps test.e2e.run',
75+
)
76+
},
77+
pretest: {
78+
script: './node_modules/.bin/tslint -c ./tslint.json -t stylish "./test/e2e/**/*.ts"'
79+
},
80+
verbose: {
81+
script: 'nps "test.e2e --verbose"'
82+
},
83+
run: series(
84+
`wait-on --timeout 120000 http-get://localhost:3000/api/info`,
85+
'./node_modules/.bin/cross-env NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=e2e -i'
86+
),
87+
}
88+
},
89+
/**
90+
* Runs TSLint over your project
91+
*/
92+
lint: {
93+
script: `./node_modules/.bin/tslint -c ./tslint.json -p tsconfig.json 'src/**/*.ts' --format stylish`
94+
},
95+
/**
96+
* Transpile your app into javascript
97+
*/
98+
transpile: {
99+
script: `./node_modules/.bin/tsc`
100+
},
101+
/**
102+
* Clean files and folders
103+
*/
104+
clean: {
105+
default: {
106+
script: series(`nps banner.clean`, `nps clean.dist`)
107+
},
108+
dist: {
109+
script: `./node_modules/.bin/trash './dist'`
110+
}
111+
},
112+
/**
113+
* Copies static files to the build folder
114+
*/
115+
copy: {
116+
default: {
117+
script: `nps copy.swagger && nps copy.public`
118+
},
119+
swagger: {
120+
script: copy('./src/api/swagger.json', './dist')
121+
},
122+
public: {
123+
script: copy('./src/public/*', './dist')
124+
}
125+
},
126+
/**
127+
* This our scaffold api
128+
* @example > nps "console update:targets"
129+
*/
130+
console: {
131+
default: {
132+
script: runFast('./src/console/lib/console.ts')
133+
},
134+
dev: run('./src/console/lib/console.ts'),
135+
help: runFast('./src/console/lib/console.ts --help')
136+
},
137+
/**
138+
* All database related scripts are here
139+
*/
140+
db: {
141+
migrate: {
142+
default: {
143+
script: series('nps banner.migrate', '\"./node_modules/.bin/knex\" migrate:latest')
144+
},
145+
rollback: series('nps banner.rollback', '\"./node_modules/.bin/knex\" migrate:rollback')
146+
},
147+
seed: {
148+
script: series('nps banner.seed', '\"./node_modules/.bin/knex\" seed:run')
149+
},
150+
reset: {
151+
script: series('nps banner.dbReset', 'nps console db:reset')
152+
}
153+
},
154+
/**
155+
* This creates pretty banner to the terminal
156+
*/
157+
banner: {
158+
build: banner('build'),
159+
serve: banner('serve'),
160+
test: banner('test'),
161+
migrate: banner('db.migrate'),
162+
rollback: banner('db.migrate.rollback'),
163+
dbReset: banner('db.reset'),
164+
seed: banner('seed'),
165+
clean: banner('clean')
166+
},
167+
}
168+
};
169+
170+
function banner(name) {
171+
return {
172+
hiddenFromHelp: true,
173+
silent: true,
174+
logLevel: 'error',
175+
description: `Shows ${name} banners to the console`,
176+
script: runFast(`./src/console/lib/banner.ts ${name}`)
177+
}
178+
}
179+
180+
function copy(source, target) {
181+
return `./node_modules/.bin/copyup ${source} ${target}`
182+
}
183+
184+
function run(path) {
185+
return `./node_modules/.bin/ts-node ${path}`
186+
}
187+
188+
function runFast(path) {
189+
return run(`-F ${path}`)
190+
}

package.json

+58-78
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,11 @@
44
"description": "A delightful way to building a RESTful API with NodeJs & TypeScript",
55
"main": "src/app.ts",
66
"scripts": {
7-
"setup": "yarn install && npm run banner setup && npm run db:migrate && npm run db:seed",
8-
"serve": "npm run banner serve && \"./node_modules/.bin/nodemon\" --watch src --watch .env",
9-
"build": "npm run banner build && npm run lint && npm run clean:dist && npm run transpile && npm run copy:assets",
107
"start": "node dist/app.js",
11-
"pretest": "./node_modules/.bin/tslint -c ./tslint.json -t stylish './test/unit/**/*.ts'",
12-
"test": "npm run banner test && cross-env NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=unit",
13-
"test:pretty": "npm run test -- --verbose",
14-
"test:coverage": "npm run test -- --coverage",
15-
"pretest:black-box": "./node_modules/.bin/tslint -c ./tslint.json -t stylish './test/black-box/**/*.ts'",
16-
"test:black-box": "npm run banner test && cross-env NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=black-box -i",
17-
"test:black-box:pretty": "npm run test:black-box -- --verbose",
18-
"db:migrate": "npm run banner migrate && \"./node_modules/.bin/knex\" migrate:latest",
19-
"db:migrate:rollback": "npm run banner rollback && \"./node_modules/.bin/knex\" migrate:rollback",
20-
"db:seed": "npm run banner seed && \"./node_modules/.bin/knex\" seed:run",
21-
"db:reset": "npm run console db:reset",
8+
"test": "nps test",
229
"console": "npm run ts-node:fast -- ./src/console/lib/console.ts",
2310
"console:dev": "npm run ts-node -- ./src/console/lib/console.ts",
24-
"console:help": "npm run ts-node:fast -- ./src/console/lib/console.ts --help",
25-
"lint": "./node_modules/.bin/tslint -c ./tslint.json -p tsconfig.json 'src/**/*.ts' --format stylish",
26-
"transpile": "./node_modules/.bin/tsc",
27-
"clean": "npm run banner clean && npm run clean:dist",
28-
"clean:dist": "./node_modules/.bin/trash './dist'",
29-
"copy:assets": "npm run copy:swagger && npm run copy:public",
30-
"copy:swagger": "./node_modules/.bin/copyup ./src/api/swagger.json ./dist",
31-
"copy:public": "./node_modules/.bin/copyup ./src/public/* ./dist",
32-
"banner": "npm run ts-node:fast -- ./src/console/lib/banner.ts",
33-
"ts-node": "./node_modules/.bin/ts-node",
34-
"ts-node:fast": "./node_modules/.bin/ts-node -F"
11+
"console:help": "npm run ts-node:fast -- ./src/console/lib/console.ts --help"
3512
},
3613
"repository": "git+ssh://git@github.com/w3tec/express-typescript-boilerplate.git",
3714
"keywords": [
@@ -58,69 +35,70 @@
5835
}
5936
],
6037
"dependencies": {
61-
"@types/bluebird": "^3.5.8",
62-
"@types/body-parser": "^1.16.4",
63-
"@types/bookshelf": "^0.9.3",
64-
"@types/chalk": "^0.4.31",
65-
"@types/commander": "^2.9.1",
38+
"@types/bluebird": "^3.5.18",
39+
"@types/body-parser": "^1.16.7",
40+
"@types/bookshelf": "^0.9.6",
41+
"@types/chalk": "^2.2.0",
42+
"@types/commander": "^2.11.0",
6643
"@types/cors": "^2.8.1",
67-
"@types/dotenv": "^4.0.0",
68-
"@types/express": "^4.0.36",
69-
"@types/faker": "^4.1.0",
70-
"@types/glob": "^5.0.30",
71-
"@types/handlebars": "^4.0.33",
72-
"@types/helmet": "0.0.35",
44+
"@types/dotenv": "^4.0.2",
45+
"@types/express": "^4.0.39",
46+
"@types/faker": "^4.1.1",
47+
"@types/glob": "^5.0.33",
48+
"@types/handlebars": "^4.0.36",
49+
"@types/helmet": "^0.0.37",
7350
"@types/inquirer": "^0.0.35",
74-
"@types/jest": "^20.0.2",
75-
"@types/jsonwebtoken": "^7.2.2",
76-
"@types/knex": "0.0.52",
77-
"@types/lodash": "^4.14.68",
78-
"@types/morgan": "^1.7.32",
79-
"@types/pluralize": "^0.0.27",
51+
"@types/jest": "^21.1.5",
52+
"@types/jsonwebtoken": "^7.2.3",
53+
"@types/knex": "^0.0.64",
54+
"@types/lodash": "^4.14.80",
55+
"@types/morgan": "^1.7.35",
56+
"@types/pluralize": "^0.0.28",
8057
"@types/reflect-metadata": "0.0.5",
81-
"@types/request": "^0.0.45",
82-
"@types/request-promise": "^4.1.36",
83-
"@types/serve-favicon": "^2.2.28",
84-
"@types/winston": "^2.3.3",
85-
"body-parser": "^1.17.2",
86-
"bookshelf": "^0.10.3",
87-
"bookshelf-camelcase": "^1.1.4",
88-
"chalk": "^2.0.1",
89-
"class-validator": "^0.7.2",
58+
"@types/request": "^2.0.7",
59+
"@types/request-promise": "^4.1.39",
60+
"@types/serve-favicon": "^2.2.29",
61+
"@types/winston": "^2.3.7",
62+
"body-parser": "^1.18.2",
63+
"bookshelf": "^0.10.4",
64+
"bookshelf-camelcase": "^2.0.1",
65+
"chalk": "^2.3.0",
66+
"class-validator": "^0.7.3",
9067
"commander": "^2.11.0",
91-
"compression": "^1.7.0",
68+
"compression": "^1.7.1",
9269
"copyfiles": "^1.2.0",
93-
"cors": "^2.8.1",
70+
"cors": "^2.8.4",
9471
"dotenv": "^4.0.0",
95-
"express": "^4.15.3",
96-
"express-status-monitor": "^0.1.9",
72+
"express": "^4.16.2",
73+
"express-status-monitor": "^1.0.1",
9774
"faker": "^4.1.0",
9875
"figlet": "^1.2.0",
9976
"glob": "^7.1.2",
100-
"handlebars": "^4.0.10",
101-
"helmet": "^3.6.1",
102-
"inquirer": "^3.2.0",
103-
"inversify": "^4.2.0",
104-
"inversify-express-utils": "^4.0.0",
105-
"jsonwebtoken": "^7.4.1",
106-
"knex": "^0.12.0",
77+
"handlebars": "^4.0.11",
78+
"helmet": "^3.9.0",
79+
"inquirer": "^3.3.0",
80+
"inversify": "^4.5.0",
81+
"inversify-express-utils": "^4.1.0",
82+
"jsonwebtoken": "^8.1.0",
83+
"knex": "^0.13.0",
10784
"lodash": "^4.17.4",
108-
"morgan": "^1.7.0",
109-
"mysql": "^2.13.0",
110-
"nodemon": "^1.11.0",
85+
"morgan": "^1.9.0",
86+
"mysql": "^2.15.0",
87+
"nodemon": "^1.12.1",
11188
"path": "^0.12.7",
112-
"pluralize": "^5.0.0",
89+
"pluralize": "^7.0.0",
11390
"reflect-metadata": "^0.1.10",
114-
"request": "^2.81.0",
115-
"request-promise": "^4.2.1",
116-
"serve-favicon": "^2.4.3",
117-
"swagger-jsdoc": "^1.9.6",
118-
"swagger-ui-express": "^2.0.1",
91+
"request": "^2.83.0",
92+
"request-promise": "^4.2.2",
93+
"serve-favicon": "^2.4.5",
94+
"swagger-jsdoc": "^1.9.7",
95+
"swagger-ui-express": "^2.0.9",
11996
"trash-cli": "^1.4.0",
120-
"ts-node": "^3.2.0",
121-
"tslint": "^5.5.0",
122-
"typescript": "^2.4.1",
123-
"winston": "^2.3.1"
97+
"ts-node": "^3.3.0",
98+
"tslint": "^5.8.0",
99+
"typescript": "^2.6.1",
100+
"wait-on": "^2.0.2",
101+
"winston": "^2.4.0"
124102
},
125103
"jest": {
126104
"transform": {
@@ -138,8 +116,10 @@
138116
},
139117
"license": "MIT",
140118
"devDependencies": {
141-
"cross-env": "^5.0.1",
142-
"jest": "^20.0.3",
143-
"ts-jest": "^20.0.7"
119+
"cross-env": "^5.1.1",
120+
"jest": "^21.2.1",
121+
"nps": "^5.7.1",
122+
"nps-utils": "^1.5.0",
123+
"ts-jest": "^21.1.4"
144124
}
145125
}

0 commit comments

Comments
 (0)