shopify-cli 0.9.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -3
  3. data/docs/_config.yml +3 -0
  4. data/docs/_data/nav.yml +9 -0
  5. data/docs/getting-started/index.md +5 -40
  6. data/docs/getting-started/install/index.md +75 -0
  7. data/docs/getting-started/migrate/index.md +96 -0
  8. data/docs/getting-started/uninstall/index.md +37 -0
  9. data/docs/getting-started/upgrade/index.md +37 -0
  10. data/docs/index.md +5 -6
  11. data/lib/project_types/extension/cli.rb +3 -2
  12. data/lib/project_types/extension/commands/build.rb +1 -1
  13. data/lib/project_types/extension/commands/tunnel.rb +1 -1
  14. data/lib/project_types/extension/forms/register.rb +2 -3
  15. data/lib/project_types/extension/graphql/get_app_by_api_key.graphql +9 -0
  16. data/lib/project_types/extension/tasks/converters/app_converter.rb +27 -0
  17. data/lib/project_types/extension/tasks/get_app.rb +22 -0
  18. data/lib/project_types/extension/tasks/get_apps.rb +1 -6
  19. data/lib/project_types/node/forms/create.rb +3 -54
  20. data/lib/project_types/node/messages/messages.rb +3 -14
  21. data/lib/project_types/rails/cli.rb +0 -1
  22. data/lib/project_types/rails/forms/create.rb +3 -52
  23. data/lib/project_types/rails/messages/messages.rb +2 -13
  24. data/lib/project_types/script/cli.rb +5 -5
  25. data/lib/project_types/script/commands/create.rb +5 -4
  26. data/lib/project_types/script/commands/disable.rb +4 -14
  27. data/lib/project_types/script/commands/enable.rb +35 -11
  28. data/lib/project_types/script/commands/push.rb +9 -9
  29. data/lib/project_types/script/config/extension_points.yml +9 -3
  30. data/lib/project_types/script/errors.rb +1 -0
  31. data/lib/project_types/script/forms/create.rb +8 -4
  32. data/lib/project_types/script/forms/script_form.rb +5 -2
  33. data/lib/project_types/script/layers/application/create_script.rb +14 -20
  34. data/lib/project_types/script/layers/application/disable_script.rb +9 -7
  35. data/lib/project_types/script/layers/application/enable_script.rb +11 -9
  36. data/lib/project_types/script/layers/application/project_dependencies.rb +0 -5
  37. data/lib/project_types/script/layers/application/push_script.rb +6 -4
  38. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +106 -0
  39. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +2 -2
  40. data/lib/project_types/script/layers/infrastructure/errors.rb +2 -1
  41. data/lib/project_types/script/layers/infrastructure/project_creator.rb +23 -0
  42. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +1 -1
  43. data/lib/project_types/script/layers/infrastructure/script_repository.rb +1 -34
  44. data/lib/project_types/script/layers/infrastructure/script_service.rb +2 -0
  45. data/lib/project_types/script/messages/messages.rb +21 -25
  46. data/lib/project_types/script/script_project.rb +8 -4
  47. data/lib/project_types/script/templates/ts/as-pect.config.js +6 -0
  48. data/lib/project_types/script/templates/ts/as-pect.d.ts +1 -0
  49. data/lib/project_types/script/ui/error_handler.rb +9 -0
  50. data/lib/project_types/script/ui/printing_spinner.rb +75 -0
  51. data/lib/shopify-cli/admin_api.rb +1 -2
  52. data/lib/shopify-cli/admin_api/populate_resource_command.rb +10 -1
  53. data/lib/shopify-cli/admin_api/schema.rb +20 -8
  54. data/lib/shopify-cli/command.rb +2 -5
  55. data/lib/shopify-cli/commands.rb +1 -0
  56. data/lib/shopify-cli/commands/config.rb +44 -0
  57. data/lib/shopify-cli/commands/connect.rb +17 -10
  58. data/lib/shopify-cli/commands/create.rb +1 -1
  59. data/lib/shopify-cli/commands/help.rb +1 -1
  60. data/lib/shopify-cli/commands/system.rb +1 -1
  61. data/lib/shopify-cli/context.rb +10 -1
  62. data/lib/shopify-cli/core.rb +0 -1
  63. data/lib/shopify-cli/core/entry_point.rb +6 -0
  64. data/lib/shopify-cli/core/finalize.rb +13 -0
  65. data/lib/shopify-cli/feature.rb +97 -0
  66. data/lib/shopify-cli/messages/messages.rb +45 -2
  67. data/lib/shopify-cli/partners_api/organizations.rb +7 -7
  68. data/lib/shopify-cli/project_type.rb +2 -5
  69. data/lib/shopify-cli/tasks.rb +1 -0
  70. data/lib/shopify-cli/tasks/ensure_env.rb +0 -1
  71. data/lib/shopify-cli/tasks/select_org_and_shop.rb +77 -0
  72. data/lib/shopify-cli/tasks/update_dashboard_urls.rb +4 -3
  73. data/lib/shopify-cli/tunnel.rb +66 -10
  74. data/lib/shopify-cli/version.rb +1 -1
  75. data/lib/shopify_cli.rb +1 -0
  76. data/vendor/deps/cli-ui/REVISION +1 -1
  77. data/vendor/deps/cli-ui/lib/cli/ui.rb +52 -11
  78. data/vendor/deps/cli-ui/lib/cli/ui/color.rb +11 -7
  79. data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +34 -21
  80. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +107 -149
  81. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +99 -0
  82. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +119 -0
  83. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +158 -0
  84. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +112 -0
  85. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +9 -15
  86. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +47 -0
  87. data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +9 -7
  88. data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +39 -14
  89. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +62 -44
  90. data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +7 -2
  91. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +23 -3
  92. data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +34 -10
  93. data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +12 -7
  94. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +26 -16
  95. data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +3 -3
  96. data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +75 -0
  97. data/vendor/deps/cli-ui/lib/cli/ui/widgets/base.rb +27 -0
  98. data/vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb +61 -0
  99. metadata +25 -9
  100. data/lib/project_types/extension/features/tunnel_url.rb +0 -20
  101. data/lib/project_types/script/forms/enable.rb +0 -24
  102. data/lib/project_types/script/forms/push.rb +0 -19
  103. data/lib/project_types/script/layers/infrastructure/assemblyscript_dependency_manager.rb +0 -51
  104. data/lib/project_types/script/layers/infrastructure/dependency_manager.rb +0 -36
  105. data/lib/project_types/script/layers/infrastructure/test_suite_repository.rb +0 -62
  106. data/vendor/deps/cli-ui/lib/cli/ui/box.rb +0 -15
