Apply code formatting

This commit is contained in:
Krzysztof Wolski 2022-07-20 16:19:49 +02:00
parent bd41853696
commit 6540dc8001
4 changed files with 27 additions and 30 deletions

View file

@ -4,8 +4,8 @@ SDK for building great Saleor Apps.
<div> <div>
[![npm version badge](https://img.shields.io/npm/v/@saleor/app-sdk)](https://www.npmjs.com/package/@saleor/app-sdk) [![npm version badge](https://img.shields.io/npm/v/@saleor/app-sdk)](https://www.npmjs.com/package/@saleor/app-sdk)
[![npm downloads count](https://img.shields.io/npm/dt/@saleor/app-sdk)](https://www.npmjs.com/package/@saleor/app-sdk) [![npm downloads count](https://img.shields.io/npm/dt/@saleor/app-sdk)](https://www.npmjs.com/package/@saleor/app-sdk)
</div> </div>

View file

@ -1,43 +1,38 @@
import path from "path";
import fg from "fast-glob"; import fg from "fast-glob";
import { print } from "graphql/language/printer.js"; import { print } from "graphql/language/printer.js";
import path from "path";
const capitalize = (value: string) => const capitalize = (value: string) => value.charAt(0).toUpperCase() + value.slice(1);
value.charAt(0).toUpperCase() + value.slice(1);
const dropFileExtension = (filename: string) => path.parse(filename).name; 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; let entries;
if (process.env.NODE_ENV === "production") { if (process.env.NODE_ENV === "production") {
entries = await fg(["*.js"], { cwd: webhooksPath }); entries = await fg(["*.js"], { cwd: webhooksPath });
} else { } else {
entries = await fg(["*.ts"], { cwd: `pages/api/webhooks` }); entries = await fg(["*.ts"], { cwd: "pages/api/webhooks" });
} }
return entries.map(dropFileExtension).map((name: string) => { 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; let eventType: string;
if ( if (Object.values(generatedGraphQL.WebhookEventTypeAsyncEnum).includes(eventName)) {
Object.values(generatedGraphQL.WebhookEventTypeAsyncEnum).includes(
eventName
)
) {
eventType = "asyncEvents"; eventType = "asyncEvents";
} else if ( } else if (Object.values(generatedGraphQL.WebhookEventTypeSyncEnum).includes(eventName)) {
Object.values(generatedGraphQL.WebhookEventTypeSyncEnum).includes(
eventName
)
) {
eventType = "syncEvents"; eventType = "syncEvents";
} else { } else {
throw Error("Event type not found."); throw Error("Event type not found.");
} }
const statement = `${camelcaseName}SubscriptionDocument`; const statement = `${camelCaseName}SubscriptionDocument`;
let query: string; let query: string;
if (statement in generatedGraphQL) { if (statement in generatedGraphQL) {
query = print((generatedGraphQL as any)[statement]); query = print((generatedGraphQL as any)[statement]);

View file

@ -11,8 +11,10 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */ /* Language and Environment */
"target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ "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. */ "lib": [
"ES2021"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
// "jsx": "preserve", /* Specify what JSX code is generated. */ // "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ // "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. */ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */ /* 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. */ // "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "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. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
@ -71,12 +73,12 @@
/* Interop Constraints */ /* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "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. */ // "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. */ // "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 */ /* 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. */ // "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'. */ // "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. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */