Skip to content

Commit

Permalink
Merge pull request #30 from dylanon/gatsby-v4-support
Browse files Browse the repository at this point in the history
Gatsby v4 support
  • Loading branch information
dylanon authored Jan 9, 2022
2 parents 5e219bc + d5c71ae commit c2b3ed4
Show file tree
Hide file tree
Showing 27 changed files with 22,254 additions and 2,534 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ node_modules
coverage
.DS_Store
.idea
.env
.env
.yalc
yalc.lock
21 changes: 21 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
node_modules
coverage
.DS_Store
.idea
.env
.yalc
yalc.lock

/__mocks__
/__tests__
/fixtures
/test_sites
/testing
/.npmignore
/.nvmrc
/.prettierrc
/.releaserc.json
/.travis.yml
/generateFixtures.js
/jest.config.js
/testUtils.js
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14.18.2
8 changes: 6 additions & 2 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"branch": "master",
"dryRun": false
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"master",
{ "name": "alpha", "prerelease": true },
{ "name": "beta", "prerelease": true }
]
}
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
language: node_js

node_js:
- 10.15.3

cache: yarn

jobs:
include:
- stage: release
node_js: 10.15.3
deploy:
provider: script
on:
branch: master
all_branches: true
skip_cleanup: true
script:
- npx semantic-release
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,24 @@ Downloads listing info and images from your Etsy shop!

## Installation

### Sites on Gatsby v3+

Install the package from npm:

`npm i gatsby-source-etsy`

Install peer dependencies:

`npm i gatsby-source-filesystem`

### Sites on Gatsby v1, v2

Install version 1 from npm:

`npm i gatsby-source-etsy@^1.0.0`

## Configuration

Next, add the plugin to your `gatsby-config.js` file:

```javascript
Expand Down Expand Up @@ -130,3 +144,28 @@ Query:
```

