Skip to content

Commit 3c2ecf9

Browse files
authored
Merge pull request #218 from samchon/features/dependencies
Publish both CJS and ESM.
2 parents 251427d + f876796 commit 3c2ecf9

41 files changed

Lines changed: 552 additions & 569 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
- uses: actions/checkout@v3
1717
- uses: actions/setup-node@v3
1818

19-
- name: Setup PNPM
20-
run: npm i -g pnpm && pnpm install
19+
- name: Setup Station
20+
run: npm install
2121

2222
- name: Test Packages
23-
run: pnpm run test
23+
run: npm run test

deploy/publish.js

Lines changed: 91 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@ const cp = require("child_process");
22
const fs = require("fs");
33
const path = require("path");
44

5-
const packages = fs.readdirSync(`${__dirname}/../packages`);
5+
const PACKAGES = [
6+
{
7+
location: "fake-iamport-server",
8+
name: "fake-iamport-server",
9+
api: "iamport-server-api",
10+
},
11+
{
12+
location: "fake-toss-payments-server",
13+
name: "fake-toss-payments-server",
14+
api: "toss-payments-server-api",
15+
},
16+
{
17+
location: "payment-backend",
18+
name: "@samchon/payment-backend",
19+
api: "@samchon/payment-api",
20+
},
21+
];
622

723
const execute =
824
(cwd, stdio = "ignore") =>
@@ -11,52 +27,96 @@ const execute =
1127
cp.execSync(command, { cwd, stdio });
1228
};
1329

