Skip to content

Commit 3a0d375

Browse files
committed
Merge branch 'feature/fix-windows-issues' into develop
2 parents 6d2f5cc + 1f18996 commit 3a0d375

File tree

12 files changed

+72
-39
lines changed

12 files changed

+72
-39
lines changed
File renamed without changes.

nodemon.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"delay": "0",
33
"execMap": {
4-
"ts": "./node_modules/.bin/ts-node"
4+
"ts": "ts-node"
55
},
66
"events": {
7-
"start": "./node_modules/.bin/tslint -c ./tslint.json -t stylish 'src/**/*.ts'",
8-
"restart": "osascript -e 'display notification \"restarting server\" with title \"node.js application\"'"
7+
"start": "tslint -c ./tslint.json -t stylish 'src/**/*.ts'"
98
}
109
}

package.json

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@
44
"description": "A delightful way to building a RESTful API with NodeJs & TypeScript",
55
"main": "src/app.ts",
66
"scripts": {
7-
"banner": "npm run ts-node:fast -- ./src/console/lib/banner.ts",
8-
"ts-node": "./node_modules/.bin/ts-node",
9-
"ts-node:fast": "./node_modules/.bin/ts-node -F",
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",
10+
"start": "node dist/app.js",
1011
"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",
1113
"test:pretty": "npm run test -- --verbose",
1214
"test:coverage": "npm run test -- --coverage",
1315
"pretest:black-box": "./node_modules/.bin/tslint -c ./tslint.json -t stylish './test/black-box/**/*.ts'",
14-
"test:black-box": "npm run banner test && NODE_ENV=test ./node_modules/.bin/jest ./test/black-box -i",
16+
"test:black-box": "npm run banner test && cross-env NODE_ENV=test \"./node_modules/.bin/jest\" --testPathPattern=black-box -i",
1517
"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",
22+
"console": "npm run ts-node:fast -- ./src/console/lib/commander.ts",
23+
"console:dev": "npm run ts-node -- ./src/console/lib/commander.ts",
24+
"console:help": "npm run ts-node:fast -- ./src/console/lib/commander.ts --help",
1625
"lint": "./node_modules/.bin/tslint -c ./tslint.json -p tsconfig.json 'src/**/*.ts' --format stylish",
1726
"transpile": "./node_modules/.bin/tsc",
27+
"clean": "npm run banner clean && npm run clean:dist",
1828
"clean:dist": "./node_modules/.bin/trash './dist'",
1929
"copy:assets": "npm run copy:swagger && npm run copy:public",
2030
"copy:swagger": "./node_modules/.bin/copyup ./src/api/swagger.json ./dist",
2131
"copy:public": "./node_modules/.bin/copyup ./src/public/* ./dist",
22-
"db:migrate": "npm run banner migrate && npm run ts-node:fast -- ./node_modules/.bin/knex migrate:latest",
23-
"db:migrate:rollback": "npm run banner rollback && npm run ts-node:fast -- ./node_modules/.bin/knex migrate:rollback",
24-
"db:seed": "npm run banner seed && npm run ts-node:fast -- ./node_modules/.bin/knex seed:run",
25-
"db:reset": "npm run console db:reset",
26-
"console": "npm run ts-node:fast -- ./src/console/lib/commander.ts",
27-
"console:dev": "npm run ts-node -- ./src/console/lib/commander.ts",
28-
"console:help": "npm run ts-node:fast -- ./src/console/lib/commander.ts --help",
29-
"setup": "npm run banner setup && yarn install && npm run db:migrate && npm run db:seed",
30-
"serve": "npm run banner serve && ./node_modules/.bin/nodemon --watch 'src/**/*.ts' --watch 'src/**/*.json' --watch '.env'",
31-
"clean": "npm run banner clean && npm run clean:dist",
32-
"test": "npm run banner test && NODE_ENV=test ./node_modules/.bin/jest ./test/unit",
33-
"build": "npm run banner build && npm run lint && npm run clean:dist && npm run transpile && npm run copy:assets",
34-
"start": "node dist/app.js"
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"
3535
},
3636
"repository": "git+ssh://git@github.com/w3tec/express-typescript-boilerplate.git",
3737
"engines": {
@@ -146,5 +146,8 @@
146146
"testEnvironment": "node",
147147
"setupTestFrameworkScriptFile": "./test/unit/lib/setup.ts"
148148
},
149-
"license": "MIT"
149+
"license": "MIT",
150+
"devDependencies": {
151+
"cross-env": "^5.0.1"
152+
}
150153
}

src/console/lib/commander.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as path from 'path';
1515
import * as commander from 'commander';
1616
import * as figlet from 'figlet';
1717
import * as chalk from 'chalk';
18+
import { isWindows } from './../../core/helpers/Path';
1819

