From f9c49f997a7491b38fa800a0ea0a2eb56cba1fa7 Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Fri, 8 Jun 2018 21:20:46 -0700 Subject: [PATCH] Minor fixes * Update gitignore with stuff from gitignore.io * Update gitignore with compiled code * Add specific list of included files for npm (test with npx pkgfiles) --- .gitignore | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++-- index.js | 28 +++++---------------- package.json | 5 ++++ 3 files changed, 80 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 76a01d9..e853aee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,70 @@ -node_modules + +# Created by https://www.gitignore.io/api/node + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +# End of https://www.gitignore.io/api/node + .DS_Store -yarn-error.log \ No newline at end of file + +index.js +gatsby-ssr.js diff --git a/index.js b/index.js index 2b309da..3b841fc 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _gatsbyConfig = require('../../gatsby-config'); - -var _gatsbyConfig2 = _interopRequireDefault(_gatsbyConfig); +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _jsonp = require('jsonp'); @@ -32,23 +30,6 @@ var subscribeEmailToMailchimp = function subscribeEmailToMailchimp(url) { }); }; -/* - * parse the plugin options to use in our jsonp request - */ - -var getPluginOptions = function getPluginOptions() { - // find gatsby-mailchimp plugin options (MC list settings) - var options = _gatsbyConfig2.default.plugins.find(function (plugin) { - return plugin.resolve === 'gatsby-plugin-mailchimp'; - }).options; - - var isString = typeof options.endpoint === 'string'; - if (!isString) { - throw 'Mailchimp endpoint required and must be of type string. See repo README for more info.'; - } - return options; -}; - /* * build a query string of MC list fields * ex: '&KEY1=value1&KEY2=value2' @@ -80,9 +61,12 @@ var addToMailchimp = function addToMailchimp(email, fields) { // note, we change `/post` to `/post-json` // otherwise, Mailchomp returns an error - var _getPluginOptions = getPluginOptions(), - endpoint = _getPluginOptions.endpoint; + var _ref = window.__GATSBY_PLUGIN_MAILCHIMP__ || {}, + endpoint = _ref.endpoint; + if (!(typeof endpoint === 'undefined' ? 'undefined' : _typeof(endpoint)) === 'string') { + return Promise.reject('Mailchimp endpoint required and must be of type string. See repo README for more info.'); + } endpoint = endpoint.replace(/\/post/g, '/post-json'); var queryParams = '&EMAIL=' + emailEncoded + convertListFields(fields); diff --git a/package.json b/package.json index bdb544d..8563f08 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,11 @@ "type": "git", "url": "https://github.com/benjaminhoffman/gatsby-plugin-mailchimp.git" }, + "files": [ + "index.js", + "gatsby-ssr.js", + "yarn.lock" + ], "keywords": [ "gatsby", "gatsby-plugin",