shopify-cli 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cff1487d9bbf811bd4640cb9d67ea439ad198794e409355477757dac56052d65
4
- data.tar.gz: 396f98fe6702a8c37cd58c906d843bc92888a7943375f99d723e7269d2dcda04
3
+ metadata.gz: aac6d7ad80aa747af6b8334b1cf6f82b3dfc0c6db77e8e22eb9638365b11317b
4
+ data.tar.gz: f5a744abb193c02bad16f0978d93bac2825ce287f95e3143848be47c28c8bbfc
5
5
  SHA512:
6
- metadata.gz: 93ad0fa7d1f935f07bc0549acaf7fdc4041dd7b00c1e097a13dcd591cec4e0a76f380c9fef0a69d33eb114703aebee8a57b6ad81fdac8f3b4c7463a22048af81
7
- data.tar.gz: d326315732e87f9343a71bbf5719c46f9a951974b31c5e927437cb8e1bb64373c312aaef2fda2ddd904bb79f36fd25309fadd3cea21b6c0482d3abd6d1e7a1ea
6
+ metadata.gz: b934e0c4c5321cdb01d733886e2eae5fc23c94c1ea7115e9b18af302244512d93617440d1a4274ca764305c6797a10ef79285c97cf03636d473deec63a6a0d23
7
+ data.tar.gz: fec928d425a1be8c543d45d495156857fcf848c12170eaf825fdf549f70536198fdf076d71b35b448b97769869ac85e2eddb8d6dd1321a2f93949160cd2929fa
@@ -1,3 +1,7 @@
1
+ Version 1.2.0
2
+ ------
3
+ * Improvements and new functionality to various internal components
4
+
1
5
  Version 1.1.2
2
6
  ------
3
7
  * Fix various minor bugs (check dir before creating Rails project, catch stderr from failed git command)
@@ -53,6 +53,7 @@ module Extension
53
53
  autoload :ArgoSetupStep, Project.project_filepath('features/argo_setup_step')
54
54
  autoload :ArgoSetupSteps, Project.project_filepath('features/argo_setup_steps')
55
55
  autoload :ArgoDependencies, Project.project_filepath('features/argo_dependencies')
56
+ autoload :ArgoConfig, Project.project_filepath('features/argo_config')
56
57
  end
57
58
 
58
59
  module Models
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Extension
4
+ module Features
5
+ class ArgoConfig
6
+ CONFIG_FILE_NAME = 'extension.config.yml'
7
+
8
+ class << self
9
+ def parse_yaml(context, permitted_keys = [])
10
+ file_name = File.join(context.root, CONFIG_FILE_NAME)
11
+
12
+ return {} unless File.size?(file_name)
13
+
14
+ require 'yaml' # takes 20ms, so deferred as late as possible.
15
+ begin
16
+ config = YAML.load_file(file_name)
17
+
18
+ # `YAML.load_file` returns nil if the file is not empty
19
+ # but does not contain any parsable yml data, e.g. only comments
20
+ # We consider this valid
21
+ return {} if config.nil?
22
+
23
+ unless config.is_a?(Hash)
24
+ raise ShopifyCli::Abort, ShopifyCli::Context.message('core.yaml.error.not_hash', CONFIG_FILE_NAME)
25
+ end
26
+
27
+ config.transform_keys!(&:to_sym)
28
+ assert_valid_config(config, permitted_keys) unless permitted_keys.empty?
29
+
30
+ config
31
+ rescue Psych::SyntaxError => e
32
+ raise(
33
+ ShopifyCli::Abort,
34
+ ShopifyCli::Context.message('core.yaml.error.invalid', CONFIG_FILE_NAME, e.message)
35
+ )
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def assert_valid_config(config, permitted_keys)
42
+ unpermitted_keys = config.keys.select do |k|
43
+ !permitted_keys.include?(k)
44
+ end
45
+
46
+ unless unpermitted_keys.empty?
47
+ raise(
48
+ ShopifyCli::Abort,
49
+ ShopifyCli::Context.message(
50
+ 'features.argo.config.unpermitted_keys',
51
+ CONFIG_FILE_NAME,
52
+ unpermitted_keys.map { |k| "\n- #{k}" }.join
53
+ )
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -96,6 +96,9 @@ module Extension
96
96
  version_too_low: 'Your node version %s does not meet the minimum required version %s',
97
97
  },
