Skip to content

Commit ba0b4a1

Browse files
committed
feat: 절대경로 설정,ts-node 로 실행하도록 변경
1 parent 66d6506 commit ba0b4a1

15 files changed

+95
-27
lines changed

example01/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
# 만들면서 배우는 헥사고날 아키텍처 설계와 구현 with Typescript
22

33
## 1. 왜 헥사고날 아키텍처인가?
4+
5+
1. ts-node 전역 설치
6+
7+
```
8+
npm install -g ts-node
9+
```
10+
11+
2. 의존성 패키지 설치
12+
13+
```
14+
yarn
15+
```
16+
17+
3. 실행
18+
19+
```
20+
// dev
21+
yarn start:dev
22+
// prod
23+
yarn start
24+
```

example01/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "hexagonal-architecture-with-ts-1",
33
"version": "0.0.0",
44
"description": "만들면서 배우는 헥사고날 아키텍처 설계와 구현 with Typescript 1장 예제",
5-
"type": "module",
65
"engines": {
76
"node": ">= 18.12 <19"
87
},
@@ -18,11 +17,13 @@
1817
"prettier": "~2.8",
1918
"rimraf": "~3.0",
2019
"ts-jest": "~29.0",
20+
"tsconfig-paths": "^4.1.2",
2121
"tsutils": "~3.21",
2222
"typescript": "~4.9"
2323
},
2424
"scripts": {
25-
"start": "node build/src/main.js",
25+
"start": "NODE_ENV=production ts-node-esm --transpile-only -r tsconfig-paths/register src/main.ts",
26+
"start:dev": "NODE_ENV=development ts-node-dev --transpile-only --respawn -r tsconfig-paths/register --trace-warnings --trace-uncaught -- ./src/main.ts",
2627
"clean": "rimraf coverage build tmp",
2728
"prebuild": "npm run lint",
2829
"build": "tsc -p tsconfig.json",

example01/resource/events.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
00:44:06.906367 100430035020260940012015 IPV6 casanova.58183 > menuvivofibra.br.domain: 64865+ PTR? 1.0.0.224.in-addr.arpa. (40)
2+
00:44:06.912775 100430035020260940012016 IPV6 menuvivofibra.br.domain > casanova.58183: 64865 1/0/0 PTR all-systems.mcast.net. (75)

example01/resource/routers.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ca23800e-9b5a-11eb-a8b3-0242ac130003;EDGE
2+
63fdd9ff-242f-4842-993a-7651b5d33e14;EDGE
3+
81579b05-4b4e-4b9b-91f4-75a5a8561296;CORE

example01/src/application/port/input/router-view.input-port.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Router } from '../../../domain/router/router.js';
2-
import { Predicate } from '../../../utils/types.js';
3-
import { RouterViewUsecase } from '../../usecase/router-view.usecase.js';
4-
import { RouterViewOutputPort } from '../output/router-view.output-port.js';
1+
import { RouterViewOutputPort } from 'src/application/port/output/router-view.output-port';
2+
import { RouterViewUsecase } from 'src/application/usecase/router-view.usecase';
3+
import { Router } from 'src/domain/router';
4+
import { Predicate } from 'src/utils/types';
55

66
export class RouterViewInputPort implements RouterViewUsecase {
77
public constructor(private readonly routerViewOutputPort: RouterViewOutputPort) {}

example01/src/application/port/output/router-view.output-port.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Router } from '../../../domain/router/router.js';
1+
import { Router } from 'src/domain/router';
22

33
export interface RouterViewOutputPort {
44
fetchRouters(): Promise<Router[]>;

example01/src/domain/router.id.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export class RouterId {
2+
constructor(private readonly _id: string) {}
3+
4+
public static of(id: string): RouterId {
5+
return new RouterId(id);
6+
}
7+
8+
toString(): string {
9+
return `RouterId { ${this._id.toString()} }`;
10+
}
11+
}

example01/src/domain/router/router.ts example01/src/domain/router.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Predicate } from '../../utils/types.js';
2-
import { RouterId } from './router.id.js';
3-
import { RouterType } from './router.type.js';
1+
import { RouterId } from 'src/domain/router.id';
2+
import { RouterType } from 'src/domain/router.type';
3+
import { Predicate } from 'src/utils/types';
44