@@ -3,27 +3,27 @@
3
3
  module Script
4
4
  module Commands
5
5
  class Push < ShopifyCli::Command
6
+ prerequisite_task :ensure_env
7
+
6
8
  options do |parser, flags|
7
- parser.on('--api_key=APIKEY') { |t| flags[:api_key] = t }
8
9
  parser.on('--force') { |t| flags[:force] = t }
9
10
  end
10
11
 
11
- def call(args, _name)
12
- form = Forms::Push.ask(@ctx, args, options.flags)
12
+ def call(_args, _name)
13
13
  project = ScriptProject.current
14
-
15
- return @ctx.puts(self.class.help) unless form && ScriptProject::SUPPORTED_LANGUAGES.include?(project.language)
16
-
14
+ api_key = project.env[:api_key]
15
+ return @ctx.puts(self.class.help) unless api_key &&
16
+ ScriptProject::SUPPORTED_LANGUAGES.include?(project.language)
17
17
  Layers::Application::PushScript.call(
18
18
  ctx: @ctx,
19
19
  language: project.language,
20
20
  extension_point_type: project.extension_point_type,
21
21
  script_name: project.script_name,
22
22
  source_file: project.source_file,
23
- api_key: form.api_key,
24
- force: form.force
23
+ api_key: api_key,
24
+ force: options.flags.key?(:force)
25
25
  )
