@hyper-fetch/cli 7.5.3 → 8.0.0

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.
Files changed (83) hide show
  1. package/.eslintrc.cjs +18 -0
  2. package/__tests__/codegen/openapi/v3/generator.spec.ts +3 -2
  3. package/__tests__/codegen/openapi/v3/operations.spec.ts +2 -2
  4. package/__tests__/codegen/openapi/v3/utils.spec.ts +1 -1
  5. package/__tests__/commands/generate/generate.spec.ts +17 -17
  6. package/__tests__/tsconfig.json +15 -4
  7. package/__tests__/vitest.setup.ts +10 -0
  8. package/dist/cli/index.d.ts +3 -0
  9. package/dist/cli/index.d.ts.map +1 -0
  10. package/dist/cli.js +12969 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/codegen/index.d.ts +2 -0
  13. package/dist/codegen/index.d.ts.map +1 -0
  14. package/dist/codegen/openapi/generator.d.ts +61 -0
  15. package/dist/codegen/openapi/generator.d.ts.map +1 -0
  16. package/dist/codegen/openapi/http-methods.enum.d.ts +11 -0
  17. package/dist/codegen/openapi/http-methods.enum.d.ts.map +1 -0
  18. package/dist/codegen/openapi/index.d.ts +4 -0
  19. package/dist/codegen/openapi/index.d.ts.map +1 -0
  20. package/dist/codegen/openapi/openapi.types.d.ts +11 -0
  21. package/dist/codegen/openapi/openapi.types.d.ts.map +1 -0
  22. package/dist/codegen/openapi/operations.d.ts +6 -0
  23. package/dist/codegen/openapi/operations.d.ts.map +1 -0
  24. package/dist/codegen/openapi/utils.d.ts +7 -0
  25. package/dist/codegen/openapi/utils.d.ts.map +1 -0
  26. package/dist/commands/add.d.ts +10 -0
  27. package/dist/commands/add.d.ts.map +1 -0
  28. package/dist/commands/generate.d.ts +14 -0
  29. package/dist/commands/generate.d.ts.map +1 -0
  30. package/dist/commands/init.d.ts +3 -0
  31. package/dist/commands/init.d.ts.map +1 -0
  32. package/dist/config/auto-init.d.ts +6 -0
  33. package/dist/config/auto-init.d.ts.map +1 -0
  34. package/dist/config/get-config.d.ts +4 -0
  35. package/dist/config/get-config.d.ts.map +1 -0
  36. package/dist/config/get-ts-alias.d.ts +2 -0
  37. package/dist/config/get-ts-alias.d.ts.map +1 -0
  38. package/dist/config/schema.d.ts +21 -0
  39. package/dist/config/schema.d.ts.map +1 -0
  40. package/dist/generator-f5QJtrBW.js +194000 -0
  41. package/dist/generator-f5QJtrBW.js.map +1 -0
  42. package/dist/index.d.ts +2 -103
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +3 -3091
  45. package/dist/preflights/preflight-add.d.ts +27 -0
  46. package/dist/preflights/preflight-add.d.ts.map +1 -0
  47. package/dist/preflights/preflight-generate.d.ts +8 -0
  48. package/dist/preflights/preflight-generate.d.ts.map +1 -0
  49. package/dist/utils/errors.d.ts +14 -0
  50. package/dist/utils/errors.d.ts.map +1 -0
  51. package/dist/utils/handle-error.d.ts +2 -0
  52. package/dist/utils/handle-error.d.ts.map +1 -0
  53. package/dist/utils/highlighter.d.ts +7 -0
  54. package/dist/utils/highlighter.d.ts.map +1 -0
  55. package/dist/utils/logger.d.ts +8 -0
  56. package/dist/utils/logger.d.ts.map +1 -0
  57. package/dist/utils/resolve-import.d.ts +3 -0
  58. package/dist/utils/resolve-import.d.ts.map +1 -0
  59. package/dist/utils/show-help.d.ts +3 -0
  60. package/dist/utils/show-help.d.ts.map +1 -0
  61. package/dist/utils/spinner.d.ts +5 -0
  62. package/dist/utils/spinner.d.ts.map +1 -0
  63. package/dist/utils/zod-to-table.d.ts +6 -0
  64. package/dist/utils/zod-to-table.d.ts.map +1 -0
  65. package/package.json +5 -8
  66. package/src/codegen/openapi/generator.ts +4 -3
  67. package/src/codegen/openapi/openapi.types.ts +2 -2
  68. package/src/codegen/openapi/operations.ts +1 -1
  69. package/src/codegen/openapi/utils.ts +1 -1
  70. package/src/commands/add.ts +2 -2
  71. package/src/commands/init.ts +4 -3
  72. package/src/config/auto-init.ts +54 -0
  73. package/src/config/get-config.ts +5 -14
  74. package/src/preflights/preflight-add.ts +2 -2
  75. package/src/preflights/preflight-generate.ts +3 -3
  76. package/src/utils/show-help.ts +1 -1
  77. package/tsconfig.json +1 -1
  78. package/vite.config.ts +45 -0
  79. package/.eslintrc.json +0 -11
  80. package/__tests__/global.d.ts +0 -1
  81. package/__tests__/jest.setup.ts +0 -5
  82. package/dist/index.js.map +0 -7
  83. package/jest.config.ts +0 -6
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ import { addOptionsSchema } from '../commands/add';
3
+ export declare function preFlightAdd(options: z.infer<typeof addOptionsSchema>): Promise<{
4
+ errors: Record<string, boolean>;
5
+ config: null;
6
+ } | {
7
+ errors: Record<string, boolean>;
8
+ config: {
9
+ tsx: boolean;
10
+ aliases: {
11
+ api: string;
12
+ hooks: string;
13
+ ui: string;
14
+ components: string;
15
+ lib: string;
16
+ };
17
+ resolvedPaths: {
18
+ cwd: string;
19
+ api: string;
20
+ hooks: string;
21
+ ui: string;
22
+ components: string;
23
+ lib: string;
24
+ };
25
+ };
26
+ }>;
27
+ //# sourceMappingURL=preflight-add.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight-add.d.ts","sourceRoot":"","sources":["../../src/preflights/preflight-add.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAMrD,wBAAsB,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;;;;;GAgC3E"}
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ import { generateOptionsSchema } from '../commands/generate';
3
+ import { Config } from '../config/schema';
4
+ export declare function preFlightGenerate(options: z.infer<typeof generateOptionsSchema>): Promise<{
5
+ errors: Record<string, boolean>;
6
+ config: Config;
7
+ }>;
8
+ //# sourceMappingURL=preflight-generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight-generate.d.ts","sourceRoot":"","sources":["../../src/preflights/preflight-generate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAK5C,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GAAG,OAAO,CAAC;IAC/F,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CA8BD"}
@@ -0,0 +1,14 @@
1
+ export declare const MISSING_DIR_OR_EMPTY_PROJECT = "1";
2
+ export declare const EXISTING_CONFIG = "2";
3
+ export declare const MISSING_CONFIG = "3";
4
+ export declare const FAILED_CONFIG_READ = "4";
5
+ export declare const TAILWIND_NOT_CONFIGURED = "5";
6
+ export declare const IMPORT_ALIAS_MISSING = "6";
7
+ export declare const UNSUPPORTED_FRAMEWORK = "7";
8
+ export declare const COMPONENT_URL_NOT_FOUND = "8";
9
+ export declare const COMPONENT_URL_UNAUTHORIZED = "9";
10
+ export declare const COMPONENT_URL_FORBIDDEN = "10";
11
+ export declare const COMPONENT_URL_BAD_REQUEST = "11";
12
+ export declare const COMPONENT_URL_INTERNAL_SERVER_ERROR = "12";
13
+ export declare const BUILD_MISSING_REGISTRY_FILE = "13";
14
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,eAAO,MAAM,eAAe,MAAM,CAAC;AACnC,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,MAAM,CAAC;AACzC,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,mCAAmC,OAAO,CAAC;AACxD,eAAO,MAAM,2BAA2B,OAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function handleError(error: unknown): void;
2
+ //# sourceMappingURL=handle-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-error.d.ts","sourceRoot":"","sources":["../../src/utils/handle-error.ts"],"names":[],"mappings":"AAKA,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,QA+BzC"}
@@ -0,0 +1,7 @@
1
+ export declare const highlighter: {
2
+ error: typeof import('kleur/colors').print;
3
+ warn: typeof import('kleur/colors').print;
4
+ info: typeof import('kleur/colors').print;
5
+ success: typeof import('kleur/colors').print;
6
+ };
7
+ //# sourceMappingURL=highlighter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"highlighter.d.ts","sourceRoot":"","sources":["../../src/utils/highlighter.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW;;;;;CAKvB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const logger: {
2
+ info(...args: unknown[]): void;
3
+ warn(...args: unknown[]): void;
4
+ error(...args: unknown[]): void;
5
+ success(...args: unknown[]): void;
6
+ break(): void;
7
+ };
8
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM;kBACH,OAAO,EAAE;kBAGT,OAAO,EAAE;mBAGR,OAAO,EAAE;qBAGP,OAAO,EAAE;;CAM3B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ConfigLoaderSuccessResult } from 'tsconfig-paths';
2
+ export declare function resolveImport(importPath: string, config: Pick<ConfigLoaderSuccessResult, "absoluteBaseUrl" | "paths">): Promise<string | undefined>;
3
+ //# sourceMappingURL=resolve-import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-import.d.ts","sourceRoot":"","sources":["../../src/utils/resolve-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAEjF,wBAAsB,aAAa,CACjC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,IAAI,CAAC,yBAAyB,EAAE,iBAAiB,GAAG,OAAO,CAAC,+BASrE"}
@@ -0,0 +1,3 @@
1
+ import { z } from 'zod';
2
+ export declare const showHelp: (schema: z.ZodType) => void;
3
+ //# sourceMappingURL=show-help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-help.d.ts","sourceRoot":"","sources":["../../src/utils/show-help.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAK7B,eAAO,MAAM,QAAQ,GAAI,QAAQ,CAAC,CAAC,OAAO,SA+BzC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Options } from 'ora';
2
+ export declare function spinner(text: Options["text"], options?: {
3
+ silent?: boolean;
4
+ }): import('ora').Ora;
5
+ //# sourceMappingURL=spinner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spinner.d.ts","sourceRoot":"","sources":["../../src/utils/spinner.ts"],"names":[],"mappings":"AAAA,OAAY,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAExC,wBAAgB,OAAO,CACrB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EACrB,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,qBAMF"}
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ export declare const zodToTable: (schema: z.ZodType) => {
3
+ name: string;
4
+ description: string | undefined;
5
+ }[];
6
+ //# sourceMappingURL=zod-to-table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-to-table.d.ts","sourceRoot":"","sources":["../../src/utils/zod-to-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,UAAU,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,EAa/F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper-fetch/cli",
3
- "version": "7.5.3",
3
+ "version": "8.0.0",
4
4
  "description": "Hyper Fetch cli for code generation and utilities",
