Skip to content

Commit 036801d

Browse files
committed
Merge branch 'feature/simplify_paths' into develop
2 parents 4992e99 + 88df3b9 commit 036801d

File tree

5 files changed

+14
-21
lines changed

5 files changed

+14
-21
lines changed

src/console/lib/console.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ 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';
1918

2019
// It also loads the .env file into the 'process.env' variable.
2120
import { config } from 'dotenv';
@@ -39,7 +38,7 @@ figlet('console', (error: any, data: any) => {
3938
.filter(m => m.search(/\/lib/g) <= 0)
4039
.map(m => ({
4140
path: m,
42-
name: m.replace((isWindows() ? __dirname.replace(/\\/g, '/') : __dirname).replace('/lib', ''), '').replace('.ts', '').substring(1)
41+
name: m.replace(__dirname.split(path.sep).join('/').replace('/lib', ''), '').replace('.ts', '').substring(1)
4342
}));
4443

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

src/core/IoC.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ 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';
1716

1817

1918
export class IoC {
@@ -185,13 +184,13 @@ export class IoC {
185184
}
186185

187186
private getBasePath(): string {
188-
const baseFolder = __dirname.indexOf(getFolderWrapping('src')) >= 0 ? getFolderWrapping('src') : getFolderWrapping('dist');
187+
const baseFolder = __dirname.indexOf(`${path.sep}src${path.sep}`) >= 0 ? `${path.sep}src${path.sep}` : `${path.sep}dist${path.sep}`;
189188
const baseRoot = __dirname.substring(0, __dirname.indexOf(baseFolder));
190189
return path.join(baseRoot, baseFolder, 'api');
191190
}
192191

193192
private getFiles(filePath: string, done: (files: any[]) => void): void {
194-
const isTypeScript = __dirname.indexOf(getFolderWrapping('src')) >= 0;
193+
const isTypeScript = __dirname.indexOf(`${path.sep}src${path.sep}`) >= 0;
195194
if (!isTypeScript) {
196195
filePath = filePath.replace('.ts', '.js');
197196
}

src/core/Logger.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getFolderWrapping, isWindows } from './helpers/Path';
1+
import * as path from 'path';
22

33
/**
44
* core.log.Log
@@ -31,17 +31,16 @@ export class Logger {
3131
private static Adapter: interfaces.LoggerAdapterConstructor;
3232
private static Adapters: Map<string, interfaces.LoggerAdapterConstructor> = new Map();
3333

34-
private static parsePathToScope(path: string): string {
35-
const pathDelimiter = isWindows() ? '\\' : '/';
36-
if (path.indexOf(pathDelimiter) >= 0) {
37-
path = path.replace(process.cwd(), '');
38-
path = path.replace(getFolderWrapping('src'), '');
39-
path = path.replace(getFolderWrapping('dist'), '');
40-
path = path.replace('.ts', '');
41-
path = path.replace('.js', '');
42-
path = path.replace(/\//g, ':');
34+
private static parsePathToScope(filepath: string): string {
35+
if (filepath.indexOf(path.sep) >= 0) {
36+
filepath = filepath.replace(process.cwd(), '');
37+
filepath = filepath.replace(`${path.sep}src${path.sep}`, '');
38+
filepath = filepath.replace(`${path.sep}dist${path.sep}`, '');
39+
filepath = filepath.replace('.ts', '');
40+
filepath = filepath.replace('.js', '');
41+
filepath = filepath.replace(path.sep, ':');
4342
}
44-
return path;
43+
return filepath;
4544
}
4645

4746
private scope: string;

src/core/SwaggerUI.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ 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';
65

76

87
export class SwaggerUI {
@@ -13,7 +12,7 @@ export class SwaggerUI {
1312

1413
public setup(app: express.Application): void {
1514
if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) {
16-
const baseFolder = __dirname.indexOf(getFolderWrapping('src')) >= 0 ? getFolderWrapping('src') : getFolderWrapping('dist');
15+
const baseFolder = __dirname.indexOf(`${path.sep}src${path.sep}`) >= 0 ? `${path.sep}src${path.sep}` : `${path.sep}dist${path.sep}`;
1716
const basePath = __dirname.substring(0, __dirname.indexOf(baseFolder));
1817
const swaggerFile = require(path.join(basePath, process.env.SWAGGER_FILE));
1918
const packageJson = require(path.join(basePath, 'package.json'));

src/core/helpers/Path.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)