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:
committed by
GitHub
parent
85eb12883e
commit
627bdb689f
5
.changeset/gentle-cups-crash.md
Normal file
5
.changeset/gentle-cups-crash.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"gatsby-source-medusa": patch
|
||||
---
|
||||
|
||||
chore(gatsby-source-medusa): Cleanup plugin setup
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"presets": [["babel-preset-gatsby-package"]],
|
||||
"overrides": [
|
||||
{
|
||||
"test": [],
|
||||
"presets": [
|
||||
["babel-preset-gatsby-package", { "browser": true, "esm": true }]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
17
packages/gatsby-source-medusa/.gitignore
vendored
17
packages/gatsby-source-medusa/.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
src
|
||||
.prettierrc
|
||||
.env
|
||||
.babelrc.js
|
||||
.eslintrc
|
||||
.gitignore
|
||||
|
||||
.yarn
|
||||
.turbo
|
||||
13
packages/gatsby-source-medusa/jest.config.js
Normal file
13
packages/gatsby-source-medusa/jest.config.js
Normal file
@@ -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`],
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
|
||||
5
packages/gatsby-source-medusa/tsconfig.spec.json
Normal file
5
packages/gatsby-source-medusa/tsconfig.spec.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
31
yarn.lock
31
yarn.lock
@@ -2294,7 +2294,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-transform-typescript@npm:^7.13.0, @babel/plugin-transform-typescript@npm:^7.15.4, @babel/plugin-transform-typescript@npm:^7.18.6":
|
||||
"@babel/plugin-transform-typescript@npm:^7.13.0, @babel/plugin-transform-typescript@npm:^7.18.6":
|
||||
version: 7.18.8
|
||||
resolution: "@babel/plugin-transform-typescript@npm:7.18.8"
|
||||
dependencies:
|
||||
@@ -2504,7 +2504,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/preset-flow@npm:^7.12.1, @babel/preset-flow@npm:^7.14.0":
|
||||
"@babel/preset-flow@npm:^7.12.1":
|
||||
version: 7.18.6
|
||||
resolution: "@babel/preset-flow@npm:7.18.6"
|
||||
dependencies:
|
||||
@@ -15057,7 +15057,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"babel-plugin-polyfill-corejs2@npm:^0.3.0, babel-plugin-polyfill-corejs2@npm:^0.3.1":
|
||||
"babel-plugin-polyfill-corejs2@npm:^0.3.1":
|
||||
version: 0.3.1
|
||||
resolution: "babel-plugin-polyfill-corejs2@npm:0.3.1"
|
||||
dependencies:
|
||||
@@ -15272,28 +15272,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"babel-preset-gatsby-package@npm:^2.0.0":
|
||||
version: 2.18.0
|
||||
resolution: "babel-preset-gatsby-package@npm:2.18.0"
|
||||
dependencies:
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator": ^7.14.5
|
||||
"@babel/plugin-proposal-optional-chaining": ^7.14.5
|
||||
"@babel/plugin-syntax-dynamic-import": ^7.8.3
|
||||
"@babel/plugin-transform-runtime": ^7.15.0
|
||||
"@babel/plugin-transform-typescript": ^7.15.4
|
||||
"@babel/preset-env": ^7.15.4
|
||||
"@babel/preset-flow": ^7.14.0
|
||||
"@babel/preset-react": ^7.14.0
|
||||
"@babel/runtime": ^7.15.4
|
||||
babel-plugin-dynamic-import-node: ^2.3.3
|
||||
babel-plugin-lodash: ^3.3.4
|
||||
core-js: ^3.22.3
|
||||
peerDependencies:
|
||||
"@babel/core": ^7.11.6
|
||||
checksum: 1c3aeda5169728507258d35e06da3dbb0559a132c8c6e82f6fbd9535aa76ce691451b0bc91398e5381f2c1484b5125dd8bb9473e06ead07bfe03af7d76891492
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"babel-preset-gatsby@npm:^2.18.0":
|
||||
version: 2.18.0
|
||||
resolution: "babel-preset-gatsby@npm:2.18.0"
|
||||
@@ -22912,13 +22890,12 @@ __metadata:
|
||||
dependencies:
|
||||
"@types/jest": ^27.0.1
|
||||
axios: ^0.24.0
|
||||
babel-plugin-polyfill-corejs2: ^0.3.0
|
||||
babel-preset-gatsby-package: ^2.0.0
|
||||
gatsby: ^4.1.0
|
||||
gatsby-core-utils: ^3.3.0
|
||||
gatsby-plugin-image: ^2.3.0
|
||||
gatsby-source-filesystem: ^4.3.0
|
||||
jest: ^27.0.6
|
||||
ts-jest: ^27.1.5
|
||||
tsc-watch: ^4.5.0
|
||||
typescript: ^4.5.2
|
||||
peerDependencies:
|
||||
|
||||
Reference in New Issue
Block a user