Skip to content
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

Add @samchon/openapi types to playground editor. #1200

Merged
merged 1 commit into from
Aug 6, 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
32 changes: 20 additions & 12 deletions website/build/raw.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
const fs = require("fs");

const emendName = (name) =>
name.replaceAll("@", "_at_").replaceAll("/", "_slash_");

const external = (container) => (config) => (lib) => {
const write = (variable) => (file) => (content) =>
fs.writeFileSync(
file,
`export const ${variable}: string = ${JSON.stringify(content)};`,
`export const ${variable.replace("@", "_dollar_")}: string = ${JSON.stringify(content)};`,
"utf8",
);

const packageJson = () => {
const location = `${__dirname}/../node_modules/${lib}/package.json`;
const directory = `${__dirname}/../raw/${lib}`;
fs.mkdirSync(directory);
fs.mkdirSync(directory, { recursive: true });

if (config.packageJson) {
write(`${lib}_packageJson`)(`${directory}/packageJson.ts`)(
write(`${emendName(lib)}_packageJson`)(`${directory}/packageJson.ts`)(
fs.readFileSync(location, "utf8"),
);
container.push({
format: "json",
name: `${lib}_packageJson`,
name: `${emendName(lib)}_packageJson`,
import: `./${lib}/packageJson`,
url: `file:///node_modules/${lib}/package.json`,
});
Expand All @@ -40,7 +43,7 @@ const external = (container) => (config) => (lib) => {
// CHECK DIRECTORY AND EXTENSION
const stats = fs.statSync(from);
if (stats.isDirectory()) {
fs.mkdirSync(link);
fs.mkdirSync(link, { recursive: true });
iterate(location);
continue;
} else if (
Expand All @@ -53,7 +56,7 @@ const external = (container) => (config) => (lib) => {
// COPY TEXT FILE
const extension = location.endsWith(".d.ts") ? ".d.ts" : ".js";
const alias = `${lib}/${location.replace(extension, extension === ".d.ts" ? "_d_ts" : "_js")}`;
const name = alias.split("/").join("_").split(".").join("_");
const name = emendName(alias.split("/").join("_").split(".").join("_"));
const content = fs.readFileSync(from, "utf8");
write(name)(
link.replace(extension, extension === ".d.ts" ? "_d_ts.ts" : "_js.ts"),
Expand All @@ -68,19 +71,19 @@ const external = (container) => (config) => (lib) => {
};
return (path) => {
if (path.length) {
fs.mkdirSync(`${__dirname}/../raw/${lib}/${path}`);
fs.mkdirSync(`${__dirname}/../raw/${lib}/${path}`, { recursive: true });
if (config.index) {
write(`${lib}_index`)(`${__dirname}/../raw/${lib}/index.ts`)(
write(`${emendName(lib)}_index`)(`${__dirname}/../raw/${lib}/index.ts`)(
[
`import * as ${lib} from "./${path}";`,
`import * as ${emendName(lib)} from "./${path}";`,
`export * from "./${path}";`,
`export default ${lib};`,
`export default ${emendName(lib)};`,
].join("\n"),
);
container.push({
format: "ts",
import: `./${lib}/index`,
name: `${lib}_index`,
name: `${emendName(lib)}_index`,
url: `file:///node_modules/${lib}/index.d.ts`,
});
}
Expand All @@ -92,17 +95,22 @@ const external = (container) => (config) => (lib) => {
// PREPARE DIRECTORIES
if (fs.existsSync(__dirname + "/../raw"))
fs.rmSync(__dirname + "/../raw", { recursive: true });
fs.mkdirSync(__dirname + "/../raw");
fs.mkdirSync(__dirname + "/../raw", { recursive: true });

//----
// CLONE DEFINITIONS
//----
// CREATE RAW TEXT FILES
const bucket = [];
external(bucket)({
index: true,
packageJson: true,
javaScript: false,
})("@samchon/openapi")("lib");
external(bucket)({
index: true,
packageJson: true,
javaScript: false,
})("typia")("lib");
external(bucket)({
packageJson: false,
Expand Down
9 changes: 5 additions & 4 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@mui/icons-material": "^5.15.4",
"@mui/material": "^5.12.0",
"@rollup/browser": "^4.13.0",
"@samchon/openapi": "^0.4.3",
"lz-string": "^1.5.0",
"monaco-editor": "^0.50.0",
"next": "^14.2.3",
Expand Down
4 changes: 1 addition & 3 deletions website/src/compilers/TypeScriptCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export namespace TypeScriptCompiler {
file.startsWith("node_modules/") && file.endsWith("/package.json")
? RAW.find((r) => r[0] === `file:///${file}`)![1]
: undefined,
getSourceFile: (file: string) => {
return dict.get(file);
},
getSourceFile: (file: string) => dict.get(file),

// ADDITIONAL OPTIONS
getDefaultLibFileName: () =>
Expand Down