98
98
  },
99
+ config: {
100
+ unpermitted_keys: '`%s` contains the following unpermitted keys: %s',
101
+ },
99
102
  },
100
103
  },
101
104
  tasks: {
@@ -6,13 +6,16 @@ module Extension
6
6
  module Types
7
7
  class CheckoutPostPurchase < Models::Type
8
8
  IDENTIFIER = 'CHECKOUT_POST_PURCHASE'
9
-
9
+ PERMITTED_CONFIG_KEYS = [:metafields]
10
10
  def create(directory_name, context)
11
11
  Features::Argo.checkout.create(directory_name, IDENTIFIER, context)
12
12
  end
13
13
 
14
14
  def config(context)
15
- Features::Argo.checkout.config(context)
15
+ {
16
+ **Features::ArgoConfig.parse_yaml(context, PERMITTED_CONFIG_KEYS),
17
+ **Features::Argo.checkout.config(context),
18
+ }
16
19
  end
17
20
  end
18
21
  end
@@ -34,7 +34,9 @@ module Script
34
34
 
35
35
  def dependencies_installed?
36
36
  # Assuming if node_modules folder exist at root of script folder, all deps are installed
37
- ctx.dir_exist?("node_modules")
37
+ return false unless ctx.dir_exist?("node_modules")
38
+ check_if_ep_dependencies_up_to_date!
39
+ true
38
40
  end
39
41
 
40
42
  private
@@ -58,6 +60,39 @@ module Script
58
60
  def bytecode
59
61
  File.read(format(BYTECODE_FILE, name: script_name))
60
62
  end
63
+
64
+ def check_if_ep_dependencies_up_to_date!
65
+ return true if ENV['SHOPIFY_CLI_SCRIPTS_IGNORE_OUTDATED']
66
+
67
+ # ignore exit code since it will not be 0 unless every package is up to date which they probably won't be
68
+ out, _ = ctx.capture2e("npm", "outdated", "--json", "--depth", "0")
69
+ parsed_outdated_check = JSON.parse(out)
70
+ outdated_ep_packages = parsed_outdated_check
71
+ .select { |package_name, _| package_name.start_with?('@shopify/extension-point-as-') }
72
+ .select { |_, version_info| !package_is_up_to_date?(version_info) }
73
+ .keys
74
+ raise Errors::PackagesOutdatedError.new(outdated_ep_packages),
75
+ "NPM packages out of date: #{outdated_ep_packages.join(', ')}" unless outdated_ep_packages.empty?
76
+ end
77
+
78
+ def package_is_up_to_date?(version_info)
79
+ require 'semantic/semantic'
80
+ current_version = version_info['current']
81
+ latest_version = version_info['latest']
82
+
83
+ # making an assumption that the script developer knows what they're doing if they're not referencing a
84
+ # semver version
85
+ begin
86
+ current_version = ::Semantic::Version.new(current_version)
87
+ latest_version = ::Semantic::Version.new(latest_version)
88
+ rescue ArgumentError
89
+ return true
90
+ end
91
+
92
+ return false if current_version.major < latest_version.major
93
+ return false if latest_version.major == 0 && current_version.minor < latest_version.minor
94
+ true
95
+ end
61
96
  end
62
97
  end
63
98
  end
@@ -34,6 +34,13 @@ module Script
34
34
  class ShopScriptConflictError < ScriptProjectError; end
35
35
  class ShopScriptUndefinedError < ScriptProjectError; end
36
36
  class TaskRunnerNotFoundError < ScriptProjectError; end
37
+ class PackagesOutdatedError < ScriptProjectError
38
+ attr_reader :outdated_packages
39
+ def initialize(outdated_packages)
40
+ super("EP packages are outdated and need to be updated: #{outdated_packages.join(', ')}")
41
+ @outdated_packages = outdated_packages
42
+ end
43
+ end
37
44
  end
38
45
  end
39
46
  end
@@ -71,6 +71,9 @@ module Script
71
71
  shop_script_conflict_help: "Disable that script or uninstall that app and try again.",
72
72
 
73
73
  shop_script_undefined_cause: "Script is already turned off in store.",
74
+
75
+ packages_outdated_cause: "The following npm packages are out of date: %s.",
76
+ packages_outdated_help: "Run `npm update` to update them.",
74
77
  },
