fauna-gql-upload
Version:
Manage your FaunaDB resources in within your project and upload them using a single command
200 lines (199 loc) • 10.6 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
exports.defaultGraphqlEndpointEnv = exports.defaultApiEndpointEnv = exports.defaultSecretEnv = exports.defaultProvidersDir = exports.defaultDataDir = exports.defaultIndexesDir = exports.defaultFnsDir = exports.defaultRolesDir = exports.defaultSchema = exports.argv = void 0;
var path_1 = __importDefault(require("path"));
var fs_1 = __importDefault(require("fs"));
var yargs_1 = __importDefault(require("yargs"));
exports.argv = yargs_1["default"]
// Config options
.option("override", {
alias: "o",
description: "Override the schema, this will delete all your data in the database. This option is deprecated.",
type: "boolean",
deprecated: "`override` flag is deprecated and will be removed in a future version of Fauna GQL Upload. Use `--mode override` instead."
})
.option("mode", {
alias: "m",
description: "The mode to use when uploading GraphQL schema.",
type: "string",
choices: ["merge", "override", "replace"]
})
.option("yes", {
alias: "y",
description: "Answer yes to all potential prompts.",
type: "boolean"
})
.option("config", {
alias: "c",
description: "Specify custom path to config file",
type: "string"
})
.option("apiEndpointEnv", {
description: "Specify environment variable for custom API endpoint",
type: "string"
})
.option("graphqlEndpointEnv", {
description: "Specify environment variable for custom GraphQL endpoint",
type: "string"
})
.option("region", {
description: "Specify database region.",
type: "string"
})
.option("schemaPath", {
description: "Specify custom path for GraphQL schema",
type: "string"
})
.option("schemaDir", {
description: "Specify custom directory for GraphQL schema files",
type: "string"
})
.option("tsconfigPath", {
description: "Specify custom path for tsconfig file",
type: "string"
})
.option("envPath", {
description: "Specify custom path to environment file",
type: "string"
})
.option("secretEnv", {
description: "Specify custom environment variable for database secret",
type: "string"
})
.option("fnsDir", {
description: "Specify custom path to functions directory",
type: "string"
})
.option("rolesDir", {
description: "Specify custom path to roles directory",
type: "string"
})
.option("indexesDir", {
description: "Specify custom path to indexes directory",
type: "string"
})
.option("dataDir", {
description: "Specify custom path to data directory",
type: "string"
})
.option("providersDir", {
description: "Specify custom path to providers directory",
type: "string"
})
.option("codegen", {
description: "Whether or not to enable codegen",
type: "boolean"
})
.option("codegenDisableTypescript", {
description: "Whether or not to enable typescript plugin",
type: "boolean"
})
.option("codegenDisableOperations", {
description: "Whether or not to enable typescript operations plugin",
type: "boolean"
})
.option("codegenOutputFile", {
description: "Specify destination file for generated code",
type: "string"
})
.option("codegenHeaders", {
description: "Optional headers to include when fetching GraphQL schema",
type: "string"
})
.option("codegenDocuments", {
description: "Specify documents containing GraphQL operations and/or fragments",
type: "array"
})
.option("codegenPlugins", {
description: "Specify plugins to use with GraphQL Codegen",
type: "array"
})
.option("codegenPluginOptions", {
description: "Specify options for GraphQL codegen plugins",
type: "string"
})
// Select resources
.option("schema", {
description: "Upload schema",
type: "boolean"
})
.option("data", {
description: "Upload data",
type: "boolean"
})
.option("functions", {
description: "Upload functions",
type: "boolean"
})
.option("indexes", {
description: "Upload indexes",
type: "boolean"
})
.option("providers", {
description: "Upload providers",
type: "boolean"
})
.option("roles", {
description: "Upload roles",
type: "boolean"
})
.option("ignoreAll", {
description: "Ignore all resources",
type: "boolean"
})
.argv;
var cwd = process.cwd();
exports.defaultSchema = fs_1["default"].existsSync("./fauna/schema.gql") ? "./fauna/schema.gql" : "./fauna/schema.graphql";
exports.defaultRolesDir = path_1["default"].join("fauna", "roles");
exports.defaultFnsDir = path_1["default"].join("fauna", "functions");
exports.defaultIndexesDir = path_1["default"].join("fauna", "indexes");
exports.defaultDataDir = path_1["default"].join("fauna", "data");
exports.defaultProvidersDir = path_1["default"].join("fauna", "providers");
exports.defaultSecretEnv = "FGU_SECRET";
exports.defaultApiEndpointEnv = "FGU_API_ENDPOINT";
exports.defaultGraphqlEndpointEnv = "FGU_GRAPHQL_ENDPOINT";
var globalConfig = null;
function getConfig(verifyConfig) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
if (verifyConfig === void 0) { verifyConfig = false; }
if (globalConfig)
return globalConfig;
var customConfig = exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.config;
var configPath = path_1["default"].join(cwd, (customConfig || ".fauna.json"));
if (customConfig && verifyConfig && !fs_1["default"].existsSync(configPath)) {
throw new Error("Could not find custom config at path " + configPath);
}
var providedConfig = fs_1["default"].existsSync(configPath) ? JSON.parse(fs_1["default"].readFileSync(configPath, "utf8")) : {};
var codegenTypescript = (_b = (_a = providedConfig.codegen) === null || _a === void 0 ? void 0 : _a.typescript) !== null && _b !== void 0 ? _b : true;
var config = {
apiEndpointEnv: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.apiEndpointEnv) || providedConfig.apiEndpointEnv || exports.defaultApiEndpointEnv,
graphqlEndpointEnv: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.graphqlEndpointEnv) || providedConfig.graphqlEndpointEnv || exports.defaultGraphqlEndpointEnv,
region: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.region) || (providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.region) || undefined,
mode: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.mode) || providedConfig.mode || "merge",
schemaPath: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.schemaPath) || providedConfig.schemaPath || exports.defaultSchema,
schemaDir: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.schemaDir) || providedConfig.schemaDir || undefined,
tsconfigPath: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.tsconfigPath) || providedConfig.tsconfigPath,
envPath: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.envPath) || providedConfig.envPath || ".env",
secretEnv: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.secretEnv) || providedConfig.secretEnv || exports.defaultSecretEnv,
fnsDir: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.fnsDir) || providedConfig.fnsDir || exports.defaultFnsDir,
rolesDir: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.rolesDir) || providedConfig.rolesDir || exports.defaultRolesDir,
indexesDir: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.indexesDir) || providedConfig.indexesDir || exports.defaultIndexesDir,
dataDir: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.dataDir) || providedConfig.dataDir || exports.defaultDataDir,
providersDir: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.providersDir) || providedConfig.providersDir || exports.defaultProvidersDir,
codegen: ((_c = exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.codegen) !== null && _c !== void 0 ? _c : providedConfig.codegen) ? {
typescript: (_d = !(exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.codegenDisableTypescript)) !== null && _d !== void 0 ? _d : codegenTypescript,
operations: (_g = (_e = !(exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.codegenDisableOperations)) !== null && _e !== void 0 ? _e : (_f = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.codegen) === null || _f === void 0 ? void 0 : _f.operations) !== null && _g !== void 0 ? _g : true,
outputFile: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.codegenOutputFile) || ((_h = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.codegen) === null || _h === void 0 ? void 0 : _h.outputFile) || (codegenTypescript ? "generated/graphql.ts" : "generated/graphql.js"),
headers: ((exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.codegenHeaders) ? JSON.parse(exports.argv.codegenHeaders) : null) || ((_j = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.codegen) === null || _j === void 0 ? void 0 : _j.headers) || {},
documents: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.codegenDocuments) || ((_k = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.codegen) === null || _k === void 0 ? void 0 : _k.documents) || [],
plugins: (exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.codegenPlugins) || ((_l = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.codegen) === null || _l === void 0 ? void 0 : _l.plugins) || [],
pluginOptions: ((exports.argv === null || exports.argv === void 0 ? void 0 : exports.argv.codegenPluginOptions) ? JSON.parse(exports.argv.codegenPluginOptions) : null) || ((_m = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.codegen) === null || _m === void 0 ? void 0 : _m.pluginOptions) || {}
} : null
};
globalConfig = config;
return config;
}
exports["default"] = getConfig;