Skip to content

Commit

Permalink
Merge pull request #1166 from samchon/feat/migrate
Browse files Browse the repository at this point in the history
Fix `@nestia/migrate` bug and support `@HumanRoute()`
  • Loading branch information
samchon authored Dec 18, 2024
2 parents d6d4411 + 9b85aec commit 27a5e2c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
12 changes: 5 additions & 7 deletions deploy/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ const setup = ({ tag, name, directory, version }) => {
fs.writeFileSync(file, JSON.stringify(info, null, 2), "utf8");
if (fs.existsSync(`${directory}/package-lock.json`))
fs.rmSync(`${directory}/package-lock.json`);
try {
execute({
cwd: directory,
script: `npm publish --tag ${tag} --access public${tag === "latest" ? " --provenance" : ""}`,
studio: "ignore",
});
} catch {}
execute({
cwd: directory,
script: `npm publish --tag ${tag} --access public${tag === "latest" ? " --provenance" : ""}`,
studio: "ignore",
});

// ROLLBACK THE PACKAGE.JSON
for (const r of rollbacks) r();
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": "@nestia/station",
"version": "4.5.0",
"version": "4.5.1",
"description": "Nestia station",
"scripts": {
"build": "node deploy build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export namespace MigrateNestControllerProgrammer {
[],
[],
controller.routes.map(
MigrateNestMethodProgrammer.write(components)(importer),
MigrateNestMethodProgrammer.write(components)(importer)(controller),
),
);
return [
Expand Down
26 changes: 24 additions & 2 deletions packages/migrate/src/programmers/MigrateNestMethodProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
import { TypeFactory } from "typia/lib/factories/TypeFactory";

import { IHttpMigrateController } from "../structures/IHttpMigrateController";
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
import { FilePrinter } from "../utils/FilePrinter";
import { StringUtil } from "../utils/StringUtil";
Expand All @@ -15,6 +16,7 @@ export namespace MigrateNestMethodProgrammer {
export const write =
(components: OpenApi.IComponents) =>
(importer: MigrateImportProgrammer) =>
(controller: IHttpMigrateController) =>
(route: IHttpMigrateRoute): ts.MethodDeclaration => {
const output: ts.TypeNode = route.success
? MigrateSchemaProgrammer.write(components)(importer)(
Expand All @@ -24,7 +26,7 @@ export namespace MigrateNestMethodProgrammer {

const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
[
...writeMethodDecorators(components)(importer)(route),
...writeMethodDecorators(components)(importer)(controller)(route),
ts.factory.createToken(ts.SyntaxKind.PublicKeyword),
ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
],
Expand Down Expand Up @@ -78,6 +80,7 @@ export namespace MigrateNestMethodProgrammer {
const writeMethodDecorators =
(components: OpenApi.IComponents) =>
(importer: MigrateImportProgrammer) =>
(controller: IHttpMigrateController) =>
(route: IHttpMigrateRoute): ts.Decorator[] => {
const external =
(lib: string) =>
Expand All @@ -99,7 +102,24 @@ export namespace MigrateNestMethodProgrammer {
),
);

// HUMAN-ONLY
if (route.operation()["x-samchon-human"] === true)
decorators.push(
ts.factory.createDecorator(
ts.factory.createCallExpression(
external("@nestia/core")("HumanRoute"),
undefined,
undefined,
),
),
);

// ROUTER
const localPath: string = route.emendedPath
.slice(controller.path.length)
.split("/")
.filter((str) => !!str.length)
.join("/");
const router = (instance: string) =>
ts.factory.createDecorator(
ts.factory.createCallExpression(
Expand All @@ -108,7 +128,9 @@ export namespace MigrateNestMethodProgrammer {
StringUtil.capitalize(route.method),
),
[],
[ts.factory.createStringLiteral(route.path)],
localPath.length
? [ts.factory.createStringLiteral(localPath)]
: undefined,
),
);
if (route.success?.["x-nestia-encrypted"])
Expand Down

0 comments on commit 27a5e2c

Please sign in to comment.