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 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.schemaURL]: {
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
- schemaURL: zod_1.z.string(),
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 bgsdkConfigPath = path_1.default.join(directoryPath, "config.json");
16
- if (!fs_1.default.existsSync(bgsdkConfigPath)) {
17
- throw new Error(`Could not find config.json in ${directoryPath}! Please create one.`);
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.2",
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
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ require("dotenv").config();
3
4
  import { main } from ".";
4
5
  import { formatError } from "./util/format-error";
5
6
  import arg from "arg";
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { BGsdkConfig } from "./util/get-b-gsdk-config";
package/src/index.ts CHANGED
@@ -22,7 +22,7 @@ export async function main(args: Args) {
22
22
  const [schemaCodegen, sdkCodegen] = await generate(
23
23
  {
24
24
  schema: {
25
- [config.schemaURL]: {
25
+ [config.endpoint]: {
26
26
  headers: config.headers,
27
27
  },
28
28
  },
@@ -3,18 +3,24 @@ import path from "path";
3
3
  import { z } from "zod";
4
4
 
5
5
  const configSchema = z.object({
6
- schemaURL: z.string(),
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 bgsdkConfigPath = path.join(directoryPath, "config.json");
12
- if (!fs.existsSync(bgsdkConfigPath)) {
13
- throw new Error(
14
- `Could not find config.json in ${directoryPath}! Please create one.`
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
  };
@@ -1,10 +0,0 @@
1
- fragment Cart on Cart {
2
- id
3
- checkoutUrl
4
- }
5
-
6
- query FetchCart($id: ID!) {
7
- cart(id: $id) {
8
- ...Cart
9
- }
10
- }