55
export class Router {
66
public constructor(private readonly _routerType: RouterType, private readonly _routerId: RouterId) {}
@@ -19,4 +19,8 @@ export class Router {
1919
public getRouterType(): RouterType {
2020
return this._routerType;
2121
}
22+
23+
public toString(): string {
24+
return `Router { type: ${RouterType[this._routerType]}, id: ${this._routerId.toString()} }`;
25+
}
2226
}
File renamed without changes.

example01/src/domain/router/router.id.ts

-5
This file was deleted.

example01/src/framework/adapter/input/router-view.cli.adapter.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { RouterViewInputPort } from '../../../application/port/input/router-view.input-port.js';
2-
import { RouterViewUsecase } from '../../../application/usecase/router-view.usecase.js';
3-
import { Router } from '../../../domain/router/router.js';
4-
import { RouterType } from '../../../domain/router/router.type.js';
5-
import { routerViewFileAdapter } from '../output/router-view.file.adapter.js';
1+
import { RouterViewInputPort } from 'src/application/port/input/router-view.input-port';
2+
import { RouterViewUsecase } from 'src/application/usecase/router-view.usecase';
3+
import { Router } from 'src/domain/router';
4+
import { RouterType } from 'src/domain/router.type';
5+
6+
import { routerViewFileAdapter } from 'src/framework/adapter/output/router-view.file.adapter';
67

78
export class RouterViewCliAdapter {
89
private _routerViewUseCase: RouterViewUsecase;

example01/src/framework/adapter/output/router-view.file.adapter.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { RouterViewOutputPort } from '../../../application/port/output/router-view.output-port.js';
2-
import { Router } from '../../../domain/router/router.js';
31
import { readFile } from 'fs/promises';
4-
import { RouterType } from '../../../domain/router/router.type.js';
5-
import { RouterId } from '../../../domain/router/router.id.js';
2+
import { join, resolve } from 'path';
3+
import { RouterViewOutputPort } from 'src/application/port/output/router-view.output-port';
4+
import { Router } from 'src/domain/router';
5+
import { RouterId } from 'src/domain/router.id';
6+
import { RouterType } from 'src/domain/router.type';
67

78
class RouterViewFileAdapter implements RouterViewOutputPort {
89
async fetchRouters(): Promise<Router[]> {
@@ -15,7 +16,7 @@ class RouterViewFileAdapter implements RouterViewOutputPort {
1516
return new Router(RouterType[type], RouterId.of(id));
1617
};
1718

18-
const routers = await readFile('routers.txt', { encoding: 'utf-8' }).toString().split('\n').map(lineToRouter);
19+
const routers = (await readFile(join(resolve(), 'resource/routers.txt'))).toString().split('\n').map(lineToRouter);
1920
return routers;
2021
}
2122
}

example01/src/main.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { RouterType } from 'src/domain/router.type';
2+
import { RouterViewCliAdapter } from 'src/framework/adapter/input/router-view.cli.adapter';
3+
4+
const cli = new RouterViewCliAdapter();
5+
cli.obtainRelatedRouters(RouterType.EDGE).then((routers) => routers.forEach((r) => console.log(r.toString())));

example01/tsconfig.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "ES2022",
4-
"module": "Node16",
4+
"module": "NodeNext",
55
"lib": ["ES2022"],
66
"moduleResolution": "Node16",
77
"rootDir": ".",
@@ -17,7 +17,12 @@
1717
"noUnusedParameters": true,
1818
"noImplicitAny": false,
1919
"noImplicitThis": false,
20-
"strictNullChecks": false
20+
"strictNullChecks": false,
21+
"esModuleInterop": true,
22+
"baseUrl": ".",
23+
"paths": {
24+
"src/*": ["src/*"]
25+
}
2126
},
2227
"include": ["src/**/*", "__tests__/**/*"]
2328
}

example01/yarn.lock

+19
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,11 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
22722272
dependencies:
22732273
brace-expansion "^1.1.7"
22742274

2275+
minimist@^1.2.6:
2276+
version "1.2.7"
2277+
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18"
2278+
integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==
2279+
22752280
22762281
version "2.1.2"
22772282
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
@@ -2622,6 +2627,11 @@ strip-ansi@^6.0.0, strip-ansi@^6.0.1:
26222627
dependencies:
26232628
ansi-regex "^5.0.1"
26242629

2630+
strip-bom@^3.0.0:
2631+
version "3.0.0"
2632+
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
2633+
integrity sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==
2634+
26252635
strip-bom@^4.0.0:
26262636
version "4.0.0"
26272637
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-4.0.0.tgz#9c3505c1db45bcedca3d9cf7a16f5c5aa3901878"
@@ -2708,6 +2718,15 @@ ts-jest@~29.0:
27082718
semver "7.x"
27092719
yargs-parser "^21.0.1"
27102720

2721+
tsconfig-paths@^4.1.2:
2722+
version "4.1.2"
2723+
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-4.1.2.tgz#4819f861eef82e6da52fb4af1e8c930a39ed979a"
2724+
integrity sha512-uhxiMgnXQp1IR622dUXI+9Ehnws7i/y6xvpZB9IbUVOPy0muvdvgXeZOn88UcGPiT98Vp3rJPTa8bFoalZ3Qhw==
2725+
dependencies:
2726+
json5 "^2.2.2"
2727+
minimist "^1.2.6"
2728+
strip-bom "^3.0.0"
2729+
27112730
tslib@^1.8.1:
27122731
version "1.14.1"
27132732
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"

0 commit comments

Comments
 (0)