flowdoc-gen 0.1.3 → 0.1.5

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/index.cjs CHANGED
@@ -38,6 +38,10 @@ __export(src_exports, {
38
38
  });
39
39
  module.exports = __toCommonJS(src_exports);
40
40
 
41
+ // ../../node_modules/.pnpm/tsup@8.5.1_jiti@1.21.7_postcss@8.5.15_tsx@4.22.4_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
42
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
43
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
44
+
41
45
  // src/generate.ts
42
46
  var import_fs3 = require("fs");
43
47
  var import_path3 = require("path");
@@ -1111,7 +1115,6 @@ var matchesGlob = (path, pattern) => {
1111
1115
  var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
1112
1116
 
1113
1117
  // src/generate.ts
1114
- var import_meta = {};
1115
1118
  var generate = async (opts = {}) => {
1116
1119
  const cwd = process.cwd();
1117
1120
  const spinner = opts.quiet ? null : (0, import_ora.default)();
@@ -1164,7 +1167,7 @@ var writeUiHtml = async (outputDir, config) => {
1164
1167
  const brand = config.theme?.brand ?? "#6366f1";
1165
1168
  const title = config.name;
1166
1169
  const darkMode = config.theme?.darkMode !== false;
1167
- const cliRoot = (0, import_path3.dirname)((0, import_path3.dirname)((0, import_url.fileURLToPath)(import_meta.url)));
1170
+ const cliRoot = (0, import_path3.dirname)((0, import_path3.dirname)((0, import_url.fileURLToPath)(importMetaUrl)));
1168
1171
  const uiAssetsSource = (0, import_path3.join)(cliRoot, "ui-assets");
1169
1172
  const uiAssetsDest = (0, import_path3.join)(outputDir, "assets");
1170
1173
  if ((0, import_fs3.existsSync)(uiAssetsSource)) {
@@ -1323,7 +1326,6 @@ var init = (cwd = process.cwd()) => {
1323
1326
  var import_fs6 = require("fs");
1324
1327
  var import_path6 = require("path");
1325
1328
  var import_url2 = require("url");
1326
- var import_meta2 = {};
1327
1329
  var MIME = {
1328
1330
  ".html": "text/html",
1329
1331
  ".js": "application/javascript",
@@ -1331,6 +1333,7 @@ var MIME = {
1331
1333
  ".json": "application/json"
1332
1334
  };
1333
1335
  var flowdoc = (opts = {}) => {
1336
+ const disabled = opts.disabled ?? process.env.NODE_ENV === "production";
1334
1337
  const cwd = process.cwd();
1335
1338
  let outputDir = null;
1336
1339
  let ready = false;
@@ -1346,7 +1349,7 @@ var flowdoc = (opts = {}) => {
1346
1349
  const spec = buildSpec(routes, config);
1347
1350
  (0, import_fs6.mkdirSync)(outputDir, { recursive: true });
1348
1351
  (0, import_fs6.writeFileSync)((0, import_path6.join)(outputDir, "flowdoc.json"), JSON.stringify(spec, null, 2));
1349
- const cliRoot = (0, import_path6.dirname)((0, import_path6.dirname)((0, import_url2.fileURLToPath)(import_meta2.url)));
1352
+ const cliRoot = (0, import_path6.dirname)((0, import_path6.dirname)((0, import_url2.fileURLToPath)(importMetaUrl)));
1350
1353
  const uiAssetsSource = (0, import_path6.join)(cliRoot, "ui-assets");
1351
1354
  if ((0, import_fs6.existsSync)(uiAssetsSource)) {
1352
1355
  const dest = (0, import_path6.join)(outputDir, "assets");
@@ -1359,6 +1362,10 @@ var flowdoc = (opts = {}) => {
1359
1362
  }
1360
1363
  })();
1361
1364
  return async (req, res, next) => {
1365
+ if (disabled) {
1366
+ res.status(403).send("API docs are not available in this environment.");
1367
+ return;
1368
+ }
1362
1369
  await init2;
1363
1370
  if (initError || !outputDir) {
1364
1371
  res.status(500).send(`flowdoc init failed: ${initError}`);
@@ -1368,8 +1375,9 @@ var flowdoc = (opts = {}) => {
1368
1375
  if (urlPath === "/index.html") {
1369
1376
  const brand = "#6366f1";
1370
1377
  const baseUrl = `${req.protocol}://${req.get("host")}`;
1378
+ const docsBase = req.baseUrl || "";
1371
1379
  res.setHeader("Content-Type", "text/html");
1372
- res.send(buildHtml({ baseUrl, brand }));
1380
+ res.send(buildHtml({ baseUrl, brand, docsBase }));
1373
1381
  return;
1374
1382
  }
1375
1383
  const filePath = (0, import_path6.join)(outputDir, urlPath);
@@ -1382,7 +1390,7 @@ var flowdoc = (opts = {}) => {
1382
1390
  (0, import_fs6.createReadStream)(filePath).pipe(res);
1383
1391
  };
1384
1392
  };
1385
- var buildHtml = ({ baseUrl, brand }) => `<!DOCTYPE html>
1393
+ var buildHtml = ({ baseUrl, brand, docsBase }) => `<!DOCTYPE html>
1386
1394
  <html lang="en" class="dark">
1387
1395
  <head>
1388
1396
  <meta charset="UTF-8" />
@@ -1391,9 +1399,10 @@ var buildHtml = ({ baseUrl, brand }) => `<!DOCTYPE html>
1391
1399
  <script>
1392
1400
  window.__FLOWDOC_BRAND__ = "${brand}";
1393
1401
  window.__FLOWDOC_BASE_URL__ = "${baseUrl}";
1402
+ window.__FLOWDOC_DOCS_BASE__ = "${docsBase}";
1394
1403
  </script>
1395
- <script type="module" crossorigin src="./assets/ui.js"></script>
1396
- <link rel="stylesheet" href="./assets/index.css" />
1404
+ <script type="module" crossorigin src="${docsBase}/assets/ui.js"></script>
1405
+ <link rel="stylesheet" href="${docsBase}/assets/index.css" />
1397
1406
  </head>
1398
1407
  <body><div id="root"></div></body>
1399
1408
  </html>`;
package/dist/index.d.cts CHANGED
@@ -131,6 +131,13 @@ interface FlowDocMiddlewareOptions {
131
131
  config?: string;
132
132
  /** Route prefix the middleware is mounted at — used only for the HTML shell */
133
133
  path?: string;
134
+ /**
135
+ * Disable the docs endpoint. Useful for production environments.
136
+ * Defaults to `process.env.NODE_ENV === "production"` when not set,
137
+ * meaning docs are served in development and blocked in production.
138
+ * Pass `false` to explicitly enable in production; `true` to always block.
139
+ */
140
+ disabled?: boolean;
134
141
  }
135
142
  /**
136
143
  * Express middleware that serves flowdoc docs at whatever route you mount it on.
package/dist/index.d.ts CHANGED
@@ -131,6 +131,13 @@ interface FlowDocMiddlewareOptions {
131
131
  config?: string;
132
132
  /** Route prefix the middleware is mounted at — used only for the HTML shell */
133
133
  path?: string;
134
+ /**
135
+ * Disable the docs endpoint. Useful for production environments.
136
+ * Defaults to `process.env.NODE_ENV === "production"` when not set,
137
+ * meaning docs are served in development and blocked in production.
138
+ * Pass `false` to explicitly enable in production; `true` to always block.
139
+ */
140
+ disabled?: boolean;
134
141
  }
135
142
  /**
136
143
  * Express middleware that serves flowdoc docs at whatever route you mount it on.
package/dist/index.js CHANGED
@@ -1293,6 +1293,7 @@ var MIME = {
1293
1293
  ".json": "application/json"
1294
1294
  };
1295
1295
  var flowdoc = (opts = {}) => {
1296
+ const disabled = opts.disabled ?? process.env.NODE_ENV === "production";
1296
1297
  const cwd = process.cwd();
1297
1298
  let outputDir = null;
1298
1299
  let ready = false;
@@ -1321,6 +1322,10 @@ var flowdoc = (opts = {}) => {
1321
1322
  }
1322
1323
  })();
1323
1324
  return async (req, res, next) => {
1325
+ if (disabled) {
1326
+ res.status(403).send("API docs are not available in this environment.");
1327
+ return;
1328
+ }
1324
1329
  await init2;
1325
1330
  if (initError || !outputDir) {
1326
1331
  res.status(500).send(`flowdoc init failed: ${initError}`);
@@ -1330,8 +1335,9 @@ var flowdoc = (opts = {}) => {
1330
1335
  if (urlPath === "/index.html") {
1331
1336
  const brand = "#6366f1";
1332
1337
  const baseUrl = `${req.protocol}://${req.get("host")}`;
1338
+ const docsBase = req.baseUrl || "";
1333
1339
  res.setHeader("Content-Type", "text/html");
1334
- res.send(buildHtml({ baseUrl, brand }));
1340
+ res.send(buildHtml({ baseUrl, brand, docsBase }));
1335
1341
  return;
1336
1342
  }
1337
1343
  const filePath = join5(outputDir, urlPath);
@@ -1344,7 +1350,7 @@ var flowdoc = (opts = {}) => {
1344
1350
  createReadStream2(filePath).pipe(res);
1345
1351
  };
1346
1352
  };
1347
- var buildHtml = ({ baseUrl, brand }) => `<!DOCTYPE html>
1353
+ var buildHtml = ({ baseUrl, brand, docsBase }) => `<!DOCTYPE html>
1348
1354
  <html lang="en" class="dark">
1349
1355
  <head>
1350
1356
  <meta charset="UTF-8" />
@@ -1353,9 +1359,10 @@ var buildHtml = ({ baseUrl, brand }) => `<!DOCTYPE html>
1353
1359
  <script>
1354
1360
  window.__FLOWDOC_BRAND__ = "${brand}";
1355
1361
  window.__FLOWDOC_BASE_URL__ = "${baseUrl}";
1362
+ window.__FLOWDOC_DOCS_BASE__ = "${docsBase}";
1356
1363
  </script>
1357
- <script type="module" crossorigin src="./assets/ui.js"></script>
1358
- <link rel="stylesheet" href="./assets/index.css" />
1364
+ <script type="module" crossorigin src="${docsBase}/assets/ui.js"></script>
1365
+ <link rel="stylesheet" href="${docsBase}/assets/index.css" />
1359
1366
  </head>
1360
1367
  <body><div id="root"></div></body>
1361
1368
  </html>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowdoc-gen",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Auto-generate beautiful API documentation from your Express codebase — no annotations required",
5
5
  "type": "module",
6
6
  "bin": {