@nestia/editor 10.0.1 → 11.0.0-dev.20260305
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +93 -93
- package/package.json +32 -23
- package/src/NestiaEditorApplication.tsx +94 -94
- package/src/NestiaEditorIframe.tsx +245 -245
- package/src/NestiaEditorModule.ts +130 -130
- package/src/NestiaEditorUploader.tsx +154 -154
- package/src/index.ts +2 -2
- package/src/internal/NestiaEditorComposer.ts +81 -82
- package/src/internal/NestiaEditorFileUploader.tsx +68 -68
- package/src/main.tsx +10 -10
- package/src/vite-env.d.ts +1 -1
- package/dist/assets/index-B4dcJE1c.js +0 -4953
- package/dist/index.html +0 -19
- package/lib/NestiaEditorApplication.d.ts +0 -1
- package/lib/NestiaEditorApplication.js +0 -161
- package/lib/NestiaEditorApplication.js.map +0 -1
- package/lib/NestiaEditorIframe.d.ts +0 -11
- package/lib/NestiaEditorIframe.js +0 -245
- package/lib/NestiaEditorIframe.js.map +0 -1
- package/lib/NestiaEditorModule.d.ts +0 -30
- package/lib/NestiaEditorModule.js +0 -229
- package/lib/NestiaEditorModule.js.map +0 -1
- package/lib/NestiaEditorUploader.d.ts +0 -6
- package/lib/NestiaEditorUploader.js +0 -135
- package/lib/NestiaEditorUploader.js.map +0 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -19
- package/lib/index.js.map +0 -1
- package/lib/index.mjs +0 -390
- package/lib/index.mjs.map +0 -1
- package/lib/internal/NestiaEditorComposer.d.ts +0 -18
- package/lib/internal/NestiaEditorComposer.js +0 -200
- package/lib/internal/NestiaEditorComposer.js.map +0 -1
- package/lib/internal/NestiaEditorFileUploader.d.ts +0 -7
- package/lib/internal/NestiaEditorFileUploader.js +0 -98
- package/lib/internal/NestiaEditorFileUploader.js.map +0 -1
- package/lib/main.d.ts +0 -1
- package/lib/main.js +0 -8
- package/lib/main.js.map +0 -1
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
import type { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@
|
|
2
|
-
import * as fs from "fs";
|
|
3
|
-
|
|
4
|
-
export namespace NestiaEditorModule {
|
|
5
|
-
export const setup = async (props: {
|
|
6
|
-
path: string;
|
|
7
|
-
application: INestApplication;
|
|
8
|
-
swagger:
|
|
9
|
-
| string
|
|
10
|
-
| SwaggerV2.IDocument
|
|
11
|
-
| OpenApiV3.IDocument
|
|
12
|
-
| OpenApiV3_1.IDocument;
|
|
13
|
-
package?: string;
|
|
14
|
-
simulate?: boolean;
|
|
15
|
-
e2e?: boolean;
|
|
16
|
-
}): Promise<void> => {
|
|
17
|
-
const prefix: string =
|
|
18
|
-
"/" +
|
|
19
|
-
[getGlobalPrefix(props.application), props.path]
|
|
20
|
-
.join("/")
|
|
21
|
-
.split("/")
|
|
22
|
-
.filter((str) => str.length !== 0)
|
|
23
|
-
.join("/");
|
|
24
|
-
const adaptor: INestHttpAdaptor = props.application.getHttpAdapter();
|
|
25
|
-
const staticFiles: IStaticFile[] = [
|
|
26
|
-
{
|
|
27
|
-
path: "/index.html",
|
|
28
|
-
type: "text/html",
|
|
29
|
-
content: await getIndex(props),
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
path: "/swagger.json",
|
|
33
|
-
type: "application/json",
|
|
34
|
-
content: JSON.stringify(
|
|
35
|
-
typeof props.swagger === "string"
|
|
36
|
-
? await getSwagger(props.swagger)
|
|
37
|
-
: props.swagger,
|
|
38
|
-
null,
|
|
39
|
-
2,
|
|
40
|
-
),
|
|
41
|
-
},
|
|
42
|
-
await getJavaScript(),
|
|
43
|
-
];
|
|
44
|
-
for (const f of staticFiles) {
|
|
45
|
-
adaptor.get(prefix + f.path, (_: any, res: any) => {
|
|
46
|
-
res.type(f.type);
|
|
47
|
-
return res.send(f.content);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
for (const p of ["", "/"])
|
|
51
|
-
adaptor.get(prefix + p, (_: any, res: any) => {
|
|
52
|
-
return res.redirect(prefix + "/index.html");
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const getGlobalPrefix = (app: INestApplication): string =>
|
|
57
|
-
typeof (app as any).config?.globalPrefix === "string"
|
|
58
|
-
? (app as any).config.globalPrefix
|
|
59
|
-
: "";
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
interface INestApplication {
|
|
63
|
-
use(...args: any[]): this;
|
|
64
|
-
getUrl(): Promise<string>;
|
|
65
|
-
getHttpAdapter(): INestHttpAdaptor;
|
|
66
|
-
setGlobalPrefix(prefix: string, options?: any): this;
|
|
67
|
-
}
|
|
68
|
-
interface INestHttpAdaptor {
|
|
69
|
-
getType(): string;
|
|
70
|
-
close(): any;
|
|
71
|
-
init?(): Promise<void>;
|
|
72
|
-
get: Function;
|
|
73
|
-
post: Function;
|
|
74
|
-
put: Function;
|
|
75
|
-
patch: Function;
|
|
76
|
-
delete: Function;
|
|
77
|
-
head: Function;
|
|
78
|
-
all: Function;
|
|
79
|
-
}
|
|
80
|
-
interface IStaticFile {
|
|
81
|
-
path: string;
|
|
82
|
-
type: string;
|
|
83
|
-
content: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const getIndex = async (props: {
|
|
87
|
-
package?: string;
|
|
88
|
-
simulate?: boolean;
|
|
89
|
-
e2e?: boolean;
|
|
90
|
-
}): Promise<string> => {
|
|
91
|
-
const content: string = await fs.promises.readFile(
|
|
92
|
-
`${__dirname}/../dist/index.html`,
|
|
93
|
-
"utf8",
|
|
94
|
-
);
|
|
95
|
-
return content
|
|
96
|
-
.replace(
|
|
97
|
-
`"@ORGANIZATION/PROJECT"`,
|
|
98
|
-
JSON.stringify(props.package ?? "@ORGANIZATION/PROJECT"),
|
|
99
|
-
)
|
|
100
|
-
.replace("window.simulate = false", `window.simulate = ${!!props.simulate}`)
|
|
101
|
-
.replace("window.e2e = false", `window.e2e = ${!!props.e2e}`);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const getJavaScript = async (): Promise<IStaticFile> => {
|
|
105
|
-
const directory: string[] = await fs.promises.readdir(
|
|
106
|
-
`${__dirname}/../dist/assets`,
|
|
107
|
-
);
|
|
108
|
-
const path: string | undefined = directory[0];
|
|
109
|
-
if (path === undefined)
|
|
110
|
-
throw new Error("Unreachable code, no JS file exists.");
|
|
111
|
-
return {
|
|
112
|
-
path: `/assets/${path}`,
|
|
113
|
-
type: "application/javascript",
|
|
114
|
-
content: await fs.promises.readFile(
|
|
115
|
-
`${__dirname}/../dist/assets/${path}`,
|
|
116
|
-
"utf8",
|
|
117
|
-
),
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const getSwagger = async (
|
|
122
|
-
url: string,
|
|
123
|
-
): Promise<
|
|
124
|
-
SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument
|
|
125
|
-
> => {
|
|
126
|
-
const response: Response = await fetch(url);
|
|
127
|
-
if (response.status !== 200)
|
|
128
|
-
throw new Error(`Failed to fetch Swagger document from ${url}`);
|
|
129
|
-
return response.json();
|
|
130
|
-
};
|
|
1
|
+
import type { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@typia/interface";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
|
|
4
|
+
export namespace NestiaEditorModule {
|
|
5
|
+
export const setup = async (props: {
|
|
6
|
+
path: string;
|
|
7
|
+
application: INestApplication;
|
|
8
|
+
swagger:
|
|
9
|
+
| string
|
|
10
|
+
| SwaggerV2.IDocument
|
|
11
|
+
| OpenApiV3.IDocument
|
|
12
|
+
| OpenApiV3_1.IDocument;
|
|
13
|
+
package?: string;
|
|
14
|
+
simulate?: boolean;
|
|
15
|
+
e2e?: boolean;
|
|
16
|
+
}): Promise<void> => {
|
|
17
|
+
const prefix: string =
|
|
18
|
+
"/" +
|
|
19
|
+
[getGlobalPrefix(props.application), props.path]
|
|
20
|
+
.join("/")
|
|
21
|
+
.split("/")
|
|
22
|
+
.filter((str) => str.length !== 0)
|
|
23
|
+
.join("/");
|
|
24
|
+
const adaptor: INestHttpAdaptor = props.application.getHttpAdapter();
|
|
25
|
+
const staticFiles: IStaticFile[] = [
|
|
26
|
+
{
|
|
27
|
+
path: "/index.html",
|
|
28
|
+
type: "text/html",
|
|
29
|
+
content: await getIndex(props),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
path: "/swagger.json",
|
|
33
|
+
type: "application/json",
|
|
34
|
+
content: JSON.stringify(
|
|
35
|
+
typeof props.swagger === "string"
|
|
36
|
+
? await getSwagger(props.swagger)
|
|
37
|
+
: props.swagger,
|
|
38
|
+
null,
|
|
39
|
+
2,
|
|
40
|
+
),
|
|
41
|
+
},
|
|
42
|
+
await getJavaScript(),
|
|
43
|
+
];
|
|
44
|
+
for (const f of staticFiles) {
|
|
45
|
+
adaptor.get(prefix + f.path, (_: any, res: any) => {
|
|
46
|
+
res.type(f.type);
|
|
47
|
+
return res.send(f.content);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
for (const p of ["", "/"])
|
|
51
|
+
adaptor.get(prefix + p, (_: any, res: any) => {
|
|
52
|
+
return res.redirect(prefix + "/index.html");
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getGlobalPrefix = (app: INestApplication): string =>
|
|
57
|
+
typeof (app as any).config?.globalPrefix === "string"
|
|
58
|
+
? (app as any).config.globalPrefix
|
|
59
|
+
: "";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface INestApplication {
|
|
63
|
+
use(...args: any[]): this;
|
|
64
|
+
getUrl(): Promise<string>;
|
|
65
|
+
getHttpAdapter(): INestHttpAdaptor;
|
|
66
|
+
setGlobalPrefix(prefix: string, options?: any): this;
|
|
67
|
+
}
|
|
68
|
+
interface INestHttpAdaptor {
|
|
69
|
+
getType(): string;
|
|
70
|
+
close(): any;
|
|
71
|
+
init?(): Promise<void>;
|
|
72
|
+
get: Function;
|
|
73
|
+
post: Function;
|
|
74
|
+
put: Function;
|
|
75
|
+
patch: Function;
|
|
76
|
+
delete: Function;
|
|
77
|
+
head: Function;
|
|
78
|
+
all: Function;
|
|
79
|
+
}
|
|
80
|
+
interface IStaticFile {
|
|
81
|
+
path: string;
|
|
82
|
+
type: string;
|
|
83
|
+
content: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const getIndex = async (props: {
|
|
87
|
+
package?: string;
|
|
88
|
+
simulate?: boolean;
|
|
89
|
+
e2e?: boolean;
|
|
90
|
+
}): Promise<string> => {
|
|
91
|
+
const content: string = await fs.promises.readFile(
|
|
92
|
+
`${__dirname}/../dist/index.html`,
|
|
93
|
+
"utf8",
|
|
94
|
+
);
|
|
95
|
+
return content
|
|
96
|
+
.replace(
|
|
97
|
+
`"@ORGANIZATION/PROJECT"`,
|
|
98
|
+
JSON.stringify(props.package ?? "@ORGANIZATION/PROJECT"),
|
|
99
|
+
)
|
|
100
|
+
.replace("window.simulate = false", `window.simulate = ${!!props.simulate}`)
|
|
101
|
+
.replace("window.e2e = false", `window.e2e = ${!!props.e2e}`);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const getJavaScript = async (): Promise<IStaticFile> => {
|
|
105
|
+
const directory: string[] = await fs.promises.readdir(
|
|
106
|
+
`${__dirname}/../dist/assets`,
|
|
107
|
+
);
|
|
108
|
+
const path: string | undefined = directory[0];
|
|
109
|
+
if (path === undefined)
|
|
110
|
+
throw new Error("Unreachable code, no JS file exists.");
|
|
111
|
+
return {
|
|
112
|
+
path: `/assets/${path}`,
|
|
113
|
+
type: "application/javascript",
|
|
114
|
+
content: await fs.promises.readFile(
|
|
115
|
+
`${__dirname}/../dist/assets/${path}`,
|
|
116
|
+
"utf8",
|
|
117
|
+
),
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const getSwagger = async (
|
|
122
|
+
url: string,
|
|
123
|
+
): Promise<
|
|
124
|
+
SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument
|
|
125
|
+
> => {
|
|
126
|
+
const response: Response = await fetch(url);
|
|
127
|
+
if (response.status !== 200)
|
|
128
|
+
throw new Error(`Failed to fetch Swagger document from ${url}`);
|
|
129
|
+
return response.json();
|
|
130
|
+
};
|
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Button,
|
|
3
|
-
FormControl,
|
|
4
|
-
FormControlLabel,
|
|
5
|
-
FormLabel,
|
|
6
|
-
Radio,
|
|
7
|
-
RadioGroup,
|
|
8
|
-
Switch,
|
|
9
|
-
TextField,
|
|
10
|
-
} from "@mui/material";
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import React from "react";
|
|
14
|
-
|
|
15
|
-
import { NestiaEditorComposer } from "./internal/NestiaEditorComposer";
|
|
16
|
-
import { NestiaEditorFileUploader } from "./internal/NestiaEditorFileUploader";
|
|
17
|
-
|
|
18
|
-
export function NestiaEditorUploader(props: NestiaEditorUploader.IProps) {
|
|
19
|
-
// PARAMETERS
|
|
20
|
-
const [mode, setMode] = React.useState<"nest" | "sdk">("sdk");
|
|
21
|
-
const [keyword, setKeyword] = React.useState(true);
|
|
22
|
-
const [simulate, setSimulate] = React.useState(true);
|
|
23
|
-
const [e2e, setE2e] = React.useState(true);
|
|
24
|
-
const [name, setName] = React.useState("@ORGINIZATION/PROJECT");
|
|
25
|
-
|
|
26
|
-
// RESULT
|
|
27
|
-
const [document, setDocument] = React.useState<
|
|
28
|
-
SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument | null
|
|
29
|
-
>(null);
|
|
30
|
-
const [progress, setProgress] = React.useState(false);
|
|
31
|
-
|
|
32
|
-
const handleError = (error: string) => {
|
|
33
|
-
if (props.onError) props.onError(error);
|
|
34
|
-
else alert(error);
|
|
35
|
-
};
|
|
36
|
-
const handleSwagger = (
|
|
37
|
-
document:
|
|
38
|
-
| SwaggerV2.IDocument
|
|
39
|
-
| OpenApiV3.IDocument
|
|
40
|
-
| OpenApiV3_1.IDocument
|
|
41
|
-
| null,
|
|
42
|
-
error: string | null,
|
|
43
|
-
) => {
|
|
44
|
-
setDocument(document);
|
|
45
|
-
if (error !== null) handleError(error);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const generate = async () => {
|
|
49
|
-
if (document === null) return;
|
|
50
|
-
|
|
51
|
-
setProgress(true);
|
|
52
|
-
try {
|
|
53
|
-
const result = await NestiaEditorComposer[mode]({
|
|
54
|
-
document,
|
|
55
|
-
keyword,
|
|
56
|
-
e2e,
|
|
57
|
-
simulate,
|
|
58
|
-
package: name,
|
|
59
|
-
});
|
|
60
|
-
if (result.success === true) {
|
|
61
|
-
StackBlitzSDK.openProject(
|
|
62
|
-
{
|
|
63
|
-
title: document.info?.title ?? "Nestia Editor",
|
|
64
|
-
template: "node",
|
|
65
|
-
files: result.data.files,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
newWindow: true,
|
|
69
|
-
openFile: result.data.openFile,
|
|
70
|
-
startScript: result.data.startScript as any,
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
} else {
|
|
74
|
-
handleError(JSON.stringify(result.errors, null, 2));
|
|
75
|
-
}
|
|
76
|
-
} catch (exp) {
|
|
77
|
-
handleError(exp instanceof Error ? exp.message : "unknown error");
|
|
78
|
-
}
|
|
79
|
-
setProgress(false);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<>
|
|
84
|
-
<NestiaEditorFileUploader onChange={handleSwagger} />
|
|
85
|
-
<br />
|
|
86
|
-
<FormControl fullWidth style={{ paddingLeft: 15 }}>
|
|
87
|
-
<TextField
|
|
88
|
-
onChange={(e) => setName(e.target.value)}
|
|
89
|
-
defaultValue={name}
|
|
90
|
-
label="Package Name"
|
|
91
|
-
variant="outlined"
|
|
92
|
-
/>
|
|
93
|
-
<FormLabel style={{ paddingTop: 20 }}> Mode </FormLabel>
|
|
94
|
-
<RadioGroup
|
|
95
|
-
defaultValue={mode}
|
|
96
|
-
onChange={(_e, value) => setMode(value as "nest" | "sdk")}
|
|
97
|
-
style={{ paddingLeft: 15 }}
|
|
98
|
-
>
|
|
99
|
-
<FormControlLabel
|
|
100
|
-
value="sdk"
|
|
101
|
-
control={<Radio />}
|
|
102
|
-
label="Software Development Kit"
|
|
103
|
-
/>
|
|
104
|
-
<FormControlLabel
|
|
105
|
-
value="nest"
|
|
106
|
-
control={<Radio />}
|
|
107
|
-
label="NestJS Project"
|
|
108
|
-
/>
|
|
109
|
-
</RadioGroup>
|
|
110
|
-
<FormLabel style={{ paddingTop: 20 }}> Options </FormLabel>
|
|
111
|
-
<FormControlLabel
|
|
112
|
-
label="Keyword Parameter"
|
|
113
|
-
style={{ paddingTop: 5, paddingLeft: 15 }}
|
|
114
|
-
control={
|
|
115
|
-
<Switch checked={keyword} onChange={() => setKeyword(!keyword)} />
|
|
116
|
-
}
|
|
117
|
-
/>
|
|
118
|
-
<FormControlLabel
|
|
119
|
-
label="Mockup Simulator"
|
|
120
|
-
style={{ paddingTop: 5, paddingLeft: 15 }}
|
|
121
|
-
control={
|
|
122
|
-
<Switch
|
|
123
|
-
checked={simulate}
|
|
124
|
-
onChange={() => setSimulate(!simulate)}
|
|
125
|
-
/>
|
|
126
|
-
}
|
|
127
|
-
/>
|
|
128
|
-
<FormControlLabel
|
|
129
|
-
label="E2E Test Functions"
|
|
130
|
-
style={{ paddingLeft: 15 }}
|
|
131
|
-
control={<Switch checked={e2e} onChange={() => setE2e(!e2e)} />}
|
|
132
|
-
/>
|
|
133
|
-
</FormControl>
|
|
134
|
-
<br />
|
|
135
|
-
<br />
|
|
136
|
-
<Button
|
|
137
|
-
component="a"
|
|
138
|
-
fullWidth
|
|
139
|
-
variant="contained"
|
|
140
|
-
color={"info"}
|
|
141
|
-
size="large"
|
|
142
|
-
disabled={progress === true || document === null}
|
|
143
|
-
onClick={() => generate()}
|
|
144
|
-
>
|
|
145
|
-
{progress ? "Generating..." : "Generate Editor"}
|
|
146
|
-
</Button>
|
|
147
|
-
</>
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
export namespace NestiaEditorUploader {
|
|
151
|
-
export interface IProps {
|
|
152
|
-
onError?: (error: string) => void;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
FormControl,
|
|
4
|
+
FormControlLabel,
|
|
5
|
+
FormLabel,
|
|
6
|
+
Radio,
|
|
7
|
+
RadioGroup,
|
|
8
|
+
Switch,
|
|
9
|
+
TextField,
|
|
10
|
+
} from "@mui/material";
|
|
11
|
+
import StackBlitzSDK from "@stackblitz/sdk";
|
|
12
|
+
import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@typia/interface";
|
|
13
|
+
import React from "react";
|
|
14
|
+
|
|
15
|
+
import { NestiaEditorComposer } from "./internal/NestiaEditorComposer";
|
|
16
|
+
import { NestiaEditorFileUploader } from "./internal/NestiaEditorFileUploader";
|
|
17
|
+
|
|
18
|
+
export function NestiaEditorUploader(props: NestiaEditorUploader.IProps) {
|
|
19
|
+
// PARAMETERS
|
|
20
|
+
const [mode, setMode] = React.useState<"nest" | "sdk">("sdk");
|
|
21
|
+
const [keyword, setKeyword] = React.useState(true);
|
|
22
|
+
const [simulate, setSimulate] = React.useState(true);
|
|
23
|
+
const [e2e, setE2e] = React.useState(true);
|
|
24
|
+
const [name, setName] = React.useState("@ORGINIZATION/PROJECT");
|
|
25
|
+
|
|
26
|
+
// RESULT
|
|
27
|
+
const [document, setDocument] = React.useState<
|
|
28
|
+
SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument | null
|
|
29
|
+
>(null);
|
|
30
|
+
const [progress, setProgress] = React.useState(false);
|
|
31
|
+
|
|
32
|
+
const handleError = (error: string) => {
|
|
33
|
+
if (props.onError) props.onError(error);
|
|
34
|
+
else alert(error);
|
|
35
|
+
};
|
|
36
|
+
const handleSwagger = (
|
|
37
|
+
document:
|
|
38
|
+
| SwaggerV2.IDocument
|
|
39
|
+
| OpenApiV3.IDocument
|
|
40
|
+
| OpenApiV3_1.IDocument
|
|
41
|
+
| null,
|
|
42
|
+
error: string | null,
|
|
43
|
+
) => {
|
|
44
|
+
setDocument(document);
|
|
45
|
+
if (error !== null) handleError(error);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const generate = async () => {
|
|
49
|
+
if (document === null) return;
|
|
50
|
+
|
|
51
|
+
setProgress(true);
|
|
52
|
+
try {
|
|
53
|
+
const result = await NestiaEditorComposer[mode]({
|
|
54
|
+
document,
|
|
55
|
+
keyword,
|
|
56
|
+
e2e,
|
|
57
|
+
simulate,
|
|
58
|
+
package: name,
|
|
59
|
+
});
|
|
60
|
+
if (result.success === true) {
|
|
61
|
+
StackBlitzSDK.openProject(
|
|
62
|
+
{
|
|
63
|
+
title: document.info?.title ?? "Nestia Editor",
|
|
64
|
+
template: "node",
|
|
65
|
+
files: result.data.files,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
newWindow: true,
|
|
69
|
+
openFile: result.data.openFile,
|
|
70
|
+
startScript: result.data.startScript as any,
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
} else {
|
|
74
|
+
handleError(JSON.stringify(result.errors, null, 2));
|
|
75
|
+
}
|
|
76
|
+
} catch (exp) {
|
|
77
|
+
handleError(exp instanceof Error ? exp.message : "unknown error");
|
|
78
|
+
}
|
|
79
|
+
setProgress(false);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<>
|
|
84
|
+
<NestiaEditorFileUploader onChange={handleSwagger} />
|
|
85
|
+
<br />
|
|
86
|
+
<FormControl fullWidth style={{ paddingLeft: 15 }}>
|
|
87
|
+
<TextField
|
|
88
|
+
onChange={(e) => setName(e.target.value)}
|
|
89
|
+
defaultValue={name}
|
|
90
|
+
label="Package Name"
|
|
91
|
+
variant="outlined"
|
|
92
|
+
/>
|
|
93
|
+
<FormLabel style={{ paddingTop: 20 }}> Mode </FormLabel>
|
|
94
|
+
<RadioGroup
|
|
95
|
+
defaultValue={mode}
|
|
96
|
+
onChange={(_e, value) => setMode(value as "nest" | "sdk")}
|
|
97
|
+
style={{ paddingLeft: 15 }}
|
|
98
|
+
>
|
|
99
|
+
<FormControlLabel
|
|
100
|
+
value="sdk"
|
|
101
|
+
control={<Radio />}
|
|
102
|
+
label="Software Development Kit"
|
|
103
|
+
/>
|
|
104
|
+
<FormControlLabel
|
|
105
|
+
value="nest"
|
|
106
|
+
control={<Radio />}
|
|
107
|
+
label="NestJS Project"
|
|
108
|
+
/>
|
|
109
|
+
</RadioGroup>
|
|
110
|
+
<FormLabel style={{ paddingTop: 20 }}> Options </FormLabel>
|
|
111
|
+
<FormControlLabel
|
|
112
|
+
label="Keyword Parameter"
|
|
113
|
+
style={{ paddingTop: 5, paddingLeft: 15 }}
|
|
114
|
+
control={
|
|
115
|
+
<Switch checked={keyword} onChange={() => setKeyword(!keyword)} />
|
|
116
|
+
}
|
|
117
|
+
/>
|
|
118
|
+
<FormControlLabel
|
|
119
|
+
label="Mockup Simulator"
|
|
120
|
+
style={{ paddingTop: 5, paddingLeft: 15 }}
|
|
121
|
+
control={
|
|
122
|
+
<Switch
|
|
123
|
+
checked={simulate}
|
|
124
|
+
onChange={() => setSimulate(!simulate)}
|
|
125
|
+
/>
|
|
126
|
+
}
|
|
127
|
+
/>
|
|
128
|
+
<FormControlLabel
|
|
129
|
+
label="E2E Test Functions"
|
|
130
|
+
style={{ paddingLeft: 15 }}
|
|
131
|
+
control={<Switch checked={e2e} onChange={() => setE2e(!e2e)} />}
|
|
132
|
+
/>
|
|
133
|
+
</FormControl>
|
|
134
|
+
<br />
|
|
135
|
+
<br />
|
|
136
|
+
<Button
|
|
137
|
+
component="a"
|
|
138
|
+
fullWidth
|
|
139
|
+
variant="contained"
|
|
140
|
+
color={"info"}
|
|
141
|
+
size="large"
|
|
142
|
+
disabled={progress === true || document === null}
|
|
143
|
+
onClick={() => generate()}
|
|
144
|
+
>
|
|
145
|
+
{progress ? "Generating..." : "Generate Editor"}
|
|
146
|
+
</Button>
|
|
147
|
+
</>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
export namespace NestiaEditorUploader {
|
|
151
|
+
export interface IProps {
|
|
152
|
+
onError?: (error: string) => void;
|
|
153
|
+
}
|
|
154
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./NestiaEditorIframe";
|
|
2
|
-
export * from "./NestiaEditorUploader";
|
|
1
|
+
export * from "./NestiaEditorIframe";
|
|
2
|
+
export * from "./NestiaEditorUploader";
|