@elysiajs/openapi 1.3.10 → 1.3.12

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.
@@ -36,15 +36,16 @@ var fromTypes = (targetFilePath, {
36
36
  instanceName,
37
37
  projectRoot = process.cwd(),
38
38
  overrideOutputPath,
39
- debug = false
39
+ debug = false,
40
+ compilerOptions,
41
+ tmpRoot = (0, import_path.join)((0, import_os.tmpdir)(), ".ElysiaAutoOpenAPI")
40
42
  } = {}) => () => {
41
- const tmpRoot = (0, import_path.join)((0, import_os.tmpdir)(), ".ElysiaAutoOpenAPI");
42
43
  try {
43
44
  if (!targetFilePath.endsWith(".ts") && !targetFilePath.endsWith(".tsx"))
44
45
  throw new Error("Only .ts files are supported");
45
46
  if (targetFilePath.startsWith("./"))
46
47
  targetFilePath = targetFilePath.slice(2);
47
- const src = targetFilePath.startsWith("/") ? targetFilePath : (0, import_path.join)(projectRoot, targetFilePath);
48
+ let src = targetFilePath.startsWith("/") ? targetFilePath : (0, import_path.join)(projectRoot, targetFilePath);
48
49
  if (!(0, import_fs.existsSync)(src))
49
50
  throw new Error(
50
51
  `Couldn't find "${targetFilePath}" from ${projectRoot}`
@@ -56,22 +57,28 @@ var fromTypes = (targetFilePath, {
56
57
  (0, import_fs.rmSync)(tmpRoot, { recursive: true, force: true });
57
58
  (0, import_fs.mkdirSync)(tmpRoot, { recursive: true });
58
59
  const tsconfig = tsconfigPath.startsWith("/") ? tsconfigPath : (0, import_path.join)(projectRoot, tsconfigPath);
59
- const extendsRef = (0, import_fs.existsSync)(tsconfig) ? `"extends": "${(0, import_path.join)(projectRoot, "tsconfig.json")}",` : "";
60
+ let extendsRef = (0, import_fs.existsSync)(tsconfig) ? `"extends": "${(0, import_path.join)(projectRoot, "tsconfig.json")}",` : "";
61
+ let distDir = (0, import_path.join)(tmpRoot, "dist");
62
+ if (typeof process !== "undefined" && process.platform === "win32") {
63
+ extendsRef = extendsRef.replace(/\\/g, "/");
64
+ src = src.replace(/\\/g, "/");
65
+ distDir = distDir.replace(/\\/g, "/");
66
+ }
60
67
  (0, import_fs.writeFileSync)(
61
68
  (0, import_path.join)(tmpRoot, "tsconfig.json"),
62
69
  `{
63
70
  ${extendsRef}
64
- "compilerOptions": {
65
- "lib": ["ESNext"],
66
- "module": "ESNext",
67
- "noEmit": false,
68
- "declaration": true,
69
- "emitDeclarationOnly": true,
70
- "moduleResolution": "bundler",
71
- "skipLibCheck": true,
72
- "skipDefaultLibCheck": true,
73
- "outDir": "./dist"
74
- },
71
+ "compilerOptions": ${compilerOptions ? JSON.stringify(compilerOptions) : `{
72
+ "lib": ["ESNext"],
73
+ "module": "ESNext",
74
+ "noEmit": false,
75
+ "declaration": true,
76
+ "emitDeclarationOnly": true,
77
+ "moduleResolution": "bundler",
78
+ "skipLibCheck": true,
79
+ "skipDefaultLibCheck": true,
80
+ "outDir": "${distDir}"
81
+ }`},
75
82
  "include": ["${src}"]
76
83
  }`
77
84
  );
@@ -113,6 +120,11 @@ var fromTypes = (targetFilePath, {
113
120
  );
114
121
  console.warn(tempFiles);
115
122
  }
123
+ } else {
124
+ console.log(
125
+ "reason: root folter doesn't exists",
126
+ (0, import_path.join)(tmpRoot, "dist")
127
+ );
116
128
  }
117
129
  return;
118
130
  }
@@ -31,6 +31,21 @@ interface OpenAPIGeneratorOptions {
31
31
  * @default false
32
32
  */
33
33
  debug?: boolean;
34
+ /**
35
+ * compilerOptions
36
+ *
37
+ * Override tsconfig.json compilerOptions
38
+ */
39
+ compilerOptions?: Record<string, any>;
40
+ /**
41
+ * Temporary root
42
+ *
43
+ * a folder where temporary files are stored
44
+ * @default os.tmpdir()/.ElysiaAutoOpenAPI
45
+ *
46
+ * ! be careful that the folder will be removed after the process ends
47
+ */
48
+ tmpRoot?: string;
34
49
  }
35
50
  /**
36
51
  * Auto generate OpenAPI schema from Elysia instance
@@ -45,5 +60,5 @@ export declare const fromTypes: (
45
60
  *
46
61
  * The path must export an Elysia instance
47
62
  */
48
- targetFilePath: string, { tsconfigPath, instanceName, projectRoot, overrideOutputPath, debug }?: OpenAPIGeneratorOptions) => () => AdditionalReference | undefined;
63
+ targetFilePath: string, { tsconfigPath, instanceName, projectRoot, overrideOutputPath, debug, compilerOptions, tmpRoot }?: OpenAPIGeneratorOptions) => () => AdditionalReference | undefined;
49
64
  export {};
@@ -19,15 +19,16 @@ var fromTypes = (targetFilePath, {
19
19
  instanceName,
20
20
  projectRoot = process.cwd(),
21
21
  overrideOutputPath,
22
- debug = false
22
+ debug = false,
23
+ compilerOptions,
24
+ tmpRoot = join(tmpdir(), ".ElysiaAutoOpenAPI")
23
25
  } = {}) => () => {
24
- const tmpRoot = join(tmpdir(), ".ElysiaAutoOpenAPI");
25
26
  try {
26
27
  if (!targetFilePath.endsWith(".ts") && !targetFilePath.endsWith(".tsx"))
27
28
  throw new Error("Only .ts files are supported");
28
29
  if (targetFilePath.startsWith("./"))
29
30
  targetFilePath = targetFilePath.slice(2);
30
- const src = targetFilePath.startsWith("/") ? targetFilePath : join(projectRoot, targetFilePath);
31
+ let src = targetFilePath.startsWith("/") ? targetFilePath : join(projectRoot, targetFilePath);
31
32
  if (!existsSync(src))
32
33
  throw new Error(
33
34
  `Couldn't find "${targetFilePath}" from ${projectRoot}`
@@ -39,22 +40,28 @@ var fromTypes = (targetFilePath, {
39
40
  rmSync(tmpRoot, { recursive: true, force: true });
40
41
  mkdirSync(tmpRoot, { recursive: true });
41
42
  const tsconfig = tsconfigPath.startsWith("/") ? tsconfigPath : join(projectRoot, tsconfigPath);
42
- const extendsRef = existsSync(tsconfig) ? `"extends": "${join(projectRoot, "tsconfig.json")}",` : "";
43
+ let extendsRef = existsSync(tsconfig) ? `"extends": "${join(projectRoot, "tsconfig.json")}",` : "";
44
+ let distDir = join(tmpRoot, "dist");
45
+ if (typeof process !== "undefined" && process.platform === "win32") {
46
+ extendsRef = extendsRef.replace(/\\/g, "/");
47
+ src = src.replace(/\\/g, "/");
48
+ distDir = distDir.replace(/\\/g, "/");
49
+ }
43
50
  writeFileSync(
44
51
  join(tmpRoot, "tsconfig.json"),
45
52
  `{
46
53
  ${extendsRef}
47
- "compilerOptions": {
48
- "lib": ["ESNext"],
49
- "module": "ESNext",
50
- "noEmit": false,
51
- "declaration": true,
52
- "emitDeclarationOnly": true,
53
- "moduleResolution": "bundler",
54
- "skipLibCheck": true,
55
- "skipDefaultLibCheck": true,
56
- "outDir": "./dist"
57
- },
54
+ "compilerOptions": ${compilerOptions ? JSON.stringify(compilerOptions) : `{
55
+ "lib": ["ESNext"],
56
+ "module": "ESNext",
57
+ "noEmit": false,
58
+ "declaration": true,
59
+ "emitDeclarationOnly": true,
60
+ "moduleResolution": "bundler",
61
+ "skipLibCheck": true,
62
+ "skipDefaultLibCheck": true,
63
+ "outDir": "${distDir}"
64
+ }`},
58
65
  "include": ["${src}"]
59
66
  }`
60
67
  );
@@ -96,6 +103,11 @@ var fromTypes = (targetFilePath, {
96
103
  );
97
104
  console.warn(tempFiles);
98
105
  }
106
+ } else {
107
+ console.log(
108
+ "reason: root folter doesn't exists",
109
+ join(tmpRoot, "dist")
110
+ );
99
111
  }
100
112
  return;
101
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiajs/openapi",
3
- "version": "1.3.10",
3
+ "version": "1.3.12",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",