@revenexx/integrations-node-devkit 0.1.0 → 0.2.1

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/cli.cjs CHANGED
@@ -23,13 +23,66 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  mod
24
24
  ));
25
25
 
26
+ // node_modules/tsup/assets/cjs_shims.js
27
+ 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;
28
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
29
+
26
30
  // src/cli.ts
27
- var import_node_fs3 = require("fs");
31
+ var import_node_fs5 = require("fs");
28
32
  var import_node_http2 = require("http");
29
33
  var import_node_module = require("module");
30
- var import_node_path3 = require("path");
34
+ var import_node_path4 = require("path");
31
35
  var import_node_url2 = require("url");
32
36
 
37
+ // src/env.ts
38
+ var import_node_fs = require("fs");
39
+ var import_node_path = require("path");
40
+ var ENV_FILE_MIN_NODE = "20.12";
41
+ var NODE_OWNED_FLAGS = ["--env-file", "--env-file-if-exists"];
42
+ function nodeOwnedEnvFlag(argv) {
43
+ return NODE_OWNED_FLAGS.find((flag) => argv.includes(flag) || argv.some((arg) => arg.startsWith(`${flag}=`))) ?? null;
44
+ }
45
+ function resolveEnvFile(argv, cwd = process.cwd()) {
46
+ if (argv.includes("--no-env")) {
47
+ return { path: null, explicit: false };
48
+ }
49
+ const flag = argv.indexOf("--env");
50
+ if (flag === -1) {
51
+ return { path: (0, import_node_path.resolve)(cwd, ".env"), explicit: false };
52
+ }
53
+ const value = argv[flag + 1];
54
+ if (!value || value.startsWith("-")) {
55
+ throw new Error("--env requires a path.");
56
+ }
57
+ return { path: (0, import_node_path.resolve)(cwd, value), explicit: true };
58
+ }
59
+ function loadEnvFile(argv, options = {}) {
60
+ const { cwd = process.cwd(), warn = (message) => console.warn(message) } = options;
61
+ const nodeFlag = nodeOwnedEnvFlag(argv);
62
+ if (nodeFlag) {
63
+ warn(`Note: ${nodeFlag} is a Node flag and Node has already applied it. The devkit's own flag is --env <path>.`);
64
+ }
65
+ const { path, explicit } = resolveEnvFile(argv, cwd);
66
+ if (!path) {
67
+ return null;
68
+ }
69
+ if (!(0, import_node_fs.existsSync)(path)) {
70
+ if (explicit) {
71
+ throw new Error(`--env: ${path} does not exist.`);
72
+ }
73
+ return null;
74
+ }
75
+ if (typeof process.loadEnvFile !== "function") {
76
+ warn(`Ignoring ${path}: env-file support needs Node >= ${ENV_FILE_MIN_NODE} (running ${process.version}).`);
77
+ return null;
78
+ }
79
+ process.loadEnvFile(path);
80
+ return path;
81
+ }
82
+
83
+ // src/index.ts
84
+ var import_node_fs3 = require("fs");
85
+
33
86
  // src/errors.ts