See [`gatsby-image`](https://www.gatsbyjs.org/packages/gatsby-image/) for more.

## Contributing

Did something break, or is there additional functionality you'd like to add to this plugin? Consider contributing to this project!

Feel free to open an issue to discuss what's happening first, or dive right in and open a PR.

### Developing this plugin locally

You can use `yalc` to test changes you make to this plugin against a local Gatsby site:

```bash
# Install yalc globally on your system
yarn global add yalc

# Publish the package to your local repository
# (Run this from this repo's root directory)
yalc publish

# Use the package from your local repository instead of one from npm
# (Run this from your Gatsby site's root directory)
yalc add gatsby-source-etsy
```

For up-to-date information and troubleshooting, see `yalc`'s [documentation](https://github.com/wclr/yalc).
25 changes: 14 additions & 11 deletions __tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,20 @@ describe('processing', () => {
}
}),
}
const mockListingNode = {
id: 'gsetsy_listing_id1',
listing_id: `id1`,
last_modified_tsz: 1570240827981,
}
const mockListingImageNode = {
id: 'gsetsy_listing_id1_image_imageId1',
listing_id: `id1`,
last_modified_tsz: 1570240827981,
}
const mockGetNode = nodeId => {
const cachedNodes = {
'cached-gsetsy_listing_id1': {
id: 'gsetsy_listing_id1',
listing_id: `id1`,
last_modified_tsz: 1570240827981,
},
'cached-gsetsy_listing_id1': mockListingNode,
gsetsy_listing_id1_image_imageId1: mockListingImageNode,
}
return cachedNodes[nodeId]
}
Expand All @@ -251,12 +258,8 @@ describe('processing', () => {
`gatsby-source-etsy: using cached version of listing node gsetsy_listing_id1`
)
expect(touchNode).toBeCalledTimes(2)
expect(touchNode.mock.calls[0][0]).toEqual({
nodeId: 'gsetsy_listing_id1',
})
expect(touchNode.mock.calls[1][0]).toEqual({
nodeId: 'gsetsy_listing_id1_image_imageId1',
})
expect(touchNode.mock.calls[0][0]).toEqual(mockListingNode)
expect(touchNode.mock.calls[1][0]).toEqual(mockListingImageNode)
expect(createNode).not.toBeCalled()
})
})
Expand Down
4 changes: 2 additions & 2 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ exports.sourceNodes = async (
reporter.info(
`gatsby-source-etsy: using cached version of listing node ${cachedListingNode.id}`
)
touchNode({ nodeId: cachedListingNode.id })
cachedImageNodeIds.forEach(nodeId => touchNode({ nodeId }))
touchNode(cachedListingNode)
cachedImageNodeIds.forEach(nodeId => touchNode(getNode(nodeId)))
return
}

Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@
},
"dependencies": {
"bottleneck": "^2.19.5",
"gatsby-source-filesystem": "^2.1.5",
"node-fetch": "^2.6.0"
},
"peerDependencies": {
"gatsby-source-filesystem": "^3.0.0 || ^4.0.0"
},
"engines": {
"node": ">=10.15.3"
"node": ">=14.15.0"
},
"devDependencies": {
"faker": "^5.1.0",
"git-cz": "^3.2.1",
"faker": "^5.5.3",
"git-cz": "^3.3.0",
"jest": "^24.9.0",
"joi": "^17.2.1",
"nock": "^13.0.4",
"joi": "^17.5.0",
"nock": "^13.2.1",
"prettier": "1.18.2",
"semantic-release": "^15.13.24"
"semantic-release": "^18.0.1"
}
}
36 changes: 18 additions & 18 deletions testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ function generateFakeEtsyPages(numberOfResults = 100, resultsPerPage = 100) {
let workingPage = { results: [] }
for (let i = 0; i < numberOfResults; i = i + 1) {
workingPage.results.push({
listing_id: faker.random.number(),
listing_id: faker.datatype.number(),
state: faker.random.word(),
user_id: faker.random.number(),
user_id: faker.datatype.number(),
category_id: null,
title: faker.lorem.words(),
description: faker.lorem.sentences(),
Expand All @@ -17,17 +17,17 @@ function generateFakeEtsyPages(numberOfResults = 100, resultsPerPage = 100) {
last_modified_tsz: faker.date.past(),
price: faker.commerce.price(),
currency_code: faker.finance.currencyCode(),
quantity: faker.random.number(),
quantity: faker.datatype.number(),
sku: [],
tags: [faker.lorem.word()],
materials: [],
shop_section_id: faker.random.number(),
featured_rank: faker.random.number(),
shop_section_id: faker.datatype.number(),
featured_rank: faker.datatype.number(),
state_tsz: faker.date.past(),
url: faker.internet.url(),
views: faker.random.number(),
num_favorers: faker.random.number(),
shipping_template_id: faker.random.number(),
views: faker.datatype.number(),
num_favorers: faker.datatype.number(),
shipping_template_id: faker.datatype.number(),
processing_min: null,
processing_max: null,
who_made: faker.lorem.word(),
Expand All @@ -39,21 +39,21 @@ function generateFakeEtsyPages(numberOfResults = 100, resultsPerPage = 100) {
item_width: null,
item_height: null,
item_dimensions_unit: faker.lorem.word(),
is_private: faker.random.boolean(),
is_private: faker.datatype.boolean(),
recipient: null,
occasion: null,
style: null,
non_taxable: faker.random.boolean(),
is_customizable: faker.random.boolean(),
is_digital: faker.random.boolean(),
non_taxable: faker.datatype.boolean(),
is_customizable: faker.datatype.boolean(),
is_digital: faker.datatype.boolean(),
file_data: '',
should_auto_renew: faker.random.boolean(),
should_auto_renew: faker.datatype.boolean(),
language: faker.random.locale(),
has_variations: faker.random.boolean(),
taxonomy_id: faker.random.number(),
has_variations: faker.datatype.boolean(),
taxonomy_id: faker.datatype.number(),
taxonomy_path: [faker.lorem.word()],
used_manufacturer: faker.random.boolean(),
is_vintage: faker.random.boolean(),
used_manufacturer: faker.datatype.boolean(),
is_vintage: faker.datatype.boolean(),
})
const resultNumber = i + 1
if (
Expand All @@ -68,7 +68,7 @@ function generateFakeEtsyPages(numberOfResults = 100, resultsPerPage = 100) {
limit: String(resultsPerPage),
offset: String(resultsPerPage * pageIndex),
page: null,
shop_id: faker.random.uuid(),
shop_id: faker.datatype.uuid(),
keywords: null,
sort_on: 'created',
sort_order: 'down',
Expand Down
5 changes: 5 additions & 0 deletions test_sites/gatsby_v3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
.cache/
.env
.env.development
public
19 changes: 19 additions & 0 deletions test_sites/gatsby_v3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Gatsby v3 Test Site

## Developing

In this repo's root directory:

- Run `yalc publish`

In this directory:

- Create `.env.development` and populate with your secrets:

```bash
GATSBY_ETSY_API_KEY=your-api-key
GATSBY_ETSY_STORE_ID=your-store-id
```

- `yalc add gatsby-source-etsy`
- `yarn develop`
19 changes: 19 additions & 0 deletions test_sites/gatsby_v3/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require('dotenv').config({
path: `.env.${process.env.NODE_ENV}`,
})

module.exports = {
siteMetadata: {
siteUrl: 'https://www.yourdomain.tld',
title: 'Gatsby v3 Test Site',
},
plugins: [
{
resolve: `gatsby-source-etsy`,
options: {
api_key: process.env.GATSBY_ETSY_API_KEY,
shop_id: process.env.GATSBY_ETSY_STORE_ID,
},
},
],
}
24 changes: 24 additions & 0 deletions test_sites/gatsby_v3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "gatsby-v3-test-site",
"version": "1.0.0",
"private": true,
"description": "Gatsby v3 Test Site",
"author": "Dylan On",
"keywords": [
"gatsby"
],
"scripts": {
"develop": "gatsby develop",
"start": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve",
"clean": "gatsby clean"
},
"dependencies": {
"gatsby": "^3.0.0",
"gatsby-source-etsy": "^2.0.0-alpha.1",
"gatsby-source-filesystem": "^3.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1"
}
}
Binary file added test_sites/gatsby_v3/src/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c2b3ed4

Please sign in to comment.