shopify-cli 1.2.0 → 1.3.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: aac6d7ad80aa747af6b8334b1cf6f82b3dfc0c6db77e8e22eb9638365b11317b
4
- data.tar.gz: f5a744abb193c02bad16f0978d93bac2825ce287f95e3143848be47c28c8bbfc
3
+ metadata.gz: 453f515f6f175bcc507b9a967880660da88455a97fc4ac593e5526ce6d410b0d
4
+ data.tar.gz: 134e8f9fc243aaad0eee527c37784680fef10ad2b53ab6d5787965a026457772
5
5
  SHA512:
6
- metadata.gz: b934e0c4c5321cdb01d733886e2eae5fc23c94c1ea7115e9b18af302244512d93617440d1a4274ca764305c6797a10ef79285c97cf03636d473deec63a6a0d23
7
- data.tar.gz: fec928d425a1be8c543d45d495156857fcf848c12170eaf825fdf549f70536198fdf076d71b35b448b97769869ac85e2eddb8d6dd1321a2f93949160cd2929fa
6
+ metadata.gz: 950380758e1d7babd1db489718f7487c6511f8d72dc26e3e894d1779c8097303ed58cb308d8db8db3ed136fd0e659af96ed06fdeff2191af8afca1e85cd68921
7
+ data.tar.gz: e3ed02e945e4211f529b2aae0c1caa6de6c39947adcf91cdd99c0ddf641e930abbd994a0f5bf918eb6f37c0142e69de477c0062985e565a25480856beaf70dd0
@@ -1,3 +1,7 @@
1
+ Version 1.3.0
2
+ ------
3
+ * Support for new `shopify config analytics` command to enable/disable anonymous usage reporting
4
+
1
5
  Version 1.2.0
2
6
  ------
3
7
  * Improvements and new functionality to various internal components
@@ -68,3 +68,19 @@ Log out of the currently authenticated partner organization and store. The `logo
68
68
  $ shopify logout
69
69
  ```
70
70
 