26
- @ctx.puts(@ctx.message('script.push.script_pushed', api_key: form.api_key))
26
+ @ctx.puts(@ctx.message('script.push.script_pushed', api_key: api_key))
27
27
  rescue StandardError => e
28
28
  UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message('script.push.error.operation_failed'))
29
29
  end
@@ -1,18 +1,24 @@
1
1
  discount:
2
2
  assemblyscript:
3
3
  package: "@shopify/extension-point-as-discount"
4
- version: "^0.2.2"
4
+ version: "^0.2.4"
5
5
  sdk-version: "^6.0.0"
6
6
  toolchain-version: "^1.1.0"
7
7
  unit_limit_per_order:
8
8
  assemblyscript:
9
9
  package: "@shopify/extension-point-as-unit-limit-per-order"
10
- version: "^0.1.2"
10
+ version: "^0.1.6"
11
11
  sdk-version: "^6.0.0"
12
12
  toolchain-version: "^1.1.0"
13
13
  payment_filter:
14
14
  assemblyscript:
15
15
  package: "@shopify/extension-point-as-payment-filter"
16
- version: "^0.1.2"
16
+ version: "^0.2.2"
17
+ sdk-version: "^6.0.0"
18
+ toolchain-version: "^1.1.0"
19
+ shipping_filter:
20
+ assemblyscript:
21
+ package: "@shopify/extension-point-as-shipping-filter"
22
+ version: "^0.2.4"
17
23
  sdk-version: "^6.0.0"
18
24
  toolchain-version: "^1.1.0"
@@ -3,6 +3,7 @@
3
3
  module Script
4
4
  module Errors
5
5
  class InvalidContextError < ScriptProjectError; end
6
+ class InvalidScriptNameError < ScriptProjectError; end
6
7
  class NoExistingAppsError < ScriptProjectError; end
7
8
  class NoExistingOrganizationsError < ScriptProjectError; end
8
9
  class NoExistingStoresError < ScriptProjectError
@@ -6,7 +6,7 @@ module Script
6
6
  flag_arguments :extension_point, :name
7
7
 
8
8
  def ask
9
- self.name = (name || ask_name).downcase.gsub(' ', '_')
9
+ self.name = valid_name
10
10
  self.extension_point ||= ask_extension_point
11
11
  end
12
12
 
@@ -20,9 +20,13 @@ module Script
20
20
  end
21
21
 
22
22
  def ask_name
23
- name = CLI::UI::Prompt.ask(@ctx.message('script.forms.create.script_name'))
24
- return name if name.match?(/^[0-9A-Za-z _-]*$/)
25
- @ctx.abort(@ctx.message('script.forms.create.error.invalid_name'))
23
+ CLI::UI::Prompt.ask(@ctx.message('script.forms.create.script_name'))
24
+ end
25
+
26
+ def valid_name
27
+ n = (name || ask_name).downcase.gsub(' ', '_')
28
+ return n if n.match?(/^[0-9A-Za-z_-]*$/)
29
+ raise Errors::InvalidScriptNameError
26
30
  end
27
31
  end
28
32
  end
@@ -11,8 +11,11 @@ module Script
11
11
 
12
12
  def organizations
13
13
  return @organizations if defined?(@organizations)
14
- ctx.puts(ctx.message('script.forms.script_form.fetching_organizations'))
15
- @organizations = ShopifyCli::PartnersAPI::Organizations.fetch_with_app(ctx)
14
+ UI::PrintingSpinner.spin(ctx, ctx.message('script.forms.script_form.fetching_organizations')) do |ctx, spinner|
15
+ @organizations = ShopifyCli::PartnersAPI::Organizations.fetch_with_app(ctx)
16
+ spinner.update_title(ctx.message('script.forms.script_form.fetched_organizations'))
17
+ end
18
+ @organizations
16
19
  end
