b-gsdk 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
package/dist/bin.js
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
|
+
};
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
+
const _1 = require(".");
|
8
|
+
const format_error_1 = require("./util/format-error");
|
9
|
+
const arg_1 = __importDefault(require("arg"));
|
10
|
+
// Show usage and exit with code
|
11
|
+
function help(code) {
|
12
|
+
console.log(`Usage:
|
13
|
+
|
14
|
+
b-gsdk generate
|
15
|
+
|
16
|
+
`);
|
17
|
+
process.exit(code);
|
18
|
+
}
|
19
|
+
// Get CLI arguments
|
20
|
+
const [, , cmd] = process.argv;
|
21
|
+
const args = (0, arg_1.default)({
|
22
|
+
// types
|
23
|
+
"--dir": String,
|
24
|
+
// aliases
|
25
|
+
"-d": "--dir",
|
26
|
+
}, { permissive: true });
|
27
|
+
// CLI commands
|
28
|
+
const cmds = {
|
29
|
+
generate: _1.main,
|
30
|
+
};
|
31
|
+
// Run CLI
|
32
|
+
try {
|
33
|
+
// Run command or show usage for unknown command
|
34
|
+
cmds[cmd] ? cmds[cmd](args) : help(0);
|
35
|
+
}
|
36
|
+
catch (e) {
|
37
|
+
console.error((0, format_error_1.formatError)(e).message);
|
38
|
+
process.exit(1);
|
39
|
+
}
|
@@ -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,23 @@
|
|
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.getBGsdkConfig = void 0;
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
8
|
+
const path_1 = __importDefault(require("path"));
|
9
|
+
const zod_1 = require("zod");
|
10
|
+
const configSchema = zod_1.z.object({
|
11
|
+
schemaURL: zod_1.z.string(),
|
12
|
+
headers: zod_1.z.record(zod_1.z.string()),
|
13
|
+
});
|
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.`);
|
18
|
+
}
|
19
|
+
const rawConfig = JSON.parse(fs_1.default.readFileSync(bgsdkConfigPath, "utf8"));
|
20
|
+
const parsedConfig = configSchema.parse(rawConfig);
|
21
|
+
return parsedConfig;
|
22
|
+
};
|
23
|
+
exports.getBGsdkConfig = getBGsdkConfig;
|
@@ -0,0 +1,16 @@
|
|
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
|
+
const getBGsdkDirectoryPath = (cwd, customDir) => {
|
10
|
+
const schemaPath = path_1.default.join(cwd, customDir || "b-gsdk");
|
11
|
+
if (fs_1.default.existsSync(schemaPath)) {
|
12
|
+
return schemaPath;
|
13
|
+
}
|
14
|
+
return null;
|
15
|
+
};
|
16
|
+
exports.getBGsdkDirectoryPath = getBGsdkDirectoryPath;
|