Skip to content

Commit

Permalink
Configurable package name at editor and migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Oct 31, 2024
1 parent f4c3520 commit 2c22348
Show file tree
Hide file tree
Showing 19 changed files with 655 additions and 80 deletions.
5 changes: 5 additions & 0 deletions packages/editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
</head>
<body style="width: 100%; height: 100%; margin: 0px; overflow: hidden;">
<div id="root" style="width: 100%; height: 100%"></div>
<script>
window.package = "@ORGANIZATION/PROJECT";
window.simulate = false;
window.e2e = false;
</script>
<script type="module" src="src/main.tsx"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/editor",
"version": "0.5.1",
"version": "0.6.2",
"typings": "lib/index.d.ts",
"main": "lib/index.js",
"module": "lib/index.mjs",
Expand Down Expand Up @@ -33,7 +33,7 @@
"homepage": "https://nestia.io",
"dependencies": {
"@mui/material": "^5.15.6",
"@nestia/migrate": "^0.18.2",
"@nestia/migrate": "^0.19.0",
"@stackblitz/sdk": "^1.11.0",
"js-yaml": "^4.1.0",
"prettier": "^3.3.3",
Expand Down
21 changes: 15 additions & 6 deletions packages/editor/src/NestiaEditorApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export function NestiaEditorApplication() {
return asset !== null ? (
<NestiaEditorIframe
swagger={asset.url}
package={asset.package}
simulate={asset.simulate}
e2e={asset.e2e}
mode={asset.mode}
/>
) : (
<div
Expand All @@ -51,15 +53,21 @@ async function getAsset(): Promise<IAsset | null> {
(await findSwagger("./swagger.yaml"));
if (url === null) return null;

const simulate: string | null = query.get("simulate");
const e2e: string | null = query.get("e2e");
const mode: string | null = query.get("mode");
const packageName: string | null =
query.get("package") ?? (window as any).package;
const simulate: boolean | string | null =
query.get("simulate") ?? (window as any).simulate;
const e2e: boolean | string | null = query.get("e2e") ?? (window as any).e2e;
return {
mode: mode === "nest" ? "nest" : "sdk",
package: packageName ?? "@ORGANIZATION/PROJECT",
url,
simulate:
simulate !== null ? simulate === "true" || simulate === "1" : false,
e2e: e2e !== null ? e2e === "true" || e2e === "1" : false,
mode: mode === "nest" ? "nest" : "sdk",
simulate !== null
? simulate === true || simulate === "true" || simulate === "1"
: false,
e2e: e2e !== null ? e2e === true || e2e === "true" || e2e === "1" : false,
};
}

Expand All @@ -69,8 +77,9 @@ async function findSwagger(file: string): Promise<string | null> {
}

interface IAsset {
mode: "nest" | "sdk";
package: string;
url: string;
simulate: boolean;
e2e: boolean;
mode: "nest" | "sdk";
}
2 changes: 2 additions & 0 deletions packages/editor/src/NestiaEditorIframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function NestiaEditorIframe(props: NestiaEditorIframe.IProps) {
document,
simulate: props.simulate ?? true,
e2e: props.e2e ?? true,
package: props.package ?? "@ORGANIZATION/PROJECT",
});
} catch (exp) {
return {
Expand Down Expand Up @@ -189,6 +190,7 @@ export namespace NestiaEditorIframe {
| SwaggerV2.IDocument
| OpenApiV3.IDocument
| OpenApiV3_1.IDocument;
package?: string;
simulate?: boolean;
e2e?: boolean;

Expand Down
11 changes: 10 additions & 1 deletion packages/editor/src/NestiaEditorUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Radio,
RadioGroup,
Switch,
TextField,
} from "@mui/material";
import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
import StackBlitzSDK from "@stackblitz/sdk";
Expand All @@ -19,6 +20,7 @@ export function NestiaEditorUploader(props: NestiaEditorUploader.IProps) {
const [mode, setMode] = React.useState<"nest" | "sdk">("sdk");
const [simulate, setSimulate] = React.useState(true);
const [e2e, setE2e] = React.useState(true);
const [name, setName] = React.useState("@ORGINIZATION/PROJECT");

// RESULT
const [document, setDocument] = React.useState<
Expand Down Expand Up @@ -51,6 +53,7 @@ export function NestiaEditorUploader(props: NestiaEditorUploader.IProps) {
document,
e2e,
simulate,
package: name,
});
if (result.success === true) {
StackBlitzSDK.openProject(
Expand Down Expand Up @@ -79,7 +82,13 @@ export function NestiaEditorUploader(props: NestiaEditorUploader.IProps) {
<NestiaEditorFileUploader onChange={handleSwagger} />
<br />
<FormControl fullWidth style={{ paddingLeft: 15 }}>
<FormLabel> Mode </FormLabel>
<TextField
onChange={(e) => setName(e.target.value)}
defaultValue={name}
label="Package Name"
variant="outlined"
/>
<FormLabel style={{ paddingTop: 20 }}> Mode </FormLabel>
<RadioGroup
defaultValue={mode}
onChange={(_e, value) => setMode(value as "nest" | "sdk")}
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/internal/NestiaEditorComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export namespace NestiaEditorComposer {
document: SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument;
e2e: boolean;
simulate: boolean;
package?: string;
/**
* @internal
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/tsconfig.app.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/nestiaeditorapplication.tsx","./src/nestiaeditoriframe.tsx","./src/nestiaeditoruploader.tsx","./src/index.ts","./src/main.tsx","./src/vite-env.d.ts","./src/internal/nestiaeditorcomposer.ts","./src/internal/nestiaeditorfileuploader.tsx"],"version":"5.6.3"}
{"root":["./src/nestiaeditorapplication.tsx","./src/nestiaeditoriframe.tsx","./src/nestiaeditoruploader.tsx","./src/index.ts","./src/main.tsx","./src/vite-env.d.ts","./src/internal/nestiaeditorcomposer.ts","./src/internal/nestiaeditorfileuploader.tsx"],"errors":true,"version":"5.6.3"}
Loading

0 comments on commit 2c22348

Please sign in to comment.