1920
// It also loads the .env file into the 'process.env' variable.
2021
import { config } from 'dotenv';
@@ -35,10 +36,10 @@ figlet('console', (error: any, data: any) => {
3536
}
3637

3738
const files = matches
38-
.filter(m => m.indexOf('/lib') < 0)
39+
.filter(m => m.search(/\/lib/g) <= 0)
3940
.map(m => ({
4041
path: m,
41-
name: m.replace(__dirname.replace('/lib', ''), '').replace('.ts', '').substring(1)
42+
name: m.replace((isWindows() ? __dirname.replace(/\\/g, '/') : __dirname).replace('/lib', ''), '').replace('.ts', '').substring(1)
4243
}));
4344

4445
const commands = files.map(f => require(f.path)[f.name]);

src/core/ApiInfo.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as express from 'express';
2-
import * as path from 'path';
32
import { Environment } from './helpers/Environment';
43
import { SwaggerUI } from './SwaggerUI';
54
import { ApiMonitor } from './ApiMonitor';
@@ -8,7 +7,7 @@ import { ApiMonitor } from './ApiMonitor';
87
export class ApiInfo {
98

109
public static getRoute(): string {
11-
return path.join(process.env.APP_URL_PREFIX, process.env.API_INFO_ROUTE);
10+
return process.env.APP_URL_PREFIX + process.env.API_INFO_ROUTE;
1211
}
1312

1413
public setup(app: express.Application): void {

src/core/ApiMonitor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import * as express from 'express';
22
import * as monitor from 'express-status-monitor';
3-
import * as path from 'path';
43
import { Environment } from './helpers/Environment';
54

65

76
export class ApiMonitor {
87

98
public static getRoute(): string {
10-
return path.join(process.env.MONITOR_ROUTE);
9+
return process.env.MONITOR_ROUTE;
1110
}
1211

1312
public setup(app: express.Application): void {

src/core/IoC.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Types, Core, Targets } from '../constants';
1313
import { events, EventEmitter } from './api/events';
1414
import { Logger } from './Logger';
1515
import { IocConfig } from '../config/IocConfig';
16+
import { getFolderwrapping } from './helpers/Path';
1617

1718

1819
export class IoC {
@@ -184,13 +185,13 @@ export class IoC {
184185
}
185186

186187
private getBasePath(): string {
187-
const baseFolder = __dirname.indexOf('/src/') >= 0 ? '/src/' : '/dist/';
188+
const baseFolder = __dirname.indexOf(getFolderwrapping('src')) >= 0 ? getFolderwrapping('src') : getFolderwrapping('dist');
188189
const baseRoot = __dirname.substring(0, __dirname.indexOf(baseFolder));
189190
return path.join(baseRoot, baseFolder, 'api');
190191
}
191192

192193
private getFiles(path: string, done: (files: any[]) => void): void {
193-
const isTypeScript = __dirname.indexOf('/src/') >= 0;
194+
const isTypeScript = __dirname.indexOf(getFolderwrapping('src')) >= 0;
194195
if (!isTypeScript) {
195196
path = path.replace('.ts', '.js');
196197
}

src/core/Logger.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getFolderwrapping, isWindows } from './helpers/Path';
2+
13
/**
24
* core.log.Log
35
* ------------------------------------------------
@@ -30,10 +32,11 @@ export class Logger {
3032
private static Adapters: Map<string, interfaces.LoggerAdapterConstructor> = new Map();
3133

3234
private static parsePathToScope(path: string): string {
33-
if (path.indexOf('/') >= 0) {
35+
const pathDelimiter = isWindows() ? '\\' : '/';
36+
if (path.indexOf(pathDelimiter) >= 0) {
3437
path = path.replace(process.cwd(), '');
35-
path = path.replace('/src/', '');
36-
path = path.replace('/dist/', '');
38+
path = path.replace(getFolderwrapping('src'), '');
39+
path = path.replace(getFolderwrapping('dist'), '');
3740
path = path.replace('.ts', '');
3841
path = path.replace('.js', '');
3942
path = path.replace(/\//g, ':');

src/core/SwaggerUI.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ import * as express from 'express';
22
import * as path from 'path';
33
import * as swaggerUi from 'swagger-ui-express';
44
import { Environment } from './helpers/Environment';
5+
import { getFolderwrapping } from './helpers/Path';
56

67

78
export class SwaggerUI {
89

910
public static getRoute(): string {
10-
return path.join(process.env.APP_URL_PREFIX, process.env.SWAGGER_ROUTE);
11+
return process.env.APP_URL_PREFIX + process.env.SWAGGER_ROUTE;
1112
}
1213

1314
public setup(app: express.Application): void {
1415
if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) {
15-
const baseFolder = __dirname.indexOf('/src/') >= 0 ? '/src/' : '/dist/';
16+
const baseFolder = __dirname.indexOf(getFolderwrapping('src')) >= 0 ? getFolderwrapping('src') : getFolderwrapping('dist');
1617
const basePath = __dirname.substring(0, __dirname.indexOf(baseFolder));
1718
const swaggerFile = require(path.join(basePath, process.env.SWAGGER_FILE));
18-
const packageJson = require(path.join(basePath, '/package.json'));
19+
const packageJson = require(path.join(basePath, 'package.json'));
1920

2021
// Add npm infos to the swagger doc
2122
swaggerFile.info = {

src/core/helpers/Path.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const isWindows = (): boolean => /^win/.test(process.platform);
2+
export const getFolderwrapping = (input: string): string => isWindows() ? `\\${input}\\` : `/${input}/`;

0 commit comments

Comments
 (0)