Apply code formatting
This commit is contained in:
parent
bd41853696
commit
6540dc8001
4 changed files with 27 additions and 30 deletions
|
@ -4,8 +4,8 @@ SDK for building great Saleor Apps.
|
|||
|
||||
<div>
|
||||
|
||||
[](https://www.npmjs.com/package/@saleor/app-sdk)
|
||||
[](https://www.npmjs.com/package/@saleor/app-sdk)
|
||||
[](https://www.npmjs.com/package/@saleor/app-sdk)
|
||||
[](https://www.npmjs.com/package/@saleor/app-sdk)
|
||||
|
||||
</div>
|
||||
|
||||
|
|
33
src/index.ts
33
src/index.ts
|
@ -1,43 +1,38 @@
|
|||
import path from "path";
|
||||
import fg from "fast-glob";
|
||||
|
||||
import { print } from "graphql/language/printer.js";
|
||||
import path from "path";
|
||||
|
||||
const capitalize = (value: string) =>
|
||||
value.charAt(0).toUpperCase() + value.slice(1);
|
||||
const capitalize = (value: string) => value.charAt(0).toUpperCase() + value.slice(1);
|
||||
|
||||
const dropFileExtension = (filename: string) => path.parse(filename).name;
|
||||
|
||||
export const inferWebhooks = async (baseURL: string, webhooksPath: string, generatedGraphQL: any) => {
|
||||
export const inferWebhooks = async (
|
||||
baseURL: string,
|
||||
webhooksPath: string,
|
||||
generatedGraphQL: any
|
||||
) => {
|
||||
let entries;
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
entries = await fg(["*.js"], { cwd: webhooksPath });
|
||||
} else {
|
||||
entries = await fg(["*.ts"], { cwd: `pages/api/webhooks` });
|
||||
entries = await fg(["*.ts"], { cwd: "pages/api/webhooks" });
|
||||
}
|
||||
|
||||
return entries.map(dropFileExtension).map((name: string) => {
|
||||
const camelcaseName = name.split("-").map(capitalize).join("");
|
||||
const camelCaseName = name.split("-").map(capitalize).join("");
|
||||
|
||||
const eventName = name.toUpperCase().replace(new RegExp("-", "g"), "_");
|
||||
const eventName = name.toUpperCase().replace(/-/g, "_");
|
||||
let eventType: string;
|
||||
if (
|
||||
Object.values(generatedGraphQL.WebhookEventTypeAsyncEnum).includes(
|
||||
eventName
|
||||
)
|
||||
) {
|
||||
if (Object.values(generatedGraphQL.WebhookEventTypeAsyncEnum).includes(eventName)) {
|
||||
eventType = "asyncEvents";
|
||||
} else if (
|
||||
Object.values(generatedGraphQL.WebhookEventTypeSyncEnum).includes(
|
||||
eventName
|
||||
)
|
||||
) {
|
||||
} else if (Object.values(generatedGraphQL.WebhookEventTypeSyncEnum).includes(eventName)) {
|
||||
eventType = "syncEvents";
|
||||
} else {
|
||||
throw Error("Event type not found.");
|
||||
}
|
||||
|
||||
const statement = `${camelcaseName}SubscriptionDocument`;
|
||||
const statement = `${camelCaseName}SubscriptionDocument`;
|
||||
let query: string;
|
||||
if (statement in generatedGraphQL) {
|
||||
query = print((generatedGraphQL as any)[statement]);
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
"lib": ["ES2021"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
"target": "ES2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
||||
"lib": [
|
||||
"ES2021"
|
||||
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
|
@ -25,7 +27,7 @@
|
|||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
"module": "commonjs" /* Specify what module code is generated. */,
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
|
@ -71,12 +73,12 @@
|
|||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
|
|
Loading…
Reference in a new issue