chore(gatsby-source-medusa): Cleanup plugin setup (#4419)

* chore(gatsby-source-medusa): Cleanup plugin setup

* fix process-node

* Create gentle-cups-crash.md
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2023-06-27 14:00:11 +02:00
1 parent 85eb12883e
commit 627bdb689f
14 files changed
+74 -92

No files matched your search

-11
View File
@@ -1,11 +0,0 @@
{
"presets": [["babel-preset-gatsby-package"]],
"overrides": [
{
"test": [],
"presets": [
["babel-preset-gatsby-package", { "browser": true, "esm": true }]
]
}
]
}
+5 -12
View File
@@ -1,13 +1,6 @@
/dist
node_modules
.DS_Store
utils
*.js
*.js.map
*.d.ts
!/types/*.d.ts
!jest.config.js
.DS_store
.env*
.env
*.sql
-9
View File
@@ -1,9 +0,0 @@
src
.prettierrc
.env
.babelrc.js
.eslintrc
.gitignore
.yarn
.turbo
@@ -0,0 +1,13 @@
module.exports = {
globals: {
"ts-jest": {
tsconfig: "tsconfig.spec.json",
isolatedModules: false,
},
},
transform: {
"^.+\\.[jt]s?$": "ts-jest",
},
testEnvironment: `node`,
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
}
+6 -4
View File
@@ -4,9 +4,12 @@
"description": "Gatsby source plugin for building websites using Medusa Commerce as a data source",
"scripts": {
"test": "jest --passWithNoTests",
"watch": "tsc-watch --outDir .",
"build": "tsc --outDir ."
"watch": "tsc-watch",
"build": "tsc"
},
"files": [
"dist"
],
"keywords": [
"gatsby",
"gatsby-plugin",
@@ -27,16 +30,15 @@
},
"dependencies": {
"axios": "^0.24.0",
"babel-preset-gatsby-package": "^2.0.0",
"gatsby-core-utils": "^3.3.0",
"gatsby-plugin-image": "^2.3.0",
"gatsby-source-filesystem": "^4.3.0"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"babel-plugin-polyfill-corejs2": "^0.3.0",
"gatsby": "^4.1.0",
"jest": "^27.0.6",
"ts-jest": "^27.1.5",
"tsc-watch": "^4.5.0",
"typescript": "^4.5.2"
},
@@ -1,20 +1,20 @@
const { processNode } = require("../src/process-node.ts");
const { processNode } = require("../process-node.ts")
describe("helper functions", () => {
it("should return return a new node from processNode", () => {
const fieldName = "product";
const fieldName = "product"
const node = {
id: "prod_test_1234",
title: "Test Shirt",
description: "A test product",
unit_price: 2500,
};
}
const createContentDigest = jest.fn(() => "digest_string");
const processNodeResult = processNode(node, fieldName, createContentDigest);
const createContentDigest = jest.fn(() => "digest_string")
const processNodeResult = processNode(node, fieldName, createContentDigest)
expect(createContentDigest).toBeCalled();
expect(createContentDigest).toBeCalled()
expect(processNodeResult).toMatchSnapshot();
});
});
expect(processNodeResult).toMatchSnapshot()
})
})
@@ -1,5 +1,3 @@
import { capitalize } from "./utils/capitalize"
export const processNode = (
node: any,
fieldName: string,
@@ -34,12 +32,14 @@ export const processNode = (
delete node.images
}
// TODO: use upperFirstCase from medusajs/utils when it's available
const type = `Medusa${fieldName[0].toUpperCase() + fieldName.slice(1)}`
const nodeData = Object.assign({}, node, {
id: nodeId,
parent: null,
children: [],
internal: {
type: `Medusa${capitalize(fieldName)}`,
type,
content: nodeContent,
contentDigest: nodeContentDigest,
},
@@ -1,3 +0,0 @@
export function capitalize(s: string): string {
return s[0].toUpperCase() + s.slice(1)
}
+24 -14
View File
@@ -1,19 +1,29 @@
{
"include": ["src/**/*.ts", "types"],
"exclude": ["node_modules"],
"compilerOptions": {
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"module": "commonjs",
"removeComments": false,
"preserveConstEnums": true,
"skipLibCheck": true,
"lib": ["es2020"],
"target": "es2020",
"outDir": "./dist",
"esModuleInterop": true,
"sourceMap": true,
"target": "es2017",
"declaration": true,
"lib": ["es2017", "dom", "esnext.asynciterable"]
}
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"allowJs": true,
"skipLibCheck": true,
"downlevelIteration": true // to use ES5 specific tooling
},
"include": ["src"],
"exclude": [
"dist",
"./src/**/__tests__",
"./src/**/__mocks__",
"./src/**/__fixtures__",
"node_modules"
]
}
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": ["node_modules"]
}