prisma-swagger-autogen 1.0.8 → 1.0.10

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/dist/bin.cjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("./cli.cjs");
@@ -1,8 +1,33 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
1
26
  // src/index.ts
2
- import fs from "fs";
3
- import path from "path";
4
- import { createRequire } from "module";
5
- import { globSync } from "glob";
27
+ var import_node_fs = __toESM(require("fs"), 1);
28
+ var import_node_path = __toESM(require("path"), 1);
29
+ var import_node_module = require("module");
30
+ var import_glob = require("glob");
6
31
  var CONFIG = {
7
32
  projectRoot: process.cwd(),
8
33
  controllersGlob: "./src/web/api/controllers/**/*.ts",
@@ -19,21 +44,21 @@ var CONFIG = {
19
44
  omitFieldsInWriteDtos: /* @__PURE__ */ new Set(["id", "createdAt", "updatedAt", "v"])
20
45
  };
21
46
  function ensurePosix(p) {
22
- return p.split(path.sep).join(path.posix.sep);
47
+ return p.split(import_node_path.default.sep).join(import_node_path.default.posix.sep);
23
48
  }
24
49
  function pluralize(name) {
25
50
  if (name.endsWith("s")) return `${name}es`;
26
51
  return `${name}s`;
27
52
  }
28
53
  function getRequire() {
29
- return createRequire(typeof __filename !== "undefined" ? __filename : process.cwd() + "/");
54
+ return (0, import_node_module.createRequire)(typeof __filename !== "undefined" ? __filename : process.cwd() + "/");
30
55
  }
31
56
  async function loadDmmfFromProject(schemaPath) {
32
- const resolvedSchemaPath = schemaPath ? path.resolve(process.cwd(), schemaPath) : path.resolve(process.cwd(), "prisma/schema.prisma");
33
- if (!fs.existsSync(resolvedSchemaPath)) {
57
+ const resolvedSchemaPath = schemaPath ? import_node_path.default.resolve(process.cwd(), schemaPath) : import_node_path.default.resolve(process.cwd(), "prisma/schema.prisma");
58
+ if (!import_node_fs.default.existsSync(resolvedSchemaPath)) {
34
59
  throw new Error(`Prisma schema not found at ${resolvedSchemaPath}`);
35
60
  }
36
- const datamodel = fs.readFileSync(resolvedSchemaPath, "utf8");
61
+ const datamodel = import_node_fs.default.readFileSync(resolvedSchemaPath, "utf8");
37
62
  const require2 = getRequire();
38
63
  const internals = require2("@prisma/internals");
39
64
  if (typeof internals.getDMMF !== "function") {
@@ -154,7 +179,7 @@ async function buildSchemasFromPrismaDmmf(schemaPath) {
154
179
  return schemas;
155
180
  }
156
181
  function generateSwaggerConfigJs(schemas) {
157
- const routes = globSync(CONFIG.controllersGlob, { nodir: true }).map((p) => ensurePosix(p));
182
+ const routes = (0, import_glob.globSync)(CONFIG.controllersGlob, { nodir: true }).map((p) => ensurePosix(p));
158
183
  const docs = {
159
184
  info: { title: CONFIG.serviceTitle },
160
185
  servers: [{ url: CONFIG.serverUrl }],
@@ -180,7 +205,7 @@ function generateSwaggerConfigJs(schemas) {
180
205
  const docs = ${JSON.stringify(docs, null, 2)};
181
206
  const routes = ${JSON.stringify(routes, null, 2)};
182
207
  swaggerAutogen('${ensurePosix(CONFIG.openapiOut)}', routes, docs);`;
183
- fs.writeFileSync(path.resolve(CONFIG.projectRoot, CONFIG.outFile), fileContent, "utf8");
208
+ import_node_fs.default.writeFileSync(import_node_path.default.resolve(CONFIG.projectRoot, CONFIG.outFile), fileContent, "utf8");
184
209
  }
185
210
  async function run(args = []) {
186
211
  const schemaFlagIndex = args.findIndex((a) => a === "--schema");
@@ -194,5 +219,3 @@ void run(process.argv.slice(2)).catch((e) => {
194
219
  console.error(e);
195
220
  process.exitCode = 1;
196
221
  });
197
- ss.exitCode = 1;
198
- });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-swagger-autogen",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Generate swagger-autogen config + Prisma DMMF schemas and fix swagger-autogen output.",
5
5
  "license": "MIT",
6
6
  "author": "Joyce Marvin Rafflenbeul",
@@ -35,11 +35,12 @@
35
35
  },
36
36
  "files": [
37
37
  "dist",
38
+ "scripts/make-bin.cjs",
38
39
  "README.md",
39
40
  "LICENSE"
40
41
  ],
41
42
  "scripts": {
42
- "build": "tsup src/index.ts --format esm,cjs --dts --out-dir dist && tsup src/cli.ts --format esm --out-dir dist --no-dts",
43
+ "build": "tsup src/index.ts --format esm,cjs --dts --out-dir dist --tsconfig tsconfig.json && tsup src/cli.ts --format cjs --out-dir dist --no-dts --tsconfig tsconfig.json && node scripts/make-bin.cjs",
43
44
  "prepublishOnly": "npm run build"
44
45
  },
45
46
  "dependencies": {
@@ -0,0 +1,14 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const distDir = path.resolve(__dirname, "../dist");
5
+ fs.mkdirSync(distDir, { recursive: true });
6
+
7
+ const out = path.join(distDir, "bin.cjs");
8
+
9
+ const content = `#!/usr/bin/env node
10
+ require("./cli.cjs");
11
+ `;
12
+
13
+ fs.writeFileSync(out, content, "utf8");
14
+ try { fs.chmodSync(out, 0o755); } catch {}