71
+ ## `config`
72
+
73
+ Configure Shopify App CLI options. Currently there are two available options.
74
+
75
+ ### `analytics`
76
+
77
+ Configure anonymous usage reporting by enabling or disabling analytics
78
+ ```console
79
+ $ shopify config analytics [ --status | --enable | --disable ]
80
+ ```
81
+
82
+ ### `feature`
83
+ Configure active [feature sets](https://github.com/Shopify/shopify-app-cli/wiki/Feature-Sets) in the CLI. This command is used for development and debugging work on the CLI tool itself. Only alter it if you know what you're doing. Check the [Shopify App CLI development guide](https://github.com/Shopify/shopify-app-cli/wiki) for more information.
84
+ ```console
85
+ $ shopify config feature [ feature_name ] [ --status | --enable | --disable ]
86
+ ```
@@ -48,12 +48,16 @@ module Extension
48
48
  end
49
49
 
50
50
  module Features
51
- autoload :Argo, Project.project_filepath('features/argo')
52
51
  autoload :ArgoSetup, Project.project_filepath('features/argo_setup')
53
52
  autoload :ArgoSetupStep, Project.project_filepath('features/argo_setup_step')
54
53
  autoload :ArgoSetupSteps, Project.project_filepath('features/argo_setup_steps')
55
54
  autoload :ArgoDependencies, Project.project_filepath('features/argo_dependencies')
56
55
  autoload :ArgoConfig, Project.project_filepath('features/argo_config')
56
+ module Argo
57
+ autoload :Base, Project.project_filepath('features/argo/base')
58
+ autoload :Admin, Project.project_filepath('features/argo/admin')
59
+ autoload :Checkout, Project.project_filepath('features/argo/checkout')
60
+ end
57
61
  end
58
62
 
59
63
  module Models
@@ -52,7 +52,7 @@ module Extension
52
52
  Tasks::CreateExtension.call(
53
53
  context: @ctx,
54
54
  api_key: app.api_key,
55
- type: extension_type.identifier,
55
+ type: extension_type.graphql_identifier,
56
56
  title: project.title,
57
57
  config: {},
58
58
  extension_context: extension_type.extension_context(@ctx)
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module Extension
3
+ module Features
4
+ module Argo
5
+ class Admin < Base
6
+ GIT_TEMPLATE = 'https://github.com/Shopify/argo-admin-template.git'
7
+ RENDERER_PACKAGE = '@shopify/argo-admin'
8
+ private_constant :GIT_TEMPLATE, :RENDERER_PACKAGE
9
+
10
+ def git_template
11
+ GIT_TEMPLATE
12
+ end
13
+
14
+ def renderer_package_name
15
+ RENDERER_PACKAGE
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+ require 'base64'
3
+ require 'shopify_cli'
4
+ require 'semantic/semantic'
5
+
6
+ module Extension
7
+ module Features
8
+ module Argo
9
+ class Base
10
+ include SmartProperties
11
+
12
+ SCRIPT_PATH = %w(build main.js).freeze
13
+
14
+ NPM_LIST_COMMAND = %w(list).freeze
15
+ YARN_LIST_COMMAND = %w(list --pattern).freeze
16
+ NPM_LIST_PARAMETERS = %w(--prod).freeze
17
+ YARN_LIST_PARAMETERS = %w(--production).freeze
18
+ private_constant :NPM_LIST_COMMAND, :YARN_LIST_COMMAND, :NPM_LIST_PARAMETERS, :YARN_LIST_PARAMETERS
19
+
20
+ YARN_INSTALL_COMMAND = %w(install).freeze
21
+ YARN_INSTALL_PARAMETERS = %w(--silent).freeze
22
+ YARN_RUN_COMMAND = %w(run).freeze
23
+ YARN_RUN_SCRIPT_NAME = %w(build).freeze
24
+ private_constant :YARN_INSTALL_COMMAND, :YARN_INSTALL_PARAMETERS, :YARN_RUN_COMMAND, :YARN_RUN_SCRIPT_NAME
25
+
26
+ def create(directory_name, identifier, context)
27
+ Features::ArgoSetup.new(git_template: git_template).call(directory_name, identifier, context)
28
+ end
29
+
30
+ def config(context)
31
+ js_system = ShopifyCli::JsSystem.new(ctx: context)
32
+ if js_system.package_manager == 'yarn'
33
+ run_yarn_install(context, js_system)
34
+ run_yarn_run_script(context, js_system)
35
+ end
36
+ filepath = File.join(context.root, SCRIPT_PATH)
37
+ context.abort(context.message('features.argo.missing_file_error')) unless File.exist?(filepath)
38
+ begin
39
+ {
40
+ renderer_version: extract_argo_renderer_version(context),
41
+ serialized_script: Base64.strict_encode64(File.read(filepath).chomp),
42
+ }
43
+ rescue StandardError
44
+ context.abort(context.message('features.argo.script_prepare_error'))
45
+ end
46
+ end
47
+
48
+ def git_template
49
+ raise NotImplementedError, "'#{__method__}' must be implemented for #{self.class}"
50
+ end
51
+
52
+ def renderer_package_name
53
+ # The renderer_package_name is used as a regex pattern to
54
+ # find a match in the output of yarn or npm list command.
55
+ # Use the full package name as it appears in the template without targeting a version.
56
+ # Examples: "@shopify/some-renderer-package", "argo-renderer-package"
57
+
58
+ raise NotImplementedError, "'#{__method__}' must be implemented for #{self.class}"
59
+ end
60
+
61
+ private
62
+
63
+ def extract_argo_renderer_version(context)
64
+ result = run_list_command(context)
65
+ found_version = find_version_number(context, result)
66
+ context.abort(
67
+ context.message('features.argo.dependencies.argo_renderer_package_invalid_version_error')
68
+ ) if found_version.nil?
69
+ ::Semantic::Version.new(found_version).to_s
70
+ rescue ArgumentError
71
+ context.abort(
72
+ context.message('features.argo.dependencies.argo_renderer_package_invalid_version_error')
73
+ )
74
+ end
75
+
76
+ def find_version_number(context, result)
77
+ packages = result.to_json.split('\n')
78
+ found_package = packages.find do |package|
79
+ package.match(/#{renderer_package_name}@/)
80
+ end
81
+ if found_package.nil?
82
+ error = "'#{renderer_package_name}' not found."
83
+ context.abort(
84
+ context.message('features.argo.dependencies.argo_missing_renderer_package_error', error)
85
+ )
86
+ end
87
+ found_package.split('@')[2]&.strip
88
+ end
89
+
90
+ def run_list_command(context)
91
+ js_system = ShopifyCli::JsSystem.new(ctx: context)
92
+ result, error, status = js_system.call(
93
+ yarn: YARN_LIST_COMMAND + [renderer_package_name] + YARN_LIST_PARAMETERS,
94
+ npm: NPM_LIST_COMMAND + [renderer_package_name] + NPM_LIST_PARAMETERS,
95
+ capture_response: true
96
+ )
97
+ context.abort(
98
+ context.message('features.argo.dependencies.argo_missing_renderer_package_error', error)
99
+ ) unless status.success?
100
+ result
101
+ end
102
+
103
+ def run_yarn_install(context, js_system)
104
+ _result, error, status = js_system.call(
105
+ yarn: YARN_INSTALL_COMMAND + YARN_INSTALL_PARAMETERS,
106
+ npm: [],
107
+ capture_response: true
108
+ )
109
+
110
+ context.abort(
111
+ context.message('features.argo.dependencies.yarn_install_error', error)
112
+ ) unless status.success?
113
+ end
114
+
115
+ def run_yarn_run_script(context, js_system)
116
+ _result, error, status = js_system.call(
117
+ yarn: YARN_RUN_COMMAND + YARN_RUN_SCRIPT_NAME,
118
+ npm: [],
119
+ capture_response: true
120
+ )
121
+
122
+ context.abort(
123
+ context.message('features.argo.dependencies.yarn_run_script_error', error)
124
+ ) unless status.success?
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module Extension
3
+ module Features
4
+ module Argo
5
+ class Checkout < Base
6
+ GIT_TEMPLATE = 'https://github.com/Shopify/argo-checkout-template.git'
7
+ RENDERER_PACKAGE = '@shopify/argo-checkout'
8
+ private_constant :GIT_TEMPLATE, :RENDERER_PACKAGE
9
+
10
+ def git_template
11
+ GIT_TEMPLATE
12
+ end
13
+
14
+ def renderer_package_name
15
+ RENDERER_PACKAGE
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -95,6 +95,12 @@ module Extension
95
95
  node_not_installed: 'Node must be installed to create this extension.',
96
96
  version_too_low: 'Your node version %s does not meet the minimum required version %s',
97
97
  },
98
+ argo_missing_renderer_package_error: '%s Install the missing package and try again.',
99
+ argo_renderer_package_invalid_version_error: <<~MESSAGE,
100
+ The renderer package version is not a valid SemVer Version (http://semver.org)
101
+ MESSAGE
102
+ yarn_install_error: "Something went wrong while running 'yarn install'. %s.",
103
+ yarn_run_script_error: 'Something went wrong while running script. %s.',
98
104
  },
99
105
  config: {
100
106
  unpermitted_keys: '`%s` contains the following unpermitted keys: %s',
@@ -112,8 +118,8 @@ module Extension
112
118
  }
113
119
 
114
120
  TYPES = {
115
- subscription_management: {
116
- name: 'Subscription Management',
121
+ product_subscription: {
122
+ name: 'Product Subscription',
117
123
  tagline: '(limit 1 per app)',
118
124
  overrides: {
119
125
  register: {
@@ -38,6 +38,10 @@ module Extension
38
38
  self.class::IDENTIFIER
39
39
  end
40
40
 
41
+ def graphql_identifier
42
+ identifier
43
+ end
44
+
41
45
  def name
42
46
  message('name')
43
47
  end
@@ -8,13 +8,13 @@ module Extension
8
8
  IDENTIFIER = 'CHECKOUT_POST_PURCHASE'
9
9
  PERMITTED_CONFIG_KEYS = [:metafields]
10
10
  def create(directory_name, context)
11
- Features::Argo.checkout.create(directory_name, IDENTIFIER, context)
11
+ Features::Argo::Checkout.new.create(directory_name, IDENTIFIER, context)
12
12
  end
13
13
 
14
14
  def config(context)
15
15
  {
16
16
  **Features::ArgoConfig.parse_yaml(context, PERMITTED_CONFIG_KEYS),
17
- **Features::Argo.checkout.config(context),
17
+ **Features::Argo::Checkout.new.config(context),
18
18
  }
19
19
  end
20
20
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'base64'
3
+
4
+ module Extension
5
+ module Models
6
+ module Types
7
+ class ProductSubscription < Models::Type
8
+ IDENTIFIER = 'PRODUCT_SUBSCRIPTION'
9
+
10
+ def graphql_identifier
11
+ 'SUBSCRIPTION_MANAGEMENT'
12
+ end
13
+
14
+ def create(directory_name, context)
15
+ Features::Argo::Admin.new.create(directory_name, graphql_identifier, context)
16
+ end
17
+
18
+ def config(context)
19
+ Features::Argo::Admin.new.config(context)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -45,9 +45,7 @@ module Script
45
45
 
46
46
  app_not_installed_cause: "App not installed on store.",
47
47
 
48
- app_script_not_pushed_help: "Push the script and then try this command again.",
49
-
50
- app_script_undefined_help: "Push script to app.",
48
+ app_script_not_pushed_help: "Script isn't on the app. Run {{command:shopify push}}, and then try again.",
51
49
 
52
50
  build_error_cause: "Something went wrong while building the script.",
53
51
  build_error_help: "Correct the errors and try again.",
@@ -73,7 +71,7 @@ module Script
73
71
  shop_script_undefined_cause: "Script is already turned off in store.",
74
72
 
75
73
  packages_outdated_cause: "The following npm packages are out of date: %s.",
76
- packages_outdated_help: "Run `npm update` to update them.",
74
+ packages_outdated_help: "Update them by running {{cyan:npm install --save-dev %s}}.",
77
75
  },
78
76
 
79
77
  create: {
@@ -96,14 +96,11 @@ module Script
96
96
  {
97
97
  cause_of_error: ShopifyCli::Context.message('script.error.app_not_installed_cause'),
98
98
  }
99
- when Layers::Infrastructure::Errors::AppScriptNotPushedError
99
+ when Layers::Infrastructure::Errors::AppScriptNotPushedError,
100
+ Layers::Infrastructure::Errors::AppScriptUndefinedError
100
101
  {
101
102
  cause_of_error: ShopifyCli::Context.message('script.error.app_script_not_pushed_help'),
102
103
  }
103
- when Layers::Infrastructure::Errors::AppScriptUndefinedError
104
- {
105
- help_suggestion: ShopifyCli::Context.message('script.error.app_script_undefined_help'),
106
- }
107
104
  when Layers::Infrastructure::Errors::BuildError
108
105
  {
109
106
  cause_of_error: ShopifyCli::Context.message('script.error.build_error_cause'),
@@ -148,7 +145,10 @@ module Script
148
145
  'script.error.packages_outdated_cause',
149
146
  e.outdated_packages.join(', ')
150
147
  ),
151
- help_suggestion: ShopifyCli::Context.message('script.error.packages_outdated_help'),
148
+ help_suggestion: ShopifyCli::Context.message(
149
+ 'script.error.packages_outdated_help',
150
+ e.outdated_packages.collect { |package| "#{package}@latest" }.join(' ')
151
+ ),
152
152
  }
153
153
  end
154
154
  end
@@ -6,6 +6,7 @@ module ShopifyCli
6
6
  hidden_feature(feature_set: :debug)
7
7
 
8
8
  subcommand :Feature, 'feature'
9
+ subcommand :Analytics, 'analytics'
9
10
 
10
11
  def call(*)
11
12
  @ctx.puts(self.class.help)
@@ -16,6 +17,10 @@ module ShopifyCli
16
17
  end
17
18
 
18
19
  class Feature < ShopifyCli::SubCommand
20
+ def self.help
21
+ ShopifyCli::Context.message('core.config.feature.help', ShopifyCli::TOOL_NAME)
22
+ end
23
+
19
24
  options do |parser, flags|
20
25
  parser.on('--enable') { flags[:action] = 'enable' }
21
26
  parser.on('--disable') { flags[:action] = 'disable' }
@@ -28,7 +33,7 @@ module ShopifyCli
28
33
  is_enabled = ShopifyCli::Feature.enabled?(feature_name)
29
34
  if options.flags[:action] == 'disable' && is_enabled
30
35
  ShopifyCli::Feature.disable(feature_name)
31
- @ctx.puts(@ctx.message('core.config.feature.disabled', is_enabled))
36
+ @ctx.puts(@ctx.message('core.config.feature.disabled', feature_name))
32
37
  elsif options.flags[:action] == 'enable' && !is_enabled
33
38
  ShopifyCli::Feature.enable(feature_name)
34
39
  @ctx.puts(@ctx.message('core.config.feature.enabled', feature_name))
@@ -39,6 +44,33 @@ module ShopifyCli
39
44
  end
40
45
  end
41
46
  end
47
+
48
+ class Analytics < ShopifyCli::SubCommand
49
+ def self.help
50
+ ShopifyCli::Context.message('core.config.analytics.help', ShopifyCli::TOOL_NAME)
51
+ end
52
+
53
+ options do |parser, flags|
54
+ parser.on('--enable') { flags[:action] = 'enable' }
55
+ parser.on('--disable') { flags[:action] = 'disable' }
56
+ parser.on('--status') { flags[:action] = 'status' }
57
+ end
58
+
59
+ def call(_args, _name)
60
+ is_enabled = ShopifyCli::Config.get_bool('analytics', 'enabled')
61
+ if options.flags[:action] == 'disable' && is_enabled
62
+ ShopifyCli::Config.set('analytics', 'enabled', false)
63
+ @ctx.puts(@ctx.message('core.config.analytics.disabled'))
64
+ elsif options.flags[:action] == 'enable' && !is_enabled
65
+ ShopifyCli::Config.set('analytics', 'enabled', true)
66
+ @ctx.puts(@ctx.message('core.config.analytics.enabled'))
67
+ elsif is_enabled
68
+ @ctx.puts(@ctx.message('core.config.analytics.is_enabled'))
69
+ else
70
+ @ctx.puts(@ctx.message('core.config.analytics.is_disabled'))
71
+ end
72
+ end
73
+ end
42
74
  end
43
75
  end
44
76
  end
@@ -76,23 +76,40 @@ module ShopifyCli
76
76
  # - `ctx`: running context from your command
77
77
  # - `yarn`: The proc, array, or string command to run if yarn is available
78
78
  # - `npm`: The proc, array, or string command to run if npm is available
79
+ # - `capture_response`: The boolean flag to capture the output of the running command if it is set to true
79
80
  #
80
81
  # #### Example
81
82
  #
82
- # ShopifyCli::JsSystem.new(ctx: ctx).call(yarn: ['install', '--silent'], npm: ['install', '--no-audit'])
83
+ # ShopifyCli::JsSystem.new(ctx: ctx).call(
84
+ # yarn: ['install', '--silent'],
85
+ # npm: ['install', '--no-audit'],
86
+ # capture_response: false
87
+ # )
83
88
  #
84
- def call(yarn:, npm:)
85
- yarn? ? call_command(yarn, YARN_CORE_COMMAND) : call_command(npm, NPM_CORE_COMMAND)
89
+ def call(yarn:, npm:, capture_response: false)
90
+ if yarn?
91
+ call_command(yarn, YARN_CORE_COMMAND, capture_response)
92
+ else
93
+ call_command(npm, NPM_CORE_COMMAND, capture_response)
94
+ end
86
95
  end
87
96
 
88
97
  private
89
98
 
90
- def call_command(command, core_command)
99
+ def call_command(command, core_command, capture_response)
91
100
  if command.is_a?(String) || command.is_a?(Array)
92
- CLI::Kit::System.system(core_command, *command, chdir: ctx.root).success?
101
+ capture_response ? call_with_capture(command, core_command) : call_without_capture(command, core_command)
93
102
  else
94
103
  command.call
95
104
  end
96
105
  end
106
+
107
+ def call_with_capture(command, core_command)
108
+ CLI::Kit::System.capture3(core_command, *command, chdir: ctx.root)
109
+ end
110
+
111
+ def call_without_capture(command, core_command)
112
+ CLI::Kit::System.system(core_command, *command, chdir: ctx.root).success?
113
+ end
97
114
  end
98
115
  end
@@ -48,13 +48,27 @@ module ShopifyCli
48
48
  config: {
49
49
  help: <<~HELP,
50
50
  Change configuration of how the CLI operates
51
- Usage: {{command:%s config [ feature ] [ feature_name ] }}
51
+ Usage: {{command:%s config [ feature | analytics ] }}
52
52
  HELP
53
53
  feature: {
54
- enabled: "{{v}} feature {{green:%s}} was enabled",
55
- disabled: "{{v}} feature {{green:%s}} was disabled",
56
- is_enabled: "{{v}} feature {{green:%s}} is enabled",
57
- is_disabled: "{{v}} feature {{green:%s}} is disabled",
54
+ help: <<~HELP,
55
+ Change configuration of various features
56
+ Usage: {{command:%s config [ feature ] [ feature_name ] }}
57
+ HELP
58
+ enabled: "{{v}} feature {{green:%s}} has been enabled",
59
+ disabled: "{{v}} feature {{green:%s}} has been disabled",
60
+ is_enabled: "{{v}} feature {{green:%s}} is currently enabled",
61
+ is_disabled: "{{v}} feature {{green:%s}} is currently disabled",
62
+ },
63
+ analytics: {
64
+ help: <<~HELP,
65
+ Opt in/out of anonymous usage reporting
66
+ Usage: {{command:%s config [ analytics ] }}
67
+ HELP
68
+ enabled: "{{v}} analytics have been enabled",
69
+ disabled: "{{v}} analytics have been disabled",
70
+ is_enabled: "{{v}} analytics are currently enabled",
71
+ is_disabled: "{{v}} analytics are currently disabled",
58
72
  },
59
73
  },
60
74
 
@@ -1,3 +1,3 @@
1
1
  module ShopifyCli
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.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.2.0
4
+ version: 1.3.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-14 00:00:00.000000000 Z
11
+ date: 2020-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -147,7 +147,9 @@ files:
147
147
  - lib/project_types/extension/commands/tunnel.rb
148
148
  - lib/project_types/extension/extension_project.rb
149
149
  - lib/project_types/extension/extension_project_keys.rb
150
- - lib/project_types/extension/features/argo.rb
150
+ - lib/project_types/extension/features/argo/admin.rb
151
+ - lib/project_types/extension/features/argo/base.rb
152
+ - lib/project_types/extension/features/argo/checkout.rb
151
153
  - lib/project_types/extension/features/argo_config.rb
152
154
  - lib/project_types/extension/features/argo_dependencies.rb
153
155
  - lib/project_types/extension/features/argo_setup.rb
@@ -162,7 +164,7 @@ files:
162
164
  - lib/project_types/extension/models/registration.rb
163
165
  - lib/project_types/extension/models/type.rb
164
166
  - lib/project_types/extension/models/types/checkout_post_purchase.rb
165
- - lib/project_types/extension/models/types/subscription_management.rb
167
+ - lib/project_types/extension/models/types/product_subscription.rb
166
168
  - lib/project_types/extension/models/validation_error.rb
167
169
  - lib/project_types/extension/models/version.rb
168
170
  - lib/project_types/extension/tasks/converters/app_converter.rb
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'base64'
3
-
4
- module Extension
5
- module Features
6
- class Argo
7
- include SmartProperties
8
-
9
- GIT_ADMIN_TEMPLATE = 'https://github.com/Shopify/argo-admin-template.git'
10
- GIT_CHECKOUT_TEMPLATE = 'https://github.com/Shopify/argo-checkout-template.git'
11
- SCRIPT_PATH = %w(build main.js).freeze
12
-
13
- class << self
14
- def admin
15
- @admin ||= Argo.new(setup: ArgoSetup.new(git_template: GIT_ADMIN_TEMPLATE))
16
- end
17
-
18
- def checkout
19
- @checkout ||= Argo.new(
20
- setup: ArgoSetup.new(
21
- git_template: GIT_CHECKOUT_TEMPLATE,
22
- dependency_checks: [ArgoDependencies.node_installed(min_major: 10, min_minor: 16)]
23
- )
24
- )
25
- end
26
- end
27
-
28
- property! :setup, accepts: Features::ArgoSetup
29
-
30
- def create(directory_name, identifier, context)
31
- setup.call(directory_name, identifier, context)
32
- end
33
-
34
- def config(context)
35
- filepath = File.join(context.root, SCRIPT_PATH)
36
- context.abort(context.message('features.argo.missing_file_error')) unless File.exist?(filepath)
37
-
38
- begin
39
- {
40
- serialized_script: Base64.strict_encode64(File.open(filepath).read.chomp),
41
- }
42
- rescue StandardError
43
- context.abort(context.message('features.argo.script_prepare_error'))
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'base64'
3
-
4
- module Extension
5
- module Models
6
- module Types
7
- class SubscriptionManagement < Models::Type
8
- IDENTIFIER = 'SUBSCRIPTION_MANAGEMENT'
9
-
10
- def create(directory_name, context)
11
- Features::Argo.admin.create(directory_name, IDENTIFIER, context)
12
- end
13
-
14
- def config(context)
15
- Features::Argo.admin.config(context)
16
- end
17
- end
18
- end
19
- end
20
- end