@omnixdp/typegen 0.2.1 → 0.2.2

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/README.md CHANGED
@@ -25,7 +25,7 @@ npx omnixdp-typegen \
25
25
  --out src/omnixdp.generated.ts
26
26
  ```
27
27
 
28
- Space arguments can be a space id, slug, or exact name. Typegen exchanges client credentials for short-lived access tokens. Existing `--management-token`, `--business-objects-token`, and `--ratings-and-reviews-token` flags remain supported when you already have bearer tokens. Regenerate the output after changing content types, taxonomy types, data types, or global fields in the admin.
28
+ Space arguments can be a space id, slug, or exact name. Typegen loads `.env` and `.env.local` before evaluating config files, then exchanges client credentials for short-lived access tokens. Existing `--management-token`, `--business-objects-token`, and `--ratings-and-reviews-token` flags remain supported when you already have bearer tokens. Regenerate the output after changing content types, taxonomy types, data types, or global fields in the admin.
29
29
 
30
30
  ## Check in CI
31
31
 
package/dist/cli.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  import type { TypegenConfig } from "./schema";
3
+ export declare function loadEnvFiles(cwd?: string): Promise<void>;
3
4
  export declare function loadConfig(file: string): Promise<Partial<TypegenConfig>>;
package/dist/cli.js CHANGED
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  return result;
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.loadEnvFiles = loadEnvFiles;
27
28
  exports.loadConfig = loadConfig;
28
29
  const promises_1 = require("node:fs/promises");
29
30
  const node_module_1 = require("node:module");
@@ -38,6 +39,7 @@ async function main() {
38
39
  printHelp();
39
40
  return;
40
41
  }
42
+ await loadEnvFiles();
41
43
  const fileConfig = args.config ? await loadConfig(args.config) : await loadDefaultConfig();
42
44
  const config = compactConfig({ ...fileConfig, ...args });
43
45
  const out = config.out ?? "src/omnixdp.generated.ts";
@@ -59,6 +61,56 @@ async function main() {
59
61
  await (0, promises_1.writeFile)(outPath, output, "utf8");
60
62
  console.log(`Generated ${out}`);
61
63
  }
64
+ async function loadEnvFiles(cwd = process.cwd()) {
65
+ const protectedKeys = new Set(Object.keys(process.env));
66
+ for (const file of [".env", ".env.local"]) {
67
+ const values = await readEnvFile((0, node_path_1.join)(cwd, file));
68
+ for (const [key, value] of Object.entries(values)) {
69
+ if (!protectedKeys.has(key)) {
70
+ process.env[key] = value;
71
+ }
72
+ }
73
+ }
74
+ }
75
+ async function readEnvFile(path) {
76
+ const content = await (0, promises_1.readFile)(path, "utf8").catch((error) => {
77
+ if (error.code === "ENOENT")
78
+ return null;
79
+ throw error;
80
+ });
81
+ if (content === null)
82
+ return {};
83
+ const values = {};
84
+ for (const line of content.split(/\r?\n/)) {
85
+ const parsed = parseEnvLine(line);
86
+ if (parsed) {
87
+ values[parsed.key] = parsed.value;
88
+ }
89
+ }
90
+ return values;
91
+ }
92
+ function parseEnvLine(line) {
93
+ const trimmed = line.trim();
94
+ if (!trimmed || trimmed.startsWith("#"))
95
+ return null;
96
+ const normalized = trimmed.startsWith("export ") ? trimmed.slice("export ".length).trimStart() : trimmed;
97
+ const separatorIndex = normalized.indexOf("=");
98
+ if (separatorIndex <= 0)
99
+ return null;
100
+ const key = normalized.slice(0, separatorIndex).trim();
101
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))
102
+ return null;
103
+ return { key, value: unquoteEnvValue(normalized.slice(separatorIndex + 1).trim()) };
104
+ }
105
+ function unquoteEnvValue(value) {
106
+ if (value.length >= 2 && value.startsWith("\"") && value.endsWith("\"")) {
107
+ return value.slice(1, -1).replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\"/g, "\"").replace(/\\\\/g, "\\");
108
+ }
109
+ if (value.length >= 2 && value.startsWith("'") && value.endsWith("'")) {
110
+ return value.slice(1, -1);
111
+ }
112
+ return value.replace(/\s+#.*$/, "");
113
+ }
62
114
  function parseArgs(argv) {
63
115
  const out = {};
64
116
  for (let i = 0; i < argv.length; i += 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnixdp/typegen",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "TypeScript type generator for Omni xDP SDK response models.",
5
5
  "license": "MIT",
6
6
  "repository": {