5
5
  "author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
6
6
  "homepage": "https://hyperfetch.bettertyped.com/",
@@ -13,17 +13,14 @@
13
13
  "climain": "dist/index.js",
14
14
  "bin": "dist/index.js",
15
15
  "scripts": {
16
- "clean": "npx rimraf dist",
17
- "test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest --watchAll --maxWorkers=3 --forceExit",
18
- "test:pipeline": "node --experimental-vm-modules ../../node_modules/jest/bin/jest --watchAll=false --maxWorkers=1 --no-cache --forceExit",
16
+ "test": "vitest run",
19
17
  "dev": "npx tsx ./src/cli/index.ts",
20
18
  "prebuild": "yarn update:version",
21
- "build": "yarn clean && node ../../scripts/build.js",
22
- "postbuild": "yarn rollup -c ../../rollup.config.js",
19
+ "build": "vite build",
23
20
  "update:version": "node ../../scripts/update-package-version.js --prefix hyper-fetch-cli-v",
24
21
  "lint": "eslint . --ext .js,.jsx,.tsx,.ts --fix",
25
22
  "format": "prettier --write .",
26
- "typescheck": "tsc --noEmit --emitDeclarationOnly false",
23
+ "typecheck": "tsc --noEmit --emitDeclarationOnly false && tsc --noEmit -p __tests__/tsconfig.json",
27
24
  "tests": "yarn lint-staged",
28
25
  "release": "yarn semantic-release --extends ../../release.config.js -t 'hyper-fetch-cli-v${version}'"
29
26
  },
