8000 Publish both CJS and ESM. by samchon · Pull Request #218 · samchon/payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Publish both CJS and ESM. #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3

- name: Setup PNPM
run: npm i -g pnpm && pnpm install
- name: Setup Station
run: npm install

- name: Test Packages
run: pnpm run test
run: npm run test
129 changes: 91 additions & 38 deletions deploy/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@ const cp = require("child_process");
const fs = require("fs");
const path = require("path");

const packages = fs.readdirSync(`${__dirname}/../packages`);
const PACKAGES = [
{
location: "fake-iamport-server",
name: "fake-iamport-server",
api: "iamport-server-api",
},
{
location: "fake-toss-payments-server",
name: "fake-toss-payments-server",
api: "toss-payments-server-api",
},
{
location: "payment-backend",
name: "@samchon/payment-backend",
api: "@samchon/payment-api",
},
];

const execute =
(cwd, stdio = "ignore") =>
Expand All @@ -11,52 +27,96 @@ const execute =
cp.execSync(command, { cwd, stdio });
};

const deploy = (tag) => (version) => (name) => {
const deploy = (tag) => (version) => (pack) => {
console.log("-----------------------------------------");
console.log(name.toUpperCase());
console.log(pack.location.toUpperCase());
console.log("-----------------------------------------");

// CHANGE PACKAGE.JSON INFO
const directory = `${__dirname}/../packages/${name}`;
const file = `${directory}/package.json`;
const info = JSON.parse(fs.readFileSync(file, "utf8"));
const location = `${__dirname}/../packages/${pack.location}`;
const info = JSON.parse(
fs.readFileSync(`${location}/package.json`, "utf8"),
);
info.version = version;

for (const record of [info.dependencies ?? {}, info.devDependencies ?? {}])
for (const key of Object.keys(record))
if (packages.includes(key.replace("@samchon/", ""))) {
if (tag === "tgz" && fs.existsSync(`${directory}/node_modules/${key}`))
execute(directory)(`pnpm uninstall ${key}`);
for (const key of Object.keys(record)) {
const backend = PACKAGES.find(p => p.name === key);
const api = PACKAGES.find(p => p.api === key);
if (backend !== undefined) {
if (tag === "tgz" && fs.existsSync(`${location}/node_modules/${key}`))
execute(location)(`npm uninstall ${key}`);
record[key] =
tag === "tgz"
? path.resolve(
`${__dirname}/../packages/${key.replace(
"@samchon/",
"",
)}/${key}-${version}.tgz`,
)
? path.resolve(`${__dirname}/../packages/${backend.location}/${key}-${version}.tgz`)
: `^${version}`;
}
else if (api !== undefined) {
if (tag === "tgz" && fs.existsSync(`${location}/node_modules/${key}`))
execute(location)(`npm uninstall ${key}`);
record[key] =
tag === "tgz"
? path.resolve(`${__dirname}/../packages/${api.location}/packages/api/${key}-${version}.tgz`)
: `^${version}`;
}
}

// SETUP UPDATED DEPENDENCIES
fs.writeFileSync(file, JSON.stringify(info, null, 2), "utf8");
execute(directory)(`pnpm install`);
execute(directory)(`npm run build`);
fs.writeFileSync(
`${location}/package.json`,
JSON.stringify(info, null, 2),
"utf8",
);
execute(location)(`npm install`);
execute(location)(`npm run build`);

// RUN TEST PROGRAM
if (name === "payment-backend") {
execute(directory)(`npm run schema`);
execute(directory, "inherit")(`npm run test -- --reset true`);
} else if (fs.existsSync(`${directory}/test`))
execute(directory, "inherit")(`npm run test`);
if (pack.name === "@samchon/payment-backend") {
execute(location)(`npm run schema`);
execute(location, "inherit")(`npm run test -- --reset true`);
} else if (fs.existsSync(`${location}/test`))
execute(location, "inherit")(`npm run test`);

// BUILD SWAGGER FILE
if (name.includes("api") === false)
execute(directory)(`npm run build:swagger`);
// PUBLISH BACKEND
if (tag === "tgz") execute(location)(`npm pack`);
else execute(location)(`npm publish --tag ${tag} --access public< 1E11 /span>`);

// PUBLISH (OR PACK)
if (tag === "tgz") execute(directory)(`npm pack`);
else execute(directory)(`npm publish --tag ${tag} --access public`);
// PUBLISH API
const apiInfo = JSON.parse(
fs.readFileSync(
`${location}/packages/api/package.json`,
"utf8",
),
);
apiInfo.version = version;
if (pack.api === "@samchon/payment-api") {
apiInfo.dependencies["iamport-server-api"] = tag === "tgz"
? path.resolve(
`${__dirname}/../packages/fake-iamport-server/packages/api/iamport-server-api-${version}.tgz`
)
: `^${version}`;
apiInfo.dependencies["toss-payments-server-api"] = tag === "tgz"
? path.resolve(
`${__dirname}/../packages/fake-toss-payments-server/packages/api/toss-payments-server-api-${version}.tgz`
)
: `^${version}`;
}
fs.writeFileSync(
`${location}/packages/api/package.json`,
JSON.stringify(apiInfo, null, 2),
"utf8",
);
execute(location)("npm run build:api");
execute(location)("npm run build:swagger");
cp.execSync(
tag === "tgz"
? "npm pack"
: `npm publish --tag ${tag} --access public`,
{
stdio: "ignore",
cwd: `${location}/packages/api`
},
);
console.log("");
};

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

// DO DEPLOY
for (const pack of [
"fake-iamport-server",
"fake-toss-payments-server",
"iamport-server-api",
"toss-payments-server-api",
"payment-backend",
"payment-api",
])
for (const pack of PACKAGES)
deploy(tag)(version)(pack);
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@samchon/payments",
"version": "8.0.2",
"version": "8.1.0",
"description": "Collection of Payment system of Samchon",
"scripts": {
"package:latest": "node deploy latest",
Expand Down
2 changes: 1 addition & 1 deletion packages/fake-iamport-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
참고로 [`nestia`](https://github.com/samchon/nestia) 는 SDK 뿐 아니라 Swagger 또한 빌드할 수 있는데, 이 또한 `fake-iamport-server` 의 소스코드 및 DTO 를 컴파일러 수준에서 분석하여 만들어지는 것인지라, 그 퀄리티가 상당하다. 어쩌면 아임포트가 공식 제공하는 개발자 가이드 문서보다, `fake-iamport-server` 로 생성한 Swagger 가 더 개발자 친화적이고 일목요연할지도?

- 서버 주소: http://localhost:10851
- **Swagger Editor**: [packages/iamport-server-api/swagger.json](https://stackblitz.com/edit/5jpnps?file=README.md,test%2Fstart.ts&startScript=swagger&startScript=hello)
- **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)
- 자료 구조: [src/api/structures/IIamportPayment.ts](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server/src/api/structures/IIamportPayment.ts)
- API 함수: [src/api/functional/payments/index.ts](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server/src/api/functional/payments/index.ts)
- 예제 코드
Expand Down
4 changes: 2 additions & 2 deletions packages/fake-iamport-server/nestia.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { FakeIamportModule } from "./src/FakeIamportModule";
const NESTIA_CONFIG: INestiaConfig = {
input: () => NestFactory.create(FakeIamportModule, new FastifyAdapter()),
output: "src/api",
distribute: "../iamport-server-api",
distribute: "packages/api",
swagger: {
output: "../iamport-server-api/swagger.json",
output: "packages/api/swagger.json",
info: {
title: "Iamport API",
description:
Expand Down
33 changes: 18 additions & 15 deletions packages/fake-iamport-server/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "fake-iamport-server",
"version": "8.0.2",
"version": "8.1.0",
"description": "Fake iamport server for testing",
"main": "lib/index.js",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
"scripts": {
"----------------------------------------------": "",
"build": "npm run build:sdk && npm run build:main && npm run build:test",
"build:api": "rimraf packages/api/lib && nestia sdk && npx copyfiles README.md packages/api && tsc -p packages/api/tsconfig.json",
"build:main": "rimraf lib && tsc",
"build:api": "rimraf packages/api/lib && nestia sdk && tsc -p packages/api/tsconfig.json && rollup -c packages/api/rollup.config.js",
"build:main": "rimraf lib && tsc && rollup -c",
"build:sdk": "rimraf src/api/functional && nestia sdk",
"build:swagger": "nestia swagger",
"build:test": "rimraf bin && tsc -p test/tsconfig.json",
"dev": "npm run build:test -- --watch",
"eslint": "eslint src && eslint --config .eslintrc.test.cjs test",
"eslint:fix": "eslint --fix src && eslint --fix --config .eslintrc.test.cjs test",
"------------------------------------------------": "",
"package:api": "npm run build:swagger && npm run build:api && cd packages/api && npm publish",
"package:latest": "npm run build && npm run test && npm publish",
"package:next": "npm run package:latest -- --tag next",
"prepare": "ts-patch install && typia patch",
Expand All @@ -38,40 +38,43 @@
},
"homepage": "https://github.com/samchon/fake-iamport-server",
"devDependencies": {
"@nestia/sdk": "^3.3.2",
"@nestia/sdk": "^3.7.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/atob": "^2.1.2",
"@types/btoa": "^1.2.3",
"@types/cli": "^0.11.19",
"@types/node": "^20.14.9",
"@types/uuid": "^9.0.1",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"chalk": "^4.1.2",
"cli": "^1.0.1",
"copyfiles": "^2.4.1",
"nestia": "^5.1.2",
"pm2": "^4.5.6",
"rimraf": "^3.0.2",
"rollup": "^4.18.1",
"sloc": "^0.2.1",
"ts-node": "^10.9.1",
"ts-patch": "^3.2.1",
"typescript": "^5.5.2"
},
"dependencies": {
"@nestia/core": "^3.3.2",
"@nestia/e2e": "^0.6.0",
"@nestia/fetcher": "^3.3.2",
"@nestjs/common": "^10.2.8",
"@nestjs/core": "^10.2.8",
"@nestjs/platform-fastify": "^10.2.8",
"@nestia/core": "^3.7.0",
"@nestia/e2e": "^0.7.0",
"@nestia/fetcher": "^3.7.0",
"@nestjs/common": "^10.3.10",
"@nestjs/core": "^10.3.10",
"@nestjs/platform-fastify": "^10.3.10",
"atob": "^2.1.2",
"btoa": "^1.2.1",
"fastify": "^4.24.3",
"serialize-error": "^4.1.0",
"source-map-support": "^0.5.19",
"tstl": "^3.0.0",
"typescript-transform-paths": "^3.4.6",
"typia": "^6.3.1",
"uuid": "^9.0.0"
"typia": "^6.5.0",
"uuid": "^10.0.0"
},
"keywords": [
"toss",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ npm install --save iamport-server-api

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

- **Swagger Editor**: [packages/iamport-server-api/swagger.json](https://stackblitz.com/edit/5jpnps?file=README.md,test%2Fstart.ts&startScript=swagger&startScript=hello)
- **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)
- 자료 구조: [src/api/structures/IIamportPayment.ts](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server/src/api/structures/IIamportPayment.ts)
- API 함수: [src/api/functional/payments/index.ts](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server/src/api/functional/payments/index.ts)
- 예제 코드
Expand Down
29 changes: 29 additions & 0 deletions packages/fake-iamport-server/packages/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "iamport-server-api",
"version": "8.1.0",
"description": "API for Iamport Server",
"main": "lib/index.js",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/samchon/payments"
},
"author": "Jeongho Nam",
"license": "MIT",
"bugs": {
"url": "https://github.com/samchon/payments/issues"
},
"homepage": "https://github.com/samchon/payments",
"files": [
"lib",
"package.json",
"swagger.json",
"README.md"
],
"dependencies": {
"@nestia/fetcher": "^3.7.0",
"tstl": "^3.0.0",
"typia": "^6.5.0"
}
}
29 changes: 29 additions & 0 deletions packages/fake-iamport-server/packages/api/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const typescript = require("@rollup/plugin-typescript");
const terser = require("@rollup/plugin-terser");

module.exports = {
input: `${__dirname}/../../src/api/index.ts`,
output: {
dir: `${__dirname}/lib`,
format: "esm",
entryFileNames: "[name].mjs",
sourcemap: true,
},
plugins: [
typescript({
tsconfig: `${__dirname}/tsconfig.json`,
module: "ESNext",
target: "ESNext",
}),
terser({
format: {
comments: "some",
beautify: true,
ecma: "2020",
},
compress: false,
mangle: false,
module: true,
}),
],
};
Loading
Loading
0