@omnixdp/typegen 0.2.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.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ import type { TypegenConfig } from "./schema";
3
+ export declare function loadConfig(file: string): Promise<Partial<TypegenConfig>>;
package/dist/cli.js CHANGED
@@ -24,11 +24,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  return result;
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.loadConfig = loadConfig;
27
28
  const promises_1 = require("node:fs/promises");
29
+ const node_module_1 = require("node:module");
28
30
  const node_path_1 = require("node:path");
29
31
  const node_url_1 = require("node:url");
30
32
  const fetch_schema_1 = require("./fetch-schema");
31
33
  const generate_1 = require("./generate");
34
+ const requireConfig = (0, node_module_1.createRequire)(__filename);
32
35
  async function main() {
33
36
  const args = parseArgs(process.argv.slice(2));
34
37
  if (args.help) {
@@ -149,8 +152,18 @@ async function loadConfig(file) {
149
152
  if (path.endsWith(".json")) {
150
153
  return JSON.parse(await (0, promises_1.readFile)(path, "utf8"));
151
154
  }
155
+ if (path.endsWith(".cjs") || path.endsWith(".js")) {
156
+ return normalizeLoadedConfig(requireConfig(path));
157
+ }
152
158
  const imported = await Promise.resolve(`${(0, node_url_1.pathToFileURL)(path).href}`).then(s => __importStar(require(s)));
153
- return (imported.default ?? imported.config ?? imported);
159
+ return normalizeLoadedConfig(imported);
160
+ }
161
+ function normalizeLoadedConfig(imported) {
162
+ if (imported && typeof imported === "object") {
163
+ const record = imported;
164
+ return (record.default ?? record.config ?? imported);
165
+ }
166
+ return {};
154
167
  }
155
168
  function compactConfig(config) {
156
169
  return Object.fromEntries(Object.entries(config).filter(([, value]) => value !== undefined && value !== ""));
@@ -179,7 +192,9 @@ Options:
179
192
  --check Fail if the output file is stale
180
193
  `);
181
194
  }
182
- main().catch((error) => {
183
- console.error(error instanceof Error ? error.message : String(error));
184
- process.exitCode = 1;
185
- });
195
+ if (require.main === module) {
196
+ main().catch((error) => {
197
+ console.error(error instanceof Error ? error.message : String(error));
198
+ process.exitCode = 1;
199
+ });
200
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnixdp/typegen",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "TypeScript type generator for Omni xDP SDK response models.",
5
5
  "license": "MIT",
6
6
  "repository": {