@ps-aux/api-client-gen 0.7.0-rc.3 → 0.7.0-rc.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/README.md CHANGED
@@ -10,11 +10,13 @@ npm install -D @ps-aux/api-client-gen
10
10
 
11
11
  ## CLI
12
12
 
13
- Create api-client-gen.config.json (via [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig?tab=readme-ov-file#usage-for-end-users)):
13
+ Create `api-client-gen.config.ts` or `api-client-gen.config.js` (loaded via [c12](https://github.com/unjs/c12)). `api-client-gen.config.ts` is recommended for the best type safety:
14
14
 
15
- ```json
16
- {
17
- "petstore": {
15
+ ```ts
16
+ import { defineConfig } from '@ps-aux/api-client-gen'
17
+
18
+ export default defineConfig({
19
+ petstore: {
18
20
  "srcSpec": "https://petstore3.swagger.io/api/v3/openapi.json",
19
21
  "dstDir": "./generated",
20
22
  "apiName": "PetstoreApi",
@@ -23,7 +25,7 @@ Create api-client-gen.config.json (via [cosmiconfig](https://github.com/cosmicon
23
25
  },
24
26
  "zodSchemas": { "enabled": true }
25
27
  }
26
- }
28
+ })
27
29
  ```
28
30
 
29
31
  Run: `npx gen-api-client petstore`
package/dist/bin.cjs CHANGED
@@ -2,25 +2,90 @@
2
2
  'use strict';
3
3
 
4
4
  var generateApiClient = require('./generateApiClient.cjs');
5
- var cosmiconfig = require('cosmiconfig');
5
+ var fs = require('node:fs');
6
+ var Path = require('node:path');
7
+ var c12 = require('c12');
6
8
  require('path');
7
9
  require('fs');
8
10
  require('fs/promises');
9
11
  require('swagger-typescript-api');
10
12
  require('node:url');
11
13
  require('node:fs/promises');
12
- require('node:path');
13
- require('node:fs');
14
14
  require('ts-to-zod');
15
15
 
16
+ function _interopNamespaceDefault(e) {
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default') {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n.default = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
34
+
35
+ const SUPPORTED_CONFIG_EXTENSIONS = ["ts", "js"];
36
+ const getSupportedConfigFiles = (name) => SUPPORTED_CONFIG_EXTENSIONS.map((ext) => `${name}.config.${ext}`);
37
+ const loadConfig = async ({
38
+ cwd = process.cwd(),
39
+ name,
40
+ parseConfig
41
+ }) => {
42
+ const supportedConfigFiles = getSupportedConfigFiles(name);
43
+ const presentConfigFiles = supportedConfigFiles.filter(
44
+ (fileName) => fs__namespace.existsSync(Path.join(cwd, fileName))
45
+ );
46
+ if (presentConfigFiles.length === 0) {
47
+ throw new Error(
48
+ `No config provided. Expected one of: ${supportedConfigFiles.join(", ")}`
49
+ );
50
+ }
51
+ if (presentConfigFiles.length > 1) {
52
+ throw new Error(
53
+ `Multiple config files found. Keep only one of: ${supportedConfigFiles.join(", ")}`
54
+ );
55
+ }
56
+ const conf = await c12.loadConfig({
57
+ cwd,
58
+ configFile: presentConfigFiles[0],
59
+ rcFile: false,
60
+ packageJson: false,
61
+ globalRc: false,
62
+ configFileRequired: true
63
+ });
64
+ if (!conf.configFile) {
65
+ throw new Error(
66
+ `No config provided. Expected one of: ${supportedConfigFiles.join(", ")}`
67
+ );
68
+ }
69
+ return {
70
+ config: parseConfig(conf.config, conf.configFile),
71
+ configFile: conf.configFile
72
+ };
73
+ };
74
+
16
75
  const profile = process.argv[2];
17
76
  if (!profile) throw new Error(`No profile specified`);
18
- const conf = cosmiconfig.cosmiconfigSync("api-client-gen").search();
19
- if (!conf) throw new Error(`No config provided`);
20
- const profileConf = conf.config[profile];
21
- if (!profileConf)
22
- throw new Error(`Profile "${profile}" not present in the configuration`);
23
- generateApiClient.generateApiClient(profileConf, conf.filepath).catch((error) => {
77
+ const main = async () => {
78
+ const conf = await loadConfig({
79
+ cwd: process.cwd(),
80
+ name: "api-client-gen",
81
+ parseConfig: generateApiClient.parseConfig
82
+ });
83
+ const profileConf = conf.config[profile];
84
+ if (!profileConf)
85
+ throw new Error(`Profile "${profile}" not present in the configuration`);
86
+ await generateApiClient.generateApiClientFromConfig(profileConf);
87
+ };
88
+ main().catch((error) => {
24
89
  console.error(error instanceof Error ? error.message : String(error));
25
90
  process.exitCode = 1;
26
91
  });
package/dist/bin.mjs CHANGED
@@ -1,24 +1,70 @@
1
1
  #!/usr/bin/env node
2
- import { g as generateApiClient } from './generateApiClient.mjs';
3
- import { cosmiconfigSync } from 'cosmiconfig';
2
+ import { a as generateApiClientFromConfig, p as parseConfig } from './generateApiClient.mjs';
3
+ import * as fs from 'node:fs';
4
+ import Path from 'node:path';
5
+ import { loadConfig as loadConfig$1 } from 'c12';
4
6
  import 'path';
5
7
  import 'fs';
6
8
  import 'fs/promises';
7
9
  import 'swagger-typescript-api';
8
10
  import 'node:url';
9
11
  import 'node:fs/promises';
10
- import 'node:path';
11
- import 'node:fs';
12
12
  import 'ts-to-zod';
13
13
 
14
+ const SUPPORTED_CONFIG_EXTENSIONS = ["ts", "js"];
15
+ const getSupportedConfigFiles = (name) => SUPPORTED_CONFIG_EXTENSIONS.map((ext) => `${name}.config.${ext}`);
16
+ const loadConfig = async ({
17
+ cwd = process.cwd(),
18
+ name,
19
+ parseConfig
20
+ }) => {
21
+ const supportedConfigFiles = getSupportedConfigFiles(name);
22
+ const presentConfigFiles = supportedConfigFiles.filter(
23
+ (fileName) => fs.existsSync(Path.join(cwd, fileName))
24
+ );
25
+ if (presentConfigFiles.length === 0) {
26
+ throw new Error(
27
+ `No config provided. Expected one of: ${supportedConfigFiles.join(", ")}`
28
+ );
29
+ }
30
+ if (presentConfigFiles.length > 1) {
31
+ throw new Error(
32
+ `Multiple config files found. Keep only one of: ${supportedConfigFiles.join(", ")}`
33
+ );
34
+ }
35
+ const conf = await loadConfig$1({
36
+ cwd,
37
+ configFile: presentConfigFiles[0],
38
+ rcFile: false,
39
+ packageJson: false,
40
+ globalRc: false,
41
+ configFileRequired: true
42
+ });
43
+ if (!conf.configFile) {
44
+ throw new Error(
45
+ `No config provided. Expected one of: ${supportedConfigFiles.join(", ")}`
46
+ );
47
+ }
48
+ return {
49
+ config: parseConfig(conf.config, conf.configFile),
50
+ configFile: conf.configFile
51
+ };
52
+ };
53
+
14
54
  const profile = process.argv[2];
15
55
  if (!profile) throw new Error(`No profile specified`);
16
- const conf = cosmiconfigSync("api-client-gen").search();
17
- if (!conf) throw new Error(`No config provided`);
18
- const profileConf = conf.config[profile];
19
- if (!profileConf)
20
- throw new Error(`Profile "${profile}" not present in the configuration`);
21
- generateApiClient(profileConf, conf.filepath).catch((error) => {
56
+ const main = async () => {
57
+ const conf = await loadConfig({
58
+ cwd: process.cwd(),
59
+ name: "api-client-gen",
60
+ parseConfig
61
+ });
62
+ const profileConf = conf.config[profile];
63
+ if (!profileConf)
64
+ throw new Error(`Profile "${profile}" not present in the configuration`);
65
+ await generateApiClientFromConfig(profileConf);
66
+ };
67
+ main().catch((error) => {
22
68
  console.error(error instanceof Error ? error.message : String(error));
23
69
  process.exitCode = 1;
24
70
  });