From d7a1f0c4bd17c7e1654cb5fbd47d490944f353ca Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Sun, 17 Jan 2021 10:57:59 -0500 Subject: [PATCH 1/7] Don't run app config for generator --- .../install/templates/shopify_app.rb.tt | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/generators/shopify_app/install/templates/shopify_app.rb.tt b/lib/generators/shopify_app/install/templates/shopify_app.rb.tt index af93719ca..8a349e3be 100644 --- a/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +++ b/lib/generators/shopify_app/install/templates/shopify_app.rb.tt @@ -1,16 +1,18 @@ -ShopifyApp.configure do |config| - config.application_name = "<%= @application_name %>" - config.api_key = ENV.fetch('SHOPIFY_API_KEY', '').presence || raise('Missing SHOPIFY_API_KEY') - config.secret = ENV.fetch('SHOPIFY_API_SECRET', '').presence || raise('Missing SHOPIFY_API_SECRET') - config.old_secret = "<%= @old_secret %>" - config.scope = "<%= @scope %>" # Consult this page for more scope options: - # https://help.shopify.com/en/api/getting-started/authentication/oauth/scopes - config.embedded_app = <%= embedded_app? %> - config.after_authenticate_job = false - config.api_version = "<%= @api_version %>" - config.shop_session_repository = 'Shop' - config.allow_jwt_authentication = <%= !with_cookie_authentication? %> - config.allow_cookie_authentication = <%= with_cookie_authentication? %> +unless defined? Rails::Generators + ShopifyApp.configure do |config| + config.application_name = "<%= @application_name %>" + config.api_key = ENV.fetch('SHOPIFY_API_KEY', '').presence || raise('Missing SHOPIFY_API_KEY') + config.secret = ENV.fetch('SHOPIFY_API_SECRET', '').presence || raise('Missing SHOPIFY_API_SECRET') + config.old_secret = "<%= @old_secret %>" + config.scope = "<%= @scope %>" # Consult this page for more scope options: + # https://help.shopify.com/en/api/getting-started/authentication/oauth/scopes + config.embedded_app = <%= embedded_app? %> + config.after_authenticate_job = false + config.api_version = "<%= @api_version %>" + config.shop_session_repository = 'Shop' + config.allow_jwt_authentication = <%= !with_cookie_authentication? %> + config.allow_cookie_authentication = <%= with_cookie_authentication? %> + end end # ShopifyApp::Utils.fetch_known_api_versions # Uncomment to fetch known api versions from shopify servers on boot From 10c89418c65cf701bf30160f127064ee00192a4a Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Sun, 17 Jan 2021 11:15:14 -0500 Subject: [PATCH 2/7] Improve error message --- README.md | 2 +- .../shopify_app/install/templates/shopify_app.rb.tt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d985c802d..c51d2a617 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Generators ---------- ### API Keys - + Before running the generators, you'll need to ensure your app can read the Shopify environment variables `SHOPIFY_API_KEY` and `SHOPIFY_API_SECRET`. A common approach is to use the [dotenv-rails](https://github.com/bkeepers/dotenv) gem, along with an `.env` file in the following format: diff --git a/lib/generators/shopify_app/install/templates/shopify_app.rb.tt b/lib/generators/shopify_app/install/templates/shopify_app.rb.tt index 8a349e3be..cb371a1d9 100644 --- a/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +++ b/lib/generators/shopify_app/install/templates/shopify_app.rb.tt @@ -1,8 +1,8 @@ unless defined? Rails::Generators ShopifyApp.configure do |config| config.application_name = "<%= @application_name %>" - config.api_key = ENV.fetch('SHOPIFY_API_KEY', '').presence || raise('Missing SHOPIFY_API_KEY') - config.secret = ENV.fetch('SHOPIFY_API_SECRET', '').presence || raise('Missing SHOPIFY_API_SECRET') + config.api_key = ENV.fetch('SHOPIFY_API_KEY', '').presence || raise('Missing SHOPIFY_API_KEY. See https://github.com/Shopify/shopify_app#api-keys') + config.secret = ENV.fetch('SHOPIFY_API_SECRET', '').presence || raise('Missing SHOPIFY_API_SECRET. See https://github.com/Shopify/shopify_app#api-keys') config.old_secret = "<%= @old_secret %>" config.scope = "<%= @scope %>" # Consult this page for more scope options: # https://help.shopify.com/en/api/getting-started/authentication/oauth/scopes From 8f95799778014997b19c0c6945dbf3b46043a9ca Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Sun, 17 Jan 2021 11:25:06 -0500 Subject: [PATCH 3/7] Fix tests --- test/generators/install_generator_test.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/generators/install_generator_test.rb b/test/generators/install_generator_test.rb index f1da3c946..e491c25f8 100644 --- a/test/generators/install_generator_test.rb +++ b/test/generators/install_generator_test.rb @@ -23,10 +23,8 @@ class InstallGeneratorTest < Rails::Generators::TestCase run_generator assert_file "config/initializers/shopify_app.rb" do |shopify_app| assert_match 'config.application_name = "My Shopify App"', shopify_app - assert_match "config.api_key = ENV.fetch('SHOPIFY_API_KEY', '').presence " \ - "|| raise('Missing SHOPIFY_API_KEY')", shopify_app - assert_match "config.secret = ENV.fetch('SHOPIFY_API_SECRET', '').presence " \ - "|| raise('Missing SHOPIFY_API_SECRET')", shopify_app + assert_match "config.api_key = ENV.fetch('SHOPIFY_API_KEY', '')", shopify_app + assert_match "config.secret = ENV.fetch('SHOPIFY_API_SECRET', '')", shopify_app assert_match 'config.scope = "read_products"', shopify_app assert_match "config.embedded_app = true", shopify_app assert_match 'config.api_version = "2019-10"', shopify_app @@ -41,10 +39,8 @@ class InstallGeneratorTest < Rails::Generators::TestCase --api_version unstable --scope read_orders write_products) assert_file "config/initializers/shopify_app.rb" do |shopify_app| assert_match 'config.application_name = "Test Name"', shopify_app - assert_match "config.api_key = ENV.fetch('SHOPIFY_API_KEY', '').presence " \ - "|| raise('Missing SHOPIFY_API_KEY')", shopify_app - assert_match "config.secret = ENV.fetch('SHOPIFY_API_SECRET', '').presence " \ - "|| raise('Missing SHOPIFY_API_SECRET')", shopify_app + assert_match "config.api_key = ENV.fetch('SHOPIFY_API_KEY', '')", shopify_app + assert_match "config.secret = ENV.fetch('SHOPIFY_API_SECRET', '')", shopify_app assert_match 'config.scope = "read_orders write_products"', shopify_app assert_match 'config.embedded_app = true', shopify_app assert_match 'config.api_version = "unstable"', shopify_app @@ -56,10 +52,8 @@ class InstallGeneratorTest < Rails::Generators::TestCase run_generator %w(--application_name Test Name --scope read_orders write_products) assert_file "config/initializers/shopify_app.rb" do |shopify_app| assert_match 'config.application_name = "Test Name"', shopify_app - assert_match "config.api_key = ENV.fetch('SHOPIFY_API_KEY', '').presence " \ - "|| raise('Missing SHOPIFY_API_KEY')", shopify_app - assert_match "config.secret = ENV.fetch('SHOPIFY_API_SECRET', '').presence " \ - "|| raise('Missing SHOPIFY_API_SECRET')", shopify_app + assert_match "config.api_key = ENV.fetch('SHOPIFY_API_KEY', '')", shopify_app + assert_match "config.secret = ENV.fetch('SHOPIFY_API_SECRET', '')", shopify_app assert_match 'config.scope = "read_orders write_products"', shopify_app assert_match 'config.embedded_app = true', shopify_app assert_match "config.shop_session_repository = 'Shop'", shopify_app From bb2cb0dd65e0f676ef8b3d707d80324c2c30f275 Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Sun, 17 Jan 2021 11:29:54 -0500 Subject: [PATCH 4/7] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c51d2a617..e16e00da0 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Generators ---------- ### API Keys - + Before running the generators, you'll need to ensure your app can read the Shopify environment variables `SHOPIFY_API_KEY` and `SHOPIFY_API_SECRET`. A common approach is to use the [dotenv-rails](https://github.com/bkeepers/dotenv) gem, along with an `.env` file in the following format: From b5fe5f797e9782c251b2617956eaeaf40de4630d Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Sun, 17 Jan 2021 11:36:55 -0500 Subject: [PATCH 5/7] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d311813..f1bce5fc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ Unreleased ---------- +* Don't attempt to read Shopify environment variables when the generators are running, since they may not be present yet [#1144](https://github.com/Shopify/shopify_app/pull/1144) + 17.0.0 (January 13, 2021) ------ * Rails 6.1 is not yet supported [#1134](https://github.com/Shopify/shopify_app/pull/1134) From c7a8daf90f2dde2af85b5ab6da3d42db5a6c8ada Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Sun, 17 Jan 2021 11:44:37 -0500 Subject: [PATCH 6/7] Update README --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e16e00da0..c6b9aac5b 100644 --- a/README.md +++ b/README.md @@ -76,16 +76,18 @@ Generators ### API Keys -Before running the generators, you'll need to ensure your app can read the Shopify environment variables `SHOPIFY_API_KEY` and `SHOPIFY_API_SECRET`. +Before starting the app, you'll need to ensure it can read the Shopify environment variables `SHOPIFY_API_KEY` and `SHOPIFY_API_SECRET`. -A common approach is to use the [dotenv-rails](https://github.com/bkeepers/dotenv) gem, along with an `.env` file in the following format: +In a development environment, a common approach is to use the [dotenv-rails](https://github.com/bkeepers/dotenv) gem, along with an `.env` file in the following format: ``` SHOPIFY_API_KEY=your api key SHOPIFY_API_SECRET=your api secret ``` -These values can be found on the "App Setup" page in the [Shopify Partners Dashboard][dashboard]. If you are checking your code into a code repository, ensure your `.gitignore` prevents your `.env` file from being checked into any publicly accessible code. +These values can be found on the "App Setup" page in the [Shopify Partners Dashboard][dashboard]. +(If you are using [shopify-app-cli](https://github.com/Shopify/) this `.env` file will be created automatically). +If you are checking your code into a code repository, ensure your `.gitignore` prevents your `.env` file from being checked into any publicly accessible code. ### Default Generator From a563c79f10ed8267f7b08215623a5fbeb7a490c3 Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Mon, 18 Jan 2021 09:19:38 -0500 Subject: [PATCH 7/7] Fix URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6b9aac5b..1a236d0fd 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ SHOPIFY_API_SECRET=your api secret ``` These values can be found on the "App Setup" page in the [Shopify Partners Dashboard][dashboard]. -(If you are using [shopify-app-cli](https://github.com/Shopify/) this `.env` file will be created automatically). +(If you are using [shopify-app-cli](https://github.com/Shopify/shopify-app-cli) this `.env` file will be created automatically). If you are checking your code into a code repository, ensure your `.gitignore` prevents your `.env` file from being checked into any publicly accessible code. ### Default Generator