@@ -63,7 +60,7 @@
63
60
  },
64
61
  "lint-staged": {
65
62
  "*.{js,jsx,ts,tsx}": [
66
- "yarn jest --passWithNoTests"
63
+ "vitest related --run --passWithNoTests"
67
64
  ]
68
65
  },
69
66
  "keywords": [
@@ -1,4 +1,5 @@
1
- import DtsGenerator, { ExportedType } from "@anttiviljami/dtsgenerator/dist/core/dtsGenerator";
1
+ import type { ExportedType } from "@anttiviljami/dtsgenerator/dist/core/dtsGenerator";
2
+ import DtsGenerator from "@anttiviljami/dtsgenerator/dist/core/dtsGenerator";
2
3
  import RefParser from "@apidevtools/json-schema-ref-parser";
3
4
  import { parseSchema } from "@anttiviljami/dtsgenerator/dist/core/type";
4
5
  import * as lodash from "lodash";
@@ -7,11 +8,11 @@ import * as fs from "fs-extra";
7
8
  import * as path from "node:path";
8
9
  import { createClient } from "@hyper-fetch/core";
9
10
 
10
- import { Document, Operation, GeneratedTypes } from "./openapi.types";
11
+ import type { Document, Operation, GeneratedTypes } from "./openapi.types";
11
12
  import { getAvailableOperations } from "./operations";
12
13
  import { adjustPathParamsFormat, normalizeOperationId, createTypeBaseName, isUrl } from "./utils";
13
14
  import { HttpMethod } from "./http-methods.enum";
14
- import { Config } from "config/schema";
15
+ import type { Config } from "config/schema";
15
16
 
16
17
  interface RefError {
17
18
  path: string;
@@ -1,6 +1,6 @@
1
- import { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
1
+ import type { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
2
2
 
3
- import { HttpMethod } from "./http-methods.enum";
3
+ import type { HttpMethod } from "./http-methods.enum";
4
4
 
5
5
  export interface Operation extends OpenAPIV3.OperationObject {
6
6
  path: string;
@@ -1,7 +1,7 @@
1
1
  import type { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
2
2
 
3
3
  import { HttpMethod } from "./http-methods.enum";
4
- import { Operation } from "./openapi.types";
4
+ import type { Operation } from "./openapi.types";
5
5
 
6
6
  export function getAvailableOperations(openApiJson: OpenAPIV3.Document | OpenAPIV3_1.Document) {
7
7
  const paths = openApiJson.paths || {};
@@ -1,4 +1,4 @@
1
- import { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
1
+ import type { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
2
2
 
3
3
  export function adjustPathParamsFormat(path: string) {
4
4
  // Naive implementation for now:
@@ -3,8 +3,8 @@ import { checkbox, confirm } from "@inquirer/prompts";
3
3
  import { z } from "zod";
4
4
 
5
5
  // import { Registry } from "registry/schema";
6
- import { logger } from "../utils/logger";
7
- import { handleError } from "../utils/handle-error";
6
+ import { logger } from "utils/logger";
7
+ import { handleError } from "utils/handle-error";
8
8
  import { preFlightAdd } from "preflights/preflight-add";
9
9
  import { showHelp } from "utils/show-help";
10
10
 
@@ -4,9 +4,10 @@ import { z } from "zod";
4
4
  import * as path from "node:path";
5
5
  import * as fs from "fs-extra";
6
6
 
7
- import { handleError } from "../utils/handle-error";
8
- import { spinner } from "../utils/spinner";
9
- import { configSchema, Config } from "config/schema";
7
+ import { handleError } from "utils/handle-error";
8
+ import { spinner } from "utils/spinner";
9
+ import type { Config } from "config/schema";
10
+ import { configSchema } from "config/schema";
10
11
  import { logger } from "utils/logger";
11
12
  import { getTsConfigAliasPrefix } from "config/get-ts-alias";
12
13
  import { showHelp } from "utils/show-help";
@@ -0,0 +1,54 @@
1
+ import * as path from "node:path";
2
+ import * as fs from "fs-extra";
3
+
4
+ import type { Config } from "config/schema";
5
+ import { configSchema } from "config/schema";
6
+ import { getTsConfigAliasPrefix } from "config/get-ts-alias";
7
+ import { logger } from "utils/logger";
8
+ import { spinner } from "utils/spinner";
9
+
10
+ /**
11
+ * Automatically initialize the project with default configuration.
12
+ * Called when `api.json` is not found during any CLI command.
13
+ */
14
+ export async function autoInit(cwd: string): Promise<void> {
15
+ logger.break();
16
+ logger.info("No api.json found — auto-initializing project...");
17
+ logger.break();
18
+
19
+ const mainPath = "src";
20
+ const apiDir = "api";
21
+ const fullPath = path.join(cwd, mainPath, apiDir);
22
+ const configPath = path.join(cwd, "api.json");
23
+
24
+ const aliasPrefix = (await getTsConfigAliasPrefix(cwd)) || "";
25
+ const alias = aliasPrefix ? `${aliasPrefix}/` : "";
26
+
27
+ const defaultAliases: Config["aliases"] = {
28
+ api: `${alias}${apiDir}`,
29
+ hooks: `${alias}hooks`,
30
+ ui: `${alias}components/ui`,
31
+ components: `${alias}components`,
32
+ lib: `${alias}lib`,
33
+ };
34
+
35
+ const defaultConfig: Omit<Config, "resolvedPaths"> = {
36
+ tsx: true,
37
+ aliases: defaultAliases,
38
+ };
39
+
40
+ const s1 = spinner(`Initialize API directory at ${path.join(mainPath, apiDir)}`).start();
41
+ if (!fs.existsSync(fullPath)) {
42
+ await fs.mkdir(fullPath, { recursive: true });
43
+ }
44
+ s1.succeed();
45
+
46
+ const s2 = spinner("Create api.json configuration file").start();
47
+ configSchema.omit({ resolvedPaths: true }).parse(defaultConfig);
48
+ await fs.writeFile(configPath, JSON.stringify(defaultConfig, null, 2));
49
+ s2.succeed();
50
+
51
+ logger.break();
52
+ logger.info("Auto-initialization complete!");
53
+ logger.break();
54
+ }
@@ -4,9 +4,10 @@ import { loadConfig } from "tsconfig-paths";
4
4
 
5
5
  import { highlighter } from "utils/highlighter";
6
6
  import { resolveImport } from "utils/resolve-import";
7
- import { logger } from "../utils/logger";
8
- import { handleError } from "../utils/handle-error";
9
- import { configSchema, Config } from "config/schema";
7
+ import { handleError } from "utils/handle-error";
8
+ import type { Config } from "config/schema";
9
+ import { configSchema } from "config/schema";
10
+ import { autoInit } from "config/auto-init";
10
11
 
11
12
  export async function resolveConfigPaths(cwd: string, config: Omit<Config, "resolvedPaths">): Promise<Config> {
12
13
  // Read tsconfig.json.
@@ -30,18 +31,8 @@ export async function resolveConfigPaths(cwd: string, config: Omit<Config, "reso
30
31
  }
31
32
 
32
33
  export async function getConfig(cwd: string): Promise<Config | null> {
33
- // Check for existing api.json file.
34
34
  if (!fs.existsSync(path.resolve(cwd, "api.json"))) {
35
- logger.break();
36
- logger.error(
37
- `An invalid ${highlighter.info("api.json")} file was found at ${highlighter.info(
38
- cwd,
39
- )}.\nBefore you can add or generate SDKs, you must create a valid ${highlighter.info(
40
- "api.json",
41
- )} file by running the ${highlighter.info("init")} command.`,
42
- );
43
- logger.break();
44
- process.exit(1);
35
+ await autoInit(cwd);
45
36
  }
46
37
  const { data, error } = await configSchema
47
38
  .omit({ resolvedPaths: true }) // We enrich it later
@@ -1,8 +1,8 @@
1
1
  import * as path from "node:path";
2
2
  import * as fs from "fs-extra";
3
- import { z } from "zod";
3
+ import type { z } from "zod";
4
4
 
5
- import { addOptionsSchema } from "commands/add";
5
+ import type { addOptionsSchema } from "commands/add";
6
6
  import * as ERRORS from "utils/errors";
7
7
  import { getConfig } from "config/get-config";
8
8
  import { highlighter } from "utils/highlighter";
@@ -1,11 +1,11 @@
1
1
  import * as path from "node:path";
2
2
  import * as fs from "fs-extra";
3
- import { z } from "zod";
3
+ import type { z } from "zod";
4
4
 
5
- import { generateOptionsSchema } from "commands/generate";
5
+ import type { generateOptionsSchema } from "commands/generate";
6
6
  import * as ERRORS from "utils/errors";
7
7
  import { getConfig } from "config/get-config";
8
- import { Config } from "config/schema";
8
+ import type { Config } from "config/schema";
9
9
  import { highlighter } from "utils/highlighter";
10
10
  import { logger } from "utils/logger";
11
11
  import { handleError } from "utils/handle-error";
@@ -1,4 +1,4 @@
1
- import { z } from "zod";
1
+ import type { z } from "zod";
2
2
  import Table from "cli-table3";
3
3
 
4
4
  import { zodToTable } from "./zod-to-table";
package/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "baseUrl": "./src",
6
6
  "jsx": "react-jsx"
7
7
  },
8
- "exclude": ["node_modules", "dist", "jest.config.ts", "__tests__"]
8
+ "exclude": ["node_modules", "dist", "vite.config.ts", "__tests__"]
9
9
  }
package/vite.config.ts ADDED
@@ -0,0 +1,45 @@
1
+ /// <reference types="vitest/config" />
2
+ import { defineConfig } from "vite";
3
+ import dts from "vite-plugin-dts";
4
+ import tsconfigPaths from "vite-tsconfig-paths";
5
+ import path from "path";
6
+ import { getDtsCompilerOptionsForPackage } from "../../scripts/vite-dts-internal-paths";
7
+ import { getRollupExternalsFromPackageJson } from "../../scripts/vite-lib-externals-from-package";
8
+
9
+ export default defineConfig({
10
+ build: {
11
+ lib: {
12
+ entry: {
13
+ index: "src/index.ts",
14
+ cli: "src/cli/index.ts",
15
+ },
16
+ formats: ["cjs"],
17
+ },
18
+ sourcemap: true,
19
+ minify: false,
20
+ rollupOptions: {
21
+ external: [...getRollupExternalsFromPackageJson(__dirname), "@hyper-fetch/core"],
22
+ },
23
+ },
24
+ plugins: [
25
+ dts({
26
+ entryRoot: "src",
27
+ compilerOptions: getDtsCompilerOptionsForPackage(__dirname),
28
+ }),
29
+ tsconfigPaths(),
30
+ ],
31
+ test: {
32
+ globals: true,
33
+ environment: "node",
34
+ setupFiles: ["./__tests__/vitest.setup.ts"],
35
+ include: ["__tests__/**/*.spec.{ts,tsx}", "src/**/*.spec.{ts,tsx}"],
36
+ coverage: {
37
+ provider: "v8",
38
+ include: ["src/**/*.{ts,tsx}"],
39
+ exclude: ["**/*.spec.*", "**/types.*", "**/constants.*", "**/index.ts"],
40
+ },
41
+ alias: {
42
+ "@hyper-fetch/core": path.resolve(__dirname, "../core/src/index.ts"),
43
+ },
44
+ },
45
+ });
package/.eslintrc.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": ["plugin:@nx/react", "../../.eslintrc.js"],
3
- "parserOptions": {
4
- "project": ["./tsconfig.json"]
5
- },
6
- "rules": {
7
- "react/jsx-props-no-spreading": 0,
8
- "react/require-default-props": 0
9
- },
10
- "ignorePatterns": ["dist/", "coverage/", "jest.config.ts", "/*.js"]
11
- }
@@ -1 +0,0 @@
1
- import "jest-extended";
@@ -1,5 +0,0 @@
1
- import { AbortController } from "abortcontroller-polyfill/dist/cjs-ponyfill";
2
-
3
- if (!global.AbortController) {
4
- global.AbortController = AbortController as any;
5
- }