b-gsdk 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bin.js +1 -0
- package/dist/index.js +1 -1
- package/dist/util/get-b-gsdk-config.js +13 -6
- package/package.json +3 -1
- package/src/bin.ts +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.ts +1 -1
- package/src/util/get-b-gsdk-config.ts +14 -8
- package/src/docs/fragments/product.gql +0 -10
package/dist/bin.js
CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
5
|
};
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
+
require("dotenv").config();
|
7
8
|
const _1 = require(".");
|
8
9
|
const format_error_1 = require("./util/format-error");
|
9
10
|
const arg_1 = __importDefault(require("arg"));
|
package/dist/index.js
CHANGED
@@ -17,7 +17,7 @@ async function main(args) {
|
|
17
17
|
const config = (0, get_b_gsdk_config_1.getBGsdkConfig)(bgsdkDirectoryPath);
|
18
18
|
const [schemaCodegen, sdkCodegen] = await (0, cli_1.generate)({
|
19
19
|
schema: {
|
20
|
-
[config.
|
20
|
+
[config.endpoint]: {
|
21
21
|
headers: config.headers,
|
22
22
|
},
|
23
23
|
},
|
@@ -8,15 +8,22 @@ const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
9
9
|
const zod_1 = require("zod");
|
10
10
|
const configSchema = zod_1.z.object({
|
11
|
-
|
12
|
-
headers: zod_1.z.record(zod_1.z.string()),
|
11
|
+
endpoint: zod_1.z.string(),
|
12
|
+
headers: zod_1.z.record(zod_1.z.string()).optional(),
|
13
13
|
});
|
14
14
|
const getBGsdkConfig = (directoryPath) => {
|
15
|
-
const
|
16
|
-
|
17
|
-
|
15
|
+
const bgsdkConfigJsonPath = path_1.default.join(directoryPath, "config.json");
|
16
|
+
const bgsdkConfigJSPath = path_1.default.join(directoryPath, "config.js");
|
17
|
+
let rawConfig = {};
|
18
|
+
if (fs_1.default.existsSync(bgsdkConfigJsonPath)) {
|
19
|
+
rawConfig = JSON.parse(fs_1.default.readFileSync(bgsdkConfigJsonPath, "utf8"));
|
20
|
+
}
|
21
|
+
else if (fs_1.default.existsSync(bgsdkConfigJSPath)) {
|
22
|
+
rawConfig = require(bgsdkConfigJSPath);
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
throw new Error(`Could not find config.{json,js} in ${directoryPath}`);
|
18
26
|
}
|
19
|
-
const rawConfig = JSON.parse(fs_1.default.readFileSync(bgsdkConfigPath, "utf8"));
|
20
27
|
const parsedConfig = configSchema.parse(rawConfig);
|
21
28
|
return parsedConfig;
|
22
29
|
};
|
package/package.json
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "b-gsdk",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.3",
|
4
4
|
"description": "A GraphQL Codegen that outputs a TypeScript SDK.",
|
5
5
|
"author": "Julian Benegas",
|
6
6
|
"license": "MIT",
|
7
7
|
"main": "dist/index.js",
|
8
8
|
"bin": "dist/bin.js",
|
9
|
+
"types": "src/index.d.ts",
|
9
10
|
"scripts": {
|
10
11
|
"build": "tsc",
|
11
12
|
"prepublish": "yarn build"
|
@@ -17,6 +18,7 @@
|
|
17
18
|
"@graphql-codegen/typescript-graphql-request": "^4.3.2",
|
18
19
|
"@graphql-codegen/typescript-operations": "^2.2.1",
|
19
20
|
"arg": "^5.0.1",
|
21
|
+
"dotenv": "^16.0.0",
|
20
22
|
"zod": "^3.14.4"
|
21
23
|
},
|
22
24
|
"peerDependencies": {
|
package/src/bin.ts
CHANGED
package/src/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { BGsdkConfig } from "./util/get-b-gsdk-config";
|
package/src/index.ts
CHANGED
@@ -3,18 +3,24 @@ import path from "path";
|
|
3
3
|
import { z } from "zod";
|
4
4
|
|
5
5
|
const configSchema = z.object({
|
6
|
-
|
7
|
-
headers: z.record(z.string()),
|
6
|
+
endpoint: z.string(),
|
7
|
+
headers: z.record(z.string()).optional(),
|
8
8
|
});
|
9
9
|
|
10
|
+
export type BGsdkConfig = z.infer<typeof configSchema>;
|
11
|
+
|
10
12
|
export const getBGsdkConfig = (directoryPath: string) => {
|
11
|
-
const
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
const bgsdkConfigJsonPath = path.join(directoryPath, "config.json");
|
14
|
+
const bgsdkConfigJSPath = path.join(directoryPath, "config.js");
|
15
|
+
|
16
|
+
let rawConfig = {};
|
17
|
+
if (fs.existsSync(bgsdkConfigJsonPath)) {
|
18
|
+
rawConfig = JSON.parse(fs.readFileSync(bgsdkConfigJsonPath, "utf8"));
|
19
|
+
} else if (fs.existsSync(bgsdkConfigJSPath)) {
|
20
|
+
rawConfig = require(bgsdkConfigJSPath);
|
21
|
+
} else {
|
22
|
+
throw new Error(`Could not find config.{json,js} in ${directoryPath}`);
|
16
23
|
}
|
17
|
-
const rawConfig = JSON.parse(fs.readFileSync(bgsdkConfigPath, "utf8"));
|
18
24
|
const parsedConfig = configSchema.parse(rawConfig);
|
19
25
|
return parsedConfig;
|
20
26
|
};
|