@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.
- package/.eslintrc.cjs +18 -0
- package/__tests__/codegen/openapi/v3/generator.spec.ts +3 -2
- package/__tests__/codegen/openapi/v3/operations.spec.ts +2 -2
- package/__tests__/codegen/openapi/v3/utils.spec.ts +1 -1
- package/__tests__/commands/generate/generate.spec.ts +17 -17
- package/__tests__/tsconfig.json +15 -4
- package/__tests__/vitest.setup.ts +10 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli.js +12969 -0
- package/dist/cli.js.map +1 -0
- package/dist/codegen/index.d.ts +2 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/openapi/generator.d.ts +61 -0
- package/dist/codegen/openapi/generator.d.ts.map +1 -0
- package/dist/codegen/openapi/http-methods.enum.d.ts +11 -0
- package/dist/codegen/openapi/http-methods.enum.d.ts.map +1 -0
- package/dist/codegen/openapi/index.d.ts +4 -0
- package/dist/codegen/openapi/index.d.ts.map +1 -0
- package/dist/codegen/openapi/openapi.types.d.ts +11 -0
- package/dist/codegen/openapi/openapi.types.d.ts.map +1 -0
- package/dist/codegen/openapi/operations.d.ts +6 -0
- package/dist/codegen/openapi/operations.d.ts.map +1 -0
- package/dist/codegen/openapi/utils.d.ts +7 -0
- package/dist/codegen/openapi/utils.d.ts.map +1 -0
- package/dist/commands/add.d.ts +10 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/generate.d.ts +14 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/config/auto-init.d.ts +6 -0
- package/dist/config/auto-init.d.ts.map +1 -0
- package/dist/config/get-config.d.ts +4 -0
- package/dist/config/get-config.d.ts.map +1 -0
- package/dist/config/get-ts-alias.d.ts +2 -0
- package/dist/config/get-ts-alias.d.ts.map +1 -0
- package/dist/config/schema.d.ts +21 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/generator-f5QJtrBW.js +194000 -0
- package/dist/generator-f5QJtrBW.js.map +1 -0
- package/dist/index.d.ts +2 -103
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -3091
- package/dist/preflights/preflight-add.d.ts +27 -0
- package/dist/preflights/preflight-add.d.ts.map +1 -0
- package/dist/preflights/preflight-generate.d.ts +8 -0
- package/dist/preflights/preflight-generate.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +14 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/handle-error.d.ts +2 -0
- package/dist/utils/handle-error.d.ts.map +1 -0
- package/dist/utils/highlighter.d.ts +7 -0
- package/dist/utils/highlighter.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/resolve-import.d.ts +3 -0
- package/dist/utils/resolve-import.d.ts.map +1 -0
- package/dist/utils/show-help.d.ts +3 -0
- package/dist/utils/show-help.d.ts.map +1 -0
- package/dist/utils/spinner.d.ts +5 -0
- package/dist/utils/spinner.d.ts.map +1 -0
- package/dist/utils/zod-to-table.d.ts +6 -0
- package/dist/utils/zod-to-table.d.ts.map +1 -0
- package/package.json +5 -8
- package/src/codegen/openapi/generator.ts +4 -3
- package/src/codegen/openapi/openapi.types.ts +2 -2
- package/src/codegen/openapi/operations.ts +1 -1
- package/src/codegen/openapi/utils.ts +1 -1
- package/src/commands/add.ts +2 -2
- package/src/commands/init.ts +4 -3
- package/src/config/auto-init.ts +54 -0
- package/src/config/get-config.ts +5 -14
- package/src/preflights/preflight-add.ts +2 -2
- package/src/preflights/preflight-generate.ts +3 -3
- package/src/utils/show-help.ts +1 -1
- package/tsconfig.json +1 -1
- package/vite.config.ts +45 -0
- package/.eslintrc.json +0 -11
- package/__tests__/global.d.ts +0 -1
- package/__tests__/jest.setup.ts +0 -5
- package/dist/index.js.map +0 -7
- 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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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": "
|
|
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
|
-
"
|
|
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": "
|
|
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
|
-
"
|
|
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
|
-
"
|
|
63
|
+
"vitest related --run --passWithNoTests"
|
|
67
64
|
]
|
|
68
65
|
},
|
|
69
66
|
"keywords": [
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
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 || {};
|
package/src/commands/add.ts
CHANGED
|
@@ -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 "
|
|
7
|
-
import { handleError } from "
|
|
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
|
|
package/src/commands/init.ts
CHANGED
|
@@ -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 "
|
|
8
|
-
import { spinner } from "
|
|
9
|
-
import {
|
|
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
|
+
}
|
package/src/config/get-config.ts
CHANGED
|
@@ -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 {
|
|
8
|
-
import {
|
|
9
|
-
import { configSchema
|
|
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
|
-
|
|
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";
|
package/src/utils/show-help.ts
CHANGED
package/tsconfig.json
CHANGED
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
|
-
}
|
package/__tests__/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "jest-extended";
|