14-
const deploy = (tag) => (version) => (name) => {
30+
const deploy = (tag) => (version) => (pack) => {
1531
console.log("-----------------------------------------");
16-
console.log(name.toUpperCase());
32+
console.log(pack.location.toUpperCase());
1733
console.log("-----------------------------------------");
1834

1935
// CHANGE PACKAGE.JSON INFO
20-
const directory = `${__dirname}/../packages/${name}`;
21-
const file = `${directory}/package.json`;
22-
const info = JSON.parse(fs.readFileSync(file, "utf8"));
36+
const location = `${__dirname}/../packages/${pack.location}`;
37+
const info = JSON.parse(
38+
fs.readFileSync(`${location}/package.json`, "utf8"),
39+
);
2340
info.version = version;
2441

2542
for (const record of [info.dependencies ?? {}, info.devDependencies ?? {}])
26-
for (const key of Object.keys(record))
27-
if (packages.includes(key.replace("@samchon/", ""))) {
28-
if (tag === "tgz" && fs.existsSync(`${directory}/node_modules/${key}`))
29-
execute(directory)(`pnpm uninstall ${key}`);
43+
for (const key of Object.keys(record)) {
44+
const backend = PACKAGES.find(p => p.name === key);
45+
const api = PACKAGES.find(p => p.api === key);
46+
if (backend !== undefined) {
47+
if (tag === "tgz" && fs.existsSync(`${location}/node_modules/${key}`))
48+
execute(location)(`npm uninstall ${key}`);
3049
record[key] =
3150
tag === "tgz"
32-
? path.resolve(
33-
`${__dirname}/../packages/${key.replace(
34-
"@samchon/",
35-
"",
36-
)}/${key}-${version}.tgz`,
37-
)
51+
? path.resolve(`${__dirname}/../packages/${backend.location}/${key}-${version}.tgz`)
3852
: `^${version}`;
3953
}
54+
else if (api !== undefined) {
55+
if (tag === "tgz" && fs.existsSync(`${location}/node_modules/${key}`))
56+
execute(location)(`npm uninstall ${key}`);
57+
record[key] =
58+
tag === "tgz"
59+
? path.resolve(`${__dirname}/../packages/${api.location}/packages/api/${key}-${version}.tgz`)
60+
: `^${version}`;
61+
}
62+
}
4063

4164
// SETUP UPDATED DEPENDENCIES
42-
fs.writeFileSync(file, JSON.stringify(info, null, 2), "utf8");
43-
execute(directory)(`pnpm install`);
44-
execute(directory)(`npm run build`);
65+
fs.writeFileSync(
66+
`${location}/package.json`,
67+
JSON.stringify(info, null, 2),
68+
"utf8",
69+
);
70+
execute(location)(`npm install`);
71+
execute(location)(`npm run build`);
4572

4673
// RUN TEST PROGRAM
47-
if (name === "payment-backend") {
48-
execute(directory)(`npm run schema`);
49-
execute(directory, "inherit")(`npm run test -- --reset true`);
50-
} else if (fs.existsSync(`${directory}/test`))
51-
execute(directory, "inherit")(`npm run test`);
74+
if (pack.name === "@samchon/payment-backend") {
75+
execute(location)(`npm run schema`);
76+
execute(location, "inherit")(`npm run test -- --reset true`);
77+
} else if (fs.existsSync(`${location}/test`))
78+
execute(location, "inherit")(`npm run test`);
5279

53-
// BUILD SWAGGER FILE
54-
if (name.includes("api") === false)
55-
execute(directory)(`npm run build:swagger`);
80+
// PUBLISH BACKEND
81+
if (tag === "tgz") execute(location)(`npm pack`);
82+
else execute(location)(`npm publish --tag ${tag} --access public`);
5683

57-
// PUBLISH (OR PACK)
58-
if (tag === "tgz") execute(directory)(`npm pack`);
59-
else execute(directory)(`npm publish --tag ${tag} --access public`);
84+
// PUBLISH API
85+
const apiInfo = JSON.parse(
86+
fs.readFileSync(
87+
`${location}/packages/api/package.json`,
88+
"utf8",
89+
),
90+
);
91+
apiInfo.version = version;
92+
if (pack.api === "@samchon/payment-api") {
93+
apiInfo.dependencies["iamport-server-api"] = tag === "tgz"
94+
? path.resolve(
95+
`${__dirname}/../packages/fake-iamport-server/packages/api/iamport-server-api-${version}.tgz`
96+
)
97+
: `^${version}`;
98+
apiInfo.dependencies["toss-payments-server-api"] = tag === "tgz"
99+
? path.resolve(
100+
`${__dirname}/../packages/fake-toss-payments-server/packages/api/toss-payments-server-api-${version}.tgz`
101+
)
102+
: `^${version}`;
103+
}
104+
fs.writeFileSync(
105+
`${location}/packages/api/package.json`,
106+
JSON.stringify(apiInfo, null, 2),
107+
"utf8",
108+
);
109+
execute(location)("npm run build:api");
110+
execute(location)("npm run build:swagger");
111+
cp.execSync(
112+
tag === "tgz"
113+
? "npm pack"
114+
: `npm publish --tag ${tag} --access public`,
115+
{
116+
stdio: "ignore",
117+
cwd: `${location}/packages/api`
118+
},
119+
);
60120
console.log("");
61121
};
62122

@@ -76,14 +136,7 @@ const publish = (tag) => {
76136
throw new Error(`latest tag can only be used for non-dev versions.`);
77137

78138
// DO DEPLOY
79-
for (const pack of [
80-
"fake-iamport-server",
81-
"fake-toss-payments-server",
82-
"iamport-server-api",
83-
"toss-payments-server-api",
84-
"payment-backend",
85-
"payment-api",
86-
])
139+
for (const pack of PACKAGES)
87140
deploy(tag)(version)(pack);
88141
};
89142

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@samchon/payments",
4-
"version": "8.0.2",
4+
"version": "8.1.0",
55
"description": "Collection of Payment system of Samchon",
66
"scripts": {
77
"package:latest": "node deploy latest",

packages/fake-iamport-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
참고로 [`nestia`](https://github.com/samchon/nestia) 는 SDK 뿐 아니라 Swagger 또한 빌드할 수 있는데, 이 또한 `fake-iamport-server` 의 소스코드 및 DTO 를 컴파일러 수준에서 분석하여 만들어지는 것인지라, 그 퀄리티가 상당하다. 어쩌면 아임포트가 공식 제공하는 개발자 가이드 문서보다, `fake-iamport-server` 로 생성한 Swagger 가 더 개발자 친화적이고 일목요연할지도?
1313

1414
- 서버 주소: http://localhost:10851
15-
- **Swagger Editor**: [packages/iamport-server-api/swagger.json](https://stackblitz.com/edit/5jpnps?file=README.md,test%2Fstart.ts&startScript=swagger&startScript=hello)
15+
- **Swagger Editor**: [packages/fake-iamport-server/packages/api/swagger.json](https://stackblitz.com/edit/5jpnps?file=README.md,test%2Fstart.ts&startScript=swagger&startScript=hello)
1616
- 자료 구조: [src/api/structures/IIamportPayment.ts](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server/src/api/structures/IIamportPayment.ts)
1717
- API 함수: [src/api/functional/payments/index.ts](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server/src/api/functional/payments/index.ts)
1818
- 예제 코드

packages/fake-iamport-server/nestia.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { FakeIamportModule } from "./src/FakeIamportModule";
77
const NESTIA_CONFIG: INestiaConfig = {
88
input: () => NestFactory.create(FakeIamportModule, new FastifyAdapter()),
99
output: "src/api",
10-
distribute: "../iamport-server-api",
10+
distribute: "packages/api",
1111
swagger: {
12-
output: "../iamport-server-api/swagger.json",
12+
output: "packages/api/swagger.json",
1313
info: {
1414
title: "Iamport API",
1515
description:

packages/fake-iamport-server/package.json

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
22
"name": "fake-iamport-server",
3-
"version": "8.0.2",
3+
"version": "8.1.0",
44
"description": "Fake iamport server for testing",
55
"main": "lib/index.js",
6+
"module": "lib/index.mjs",
67
"typings": "lib/index.d.ts",
78
"scripts": {
89
"----------------------------------------------": "",
910
"build": "npm run build:sdk && npm run build:main && npm run build:test",
10-
"build:api": "rimraf packages/api/lib && nestia sdk && npx copyfiles README.md packages/api && tsc -p packages/api/tsconfig.json",
11-
"build:main": "rimraf lib && tsc",
11+
"build:api": "rimraf packages/api/lib && nestia sdk && tsc -p packages/api/tsconfig.json && rollup -c packages/api/rollup.config.js",
12+
"build:main": "rimraf lib && tsc && rollup -c",
1213
"build:sdk": "rimraf src/api/functional && nestia sdk",
1314
"build:swagger": "nestia swagger",
1415
"build:test": "rimraf bin && tsc -p test/tsconfig.json",
1516
"dev": "npm run build:test -- --watch",
1617
"eslint": "eslint src && eslint --config .eslintrc.test.cjs test",
1718
"eslint:fix": "eslint --fix src && eslint --fix --config .eslintrc.test.cjs test",
1819
"------------------------------------------------": "",
19-
"package:api": "npm run build:swagger && npm run build:api && cd packages/api && npm publish",
2020
"package:latest": "npm run build && npm run test && npm publish",
2121
"package:next": "npm run package:latest -- --tag next",
2222
"prepare": "ts-patch install && typia patch",
@@ -38,40 +38,43 @@
3838
},
3939
"homepage": "https://github.com/samchon/fake-iamport-server",
4040
"devDependencies": {
41-
"@nestia/sdk": "^3.3.2",
41+
"@nestia/sdk": "^3.7.0",
42+
"@rollup/plugin-terser": "^0.4.4",
43+
"@rollup/plugin-typescript": "^11.1.6",
4244
"@types/atob": "^2.1.2",
4345
"@types/btoa": "^1.2.3",
4446
"@types/cli": "^0.11.19",
4547
"@types/node": "^20.14.9",
46-
"@types/uuid": "^9.0.1",
48+
"@types/uuid": "^10.0.0",
4749
"@typescript-eslint/eslint-plugin": "^5.26.0",
4850
"@typescript-eslint/parser": "^5.26.0",
51+
"chalk": "^4.1.2",
4952
"cli": "^1.0.1",
5053
"copyfiles": "^2.4.1",
5154
"nestia": "^5.1.2",
5255
"pm2": "^4.5.6",
5356
"rimraf": "^3.0.2",
57+
"rollup": "^4.18.1",
5458
"sloc": "^0.2.1",
5559
"ts-node": "^10.9.1",
5660
"ts-patch": "^3.2.1",
5761
"typescript": "^5.5.2"
5862
},
5963
"dependencies": {
60-
"@nestia/core": "^3.3.2",
61-
"@nestia/e2e": "^0.6.0",
62-
"@nestia/fetcher": "^3.3.2",
63-
"@nestjs/common": "^10.2.8",
64-
"@nestjs/core": "^10.2.8",
65-
"@nestjs/platform-fastify": "^10.2.8",
64+
"@nestia/core": "^3.7.0",
65+
"@nestia/e2e": "^0.7.0",
66+
"@nestia/fetcher": "^3.7.0",
67+
"@nestjs/common": "^10.3.10",
68+
"@nestjs/core": "^10.3.10",
69+
"@nestjs/platform-fastify": "^10.3.10",
6670
"atob": "^2.1.2",
6771
"btoa": "^1.2.1",
68-
"fastify": "^4.24.3",
6972
"serialize-error": "^4.1.0",
7073
"source-map-support": "^0.5.19",
7174
"tstl": "^3.0.0",
7275
"typescript-transform-paths": "^3.4.6",
73-
"typia": "^6.3.1",
74-
"uuid": "^9.0.0"
76+
"typia": "^6.5.0",
77+
"uuid": "^10.0.0"
7578
},
7679
"keywords": [
7780
"toss",

packages/iamport-server-api/README.md renamed to packages/fake-iamport-server/packages/api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ npm install --save iamport-server-api
1212

1313
고로 아임포트와 연동하는 TypeScript 기반 백엔드 서버를 개발함에 있어, 가짜 아임포트 서버 [`fake-iamport-server`](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server) 는 직접 이용치 않더라도, 실제 아임포트 서버와의 연동을 위하여, 본 SDK 라이브러리만큼은 반드시 설치하기를 권장하는 바이다.
1414

15-
- **Swagger Editor**: [packages/iamport-server-api/swagger.json](https://stackblitz.com/edit/5jpnps?file=README.md,test%2Fstart.ts&startScript=swagger&startScript=hello)
15+
- **Swagger Editor**: [packages/fake-iamport-server/packages/api/swagger.json](https://stackblitz.com/edit/5jpnps?file=README.md,test%2Fstart.ts&startScript=swagger&startScript=hello)
1616
- 자료 구조: [src/api/structures/IIamportPayment.ts](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server/src/api/structures/IIamportPayment.ts)
1717
- API 함수: [src/api/functional/payments/index.ts](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server/src/api/functional/payments/index.ts)
1818
- 예제 코드
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "iamport-server-api",
3+
"version": "8.1.0",
4+
"description": "API for Iamport Server",
5+
"main": "lib/index.js",
6+
"module": "lib/index.mjs",
7+
"typings": "lib/index.d.ts",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/samchon/payments"
11+
},
12+
"author": "Jeongho Nam",
13+
"license": "MIT",
14+
"bugs": {
15+
"url": "https://github.com/samchon/payments/issues"
16+
},
17+
"homepage": "https://github.com/samchon/payments",
18+
"files": [
19+
"lib",
20+
"package.json",
21+
"swagger.json",
22+
"README.md"
23+
],
24+
"dependencies": {
25+
"@nestia/fetcher": "^3.7.0",
26+
"tstl": "^3.0.0",
27+
"typia": "^6.5.0"
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const typescript = require("@rollup/plugin-typescript");
2+
const terser = require("@rollup/plugin-terser");
3+
4+
module.exports = {
5+
input: `${__dirname}/../../src/api/index.ts`,
6+
output: {
7+
dir: `${__dirname}/lib`,
8+
format: "esm",
9+
entryFileNames: "[name].mjs",
10+
sourcemap: true,
11+
},
12+
plugins: [
13+
typescript({
14+
tsconfig: `${__dirname}/tsconfig.json`,
15+
module: "ESNext",
16+
target: "ESNext",
17+
}),
18+
terser({
19+
format: {
20+
comments: "some",
21+
beautify: true,
22+
ecma: "2020",
23+
},
24+
compress: false,
25+
mangle: false,
26+
module: true,
27+
}),
28+
],
29+
};

0 commit comments

Comments
 (0)