diff --git a/package.json b/package.json index cfad611da..3bb6338ea 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,5 @@ "prettier": "^3.2.4", "rimraf": "^5.0.1", "sloc": "^0.3.0" - }, - "dependencies": { - "@nestia/migrate": "^0.18.2", - "@stackblitz/sdk": "^1.11.0" } } diff --git a/packages/editor/package.json b/packages/editor/package.json index 0fea44cb1..acbb5c21b 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -1,6 +1,6 @@ { "name": "@nestia/editor", - "version": "0.5.0", + "version": "0.5.1", "typings": "lib/index.d.ts", "main": "lib/index.js", "module": "lib/index.mjs", diff --git a/packages/editor/src/internal/NestiaEditorComposer.ts b/packages/editor/src/internal/NestiaEditorComposer.ts index 48d1c48ca..efc50a152 100644 --- a/packages/editor/src/internal/NestiaEditorComposer.ts +++ b/packages/editor/src/internal/NestiaEditorComposer.ts @@ -1,7 +1,7 @@ import { MigrateApplication } from "@nestia/migrate"; import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi"; -import prettierEsTreePlugin from "prettier/plugins/estree"; -import prettierTsPlugin from "prettier/plugins/typescript"; +import * as prettierEsTreePlugin from "prettier/plugins/estree"; +import * as prettierTsPlugin from "prettier/plugins/typescript"; import { format } from "prettier/standalone"; import { IValidation } from "typia"; @@ -67,7 +67,9 @@ export namespace NestiaEditorComposer { parser: "typescript", plugins: [prettierEsTreePlugin, prettierTsPlugin], }); - } catch {} + } catch (exp) { + console.log(exp); + } return { success: true, data: { diff --git a/website/package-lock.json b/website/package-lock.json index 1739eb8fc..25803d2c5 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -14,7 +14,8 @@ "@mui/icons-material": "5.15.6", "@mui/material": "5.15.6", "@mui/system": "5.15.6", - "@nestia/editor": "0.3.0", + "@nestia/editor": "^0.5.1", + "jszip": "^3.10.1", "next": "14.2.13", "nextra": "^2.13.4", "nextra-theme-docs": "^2.13.4", @@ -1068,9 +1069,9 @@ } }, "node_modules/@nestia/editor": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@nestia/editor/-/editor-0.3.0.tgz", - "integrity": "sha512-daAeLCdQliJxDL/bpaNVowkbTI2bMDkeQ/AIoK7/HnpbuC/D/hZu0Gg5sStS0XyOTsUAcywnCTC0euRAdqGbxQ==", + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@nestia/editor/-/editor-0.5.1.tgz", + "integrity": "sha512-95VEBe3Hp5/0H89WMgaCmm3Ck+857TSTTmcqWWSnBZ3aSJAFTMapyhZFmaYXjL3aAydTgbHyidS11YXx0lhVog==", "dependencies": { "@mui/material": "^5.15.6", "@nestia/migrate": "^0.18.2", @@ -3774,6 +3775,11 @@ } ] }, + "node_modules/immediate": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==" + }, "node_modules/import-fresh": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", @@ -4040,6 +4046,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -4106,6 +4117,44 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jszip": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", + "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", + "dependencies": { + "lie": "~3.3.0", + "pako": "~1.0.2", + "readable-stream": "~2.3.6", + "setimmediate": "^1.0.5" + } + }, + "node_modules/jszip/node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/jszip/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "node_modules/jszip/node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, "node_modules/katex": { "version": "0.16.11", "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.11.tgz", @@ -4155,6 +4204,14 @@ "resolved": "https://registry.npmjs.org/layout-base/-/layout-base-1.0.2.tgz", "integrity": "sha512-8h2oVEZNktL4BH2JCOI90iD1yXwL6iNW7KcCKT2QZgQJR2vbqDsldCTPRU9NifTCqHZci57XvQQ15YTu+sTYPg==" }, + "node_modules/lie": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", + "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "dependencies": { + "immediate": "~3.0.5" + } + }, "node_modules/lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", @@ -6108,6 +6165,11 @@ "resolved": "https://registry.npmjs.org/package-manager-detector/-/package-manager-detector-0.2.2.tgz", "integrity": "sha512-VgXbyrSNsml4eHWIvxxG/nTL4wgybMTXCV2Un/+yEc3aDKKU6nQBZjbeP3Pl3qm9Qg92X/1ng4ffvCeD/zwHgg==" }, + "node_modules/pako": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" + }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -6358,6 +6420,11 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + }, "node_modules/prop-types": { "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", @@ -7026,6 +7093,11 @@ "semver": "bin/semver.js" } }, + "node_modules/setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==" + }, "node_modules/shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", diff --git a/website/package.json b/website/package.json index 7580f051e..e604a543b 100644 --- a/website/package.json +++ b/website/package.json @@ -23,7 +23,7 @@ "@mui/icons-material": "5.15.6", "@mui/material": "5.15.6", "@mui/system": "5.15.6", - "@nestia/editor": "0.5.0", + "@nestia/editor": "^0.5.1", "jszip": "^3.10.1", "next": "14.2.13", "nextra": "^2.13.4", diff --git a/website/src/functional/EditorComposer.ts b/website/src/functional/EditorComposer.ts deleted file mode 100644 index a44e69f04..000000000 --- a/website/src/functional/EditorComposer.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { MigrateApplication } from "@nestia/migrate"; -import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi"; -import StackBlitz from "@stackblitz/sdk"; -import prettierEsTreePlugin from "prettier/plugins/estree"; -import prettierTsPlugin from "prettier/plugins/typescript"; -import { format } from "prettier/standalone"; -import { IValidation } from "typia"; - -export namespace EditorComposer { - export interface IProps { - title?: string | undefined | null; - swagger: - | SwaggerV2.IDocument - | OpenApiV3.IDocument - | OpenApiV3_1.IDocument - | string; - e2e: boolean; - simulate: boolean; - } - - export const nest = (props: IProps) => - compose({ - openFile: "README.md,test/start.ts", - startScript: ["build:test,test", ""], - migrate: (app) => app.nest(props), - })(props); - - export const sdk = (props: IProps) => - compose({ - openFile: "README.md,test/start.ts", - startScript: ["swagger", "hello"], - migrate: (app) => app.sdk(props), - })(props); - - const compose = - (config: { - openFile: string; - startScript: string[]; - migrate: (app: MigrateApplication) => MigrateApplication.IOutput; - }) => - async (props: IProps): Promise => { - const input: - | SwaggerV2.IDocument - | OpenApiV3.IDocument - | OpenApiV3_1.IDocument = - typeof props.swagger === "string" - ? await download(props.swagger) - : props.swagger; - const result: IValidation = - await MigrateApplication.create(input); - if (result.success === false) - throw new Error( - "Invalid swagger file (based on OpenAPI 3.0 spec).\n\n" + - JSON.stringify(result.errors, null, 2), - ); - - const app: MigrateApplication = result.data; - const { files } = config.migrate(app); - for (const f of files) - if (f.file.substring(f.file.length - 3) === ".ts") - f.content = await format(f.content, { - parser: "typescript", - plugins: [prettierEsTreePlugin, prettierTsPlugin], - }); - - StackBlitz.openProject( - { - title: - props.title ?? input.info?.title ?? "TypeScript Swagger Editor", - template: "node", - files: Object.fromEntries( - files.map( - (f) => - [ - [f.location, f.location.length ? "/" : "", f.file].join(""), - f.content, - ] as const, - ), - ), - }, - { - newWindow: true, - openFile: config.openFile, - startScript: config.startScript as any, - }, - ); - }; - - const download = async ( - url: string, - ): Promise< - SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument - > => { - const response: Response = await fetch(url); - const text: string = await response.text(); - return JSON.parse(text); - }; -}