75
78
 
76
79
  create: {
@@ -142,6 +142,14 @@ module Script
142
142
  {
143
143
  cause_of_error: ShopifyCli::Context.message('script.error.shop_script_undefined_cause'),
144
144
  }
145
+ when Layers::Infrastructure::Errors::PackagesOutdatedError
146
+ {
147
+ cause_of_error: ShopifyCli::Context.message(
148
+ 'script.error.packages_outdated_cause',
149
+ e.outdated_packages.join(', ')
150
+ ),
151
+ help_suggestion: ShopifyCli::Context.message('script.error.packages_outdated_help'),
152
+ }
145
153
  end
146
154
  end
147
155
  end
@@ -184,11 +184,14 @@ module ShopifyCli
184
184
  {{x}} You are not in a Shopify app project
185
185
  {{yellow:{{*}}}}{{reset: Run}}{{cyan: shopify create}}{{reset: to create your app}}
186
186
  MESSAGE
187
- cli_yaml: {
188
- not_hash: "{{x}} .shopify-cli.yml was not a proper YAML file. Expecting a hash.",
189
- invalid: "{{x}} %s contains invalid YAML: %s",
190
- not_found: "{{x}} %s not found",
191
- },
187
+ },
188
+ },
189
+
190
+ yaml: {
191
+ error: {
192
+ not_hash: "{{x}} %s was not a proper YAML file. Expecting a hash.",
193
+ invalid: "{{x}} %s contains invalid YAML: %s",
194
+ not_found: "{{x}} %s not found",
192
195
  },
193
196
  },
194
197
 
@@ -166,7 +166,7 @@ module ShopifyCli
166
166
  @config ||= begin
167
167
  config = load_yaml_file('.shopify-cli.yml')
168
168
  unless config.is_a?(Hash)
169
- raise ShopifyCli::Abort, Context.message('core.project.error.cli_yaml.not_hash')
169
+ raise ShopifyCli::Abort, Context.message('core.yaml.error.not_hash', '.shopify-cli.yml')
170
170
  end
171
171
 
172
172
  # The app_type key was deprecated in favour of project_type, so replace it
@@ -187,12 +187,12 @@ module ShopifyCli
187
187
  begin
188
188
  YAML.load_file(f)
189
189
  rescue Psych::SyntaxError => e
190
- raise(ShopifyCli::Abort, Context.message('core.project.error.cli_yaml.invalid', relative_path, e.message))
190
+ raise(ShopifyCli::Abort, Context.message('core.yaml.error.invalid', relative_path, e.message))
191
191
  # rescue Errno::EACCES => e
192
192
  # TODO
193
193
  # Dev::Helpers::EaccesHandler.diagnose_and_raise(f, e, mode: :read)
194
194
  rescue Errno::ENOENT
195
- raise ShopifyCli::Abort, Context.message('core.project.error.cli_yaml.not_found', f)
195
+ raise ShopifyCli::Abort, Context.message('core.yaml.error.not_found', f)
196
196
  end
197
197
  end
198
198
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyCli
2
- VERSION = '1.1.2'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-08 00:00:00.000000000 Z
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,6 +148,7 @@ files:
148
148
  - lib/project_types/extension/extension_project.rb
149
149
  - lib/project_types/extension/extension_project_keys.rb
150
150
  - lib/project_types/extension/features/argo.rb
151
+ - lib/project_types/extension/features/argo_config.rb
151
152
  - lib/project_types/extension/features/argo_dependencies.rb
152
153
  - lib/project_types/extension/features/argo_setup.rb
153
154
  - lib/project_types/extension/features/argo_setup_step.rb