b-gsdk 0.0.2 → 0.0.3
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/dist/bin.js +27 -0
- package/dist/index.js +59 -0
- package/dist/util/format-error.js +16 -0
- package/dist/util/get-b-gsdk-directory-path.js +17 -0
- package/package.json +4 -7
- package/src/bin.ts +29 -0
- package/src/index.ts +18 -9
- package/src/util/format-error.ts +15 -0
- package/src/util/get-b-gsdk-directory-path.ts +12 -0
- package/tsconfig.json +2 -5
- package/bin/fsevents.node +0 -0
- package/bin/index.js +0 -165
- package/bin/worker.js +0 -35
package/dist/bin.js
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
const _1 = require(".");
|
5
|
+
const format_error_1 = require("./util/format-error");
|
6
|
+
// Show usage and exit with code
|
7
|
+
function help(code) {
|
8
|
+
console.log(`Usage:
|
9
|
+
b-gsdk generate
|
10
|
+
`);
|
11
|
+
process.exit(code);
|
12
|
+
}
|
13
|
+
// Get CLI arguments
|
14
|
+
const [, , cmd] = process.argv;
|
15
|
+
// CLI commands
|
16
|
+
const cmds = {
|
17
|
+
generate: _1.main,
|
18
|
+
};
|
19
|
+
// Run CLI
|
20
|
+
try {
|
21
|
+
// Run command or show usage for unknown command
|
22
|
+
cmds[cmd] ? cmds[cmd]() : help(0);
|
23
|
+
}
|
24
|
+
catch (e) {
|
25
|
+
console.error((0, format_error_1.formatError)(e).message);
|
26
|
+
process.exit(1);
|
27
|
+
}
|
package/dist/index.js
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.main = void 0;
|
7
|
+
const cli_1 = require("@graphql-codegen/cli");
|
8
|
+
const resolve_pkg_1 = __importDefault(require("resolve-pkg"));
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
10
|
+
const path_1 = __importDefault(require("path"));
|
11
|
+
const get_b_gsdk_directory_path_1 = require("./util/get-b-gsdk-directory-path");
|
12
|
+
async function main() {
|
13
|
+
console.log("starting main");
|
14
|
+
const bgsdkDirectoryPath = (0, get_b_gsdk_directory_path_1.getBGsdkDirectoryPath)(process.cwd());
|
15
|
+
console.log("got dir path:", bgsdkDirectoryPath);
|
16
|
+
if (!bgsdkDirectoryPath) {
|
17
|
+
throw new Error("Make sure you have a b-gsdk directory in the root of your project.");
|
18
|
+
}
|
19
|
+
console.log("attempting codegen");
|
20
|
+
const [schemaCodegen, sdkCodegen] = await (0, cli_1.generate)({
|
21
|
+
schema: {
|
22
|
+
"https://mr-beast-2.myshopify.com/api/2021-10/graphql": {
|
23
|
+
headers: {
|
24
|
+
"x-shopify-storefront-access-token": "374a3639228aeb7798d99d88002c4b2e",
|
25
|
+
},
|
26
|
+
},
|
27
|
+
},
|
28
|
+
generates: {
|
29
|
+
[__dirname + "/generated/index.ts"]: {
|
30
|
+
documents: [
|
31
|
+
bgsdkDirectoryPath + "/**/*.{gql,graphql}",
|
32
|
+
bgsdkDirectoryPath + "/*.{gql,graphql}",
|
33
|
+
],
|
34
|
+
plugins: [
|
35
|
+
"typescript",
|
36
|
+
"typescript-operations",
|
37
|
+
"typescript-graphql-request",
|
38
|
+
],
|
39
|
+
},
|
40
|
+
[__dirname + "/generated/graphql.schema.json"]: {
|
41
|
+
plugins: ["introspection"],
|
42
|
+
config: {
|
43
|
+
documentMode: "documentNode",
|
44
|
+
withHooks: true,
|
45
|
+
},
|
46
|
+
},
|
47
|
+
},
|
48
|
+
}, false);
|
49
|
+
console.log("ok COOl, i got it:", sdkCodegen);
|
50
|
+
console.log("attempting to write to file");
|
51
|
+
const resolved = (0, resolve_pkg_1.default)("@b-gsdk/client");
|
52
|
+
if (!resolved) {
|
53
|
+
throw new Error("Please install @b-gsdk/client");
|
54
|
+
}
|
55
|
+
fs_1.default.writeFileSync(path_1.default.join(resolved, "generated/graphql.schema.json"), schemaCodegen.content);
|
56
|
+
fs_1.default.writeFileSync(path_1.default.join(resolved, "generated/index.ts"), sdkCodegen.content);
|
57
|
+
console.log("done");
|
58
|
+
}
|
59
|
+
exports.main = main;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.formatError = void 0;
|
4
|
+
const formatError = (error) => {
|
5
|
+
if (error instanceof Error) {
|
6
|
+
return error;
|
7
|
+
}
|
8
|
+
if (typeof error === "string") {
|
9
|
+
return new Error(error);
|
10
|
+
}
|
11
|
+
if (typeof error === "object") {
|
12
|
+
return new Error(JSON.stringify(error, null, 2));
|
13
|
+
}
|
14
|
+
return new Error(`Unknown error: ${error}`);
|
15
|
+
};
|
16
|
+
exports.formatError = formatError;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.getBGsdkDirectoryPath = void 0;
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
8
|
+
const path_1 = __importDefault(require("path"));
|
9
|
+
// taken from prisma https://github.com/prisma/prisma/blob/8f6b7c7c99c1c720cf5bfed5d563423e71c1b84f/packages/sdk/src/cli/getSchema.ts#L46-L49
|
10
|
+
const getBGsdkDirectoryPath = async (cwd) => {
|
11
|
+
const schemaPath = path_1.default.join(cwd, "b-gsdk");
|
12
|
+
if (fs_1.default.existsSync(schemaPath)) {
|
13
|
+
return schemaPath;
|
14
|
+
}
|
15
|
+
return null;
|
16
|
+
};
|
17
|
+
exports.getBGsdkDirectoryPath = getBGsdkDirectoryPath;
|
package/package.json
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "b-gsdk",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.3",
|
4
4
|
"description": "A GraphQL Codegen that outputs a TypeScript SDK.",
|
5
5
|
"author": "Julian Benegas",
|
6
6
|
"license": "MIT",
|
7
|
-
"main": "
|
8
|
-
"bin":
|
9
|
-
"b-gsdk": "./bin/index.js"
|
10
|
-
},
|
7
|
+
"main": "dist/index.js",
|
8
|
+
"bin": "dist/bin.js",
|
11
9
|
"dependencies": {
|
12
10
|
"@graphql-codegen/cli": "^2.6.2",
|
13
11
|
"@graphql-codegen/core": "^2.5.1",
|
@@ -31,7 +29,6 @@
|
|
31
29
|
"typescript": "^4.6.3"
|
32
30
|
},
|
33
31
|
"scripts": {
|
34
|
-
"build": "
|
35
|
-
"generate": "ts-node ./src/index.ts"
|
32
|
+
"build": "tsc"
|
36
33
|
}
|
37
34
|
}
|
package/src/bin.ts
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
import { main } from ".";
|
4
|
+
import { formatError } from "./util/format-error";
|
5
|
+
|
6
|
+
// Show usage and exit with code
|
7
|
+
function help(code: number) {
|
8
|
+
console.log(`Usage:
|
9
|
+
b-gsdk generate
|
10
|
+
`);
|
11
|
+
process.exit(code);
|
12
|
+
}
|
13
|
+
|
14
|
+
// Get CLI arguments
|
15
|
+
const [, , cmd] = process.argv;
|
16
|
+
|
17
|
+
// CLI commands
|
18
|
+
const cmds: { [key: string]: () => void } = {
|
19
|
+
generate: main,
|
20
|
+
};
|
21
|
+
|
22
|
+
// Run CLI
|
23
|
+
try {
|
24
|
+
// Run command or show usage for unknown command
|
25
|
+
cmds[cmd] ? cmds[cmd]() : help(0);
|
26
|
+
} catch (e) {
|
27
|
+
console.error(formatError(e).message);
|
28
|
+
process.exit(1);
|
29
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,11 +1,21 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
1
|
import { generate } from "@graphql-codegen/cli";
|
4
2
|
import resolvePkg from "resolve-pkg";
|
5
3
|
import fs from "fs";
|
6
4
|
import path from "path";
|
5
|
+
import { getBGsdkDirectoryPath } from "./util/get-b-gsdk-directory-path";
|
6
|
+
|
7
|
+
export async function main() {
|
8
|
+
console.log("starting main");
|
9
|
+
const bgsdkDirectoryPath = getBGsdkDirectoryPath(process.cwd());
|
7
10
|
|
8
|
-
|
11
|
+
console.log("got dir path:", bgsdkDirectoryPath);
|
12
|
+
if (!bgsdkDirectoryPath) {
|
13
|
+
throw new Error(
|
14
|
+
"Make sure you have a b-gsdk directory in the root of your project."
|
15
|
+
);
|
16
|
+
}
|
17
|
+
|
18
|
+
console.log("attempting codegen");
|
9
19
|
const [schemaCodegen, sdkCodegen] = await generate(
|
10
20
|
{
|
11
21
|
schema: {
|
@@ -19,8 +29,8 @@ async function main() {
|
|
19
29
|
generates: {
|
20
30
|
[__dirname + "/generated/index.ts"]: {
|
21
31
|
documents: [
|
22
|
-
|
23
|
-
|
32
|
+
bgsdkDirectoryPath + "/**/*.{gql,graphql}",
|
33
|
+
bgsdkDirectoryPath + "/*.{gql,graphql}",
|
24
34
|
],
|
25
35
|
plugins: [
|
26
36
|
"typescript",
|
@@ -39,10 +49,11 @@ async function main() {
|
|
39
49
|
},
|
40
50
|
false
|
41
51
|
);
|
52
|
+
console.log("ok COOl, i got it:", sdkCodegen);
|
53
|
+
console.log("attempting to write to file");
|
42
54
|
const resolved = resolvePkg("@b-gsdk/client");
|
43
55
|
if (!resolved) {
|
44
|
-
|
45
|
-
return;
|
56
|
+
throw new Error("Please install @b-gsdk/client");
|
46
57
|
}
|
47
58
|
fs.writeFileSync(
|
48
59
|
path.join(resolved, "generated/graphql.schema.json"),
|
@@ -54,5 +65,3 @@ async function main() {
|
|
54
65
|
);
|
55
66
|
console.log("done");
|
56
67
|
}
|
57
|
-
|
58
|
-
main();
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export const formatError = (error: unknown): Error => {
|
2
|
+
if (error instanceof Error) {
|
3
|
+
return error;
|
4
|
+
}
|
5
|
+
|
6
|
+
if (typeof error === "string") {
|
7
|
+
return new Error(error);
|
8
|
+
}
|
9
|
+
|
10
|
+
if (typeof error === "object") {
|
11
|
+
return new Error(JSON.stringify(error, null, 2));
|
12
|
+
}
|
13
|
+
|
14
|
+
return new Error(`Unknown error: ${error}`);
|
15
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import fs from "fs";
|
2
|
+
import path from "path";
|
3
|
+
|
4
|
+
// taken from prisma https://github.com/prisma/prisma/blob/8f6b7c7c99c1c720cf5bfed5d563423e71c1b84f/packages/sdk/src/cli/getSchema.ts#L46-L49
|
5
|
+
export const getBGsdkDirectoryPath = async (cwd: string) => {
|
6
|
+
const schemaPath = path.join(cwd, "b-gsdk");
|
7
|
+
if (fs.existsSync(schemaPath)) {
|
8
|
+
return schemaPath;
|
9
|
+
}
|
10
|
+
|
11
|
+
return null;
|
12
|
+
};
|
package/tsconfig.json
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"extends": "@tsconfig/node16/tsconfig.json",
|
3
|
-
|
4
|
-
// Most ts-node options can be specified here using their programmatic names.
|
5
3
|
"ts-node": {
|
6
4
|
// It is faster to skip typechecking.
|
7
5
|
// Remove if you want ts-node to do typechecking.
|
8
6
|
"transpileOnly": true,
|
9
|
-
|
10
7
|
"files": true,
|
11
|
-
|
12
8
|
"compilerOptions": {
|
13
9
|
// compilerOptions specified here will override those declared below,
|
14
10
|
// but *only* in ts-node. Useful if you want ts-node and tsc to use
|
@@ -16,6 +12,7 @@
|
|
16
12
|
}
|
17
13
|
},
|
18
14
|
"compilerOptions": {
|
19
|
-
|
15
|
+
"rootDir": "src",
|
16
|
+
"outDir": "dist"
|
20
17
|
}
|
21
18
|
}
|
package/bin/fsevents.node
DELETED
Binary file
|