34
87
  var DevApiError = class extends Error {
35
88
  constructor(status, message, errors) {
@@ -86,8 +139,8 @@ async function loadPackageFromEntry(entryPath) {
86
139
  }
87
140
 
88
141
  // src/persistence.ts
89
- var import_node_fs = require("fs");
90
- var import_node_path = require("path");
142
+ var import_node_fs2 = require("fs");
143
+ var import_node_path2 = require("path");
91
144
 
92
145
  // src/store.ts
93
146
  var import_node_crypto = require("crypto");
@@ -368,12 +421,12 @@ function applySeeds(store, seeds, env = process.env) {
368
421
  }
369
422
  }
370
423
  function loadState(file, log = console.warn) {
371
- if (!(0, import_node_fs.existsSync)(file)) {
424
+ if (!(0, import_node_fs2.existsSync)(file)) {
372
425
  return null;
373
426
  }
374
427
  let parsed;
375
428
  try {
376
- parsed = JSON.parse((0, import_node_fs.readFileSync)(file, "utf-8"));
429
+ parsed = JSON.parse((0, import_node_fs2.readFileSync)(file, "utf-8"));
377
430
  } catch {
378
431
  log(`Ignoring ${file}: not valid JSON.`);
379
432
  return null;
@@ -385,14 +438,14 @@ function loadState(file, log = console.warn) {
385
438
  return parsed;
386
439
  }
387
440
  function saveState(file, snapshot) {
388
- (0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(file), { recursive: true });
389
- (0, import_node_fs.writeFileSync)(file, JSON.stringify(snapshot, null, 2), "utf-8");
441
+ (0, import_node_fs2.mkdirSync)((0, import_node_path2.dirname)(file), { recursive: true });
442
+ (0, import_node_fs2.writeFileSync)(file, JSON.stringify(snapshot, null, 2), "utf-8");
390
443
  }
391
444
  var SEED_ENTRY_CANDIDATES = ["index.ts", "index.mjs", "index.js", "seeds.ts", "seeds.js"];
392
445
  async function loadSeedsFromDir(dir) {
393
446
  for (const candidate of SEED_ENTRY_CANDIDATES) {
394
- const path = (0, import_node_path.resolve)(dir, candidate);
395
- if ((0, import_node_fs.existsSync)(path)) {
447
+ const path = (0, import_node_path2.resolve)(dir, candidate);
448
+ if ((0, import_node_fs2.existsSync)(path)) {
396
449
  const mod = await importFresh(path);
397
450
  return mod.default ?? mod.seeds ?? {};
398
451
  }
@@ -1202,11 +1255,12 @@ async function handleWorkflows(req, res, method, store, seg) {
1202
1255
  }
1203
1256
 
1204
1257
  // src/index.ts
1205
- var DEVKIT_VERSION = "0.1.0";
1258
+ var manifestUrl = new URL("../package.json", importMetaUrl);
1259
+ var DEVKIT_VERSION = JSON.parse((0, import_node_fs3.readFileSync)(manifestUrl, "utf8")).version;
1206
1260
 
1207
1261
  // src/preview/scaffold.ts
1208
- var import_node_fs2 = require("fs");
1209
- var import_node_path2 = require("path");
1262
+ var import_node_fs4 = require("fs");
1263
+ var import_node_path3 = require("path");
1210
1264
 
1211
1265
  // src/preview/templates.ts
1212
1266
  var VERSIONS = {
@@ -1626,13 +1680,13 @@ function scaffoldPreview(options) {
1626
1680
  const written = [];
1627
1681
  const skipped = [];
1628
1682
  for (const [relative, content] of Object.entries(files)) {
1629
- const target = (0, import_node_path2.resolve)(options.dir, relative);
1630
- if ((0, import_node_fs2.existsSync)(target) && !options.force) {
1683
+ const target = (0, import_node_path3.resolve)(options.dir, relative);
1684
+ if ((0, import_node_fs4.existsSync)(target) && !options.force) {
1631
1685
  skipped.push(relative);
1632
1686
  continue;
1633
1687
  }
1634
- (0, import_node_fs2.mkdirSync)((0, import_node_path2.dirname)(target), { recursive: true });
1635
- (0, import_node_fs2.writeFileSync)(target, content, "utf-8");
1688
+ (0, import_node_fs4.mkdirSync)((0, import_node_path3.dirname)(target), { recursive: true });
1689
+ (0, import_node_fs4.writeFileSync)(target, content, "utf-8");
1636
1690
  written.push(relative);
1637
1691
  }
1638
1692
  if (written.length > 0) {
@@ -1644,26 +1698,25 @@ function scaffoldPreview(options) {
1644
1698
  return { dir: options.dir, written, skipped };
1645
1699
  }
1646
1700
  function previewDepsInstalled(dir) {
1647
- return (0, import_node_fs2.existsSync)((0, import_node_path2.join)(dir, "node_modules"));
1701
+ return (0, import_node_fs4.existsSync)((0, import_node_path3.join)(dir, "node_modules"));
1648
1702
  }
1649
1703
  function previewExists(dir) {
1650
- return (0, import_node_fs2.existsSync)((0, import_node_path2.join)(dir, "package.json")) && (0, import_node_fs2.existsSync)((0, import_node_path2.join)(dir, "nuxt.config.ts"));
1704
+ return (0, import_node_fs4.existsSync)((0, import_node_path3.join)(dir, "package.json")) && (0, import_node_fs4.existsSync)((0, import_node_path3.join)(dir, "nuxt.config.ts"));
1651
1705
  }
1652
1706
 
1653
1707
  // src/cli.ts
1654
- var import_meta = {};
1655
1708
  function parseArgs(argv) {
1656
1709
  const cwd = process.cwd();
1657
1710
  const opts = {
1658
1711
  entry: "",
1659
- seedDir: (0, import_node_path3.resolve)(cwd, "dev/seeds"),
1660
- stateFile: (0, import_node_path3.resolve)(cwd, ".revenexx-dev/state.json"),
1712
+ seedDir: (0, import_node_path4.resolve)(cwd, "dev/seeds"),
1713
+ stateFile: (0, import_node_path4.resolve)(cwd, ".revenexx-dev/state.json"),
1661
1714
  persist: true,
1662
1715
  port: Number.parseInt(process.env.PORT ?? "3555", 10),
1663
1716
  uiDir: null,
1664
1717
  serveUi: true,
1665
1718
  open: false,
1666
- previewDir: (0, import_node_path3.resolve)(cwd, ".revenexx-dev/preview"),
1719
+ previewDir: (0, import_node_path4.resolve)(cwd, ".revenexx-dev/preview"),
1667
1720
  force: false
1668
1721
  };
1669
1722
  let command = null;
@@ -1680,19 +1733,19 @@ function parseArgs(argv) {
1680
1733
  command = "preview";
1681
1734
  break;
1682
1735
  case "--dir":
1683
- opts.previewDir = (0, import_node_path3.resolve)(cwd, argv[++i] ?? "");
1736
+ opts.previewDir = (0, import_node_path4.resolve)(cwd, argv[++i] ?? "");
1684
1737
  break;
1685
1738
  case "--force":
1686
1739
  opts.force = true;
1687
1740
  break;
1688
1741
  case "--entry":
1689
- opts.entry = (0, import_node_path3.resolve)(cwd, argv[++i] ?? "");
1742
+ opts.entry = (0, import_node_path4.resolve)(cwd, argv[++i] ?? "");
1690
1743
  break;
1691
1744
  case "--seed":
1692
- opts.seedDir = (0, import_node_path3.resolve)(cwd, argv[++i] ?? "");
1745
+ opts.seedDir = (0, import_node_path4.resolve)(cwd, argv[++i] ?? "");
1693
1746
  break;
1694
1747
  case "--state":
1695
- opts.stateFile = (0, import_node_path3.resolve)(cwd, argv[++i] ?? "");
1748
+ opts.stateFile = (0, import_node_path4.resolve)(cwd, argv[++i] ?? "");
1696
1749
  break;
1697
1750
  case "--no-persist":
1698
1751
  opts.persist = false;
@@ -1701,7 +1754,7 @@ function parseArgs(argv) {
1701
1754
  opts.port = Number.parseInt(argv[++i] ?? "3555", 10);
1702
1755
  break;
1703
1756
  case "--ui":
1704
- opts.uiDir = (0, import_node_path3.resolve)(cwd, argv[++i] ?? "");
1757
+ opts.uiDir = (0, import_node_path4.resolve)(cwd, argv[++i] ?? "");
1705
1758
  break;
1706
1759
  case "--no-ui":
1707
1760
  opts.serveUi = false;
@@ -1709,11 +1762,24 @@ function parseArgs(argv) {
1709
1762
  case "--open":
1710
1763
  opts.open = true;
1711
1764
  break;
1765
+ // Both are consumed by loadEnvFile() before parsing; listed here so they
1766
+ // do not fall through to the unknown-option branch.
1767
+ case "--env":
1768
+ i++;
1769
+ break;
1770
+ case "--no-env":
1771
+ break;
1712
1772
  case "--version":
1713
1773
  case "-v":
1714
1774
  command = "version";
1715
1775
  break;
1716
1776
  default:
1777
+ if (arg?.startsWith("--env-file")) {
1778
+ if (!arg.includes("=")) {
1779
+ i++;
1780
+ }
1781
+ break;
1782
+ }
1717
1783
  if (arg?.startsWith("-")) {
1718
1784
  console.error(`Unknown option: ${arg}`);
1719
1785
  process.exit(1);
@@ -1721,23 +1787,23 @@ function parseArgs(argv) {
1721
1787
  }
1722
1788
  }
1723
1789
  if (!opts.entry) {
1724
- const src = (0, import_node_path3.resolve)(cwd, "src/index.ts");
1725
- opts.entry = (0, import_node_fs3.existsSync)(src) ? src : (0, import_node_path3.resolve)(cwd, "dist/index.js");
1790
+ const src = (0, import_node_path4.resolve)(cwd, "src/index.ts");
1791
+ opts.entry = (0, import_node_fs5.existsSync)(src) ? src : (0, import_node_path4.resolve)(cwd, "dist/index.js");
1726
1792
  }
1727
1793
  return { command, options: opts };
1728
1794
  }
1729
1795
  function loadSchemas() {
1730
- const here = (0, import_node_url2.fileURLToPath)(new URL(".", import_meta.url));
1731
- const schemasDir = (0, import_node_path3.resolve)(here, "..", "assets", "schemas");
1796
+ const here = (0, import_node_url2.fileURLToPath)(new URL(".", importMetaUrl));
1797
+ const schemasDir = (0, import_node_path4.resolve)(here, "..", "assets", "schemas");
1732
1798
  const schemas = {};
1733
- if (!(0, import_node_fs3.existsSync)(schemasDir)) {
1799
+ if (!(0, import_node_fs5.existsSync)(schemasDir)) {
1734
1800
  return schemas;
1735
1801
  }
1736
- for (const file of (0, import_node_fs3.readdirSync)(schemasDir)) {
1737
- if ((0, import_node_path3.extname)(file) !== ".json") {
1802
+ for (const file of (0, import_node_fs5.readdirSync)(schemasDir)) {
1803
+ if ((0, import_node_path4.extname)(file) !== ".json") {
1738
1804
  continue;
1739
1805
  }
1740
- const parsed = JSON.parse((0, import_node_fs3.readFileSync)((0, import_node_path3.join)(schemasDir, file), "utf-8"));
1806
+ const parsed = JSON.parse((0, import_node_fs5.readFileSync)((0, import_node_path4.join)(schemasDir, file), "utf-8"));
1741
1807
  const base = file.replace(/\.json$/, "");
1742
1808
  const dash = base.indexOf("-");
1743
1809
  if (dash > 0) {
@@ -1753,15 +1819,15 @@ function loadSchemas() {
1753
1819
  }
1754
1820
  function resolveUiDir(explicit) {
1755
1821
  if (explicit) {
1756
- return (0, import_node_fs3.existsSync)(explicit) ? explicit : null;
1822
+ return (0, import_node_fs5.existsSync)(explicit) ? explicit : null;
1757
1823
  }
1758
1824
  const candidates = ["@revenexx/studio-integrations"];
1759
- const req = (0, import_node_module.createRequire)(import_meta.url);
1825
+ const req = (0, import_node_module.createRequire)(importMetaUrl);
1760
1826
  for (const pkg of candidates) {
1761
1827
  try {
1762
1828
  const entry = req.resolve(`${pkg}/package.json`);
1763
- const dist = (0, import_node_path3.resolve)(entry, "..", "dist");
1764
- if ((0, import_node_fs3.existsSync)((0, import_node_path3.join)(dist, "index.html"))) {
1829
+ const dist = (0, import_node_path4.resolve)(entry, "..", "dist");
1830
+ if ((0, import_node_fs5.existsSync)((0, import_node_path4.join)(dist, "index.html"))) {
1765
1831
  return dist;
1766
1832
  }
1767
1833
  } catch {
@@ -1783,16 +1849,16 @@ var MIME = {
1783
1849
  function serveStatic(uiDir, req, res) {
1784
1850
  const url = new URL(req.url ?? "/", "http://localhost");
1785
1851
  const relative = url.pathname === "/" ? "index.html" : url.pathname.replace(/^\/+/, "");
1786
- let filePath = (0, import_node_path3.resolve)(uiDir, relative);
1787
- if (!filePath.startsWith(uiDir) || !(0, import_node_fs3.existsSync)(filePath)) {
1788
- filePath = (0, import_node_path3.join)(uiDir, "index.html");
1852
+ let filePath = (0, import_node_path4.resolve)(uiDir, relative);
1853
+ if (!filePath.startsWith(uiDir) || !(0, import_node_fs5.existsSync)(filePath)) {
1854
+ filePath = (0, import_node_path4.join)(uiDir, "index.html");
1789
1855
  }
1790
- if (!(0, import_node_fs3.existsSync)(filePath)) {
1856
+ if (!(0, import_node_fs5.existsSync)(filePath)) {
1791
1857
  res.writeHead(404).end("UI build not found");
1792
1858
  return;
1793
1859
  }
1794
- res.writeHead(200, { "Content-Type": MIME[(0, import_node_path3.extname)(filePath)] ?? "application/octet-stream" });
1795
- res.end((0, import_node_fs3.readFileSync)(filePath));
1860
+ res.writeHead(200, { "Content-Type": MIME[(0, import_node_path4.extname)(filePath)] ?? "application/octet-stream" });
1861
+ res.end((0, import_node_fs5.readFileSync)(filePath));
1796
1862
  }
1797
1863
  async function startMock(options) {
1798
1864
  let loaded = await loadPackageFromEntry(options.entry);
@@ -1866,10 +1932,10 @@ async function run(options) {
1866
1932
  process.on("SIGTERM", shutdown);
1867
1933
  }
1868
1934
  function watchAndReload(entry, onChange) {
1869
- const dir = (0, import_node_path3.resolve)(entry, "..");
1935
+ const dir = (0, import_node_path4.resolve)(entry, "..");
1870
1936
  let timer;
1871
1937
  try {
1872
- const watcher = (0, import_node_fs3.watch)(dir, { recursive: true }, (_event, file) => {
1938
+ const watcher = (0, import_node_fs5.watch)(dir, { recursive: true }, (_event, file) => {
1873
1939
  if (file && /\.[cm]?tsx?$|\.js$/.test(file.toString())) {
1874
1940
  clearTimeout(timer);
1875
1941
  timer = setTimeout(onChange, 200);
@@ -1932,11 +1998,16 @@ async function openBrowser(url) {
1932
1998
  spawn(cmd, [url], { stdio: "ignore", detached: true }).unref();
1933
1999
  }
1934
2000
  async function main() {
1935
- const { command, options } = parseArgs(process.argv.slice(2));
2001
+ const argv = process.argv.slice(2);
2002
+ const envFile = loadEnvFile(argv);
2003
+ const { command, options } = parseArgs(argv);
1936
2004
  if (command === "version") {
1937
2005
  console.log(DEVKIT_VERSION);
1938
2006
  return;
1939
2007
  }
2008
+ if (envFile) {
2009
+ console.log(`Loaded env from ${envFile}`);
2010
+ }
1940
2011
  if (command === "reset") {
1941
2012
  const { rmSync } = await import("fs");
1942
2013
  rmSync(options.stateFile, { force: true });