17
20
 
18
21
  def ask_app_api_key(apps, message: ctx.message('script.forms.script_form.ask_app_api_key_default'))
@@ -9,14 +9,17 @@ module Script
9
9
  class << self
10
10
  def call(ctx:, language:, script_name:, extension_point_type:)
11
11
  extension_point = ExtensionPoints.get(type: extension_point_type)
12
- project = create_project(ctx, script_name, extension_point)
13
- install_dependencies(ctx, language, script_name, extension_point, project)
14
- create_definition(ctx, language, extension_point, script_name)
12
+ project = setup_project(ctx, script_name, extension_point)
13
+ project_creator = Infrastructure::ProjectCreator
14
+ .for(ctx, language, extension_point, script_name, project.directory)
15
+ install_dependencies(ctx, language, script_name, project.source_file, project_creator)
16
+ bootstrap(ctx, project.source_path, project_creator)
17
+ project
15
18
  end
16
19
 
17
20
  private
18
21
 
19
- def create_project(ctx, script_name, extension_point)
22
+ def setup_project(ctx, script_name, extension_point)
20
23
  ScriptProject.create(ctx, script_name)
21
24
  ScriptProject.write(
22
25
  ctx,
@@ -28,26 +31,17 @@ module Script
28
31
  ScriptProject.current
29
32
  end
30
33
 
31
- def install_dependencies(ctx, language, script_name, extension_point, project)
32
- task_runner = Infrastructure::TaskRunner.for(ctx, language, script_name, project.source_file)
33
- ProjectDependencies
34
- .bootstrap(ctx: ctx, language: language, extension_point: extension_point, script_name: script_name)
35
- ProjectDependencies
36
- .install(ctx: ctx, task_runner: task_runner)
34
+ def install_dependencies(ctx, language, script_name, source_file, project_creator)
35
+ task_runner = Infrastructure::TaskRunner.for(ctx, language, script_name, source_file)
36
+ project_creator.setup_dependencies
37
+ ProjectDependencies.install(ctx: ctx, task_runner: task_runner)
37
38
  end
38
39
 
39
- def create_definition(ctx, language, extension_point, script_name)
40
- script = nil
40
+ def bootstrap(ctx, source_path, project_creator)
41
41
  UI::StrictSpinner.spin(ctx.message('script.create.creating')) do |spinner|
42
- script = Infrastructure::ScriptRepository.new(ctx: ctx).create_script(
43
- language,
44
- extension_point,
45
- script_name
46
- )
47
- Infrastructure::TestSuiteRepository.new(ctx: ctx).create_test_suite(script)
48
- spinner.update_title(ctx.message('script.create.created'))
42
+ project_creator.bootstrap
43
+ spinner.update_title(ctx.message('script.create.created', source_path))
49
44
  end
50
- script
51
45
  end
52
46
  end
53
47
  end
@@ -5,13 +5,15 @@ module Script
5
5
  module Application
6
6
  class DisableScript
7
7
  def self.call(ctx:, api_key:, shop_domain:, extension_point_type:)
8
- script_service = Infrastructure::ScriptService.new(ctx: ctx)
9
- script_service.disable(
10
- api_key: api_key,
11
- shop_domain: shop_domain,
12
- extension_point_type: extension_point_type,
13
- )
14
- ctx.puts(ctx.message('script.application.disabled'))
8
+ UI::PrintingSpinner.spin(ctx, ctx.message('script.application.disabling')) do |p_ctx, spinner|
9
+ script_service = Infrastructure::ScriptService.new(ctx: p_ctx)
10
+ script_service.disable(
11
+ api_key: api_key,
12
+ shop_domain: shop_domain,
13
+ extension_point_type: extension_point_type,
14
+ )
15
+ spinner.update_title(p_ctx.message('script.application.disabled'))
16
+ end
15
17
  end
16
18
  end
17
19
  end
@@ -5,15 +5,17 @@ module Script
5
5
  module Application
6
6
  class EnableScript
7
7
  def self.call(ctx:, api_key:, shop_domain:, configuration:, extension_point_type:, title:)
8
- script_service = Infrastructure::ScriptService.new(ctx: ctx)
9
- script_service.enable(
10
- api_key: api_key,
11
- shop_domain: shop_domain,
12
- configuration: configuration,
13
- extension_point_type: extension_point_type,
14
- title: title
15
- )
16
- ctx.puts(ctx.message('script.application.enabled'))
8
+ UI::PrintingSpinner.spin(ctx, ctx.message('script.application.enabling')) do |p_ctx, spinner|
9
+ script_service = Infrastructure::ScriptService.new(ctx: p_ctx)
10
+ script_service.enable(
11
+ api_key: api_key,
12
+ shop_domain: shop_domain,
13
+ configuration: configuration,
14
+ extension_point_type: extension_point_type,
15
+ title: title
16
+ )
17
+ spinner.update_title(p_ctx.message('script.application.enabled'))
18
+ end
17
19
  end
18
20
  end
19
21
  end
@@ -2,11 +2,6 @@ module Script
2
2
  module Layers
3
3
  module Application
4
4
  class ProjectDependencies
5
- def self.bootstrap(ctx:, language:, extension_point:, script_name:)
6
- dep_manager = Infrastructure::DependencyManager.for(ctx, language, extension_point, script_name)
7
- dep_manager.bootstrap
8
- end
9
-
10
5
  def self.install(ctx:, task_runner:)
11
6
  CLI::UI::Frame.open(ctx.message('script.project_deps.checking_with_npm')) do
12
7
  begin
@@ -20,10 +20,12 @@ module Script
20
20
  private
21
21
 
22
22
  def push_script(ctx, task_runner, script, api_key, force)
23
- Infrastructure::PushPackageRepository.new(ctx: ctx)
24
- .get_push_package(script, task_runner.compiled_type)
25
- .push(Infrastructure::ScriptService.new(ctx: ctx), api_key, force)
26
- ctx.puts(ctx.message('script.application.pushed'))
23
+ UI::PrintingSpinner.spin(ctx, ctx.message('script.application.pushing')) do |p_ctx, spinner|
24
+ Infrastructure::PushPackageRepository.new(ctx: p_ctx)
25
+ .get_push_package(script, task_runner.compiled_type)
26
+ .push(Infrastructure::ScriptService.new(ctx: p_ctx), api_key, force)
27
+ spinner.update_title(p_ctx.message('script.application.pushed'))
28
+ end
27
29
  end
28
30
  end
29
31
  end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Infrastructure
6
+ class AssemblyScriptProjectCreator
7
+ include SmartProperties
8
+ property! :ctx, accepts: ShopifyCli::Context
9
+ property! :extension_point, accepts: Domain::ExtensionPoint
10
+ property! :script_name, accepts: String
11
+ property! :path_to_project, accepts: String
12
+
13
+ BOOTSTRAP_SRC = "npx --no-install shopify-scripts-bootstrap src %{src_base}"
14
+ BOOTSTRAP_TEST = "npx --no-install shopify-scripts-bootstrap test %{test_base}"
15
+ SOURCE_DIR = "src"
16
+ TEST_DIR = "test"
17
+ LANGUAGE = "ts"
18
+
19
+ def setup_dependencies
20
+ write_npmrc
21
+ write_package_json
22
+ end
23
+
24
+ def bootstrap
25
+ create_src_folder
26
+ create_test_folder
27
+ end
28
+
29
+ private
30
+
31
+ def create_src_folder
32
+ ctx.mkdir_p(src_base)
33
+ out, status = ctx.capture2e(format(BOOTSTRAP_SRC, src_base: src_base))
34
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
35
+
36
+ write_tsconfig_file(SOURCE_DIR, ".")
37
+ end
38
+
39
+ def create_test_folder
40
+ ctx.mkdir_p(test_base)
41
+ out, status = ctx.capture2e(format(BOOTSTRAP_TEST, test_base: test_base))
42
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
43
+
44
+ copy_template_file(test_base, 'as-pect.config.js')
45
+ copy_template_file(test_base, 'as-pect.d.ts')
46
+ write_tsconfig_file(TEST_DIR, "../#{SOURCE_DIR}")
47
+ end
48
+
49
+ def test_base
50
+ "#{path_to_project}/#{TEST_DIR}"
51
+ end
52
+
53
+ def src_base
54
+ "#{path_to_project}/#{SOURCE_DIR}"
55
+ end
56
+
57
+ def copy_template_file(destination, name)
58
+ template_file = Project.project_filepath("templates/#{LANGUAGE}/#{name}")
59
+ ctx.cp(template_file, "#{destination}/#{name}")
60
+ end
61
+
62
+ def write_npmrc
63
+ ctx.system(
64
+ 'npm', '--userconfig', './.npmrc', 'config', 'set', '@shopify:registry', 'https://registry.npmjs.com'
65
+ )
66
+ ctx.system(
67
+ 'npm', '--userconfig', './.npmrc', 'config', 'set', 'engine-strict', 'true'
68
+ )
69
+ end
70
+
71
+ def write_tsconfig_file(dir, path_to_source)
72
+ AssemblyScriptTsConfig
73
+ .new(dir_to_write_in: dir)
74
+ .with_extends_assemblyscript_config(relative_path_to_node_modules: ".")
75
+ .with_module_resolution_paths(paths: { "*": ["#{path_to_source}/*.ts"] })
76
+ .write
77
+ end
78
+
79
+ def write_package_json
80
+ package_json = <<~HERE
81
+ {
82
+ "name": "#{script_name}",
83
+ "version": "1.0.0",
84
+ "devDependencies": {
85
+ "@shopify/scripts-sdk-as": "#{extension_point.sdks[:ts].sdk_version}",
86
+ "@shopify/scripts-toolchain-as": "#{extension_point.sdks[:ts].toolchain_version}",
87
+ "#{extension_point.sdks[:ts].package}": "#{extension_point.sdks[:ts].version}",
88
+ "@as-pect/cli": "4.0.0",
89
+ "as-wasi": "^0.2.0",
90
+ "assemblyscript": "^0.12.0"
91
+ },
92
+ "scripts": {
93
+ "test": "asp --config test/as-pect.config.js --summary --verbose"
94
+ },
95
+ "engines": {
96
+ "node": ">=14.5"
97
+ }
98
+ }
99
+ HERE
100
+
101
+ ctx.write("package.json", package_json)
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -6,7 +6,7 @@ module Script
6
6
  class AssemblyScriptTaskRunner
7
7
  BYTECODE_FILE = "%{name}.wasm"
8
8
  SCRIPT_SDK_BUILD = "npx --no-install shopify-scripts-build --src=../%{source} --binary=#{BYTECODE_FILE} "\
9
- "-- --lib=../node_modules --validate --optimize"
9
+ "-- --lib=../node_modules --optimize --use Date="
10
10
 
11
11
  attr_reader :ctx, :script_name, :script_source_file
12
12
 
@@ -34,7 +34,7 @@ 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.exist?("node_modules")
37
+ ctx.dir_exist?("node_modules")
38
38
  end
39
39
 
40
40
  private
@@ -5,9 +5,9 @@ module Script
5
5
  module Infrastructure
6
6
  module Errors
7
7
  class AppNotInstalledError < ScriptProjectError; end
8
+ class AppScriptNotPushedError < ScriptProjectError; end
8
9
  class AppScriptUndefinedError < ScriptProjectError; end
9
10
  class BuildError < ScriptProjectError; end
10
- class DependencyError < ScriptProjectError; end
11
11
  class DependencyInstallError < ScriptProjectError; end
12
12
  class ForbiddenError < ScriptProjectError; end
13
13
  class GraphqlError < ScriptProjectError
@@ -17,6 +17,7 @@ module Script
17
17
  super("GraphQL failed with errors: #{errors}")
18
18
  end
19
19
  end
20
+ class ProjectCreatorNotFoundError < ScriptProjectError; end
20
21
  class ScriptRepushError < ScriptProjectError
21
22
  attr_reader :api_key
22
23
  def initialize(api_key)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Infrastructure
6
+ class ProjectCreator
7
+ PROJECT_CREATORS = {
8
+ "ts" => Infrastructure::AssemblyScriptProjectCreator,
9
+ }
10
+
11
+ def self.for(ctx, language, extension_point, script_name, path_to_project)
12
+ raise Errors::ProjectCreatorNotFoundError unless PROJECT_CREATORS[language]
13
+ PROJECT_CREATORS[language].new(
14
+ ctx: ctx,
15
+ extension_point: extension_point,
16
+ script_name: script_name,
17
+ path_to_project: path_to_project
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -22,7 +22,7 @@ module Script
22
22
  def get_push_package(script, compiled_type)
23
23
  build_file_path = file_path(script.name, compiled_type)
24
24
 
25
- raise Domain::PushPackageNotFoundError unless File.exist?(build_file_path)
25
+ raise Domain::PushPackageNotFoundError unless ctx.file_exist?(build_file_path)
26
26
 
27
27
  script_content = File.read(build_file_path)
28
28
 
@@ -7,26 +7,9 @@ module Script
7
7
  include SmartProperties
8
8
  property! :ctx, accepts: ShopifyCli::Context
9
9
 
10
- BOOTSTRAP_SRC = "npx --no-install shopify-scripts-bootstrap src %{src_base}"
11
-
12
- def create_script(language, extension_point, script_name)
13
- ctx.mkdir_p(src_base)
14
- out, status = CLI::Kit::System.capture2e(format(BOOTSTRAP_SRC, src_base: src_base))
15
- raise Domain::Errors::ServiceFailureError, out unless status.success?
16
-
17
- write_tsconfig if language == "ts"
18
-
19
- Domain::Script.new(
20
- script_id(language),
21
- script_name,
22
- extension_point.type,
23
- language
24
- )
25
- end
26
-
27
10
  def get_script(language, extension_point_type, script_name)
28
11
  source_file_path = src_code_file(language)
29
- unless File.exist?(source_file_path)
12
+ unless ctx.file_exist?(source_file_path)
30
13
  raise Domain::Errors::ScriptNotFoundError.new(extension_point_type, source_file_path)
31
14
  end
32
15
 
@@ -51,18 +34,6 @@ module Script
51
34
 
52
35
  private
53
36
 
54
- def write_sdk(extension_point_type, language, sdk_types)
55
- return unless language == "ts"
56
- File.write(sdk_types_file(extension_point_type, language), sdk_types)
57
- end
58
-
59
- def write_tsconfig
60
- AssemblyScriptTsConfig
61
- .new(dir_to_write_in: relative_path_to_src)
62
- .with_extends_assemblyscript_config(relative_path_to_node_modules: ".")
63
- .write
64
- end
65
-
66
37
  def project_base
67
38
  ScriptProject.current.directory
68
39
  end
@@ -82,10 +53,6 @@ module Script
82
53
  def file_name(language)
83
54
  "script.#{language}"
84
55
  end
85
-
86
- def sdk_types_file(extension_point_type, language)
87
- "#{src_base}/#{extension_point_type}.#{language}"
88
- end
89
56
  end
90
57
  end
91
58
  end