From 7e18b0a56a54a2192fcc4bd4b14a420526ecdd00 Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Thu, 7 May 2020 01:37:17 +1000 Subject: [PATCH 01/18] created PluginOptions Singleton class Co-authored-by: Luke Bennett --- .../src/pluginOptions.js | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 packages/gatsby-source-shopify/src/pluginOptions.js diff --git a/packages/gatsby-source-shopify/src/pluginOptions.js b/packages/gatsby-source-shopify/src/pluginOptions.js new file mode 100644 index 0000000000000..8654843bbc5a4 --- /dev/null +++ b/packages/gatsby-source-shopify/src/pluginOptions.js @@ -0,0 +1,93 @@ +// created this singalton class as a quick way to reference options anywhere within the plugin + +class PluginOptions { + #shopName; + + #accessToken; + + #apiVersion; + + #verbose; + + #paginationSize; + + #includeCollections; + + #downloadImages; + + #defaultImageUrl; + + get shopName() { + return this.#shopName; + } + + get accessToken() { + return this.#accessToken; + } + + get apiVersion() { + return this.#apiVersion || '2020-01'; + } + + get verbose() { + return this.#verbose || true; + } + + get paginationSize() { + return this.#paginationSize || 250; + } + + get includeCollections() { + return this.#includeCollections || ['shop', 'content']; + } + + get downloadImages() { + return this.#downloadImages; + } + + get defaultImageUrl() { + return this.#defaultImage; + } + + setShopName(shopName) { + this.#shopName = shopName; + return this; + } + + setAccessToken(accessToken) { + this.#accessToken = accessToken; + return this; + } + + setApiVersion(apiVersion) { + this.#apiVersion = apiVersion; + return this; + } + + setVerbose(verbose) { + this.#verbose = verbose; + return this; + } + + setPaginationSize(paginationSize) { + this.#paginationSize = paginationSize; + return this; + } + + setIncludeCollections(includeCollections) { + this.#includeCollections = includeCollections; + return this; + } + + setDownloadImages(downloadImages) { + this.#downloadImages = downloadImages; + return this; + } + + setDefaultImageUrl(defaultImageUrl) { + this.#defaultImageUrl = defaultImageUrl; + return this; + } +} + +export default new PluginOptions(); From 80ccf1c88608feaabb08d3b5b6fdce705a47ec2d Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Thu, 7 May 2020 01:45:01 +1000 Subject: [PATCH 02/18] set upnew plugin Options defintion Co-authored-by: Luke Bennett --- packages/gatsby-source-shopify/src/gatsby-node.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/gatsby-source-shopify/src/gatsby-node.js b/packages/gatsby-source-shopify/src/gatsby-node.js index 44df87704998a..c9bbd9b3864cd 100644 --- a/packages/gatsby-source-shopify/src/gatsby-node.js +++ b/packages/gatsby-source-shopify/src/gatsby-node.js @@ -3,6 +3,7 @@ import chalk from "chalk" import { forEach } from "p-iteration" import { printGraphQLError, queryAll, queryOnce } from "./lib" import { createClient } from "./create-client" +import PluginOptions from './pluginOptions' import { ArticleNode, @@ -53,8 +54,20 @@ export const sourceNodes = async ( verbose = true, paginationSize = 250, includeCollections = [SHOP, CONTENT], + downloadImages, + defaultImageUrl, } ) => { + // sending options into PluginOptions Singleton Class + PluginOptions.setShopName(shopName) + .setAccessToken(accessToken) + .setApiVersion(apiVersion) + .setVerbose(verbose) + .setPaginationSize(paginationSize) + .setIncludeCollections(includeCollections) + .setDownloadImages(downloadImages) + .setDefaultImageUrl(defaultImageUrl); + const client = createClient(shopName, accessToken, apiVersion) // Convenience function to namespace console messages. From 86228d6b9be1d3b317e87b0be92f8575dfcbabcc Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Thu, 7 May 2020 01:46:14 +1000 Subject: [PATCH 03/18] create default values for new options Co-authored-by: Luke Bennett --- packages/gatsby-source-shopify/src/gatsby-node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-shopify/src/gatsby-node.js b/packages/gatsby-source-shopify/src/gatsby-node.js index c9bbd9b3864cd..d20e0d9ef2612 100644 --- a/packages/gatsby-source-shopify/src/gatsby-node.js +++ b/packages/gatsby-source-shopify/src/gatsby-node.js @@ -54,8 +54,8 @@ export const sourceNodes = async ( verbose = true, paginationSize = 250, includeCollections = [SHOP, CONTENT], - downloadImages, - defaultImageUrl, + downloadImages=true, + defaultImageUrl='https://raw.githubusercontent.com/lukebennett88/gatsby-transformer-shopify-images/topic/shopify-option-downloadImages/plugins/gatsby-source-shopify/src/default.png', } ) => { // sending options into PluginOptions Singleton Class From 2611e616b8d95f2d58ec29da5222f5e14638098a Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Thu, 7 May 2020 01:59:08 +1000 Subject: [PATCH 04/18] if downloadImages set to false download default image instead (caching will make that defaultImage only download once) Co-authored-by: Luke Bennett --- packages/gatsby-source-shopify/src/nodes.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-source-shopify/src/nodes.js b/packages/gatsby-source-shopify/src/nodes.js index 4a89f45c972dc..d3235634b54ed 100644 --- a/packages/gatsby-source-shopify/src/nodes.js +++ b/packages/gatsby-source-shopify/src/nodes.js @@ -1,6 +1,7 @@ import createNodeHelpers from "gatsby-node-helpers" import { map } from "p-iteration" import { createRemoteFileNode } from "gatsby-source-filesystem" +import PluginOptions from "./pluginOptions" import { TYPE_PREFIX, @@ -26,8 +27,9 @@ const downloadImageAndCreateFileNode = async ( { createNode, createNodeId, touchNode, store, cache, getCache, reporter } ) => { let fileNodeID - - const mediaDataCacheKey = `${TYPE_PREFIX}__Media__${url}` + + const effectiveUrl = PluginOptions.downloadImages ? url : PluginOptions.defaultImageUrl + const mediaDataCacheKey = `${TYPE_PREFIX}__Media__${effectiveUrl}` const cacheMediaData = await cache.get(mediaDataCacheKey) if (cacheMediaData) { @@ -37,7 +39,7 @@ const downloadImageAndCreateFileNode = async ( } const fileNode = await createRemoteFileNode({ - url, + url: effectiveUrl, store, cache, createNode, From c18f7c6618bfbe460b6656cb1e1393edb6ab711a Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Thu, 7 May 2020 02:48:31 +1000 Subject: [PATCH 05/18] default image --- packages/gatsby-source-shopify/src/default.png | Bin 0 -> 10929 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 packages/gatsby-source-shopify/src/default.png diff --git a/packages/gatsby-source-shopify/src/default.png b/packages/gatsby-source-shopify/src/default.png new file mode 100644 index 0000000000000000000000000000000000000000..6bb5c3c7a168650a8b690f56bc3c0d72f71d378f GIT binary patch literal 10929 zcmch72|Sf=yY7pSlBq(Gu~L~88KcYz6(aMHd7kGfg`$w5WGX{so~MOX#t<@(%a|#% z%q-5m{$JlY-#PpH_C9-`{X62GHd+{%Qhk3>u=5i0U=?VLv28f5K5!0CJT+k-Gy-Hl)+$rBFefNOt zYH{$|>nVoO{n59m73AXsgUmsGvW)k}sgu0Caaw0ldXygq!_1FeGWqpl!;mO(YJuTa z&6u=%j4LK7MZGzWboE8Owv)zq ztO0A}dp5GuAq`|PBJZL}qupK#CTE zkx=qkTuH${`Cy3u;l0#3(U}QGhXZ+s=AYLBB8>3VGQ#P_cNhUp z%{w2Fs-(`F(|-P1Oyx6MInJ-UiJ2s;HEZz5$oxB5jPpFJQ0YasM}5V6+XR->4yn~M z-3zcUM1~5oQpgeR--qh-NO*byTWf1$8z)54!Pvmb_z9D%xsw@_ti0lVb$>D%1YtttrEaUb4K0m$-d8nE zytPVvDLI5TrJ(v*J)umbUF*1C7M1BYnOc22=7n#XQa6RKUTy19?Q2sq#>~|#kec)a zm!#%XoyM^6lA+9QpD|yhsxV{Y3pOL>ek{QxcfR7v%{ZH#!^463-$hH^5{yi@e|u$S z+!dVNa35Q7ci-Fa9PLw-IwmEx?N7;pN6DKX989YrRsV&B#ZaH}uSkH!Ut$&ex^N{r6>3B7*h=k)RM7?#bHc zC*3Aru<=;-aXfqWjOpUVW6HO7FOFa^K^XlDLJk*^4@o*{#60uwNYDMH#((`I5(Wv?{5uA?lWsv$MRW=6g4HcM?BcUtO;?=?bsi zLQ+*byL==(H#Zj#{m9j|tn1dEc_m|`gn~jyS0hXrWgSG$NR6zgi(}<&Mysx3Fc|Sc z%fSWNJ6XLiT}R!CTiSbp7Htf*8~w){Sr<4g+5MIHMNOv5v;*sVNIPW zvJceNo64M6Xv7Xy>nJFLgE5%12r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z9h$-#O=rj2KI8=yWVP zZtrD!_FD>_9Q{fL_DZMlKa|#am0B>2SwuzYi30H87aZ+(BCcG(o%4YoiEj3&xI{K~ zrz^`odPKe9A?D!VUu`#O;2Rpg1BmCpDI*8S3eFMk+U19&BLVU=` zI1V-1==NMq!xs+;dJz{=Yinya|@j?q4jzo-4HiY0(AI>_hL0TCs4is=uW6E|` z48)i~Y*E4in@Yv>Ze|gYI0Naby5xzE$;tR^%8B*RZGrB1=g3GX6y+&(^xj!0s%ryA zVFhxyQ)GJ|SM}&G{afn&cjo^u&WHUsb`Ef}_o&qw+Xr}$4!(ES%j n!Yu{vtA9@F{e55rIU<*xNT^t)i^7M4i-^3ml2q;;{ipu}n-T)v literal 0 HcmV?d00001 From 0f0e423187d831a82141fd7b5796b822ffa9ffe6 Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Thu, 7 May 2020 02:52:22 +1000 Subject: [PATCH 06/18] change default image --- packages/gatsby-source-shopify/src/gatsby-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-shopify/src/gatsby-node.js b/packages/gatsby-source-shopify/src/gatsby-node.js index d20e0d9ef2612..ae85c5c0d2547 100644 --- a/packages/gatsby-source-shopify/src/gatsby-node.js +++ b/packages/gatsby-source-shopify/src/gatsby-node.js @@ -55,7 +55,7 @@ export const sourceNodes = async ( paginationSize = 250, includeCollections = [SHOP, CONTENT], downloadImages=true, - defaultImageUrl='https://raw.githubusercontent.com/lukebennett88/gatsby-transformer-shopify-images/topic/shopify-option-downloadImages/plugins/gatsby-source-shopify/src/default.png', + defaultImageUrl='https://raw.githubusercontent.com/mrhut10/gatsby/Feature/gatsby-source-shopify/downloadImagesOption/packages/gatsby-source-shopify/src/default.png', } ) => { // sending options into PluginOptions Singleton Class From d4ddd8e6cd1b80d11dc34c45f14510d32acae2b1 Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Thu, 7 May 2020 02:52:39 +1000 Subject: [PATCH 07/18] add documentation --- packages/gatsby-source-shopify/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/gatsby-source-shopify/README.md b/packages/gatsby-source-shopify/README.md index 957aca52b2f94..41873926c5024 100644 --- a/packages/gatsby-source-shopify/README.md +++ b/packages/gatsby-source-shopify/README.md @@ -70,6 +70,12 @@ plugins: [ // Possible values are: 'shop' and 'content'. // Defaults to ['shop', 'content']. includeCollections: ["shop", "content"], + // Download Images Locally + // set to false if you plan on using shopify's CDN + downloadImages: true, + // default image URL + // if you set downloadImages to false then it will set all localFile of file from this URL this is to make graphQL types unchanged + defaultImageURL: 'https://raw.githubusercontent.com/mrhut10/gatsby/Feature/gatsby-source-shopify/downloadImagesOption/packages/gatsby-source-shopify/src/default.png' }, }, ] From 4e64a4a2a9ab04f5d868e6d1f00d77880f2435f8 Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Thu, 7 May 2020 03:00:26 +1000 Subject: [PATCH 08/18] small mistake fix Co-authored-by: Luke Bennett --- packages/gatsby-source-shopify/src/pluginOptions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-shopify/src/pluginOptions.js b/packages/gatsby-source-shopify/src/pluginOptions.js index 8654843bbc5a4..a21bac7cbc239 100644 --- a/packages/gatsby-source-shopify/src/pluginOptions.js +++ b/packages/gatsby-source-shopify/src/pluginOptions.js @@ -46,7 +46,7 @@ class PluginOptions { } get defaultImageUrl() { - return this.#defaultImage; + return this.#defaultImageUrl; } setShopName(shopName) { From 314232571534f3c405a6c0703d3dd32ec24676f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Gazda?= Date: Thu, 14 May 2020 08:48:13 +0200 Subject: [PATCH 09/18] refact(plugin-options): follow filename convention --- .../src/{pluginOptions.js => plugin-options.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/gatsby-source-shopify/src/{pluginOptions.js => plugin-options.js} (100%) diff --git a/packages/gatsby-source-shopify/src/pluginOptions.js b/packages/gatsby-source-shopify/src/plugin-options.js similarity index 100% rename from packages/gatsby-source-shopify/src/pluginOptions.js rename to packages/gatsby-source-shopify/src/plugin-options.js From 7153d62718514a00a336caca915c8ac63a234e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Gazda?= Date: Thu, 14 May 2020 09:01:43 +0200 Subject: [PATCH 10/18] style(plugin-options): delete semicolons --- .../src/plugin-options.js | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/packages/gatsby-source-shopify/src/plugin-options.js b/packages/gatsby-source-shopify/src/plugin-options.js index a21bac7cbc239..40a41488293ee 100644 --- a/packages/gatsby-source-shopify/src/plugin-options.js +++ b/packages/gatsby-source-shopify/src/plugin-options.js @@ -1,93 +1,93 @@ // created this singalton class as a quick way to reference options anywhere within the plugin class PluginOptions { - #shopName; + #shopName - #accessToken; + #accessToken - #apiVersion; + #apiVersion - #verbose; + #verbose - #paginationSize; + #paginationSize - #includeCollections; + #includeCollections - #downloadImages; + #downloadImages - #defaultImageUrl; + #defaultImageUrl get shopName() { - return this.#shopName; + return this.#shopName } get accessToken() { - return this.#accessToken; + return this.#accessToken } get apiVersion() { - return this.#apiVersion || '2020-01'; + return this.#apiVersion || '2020-01' } get verbose() { - return this.#verbose || true; + return this.#verbose || true } get paginationSize() { - return this.#paginationSize || 250; + return this.#paginationSize || 250 } get includeCollections() { - return this.#includeCollections || ['shop', 'content']; + return this.#includeCollections || ['shop', 'content'] } get downloadImages() { - return this.#downloadImages; + return this.#downloadImages } get defaultImageUrl() { - return this.#defaultImageUrl; + return this.#defaultImageUrl } setShopName(shopName) { - this.#shopName = shopName; - return this; + this.#shopName = shopName + return this } setAccessToken(accessToken) { - this.#accessToken = accessToken; - return this; + this.#accessToken = accessToken + return this } setApiVersion(apiVersion) { - this.#apiVersion = apiVersion; - return this; + this.#apiVersion = apiVersion + return this } setVerbose(verbose) { - this.#verbose = verbose; - return this; + this.#verbose = verbose + return this } setPaginationSize(paginationSize) { - this.#paginationSize = paginationSize; - return this; + this.#paginationSize = paginationSize + return this } setIncludeCollections(includeCollections) { - this.#includeCollections = includeCollections; - return this; + this.#includeCollections = includeCollections + return this } setDownloadImages(downloadImages) { - this.#downloadImages = downloadImages; - return this; + this.#downloadImages = downloadImages + return this } setDefaultImageUrl(defaultImageUrl) { - this.#defaultImageUrl = defaultImageUrl; - return this; + this.#defaultImageUrl = defaultImageUrl + return this } } -export default new PluginOptions(); +export default new PluginOptions() From 6eb2286c9a01f40dfeb47e245431eaf0ce83235b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Gazda?= Date: Thu, 14 May 2020 09:09:56 +0200 Subject: [PATCH 11/18] style(plugin-options): prettier fixes --- packages/gatsby-source-shopify/src/plugin-options.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-shopify/src/plugin-options.js b/packages/gatsby-source-shopify/src/plugin-options.js index 40a41488293ee..33d54d646f947 100644 --- a/packages/gatsby-source-shopify/src/plugin-options.js +++ b/packages/gatsby-source-shopify/src/plugin-options.js @@ -26,7 +26,7 @@ class PluginOptions { } get apiVersion() { - return this.#apiVersion || '2020-01' + return this.#apiVersion || `2020-01` } get verbose() { @@ -38,7 +38,7 @@ class PluginOptions { } get includeCollections() { - return this.#includeCollections || ['shop', 'content'] + return this.#includeCollections || [`shop`, `content`] } get downloadImages() { From e1b915a0e16eb466b72c7448e6d6f2039bea2f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Gazda?= Date: Thu, 14 May 2020 09:12:01 +0200 Subject: [PATCH 12/18] style(gatsby-node): prettier fixes --- packages/gatsby-source-shopify/src/gatsby-node.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-source-shopify/src/gatsby-node.js b/packages/gatsby-source-shopify/src/gatsby-node.js index ae85c5c0d2547..8c09e380b897e 100644 --- a/packages/gatsby-source-shopify/src/gatsby-node.js +++ b/packages/gatsby-source-shopify/src/gatsby-node.js @@ -3,7 +3,7 @@ import chalk from "chalk" import { forEach } from "p-iteration" import { printGraphQLError, queryAll, queryOnce } from "./lib" import { createClient } from "./create-client" -import PluginOptions from './pluginOptions' +import PluginOptions from "./plugin-options" import { ArticleNode, @@ -54,8 +54,8 @@ export const sourceNodes = async ( verbose = true, paginationSize = 250, includeCollections = [SHOP, CONTENT], - downloadImages=true, - defaultImageUrl='https://raw.githubusercontent.com/mrhut10/gatsby/Feature/gatsby-source-shopify/downloadImagesOption/packages/gatsby-source-shopify/src/default.png', + downloadImages = true, + defaultImageUrl = `https://raw.githubusercontent.com/mrhut10/gatsby/Feature/gatsby-source-shopify/downloadImagesOption/packages/gatsby-source-shopify/src/default.png`, } ) => { // sending options into PluginOptions Singleton Class @@ -66,7 +66,7 @@ export const sourceNodes = async ( .setPaginationSize(paginationSize) .setIncludeCollections(includeCollections) .setDownloadImages(downloadImages) - .setDefaultImageUrl(defaultImageUrl); + .setDefaultImageUrl(defaultImageUrl) const client = createClient(shopName, accessToken, apiVersion) From 215deae19c8e3e64dcba768d6affcb868bacc1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Gazda?= Date: Thu, 14 May 2020 09:13:45 +0200 Subject: [PATCH 13/18] style(node): prettier fixes --- packages/gatsby-source-shopify/src/nodes.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-shopify/src/nodes.js b/packages/gatsby-source-shopify/src/nodes.js index d3235634b54ed..8163def836784 100644 --- a/packages/gatsby-source-shopify/src/nodes.js +++ b/packages/gatsby-source-shopify/src/nodes.js @@ -27,8 +27,10 @@ const downloadImageAndCreateFileNode = async ( { createNode, createNodeId, touchNode, store, cache, getCache, reporter } ) => { let fileNodeID - - const effectiveUrl = PluginOptions.downloadImages ? url : PluginOptions.defaultImageUrl + + const effectiveUrl = PluginOptions.downloadImages + ? url + : PluginOptions.defaultImageUrl const mediaDataCacheKey = `${TYPE_PREFIX}__Media__${effectiveUrl}` const cacheMediaData = await cache.get(mediaDataCacheKey) From 7ef8cc4cb6801b162430fabd552eac9f6be459f1 Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Fri, 15 May 2020 01:38:37 +1000 Subject: [PATCH 14/18] missed import reference --- packages/gatsby-source-shopify/src/nodes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-shopify/src/nodes.js b/packages/gatsby-source-shopify/src/nodes.js index 8163def836784..1903006bf2a43 100644 --- a/packages/gatsby-source-shopify/src/nodes.js +++ b/packages/gatsby-source-shopify/src/nodes.js @@ -1,7 +1,7 @@ import createNodeHelpers from "gatsby-node-helpers" import { map } from "p-iteration" import { createRemoteFileNode } from "gatsby-source-filesystem" -import PluginOptions from "./pluginOptions" +import PluginOptions from "./plugin-options" import { TYPE_PREFIX, From fefd72b4eedb111279db561b6301e63f1e5aff3a Mon Sep 17 00:00:00 2001 From: mrhut10 Date: Fri, 15 May 2020 02:28:10 +1000 Subject: [PATCH 15/18] lint error in document --- packages/gatsby-source-shopify/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-source-shopify/README.md b/packages/gatsby-source-shopify/README.md index 41873926c5024..9e1846d74f304 100644 --- a/packages/gatsby-source-shopify/README.md +++ b/packages/gatsby-source-shopify/README.md @@ -75,7 +75,8 @@ plugins: [ downloadImages: true, // default image URL // if you set downloadImages to false then it will set all localFile of file from this URL this is to make graphQL types unchanged - defaultImageURL: 'https://raw.githubusercontent.com/mrhut10/gatsby/Feature/gatsby-source-shopify/downloadImagesOption/packages/gatsby-source-shopify/src/default.png' + defaultImageURL: + "https://raw.githubusercontent.com/mrhut10/gatsby/Feature/gatsby-source-shopify/downloadImagesOption/packages/gatsby-source-shopify/src/default.png", }, }, ] From 1569974ca9e7e23a15d9ed14c979c7fb612ac3bb Mon Sep 17 00:00:00 2001 From: Alistair Hutten Date: Tue, 8 Sep 2020 02:50:11 +1000 Subject: [PATCH 16/18] yarn format --- packages/gatsby-source-shopify/README.md | 16 +- .../gatsby-source-shopify/src/gatsby-node.js | 144 +++++++++--------- 2 files changed, 80 insertions(+), 80 deletions(-) diff --git a/packages/gatsby-source-shopify/README.md b/packages/gatsby-source-shopify/README.md index f309e72f50179..b024c540918c0 100644 --- a/packages/gatsby-source-shopify/README.md +++ b/packages/gatsby-source-shopify/README.md @@ -104,7 +104,7 @@ plugins: [ }, }, }, -]; +] ``` NOTE: By default, all metafields are private. In order to pull metafields, @@ -472,10 +472,10 @@ To learn more about image processing, check the documentation of ## Site's `gatsby-node.js` example ```js -const path = require("path"); +const path = require("path") exports.createPages = async ({ graphql, boundActionCreators }) => { - const { createPage } = boundActionCreators; + const { createPage } = boundActionCreators const pages = await graphql(` { @@ -488,18 +488,18 @@ exports.createPages = async ({ graphql, boundActionCreators }) => { } } } - `); + `) - pages.data.allShopifyProduct.edges.forEach((edge) => { + pages.data.allShopifyProduct.edges.forEach(edge => { createPage({ path: `/${edge.node.handle}`, component: path.resolve("./src/templates/product.js"), context: { id: edge.node.id, }, - }); - }); -}; + }) + }) +} ``` ## shopifyQueries Defaults diff --git a/packages/gatsby-source-shopify/src/gatsby-node.js b/packages/gatsby-source-shopify/src/gatsby-node.js index 40212b7bc679a..09537dd3f83eb 100644 --- a/packages/gatsby-source-shopify/src/gatsby-node.js +++ b/packages/gatsby-source-shopify/src/gatsby-node.js @@ -1,9 +1,9 @@ -import { pipe } from "lodash/fp"; -import chalk from "chalk"; -import { forEach } from "p-iteration"; -import { printGraphQLError, queryAll, queryOnce } from "./lib"; -import { createClient } from "./create-client"; -import PluginOptions from "./plugin-options"; +import { pipe } from "lodash/fp" +import chalk from "chalk" +import { forEach } from "p-iteration" +import { printGraphQLError, queryAll, queryOnce } from "./lib" +import { createClient } from "./create-client" +import PluginOptions from "./plugin-options" import { ArticleNode, @@ -18,7 +18,7 @@ import { ShopPolicyNode, ShopDetailsNode, PageNode, -} from "./nodes"; +} from "./nodes" import { SHOP, CONTENT, @@ -30,7 +30,7 @@ import { SHOP_POLICY, SHOP_DETAILS, PAGE, -} from "./constants"; +} from "./constants" import { ARTICLES_QUERY, BLOGS_QUERY, @@ -39,7 +39,7 @@ import { SHOP_POLICIES_QUERY, SHOP_DETAILS_QUERY, PAGES_QUERY, -} from "./queries"; +} from "./queries" export const sourceNodes = async ( { @@ -70,9 +70,9 @@ export const sourceNodes = async ( .setPaginationSize(paginationSize) .setIncludeCollections(includeCollections) .setDownloadImages(downloadImages) - .setDefaultImageUrl(defaultImageUrl); + .setDefaultImageUrl(defaultImageUrl) - const client = createClient(shopName, accessToken, apiVersion); + const client = createClient(shopName, accessToken, apiVersion) const defaultQueries = { articles: ARTICLES_QUERY, @@ -82,16 +82,16 @@ export const sourceNodes = async ( shopPolicies: SHOP_POLICIES_QUERY, shopDetails: SHOP_DETAILS_QUERY, pages: PAGES_QUERY, - }; + } - const queries = { ...defaultQueries, ...shopifyQueries }; + const queries = { ...defaultQueries, ...shopifyQueries } // Convenience function to namespace console messages. - const formatMsg = (msg) => - chalk`\n{blue gatsby-source-shopify/${shopName}} ${msg}`; + const formatMsg = msg => + chalk`\n{blue gatsby-source-shopify/${shopName}} ${msg}` try { - console.log(formatMsg(`starting to fetch data from Shopify`)); + console.log(formatMsg(`starting to fetch data from Shopify`)) // Arguments used for file node creation. const imageArgs = { @@ -102,7 +102,7 @@ export const sourceNodes = async ( cache, getCache, reporter, - }; + } // Arguments used for node creation. const args = { @@ -114,12 +114,12 @@ export const sourceNodes = async ( imageArgs, paginationSize, queries, - }; + } // Message printed when fetching is complete. - const msg = formatMsg(`finished fetching data from Shopify`); + const msg = formatMsg(`finished fetching data from Shopify`) - let promises = []; + let promises = [] if (includeCollections.includes(SHOP)) { promises = promises.concat([ createNodes(COLLECTION, queries.collections, CollectionNode, args), @@ -130,59 +130,59 @@ export const sourceNodes = async ( args, async (product, productNode) => { if (product.variants) - await forEach(product.variants.edges, async (edge) => { - const v = edge.node; + await forEach(product.variants.edges, async edge => { + const v = edge.node if (v.metafields) - await forEach(v.metafields.edges, async (edge) => + await forEach(v.metafields.edges, async edge => createNode( await ProductVariantMetafieldNode(imageArgs)(edge.node) ) - ); + ) return createNode( await ProductVariantNode(imageArgs, productNode)(edge.node) - ); - }); + ) + }) if (product.metafields) - await forEach(product.metafields.edges, async (edge) => + await forEach(product.metafields.edges, async edge => createNode(await ProductMetafieldNode(imageArgs)(edge.node)) - ); + ) if (product.options) - await forEach(product.options, async (option) => + await forEach(product.options, async option => createNode(await ProductOptionNode(imageArgs)(option)) - ); + ) } ), createShopPolicies(args), createShopDetails(args), - ]); + ]) } if (includeCollections.includes(CONTENT)) { promises = promises.concat([ createNodes(BLOG, queries.blogs, BlogNode, args), - createNodes(ARTICLE, queries.articles, ArticleNode, args, async (x) => { + createNodes(ARTICLE, queries.articles, ArticleNode, args, async x => { if (x.comments) - await forEach(x.comments.edges, async (edge) => + await forEach(x.comments.edges, async edge => createNode(await CommentNode(imageArgs)(edge.node)) - ); + ) }), createPageNodes(PAGE, queries.pages, PageNode, args), - ]); + ]) } - console.time(msg); - await Promise.all(promises); - console.timeEnd(msg); + console.time(msg) + await Promise.all(promises) + console.timeEnd(msg) } catch (e) { - console.error(chalk`\n{red error} an error occurred while sourcing data`); + console.error(chalk`\n{red error} an error occurred while sourcing data`) // If not a GraphQL request error, let Gatsby print the error. - if (!e.hasOwnProperty(`request`)) throw e; + if (!e.hasOwnProperty(`request`)) throw e - printGraphQLError(e); + printGraphQLError(e) } -}; +} /** * Fetch and create nodes for the provided endpoint, query, and node factory. @@ -195,9 +195,9 @@ const createNodes = async ( f = async () => {} ) => { // Message printed when fetching is complete. - const msg = formatMsg(`fetched and processed ${endpoint} nodes`); + const msg = formatMsg(`fetched and processed ${endpoint} nodes`) - if (verbose) console.time(msg); + if (verbose) console.time(msg) await forEach( await queryAll( client, @@ -205,14 +205,14 @@ const createNodes = async ( query, paginationSize ), - async (entity) => { - const node = await nodeFactory(imageArgs)(entity); - createNode(node); - await f(entity, node); + async entity => { + const node = await nodeFactory(imageArgs)(entity) + createNode(node) + await f(entity, node) } - ); - if (verbose) console.timeEnd(msg); -}; + ) + if (verbose) console.timeEnd(msg) +} /** * Fetch and create nodes for shop policies. @@ -225,13 +225,13 @@ const createShopDetails = async ({ queries, }) => { // // Message printed when fetching is complete. - const msg = formatMsg(`fetched and processed ${SHOP_DETAILS} nodes`); + const msg = formatMsg(`fetched and processed ${SHOP_DETAILS} nodes`) - if (verbose) console.time(msg); - const { shop } = await queryOnce(client, queries.shopDetails); - createNode(ShopDetailsNode(shop)); - if (verbose) console.timeEnd(msg); -}; + if (verbose) console.time(msg) + const { shop } = await queryOnce(client, queries.shopDetails) + createNode(ShopDetailsNode(shop)) + if (verbose) console.timeEnd(msg) +} /** * Fetch and create nodes for shop policies. @@ -244,17 +244,17 @@ const createShopPolicies = async ({ queries, }) => { // Message printed when fetching is complete. - const msg = formatMsg(`fetched and processed ${SHOP_POLICY} nodes`); + const msg = formatMsg(`fetched and processed ${SHOP_POLICY} nodes`) - if (verbose) console.time(msg); - const { shop: policies } = await queryOnce(client, queries.shopPolicies); + if (verbose) console.time(msg) + const { shop: policies } = await queryOnce(client, queries.shopPolicies) Object.entries(policies) .filter(([_, policy]) => Boolean(policy)) .forEach( pipe(([type, policy]) => ShopPolicyNode(policy, { type }), createNode) - ); - if (verbose) console.timeEnd(msg); -}; + ) + if (verbose) console.timeEnd(msg) +} const createPageNodes = async ( endpoint, @@ -264,9 +264,9 @@ const createPageNodes = async ( f = async () => {} ) => { // Message printed when fetching is complete. - const msg = formatMsg(`fetched and processed ${endpoint} nodes`); + const msg = formatMsg(`fetched and processed ${endpoint} nodes`) - if (verbose) console.time(msg); + if (verbose) console.time(msg) await forEach( await queryAll( client, @@ -274,11 +274,11 @@ const createPageNodes = async ( query, paginationSize ), - async (entity) => { - const node = await nodeFactory(entity); - createNode(node); - await f(entity); + async entity => { + const node = await nodeFactory(entity) + createNode(node) + await f(entity) } - ); - if (verbose) console.timeEnd(msg); -}; + ) + if (verbose) console.timeEnd(msg) +} From c24c951315faf6fedd8ebb26dfb9cb1f3e9e6d47 Mon Sep 17 00:00:00 2001 From: Alistair Hutten Date: Mon, 11 Jan 2021 02:35:45 +1100 Subject: [PATCH 17/18] * removed pluginOption singleton * removed and defaultUrl image config * removed the default.png image * fixed up documentation --- packages/gatsby-source-shopify/README.md | 4 - .../gatsby-source-shopify/src/default.png | Bin 10929 -> 0 bytes .../gatsby-source-shopify/src/gatsby-node.js | 12 --- packages/gatsby-source-shopify/src/nodes.js | 18 ++-- .../src/plugin-options.js | 93 ------------------ 5 files changed, 11 insertions(+), 116 deletions(-) delete mode 100644 packages/gatsby-source-shopify/src/default.png delete mode 100644 packages/gatsby-source-shopify/src/plugin-options.js diff --git a/packages/gatsby-source-shopify/README.md b/packages/gatsby-source-shopify/README.md index d5a52c35e62b9..3c350ddabb08f 100644 --- a/packages/gatsby-source-shopify/README.md +++ b/packages/gatsby-source-shopify/README.md @@ -75,10 +75,6 @@ plugins: [ // Download Images Locally // set to false if you plan on using shopify's CDN downloadImages: true, - // default image URL - // if you set downloadImages to false then it will set all localFile of file from this URL this is to make graphQL types unchanged - defaultImageURL: - "https://raw.githubusercontent.com/mrhut10/gatsby/Feature/gatsby-source-shopify/downloadImagesOption/packages/gatsby-source-shopify/src/default.png", // Allow overriding the default queries // This allows you to include/exclude extra fields when sourcing nodes diff --git a/packages/gatsby-source-shopify/src/default.png b/packages/gatsby-source-shopify/src/default.png deleted file mode 100644 index 6bb5c3c7a168650a8b690f56bc3c0d72f71d378f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10929 zcmch72|Sf=yY7pSlBq(Gu~L~88KcYz6(aMHd7kGfg`$w5WGX{so~MOX#t<@(%a|#% z%q-5m{$JlY-#PpH_C9-`{X62GHd+{%Qhk3>u=5i0U=?VLv28f5K5!0CJT+k-Gy-Hl)+$rBFefNOt zYH{$|>nVoO{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ryA zVFhxyQ)GJ|SM}&G{afn&cjo^u&WHUsb`Ef}_o&qw+Xr}$4!(ES%j n!Yu{vtA9@F{e55rIU<*xNT^t)i^7M4i-^3ml2q;;{ipu}n-T)v diff --git a/packages/gatsby-source-shopify/src/gatsby-node.js b/packages/gatsby-source-shopify/src/gatsby-node.js index 09537dd3f83eb..89c315c375bff 100644 --- a/packages/gatsby-source-shopify/src/gatsby-node.js +++ b/packages/gatsby-source-shopify/src/gatsby-node.js @@ -3,7 +3,6 @@ import chalk from "chalk" import { forEach } from "p-iteration" import { printGraphQLError, queryAll, queryOnce } from "./lib" import { createClient } from "./create-client" -import PluginOptions from "./plugin-options" import { ArticleNode, @@ -58,20 +57,9 @@ export const sourceNodes = async ( paginationSize = 250, includeCollections = [SHOP, CONTENT], downloadImages = true, - defaultImageUrl = `https://raw.githubusercontent.com/mrhut10/gatsby/Feature/gatsby-source-shopify/downloadImagesOption/packages/gatsby-source-shopify/src/default.png`, shopifyQueries = {}, } ) => { - // sending options into PluginOptions Singleton Class - PluginOptions.setShopName(shopName) - .setAccessToken(accessToken) - .setApiVersion(apiVersion) - .setVerbose(verbose) - .setPaginationSize(paginationSize) - .setIncludeCollections(includeCollections) - .setDownloadImages(downloadImages) - .setDefaultImageUrl(defaultImageUrl) - const client = createClient(shopName, accessToken, apiVersion) const defaultQueries = { diff --git a/packages/gatsby-source-shopify/src/nodes.js b/packages/gatsby-source-shopify/src/nodes.js index 05d1f1060dc58..04c30f982c370 100644 --- a/packages/gatsby-source-shopify/src/nodes.js +++ b/packages/gatsby-source-shopify/src/nodes.js @@ -1,7 +1,6 @@ import createNodeHelpers from "gatsby-node-helpers" import { map } from "p-iteration" import { createRemoteFileNode } from "gatsby-source-filesystem" -import PluginOptions from "./plugin-options" import { TYPE_PREFIX, @@ -25,14 +24,19 @@ const { createNodeFactory, generateNodeId } = createNodeHelpers({ const downloadImageAndCreateFileNode = async ( { url, nodeId }, - { createNode, createNodeId, touchNode, store, cache, getCache, reporter } + { + createNode, + createNodeId, + touchNode, + store, + cache, + getCache, + reporter, + } ) => { let fileNodeID - const effectiveUrl = PluginOptions.downloadImages - ? url - : PluginOptions.defaultImageUrl - const mediaDataCacheKey = `${TYPE_PREFIX}__Media__${effectiveUrl}` + const mediaDataCacheKey = `${TYPE_PREFIX}__Media__${url}` const cacheMediaData = await cache.get(mediaDataCacheKey) if (cacheMediaData) { @@ -42,7 +46,7 @@ const downloadImageAndCreateFileNode = async ( } const fileNode = await createRemoteFileNode({ - url: effectiveUrl, + url, store, cache, createNode, diff --git a/packages/gatsby-source-shopify/src/plugin-options.js b/packages/gatsby-source-shopify/src/plugin-options.js deleted file mode 100644 index 33d54d646f947..0000000000000 --- a/packages/gatsby-source-shopify/src/plugin-options.js +++ /dev/null @@ -1,93 +0,0 @@ -// created this singalton class as a quick way to reference options anywhere within the plugin - -class PluginOptions { - #shopName - - #accessToken - - #apiVersion - - #verbose - - #paginationSize - - #includeCollections - - #downloadImages - - #defaultImageUrl - - get shopName() { - return this.#shopName - } - - get accessToken() { - return this.#accessToken - } - - get apiVersion() { - return this.#apiVersion || `2020-01` - } - - get verbose() { - return this.#verbose || true - } - - get paginationSize() { - return this.#paginationSize || 250 - } - - get includeCollections() { - return this.#includeCollections || [`shop`, `content`] - } - - get downloadImages() { - return this.#downloadImages - } - - get defaultImageUrl() { - return this.#defaultImageUrl - } - - setShopName(shopName) { - this.#shopName = shopName - return this - } - - setAccessToken(accessToken) { - this.#accessToken = accessToken - return this - } - - setApiVersion(apiVersion) { - this.#apiVersion = apiVersion - return this - } - - setVerbose(verbose) { - this.#verbose = verbose - return this - } - - setPaginationSize(paginationSize) { - this.#paginationSize = paginationSize - return this - } - - setIncludeCollections(includeCollections) { - this.#includeCollections = includeCollections - return this - } - - setDownloadImages(downloadImages) { - this.#downloadImages = downloadImages - return this - } - - setDefaultImageUrl(defaultImageUrl) { - this.#defaultImageUrl = defaultImageUrl - return this - } -} - -export default new PluginOptions() From 57f2ac61dcc86ab5e52c2c6e3b2edee493d51d56 Mon Sep 17 00:00:00 2001 From: Alistair Hutten Date: Mon, 11 Jan 2021 02:53:48 +1100 Subject: [PATCH 18/18] * pass though downloadImages config option in imageArgs * if !downloadImages then don't download image --- packages/gatsby-source-shopify/src/gatsby-node.js | 1 + packages/gatsby-source-shopify/src/nodes.js | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-source-shopify/src/gatsby-node.js b/packages/gatsby-source-shopify/src/gatsby-node.js index 89c315c375bff..171a5606637d9 100644 --- a/packages/gatsby-source-shopify/src/gatsby-node.js +++ b/packages/gatsby-source-shopify/src/gatsby-node.js @@ -90,6 +90,7 @@ export const sourceNodes = async ( cache, getCache, reporter, + downloadImages, } // Arguments used for node creation. diff --git a/packages/gatsby-source-shopify/src/nodes.js b/packages/gatsby-source-shopify/src/nodes.js index 04c30f982c370..a1799334fc541 100644 --- a/packages/gatsby-source-shopify/src/nodes.js +++ b/packages/gatsby-source-shopify/src/nodes.js @@ -32,15 +32,16 @@ const downloadImageAndCreateFileNode = async ( cache, getCache, reporter, + downloadImages, } ) => { - let fileNodeID + if (!downloadImages) return undefined const mediaDataCacheKey = `${TYPE_PREFIX}__Media__${url}` const cacheMediaData = await cache.get(mediaDataCacheKey) if (cacheMediaData) { - fileNodeID = cacheMediaData.fileNodeID + const fileNodeID = cacheMediaData.fileNodeID touchNode({ nodeId: fileNodeID }) return fileNodeID } @@ -57,7 +58,7 @@ const downloadImageAndCreateFileNode = async ( }) if (fileNode) { - fileNodeID = fileNode.id + const fileNodeID = fileNode.id await cache.set(mediaDataCacheKey, { fileNodeID }) return fileNodeID }