Skip to content

Commit

Permalink
Updated dependencies of generator and main scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
enenkel committed Jan 22, 2018
1 parent 2f768ce commit d25f8aa
Show file tree
Hide file tree
Showing 6 changed files with 8,711 additions and 111 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- "node"
- "6"
- "5"
- "4"
- "8"
- "7"
55 changes: 29 additions & 26 deletions generators/app/templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const PRETEST = "pretest";
const RUN_TESTS = "run:tests";
const TEST = "test";
const REMAP_COVERAGE = "remap:coverage";
const WATCH = "watch";

const TS_SRC_GLOB = "./src/**/*.ts";
const TS_TEST_GLOB = "./test/**/*.ts";
Expand All @@ -32,6 +33,8 @@ const TS_GLOB = [TS_SRC_GLOB, TS_TEST_GLOB];

const tsProject = typescript.createProject("tsconfig.json");

// ###### CLEAN ######

// Removes the ./build directory with all its content.
gulp.task(CLEAN_BUILD, function(callback) {
rimraf("./build", callback);
Expand All @@ -47,6 +50,8 @@ gulp.task(CLEAN_DOC, function(callback) {
rimraf("./docs", callback);
});

// ###### LINTING ######

// Checks all *.ts-files if they are conform to the rules specified in tslint.json.
gulp.task(TSLINT, function() {
return gulp.src(TS_GLOB)
Expand All @@ -57,9 +62,12 @@ gulp.task(TSLINT, function() {
}));
});

// ###### COMPILE ######

// Compiles all *.ts-files to *.js-files.
gulp.task(COMPILE_TYPESCRIPT, function() {
return gulp.src(TS_GLOB, {base: "."})
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write())
Expand All @@ -76,67 +84,62 @@ gulp.task(GENERATE_DOC, [CLEAN_DOC], function() {
return gulp.src(TS_SRC_GLOB)
.pipe(typedoc({
out: "./docs",
readme: "readme.md",
readme: "README.md",
version: true,
module: "commonjs"
}))
});

// Sets up the istanbul coverage
// ###### TESTING ######

// Sets up istanbul coverage
gulp.task(PRETEST, function() {
gulp.src(JS_SRC_GLOB)
.pipe(sourcemaps.init({loadMaps: true}))
return gulp.src(JS_SRC_GLOB)
.pipe(istanbul({includeUntested: true}))
.pipe(istanbul.hookRequire())
.pipe(istanbul.hookRequire());
});

// Run the tests via mocha and generate a istanbul json report.
gulp.task(RUN_TESTS, function(callback) {
let mochaError;
gulp.src(JS_TEST_GLOB)
gulp.task(RUN_TESTS, [PRETEST], function() {
return gulp.src(JS_TEST_GLOB, {read: false})
.pipe(plumber())
.pipe(mocha({reporter: "spec"}))
.pipe(istanbul.writeReports({reporters: ["json"]}))
.pipe(gulp.dest("./coverage"))
.on("error", function(err) {
mochaError = err;
console.log("error: ", err);
process.exit(1);
})
.pipe(istanbul.writeReports({
reporters: ["json"]
}))
.on("end", function() {
callback(mochaError);
});
});

// Remap Coverage to *.ts-files and generate html, text and json summary
// Remap coverage to *.ts-files and generate html, text and lcov reports.
gulp.task(REMAP_COVERAGE, function() {
return gulp.src("./coverage/coverage-final.json")
.pipe(remapIstanbul({
// basePath: ".",
fail: true,
reports: {
"html": "./coverage",
"json": "./coverage",
"html": "./coverage/html-report",
"text-summary": null,
"lcovonly": "./coverage/lcov.info"
}
}))
.pipe(gulp.dest("coverage"))
.on("end", function() {
console.log("--> For a more detailed report, check the ./coverage directory <--")
});
.on("end", () => console.log("--> For a more detailed report, check the ./coverage/html-report directory <--"));
});

// Runs all required steps for testing in sequence.
// Runs all required steps for testing in sequence (includes rebuilding the project)
gulp.task(TEST, function(callback) {
runSequence(BUILD, CLEAN_COVERAGE, PRETEST, RUN_TESTS, REMAP_COVERAGE, callback);
runSequence(BUILD, CLEAN_COVERAGE, RUN_TESTS, REMAP_COVERAGE, callback);
});

// ###### WATCH ######

// Runs the build task and starts the server every time changes are detected.
gulp.task("watch", [BUILD], function() {
gulp.task(WATCH, [BUILD], function () {
return nodemon({
ext: "ts js json",
script: "build/src/server.js",
watch: ["src/*", "test/*"],
env: {"NODE_ENV": "development"},
tasks: [BUILD]
});
});
47 changes: 24 additions & 23 deletions generators/app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,40 @@
"doc": "gulp generate:doc",
"start": "gulp watch",
"test": "gulp test",
"pretest": "gulp pretest",
"tslint": "gulp tslint"
},
"dependencies": {
"body-parser": "1.16.0",
"express": "4.14.0",
"morgan": "1.7.0",
"winston": "2.3.1"
"body-parser": "1.18.2",
"express": "4.16.2",
"morgan": "1.9.0"
},
"devDependencies": {
"@types/body-parser": "0.0.33",
"@types/chai": "3.4.34",
"@types/express": "4.0.35",
"@types/mocha": "2.2.38",
"@types/morgan": "1.7.32",
"@types/winston": "2.2.0",
"chai": "3.5.0",
"@types/body-parser": "~1.16.8",
"@types/chai": "~4.1.1",
"@types/express": "~4.11.0",
"@types/mocha": "~2.2.46",
"@types/morgan": "~1.7.35",
"@types/winston": "~2.3.7",
"chai": "4.1.2",
"gulp": "3.9.1",
"gulp-istanbul": "1.1.1",
"gulp-istanbul": "1.1.3",
"gulp-mocha": "3.0.1",
"gulp-nodemon": "2.2.1",
"gulp-plumber": "1.1.0",
"gulp-sourcemaps": "2.4.0",
"gulp-tslint": "7.0.1",
"gulp-typedoc": "2.0.2",
"gulp-typescript": "3.1.4",
"remap-istanbul": "0.8.4",
"rimraf": "2.5.4",
"run-sequence": "1.2.2",
"tslint": "4.3.1",
"typedoc": "0.5.5",
"typescript": "2.1.5"
"gulp-sourcemaps": "2.6.3",
"gulp-tslint": "8.1.2",
"gulp-typedoc": "2.2.0",
"gulp-typescript": "3.2.3",
"remap-istanbul": "0.10.0",
"rimraf": "2.6.2",
"run-sequence": "2.2.1",
"tslint": "5.9.1",
"typedoc": "0.9.0",
"typescript": "2.6.2",
"winston": "2.4.0"
},
"engines": {
"node": ">=4.0.0"
"node": ">=8.0.0"
}
}
37 changes: 24 additions & 13 deletions generators/app/templates/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,43 @@ import {Express, Request, Response} from "express";
const PORT: number = <%= port %>;

/**
* Root class of your node server.
* Can be used for basic configurations, for instance starting up the server or registering middleware.
* Basic configurations of all middleware libraries are applied here.
*/
export class Server {

private app: Express;
public static start() {

constructor() {
this.app = express();
this.app.use(json());
this.app.use(morgan("combined"));
this.setupRoutes();
this.app.listen(PORT, () => {
winston.log("info", "--> Server successfully started at port %d", PORT);
let app: Express = express();

// Decode payload as json with body-parser
app.use(json());

// Apply morgan request logger
app.use(morgan("combined"));

// Set headers for CORS requests
// TODO: Adjust these settings to your security concerns!
app.use((req: Request, res: Response, next: any) => {
res.setHeader("Access-Control-Allow-Origin", "http://localhost:*");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type,authorization");
next();
});

Server.setupRoutes(app);
app.listen(PORT, () => winston.log("info", "--> Server successfully started at port %d", PORT));
}

/**
* Setup all endpoints of your API. You can extend this method or if there are many different routes,
* it might be better to move this to a separate class.
*/
private setupRoutes(): void {
this.app.get("/", (req: Request, res: Response) => {
private static setupRoutes(app: Express): void {
app.get("/", (req: Request, res: Response) => {
res.status(200).send("Server running ...");
});
}

}
new Server();

Server.start();
Loading

0 comments on commit d25f8aa

Please sign in to comment.