diff --git a/README.md b/README.md index 2b9d8b1..17ba316 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,11 @@ Then, open a different terminal and simply run: ``` $ npm test ``` + +## CI / CD +Continuous integration it's been done by [Travis CI](https://travis-ci.org/josemigallas/users-api). It tracks every push and PR and un the full test suite. + +Additionally, the app is being deployed on Heroku, both in development (when changes are pushed to `dev`) and production (when commits are merged into `master`). + +Development deployment -> https://screener-users-api-development.herokuapp.com/ +Production deployment -> https://screener-users-api.herokuapp.com/users diff --git a/package-lock.json b/package-lock.json index 7af56b0..212453d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "users-api", - "version": "0.1.0", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -8,7 +8,6 @@ "version": "4.0.36", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.0.36.tgz", "integrity": "sha512-bT9q2eqH/E72AGBQKT50dh6AXzheTqigGZ1GwDiwmx7vfHff0bZOrvUWjvGpNWPNkRmX1vDF6wonG6rlpBHb1A==", - "dev": true, "requires": { "@types/express-serve-static-core": "4.0.49", "@types/serve-static": "1.7.31" @@ -18,7 +17,6 @@ "version": "4.0.49", "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.0.49.tgz", "integrity": "sha512-b7mVHoURu1xaP/V6xw1sYwyv9V0EZ7euyi+sdnbnTZxEkAh4/hzPsI6Eflq+ZzHQ/Tgl7l16Jz+0oz8F46MLnA==", - "dev": true, "requires": { "@types/node": "8.0.13" } @@ -34,14 +32,12 @@ "@types/jasmine": { "version": "2.5.53", "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.5.53.tgz", - "integrity": "sha512-2YNL0jXYuN7w07mb1sMZQ6T6zOvGi83v8UbjhBZ8mhvI1VkQ2STU9XOrTFyvWswMyh5rW1evS+e7qltYJvTqPA==", - "dev": true + "integrity": "sha512-2YNL0jXYuN7w07mb1sMZQ6T6zOvGi83v8UbjhBZ8mhvI1VkQ2STU9XOrTFyvWswMyh5rW1evS+e7qltYJvTqPA==" }, "@types/mime": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.1.tgz", - "integrity": "sha512-rek8twk9C58gHYqIrUlJsx8NQMhlxqHzln9Z9ODqiNgv3/s+ZwIrfr+djqzsnVM12xe9hL98iJ20lj2RvCBv6A==", - "dev": true + "integrity": "sha512-rek8twk9C58gHYqIrUlJsx8NQMhlxqHzln9Z9ODqiNgv3/s+ZwIrfr+djqzsnVM12xe9hL98iJ20lj2RvCBv6A==" }, "@types/node": { "version": "8.0.13", @@ -51,8 +47,7 @@ "@types/realm": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@types/realm/-/realm-1.0.3.tgz", - "integrity": "sha1-iURUrP583P1oBWNt0VC4rFCEh9I=", - "dev": true + "integrity": "sha1-iURUrP583P1oBWNt0VC4rFCEh9I=" }, "@types/request": { "version": "2.0.0", @@ -67,7 +62,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/request-promise-native/-/request-promise-native-1.0.6.tgz", "integrity": "sha512-SbsRP/CnMW09mF8mIfOBgQzSJJKZkSbXIC3g1RSKgZSGNz5MK7dedxImr30ekjY71WzRRtQh4VwiAaHA3+Uu8w==", - "dev": true, "requires": { "@types/request": "2.0.0" } @@ -76,7 +70,6 @@ "version": "1.7.31", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.7.31.tgz", "integrity": "sha1-FUVt6NmNa0z/Mb5savdJKuY/Uho=", - "dev": true, "requires": { "@types/express-serve-static-core": "4.0.49", "@types/mime": "1.3.1" @@ -384,8 +377,7 @@ "exit": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", - "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", - "dev": true + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=" }, "express": { "version": "4.15.3", @@ -718,7 +710,6 @@ "version": "2.6.0", "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-2.6.0.tgz", "integrity": "sha1-ayLnCIPo5YnUVjRhU7TSBt2+IX8=", - "dev": true, "requires": { "exit": "0.1.2", "glob": "7.1.2", @@ -728,8 +719,7 @@ "jasmine-core": { "version": "2.6.4", "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-2.6.4.tgz", - "integrity": "sha1-3skmzQqfoof7bbXHVfpIfnTOysU=", - "dev": true + "integrity": "sha1-3skmzQqfoof7bbXHVfpIfnTOysU=" }, "jsbn": { "version": "0.1.1", diff --git a/package.json b/package.json index 70914f3..7fc5260 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "users-api", - "version": "0.1.0", - "description": "This API allows all CRUDL operations over the dataset hosted in https://gist.githubusercontent.com/jasonmadigan/009c15b5dc4b4eccd32b/raw/34759c44e77d2f3515e20ed561cdd7a5e8345585/users.json.", + "version": "1.0.1", + "description": "This API allows all RESTL operations over the dataset hosted in https://gist.githubusercontent.com/jasonmadigan/009c15b5dc4b4eccd32b/raw/34759c44e77d2f3515e20ed561cdd7a5e8345585/users.json.", "scripts": { "start": "node dist/src/server.js", - "postinstall": "node_modules/typescript/bin/tsc -p . && cp src/repository/seed.json dist/src/repository/", + "postinstall": "node_modules/typescript/bin/tsc -p . && cp -r src/assets dist/src/assets", "test": "node_modules/.bin/jasmine", + "posttest": "rm -r database/test", "clean": "rm -rf node_modules database realm-object-server dist" }, "repository": { @@ -15,19 +16,20 @@ "author": "Jose Miguel Gallas Olmedo", "license": "ISC", "dependencies": { + "@types/express": "^4.0.36", + "@types/jasmine": "^2.5.53", "@types/node": "^8.0.13", + "@types/realm": "^1.0.3", "@types/request": "^2.0.0", + "@types/request-promise-native": "^1.0.6", "body-parser": "^1.17.2", "express": "^4.15.3", + "jasmine": "^2.6.0", "realm": "^1.10.0", "request-promise-native": "^1.0.4", "typescript": "^2.4.1" }, - "devDependencies": { - "@types/express": "^4.0.36", - "@types/jasmine": "^2.5.53", - "@types/realm": "^1.0.3", - "@types/request-promise-native": "^1.0.6", - "jasmine": "^2.6.0" + "engines": { + "node": "4.4.7" } } diff --git a/src/repository/seed.json b/src/assets/seed.json similarity index 100% rename from src/repository/seed.json rename to src/assets/seed.json diff --git a/src/repository/realm-helper.ts b/src/repository/realm-helper.ts index 091553b..c534ab0 100644 --- a/src/repository/realm-helper.ts +++ b/src/repository/realm-helper.ts @@ -34,9 +34,14 @@ export default class RealmHelper { return this._config; } - public static init(development): void { - if (development) { + public static init(mode: string): void { + let users: User[]; + + if (mode === "development") { this._config.path = "database/test/users"; + users = require("../../spec/support/test-users").default; + } else { + users = require("../assets/seed.json").users; } const realm = this.defaultRealm; @@ -45,8 +50,6 @@ export default class RealmHelper { return; } - const users: User[] = require("./seed.json").users; - realm.write(() => { for (const user of users) { realm.create(UserSchema.name, user); diff --git a/src/routes/index.ts b/src/routes/index.ts index 4e09b7a..4f67d34 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -7,7 +7,7 @@ import User from "../model/user"; const index: Router = Router(); index.get("/", (req, res) => { - res.send("Hello from Users API!"); + res.send(`Hello from Users API v${process.env.npm_package_version}!`); }); export default index; diff --git a/src/server.ts b/src/server.ts index c37be0b..f1d8f91 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,6 +1,10 @@ import * as express from "express"; import * as bodyParser from "body-parser"; +// Constants +const port: string = process.env.PORT || "3000"; +const mode: string = process.env.ENV_NODE || "development"; + // Server app definitions const app: express.Express = express(); @@ -16,8 +20,8 @@ app.use("/users", users); // Realm configuration import RealmHelper from "./repository/realm-helper"; -RealmHelper.init(process.env.ENV_NODE === "development"); +RealmHelper.init(mode); -app.listen(3000, () => { - console.log(`Users API listening on port 3000 in ${process.env.ENV_NODE} mode`); -}) \ No newline at end of file +app.listen(port, () => { + console.log(`Users API v${process.env.npm_package_version} listening on port ${port} in ${process.env.ENV_NODE} mode`); +});