shopify-cli 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +3 -0
  3. data/CHANGELOG.md +5 -0
  4. data/RELEASING.md +4 -4
  5. data/lib/project_types/script/cli.rb +2 -3
  6. data/lib/project_types/script/commands/push.rb +1 -0
  7. data/lib/project_types/script/layers/application/build_script.rb +7 -10
  8. data/lib/project_types/script/layers/application/create_script.rb +16 -7
  9. data/lib/project_types/script/layers/application/project_dependencies.rb +3 -4
  10. data/lib/project_types/script/layers/application/push_script.rb +13 -11
  11. data/lib/project_types/script/layers/infrastructure/assemblyscript_dependency_manager.rb +0 -22
  12. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +64 -0
  13. data/lib/project_types/script/layers/infrastructure/errors.rb +1 -1
  14. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +5 -2
  15. data/lib/project_types/script/layers/infrastructure/script_repository.rb +9 -6
  16. data/lib/project_types/script/layers/infrastructure/task_runner.rb +18 -0
  17. data/lib/project_types/script/layers/infrastructure/test_suite_repository.rb +6 -3
  18. data/lib/project_types/script/script_project.rb +22 -9
  19. data/lib/shopify-cli/api.rb +2 -0
  20. data/lib/shopify-cli/context.rb +51 -0
  21. data/lib/shopify-cli/git.rb +14 -10
  22. data/lib/shopify-cli/messages/messages.rb +8 -2
  23. data/lib/shopify-cli/version.rb +1 -1
  24. metadata +4 -4
  25. data/lib/project_types/script/layers/infrastructure/assemblyscript_wasm_builder.rb +0 -39
  26. data/lib/project_types/script/layers/infrastructure/script_builder.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c41d92242b50f6d361cd7ad137799bffe507581437f25a1eb1bd183cc206c63
4
- data.tar.gz: '06887cc6c8442a754bf9a9d60e10968c5c59325b98a50d452e6f849a80db7226'
3
+ metadata.gz: c2b12fdb1aec476c1b05eee2e33817d3636f76927d4cdc5700347344b687e28d
4
+ data.tar.gz: 83411b72925dbe120a4c89fa1d715f3fe61a7596ed4d356f03b537ea6bb31481
5
5
  SHA512:
6
- metadata.gz: 23260cf14a8e617539fedb1bddf1beb5f91604fc5db87d147335649dd01f7fb9859c87da6a01bba5c19743dabc8aa0c1c55bf269cdaec57943f076a88fffcff9
7
- data.tar.gz: eddd93f62bb2bd7f8364c4c423847568838d08fdbf77f777f03f2adb9fbfa67f7a3af83bedc48025f217e1787288f5b6e10424e5dbdad1156a8faaf80ddb041c
6
+ metadata.gz: 3557bcc2a93f0775a294b0c2d1c784949e84602155de21d3d3db89237ae7e50bbf3ba591bdc329ca6074ae27178444c6c939cd42ac361dcb5a9d50a9de4e8567
7
+ data.tar.gz: 78ebf53316d6bebf24bb04832a5b052512d46df48f9f71cc3f388305c6210cd0ec32b2f1ba9151cd80d8199a26142c8684775f93198d7d9b61bf1291d1d39732
@@ -1 +1,4 @@
1
1
  * @shopify/platform-dev-tools-education
2
+
3
+ /lib/project_types/script/ @shopify/scripts
4
+ /test/project_types/script/ @shopify/scripts
@@ -1,3 +1,8 @@
1
+ Version 0.9.2
2
+ ------
3
+ * Rebased to master, to pull in 7+ Pull Requests
4
+ * Updates to dependencies to package files (updated Ruby version)
5
+
1
6
  Version 0.9.1
2
7
  ------
3
8
  * Updated required Ruby version for the CLI
@@ -13,7 +13,7 @@
13
13
 
14
14
  5. Commit the changes with a commit message like "Packaging for release X.Y.Z"
15
15
  ```
16
- $ git commit -am "Packaging for release X.Y.Z"
16
+ $ git commit -am "Packaging for release vX.Y.Z"
17
17
  ```
18
18
 
19
19
  6. Push out the changes
@@ -21,7 +21,7 @@
21
21
  $ git push -u origin release_X_Y_Z
22
22
  ```
23
23
 
24
- 7. Open a PR for the branch, get necessary approvals from code owners and merge into main branch
24
+ 7. Open a PR for the branch, get necessary approvals from code owners and merge into main branch. Note that the PR title will be the release note in Shipit, so make sure it mentions the release
25
25
 
26
26
  8. Deploy using Shipit
27
27
 
@@ -34,8 +34,8 @@
34
34
  10. Clone the `Shopify/homebrew-shopify` repository (if not already cloned), and then
35
35
  * create a branch named `release_X_Y_Z_of_shopify-cli`
36
36
  * update the brew formula in `shopify-cli.rb` with the generated formula in `packaging/builds/X.Y.Z/` in the `Shopify/shopify-app-cli` repo (from step 9)
37
- * commit the change and create a PR
38
- * when PR is approved, merge into main branch of `Shopify/homebrew-shopify` repository
37
+ * commit the change and create a PR on the [Shopify Homebrew repository](https://github.com/Shopify/homebrew-shopify)
38
+ * when PR is approved, merge into main branch
39
39
 
40
40
  11. Go to [releases](https://github.com/Shopify/shopify-app-cli/releases) page of `Shopify/shopify-app-cli` repo and create a new release:
41
41
  * use the tag created in step 8 by Shipit (should be "vX.Y.Z")
@@ -51,15 +51,14 @@ module Script
51
51
  autoload :Errors, Project.project_filepath('layers/infrastructure/errors')
52
52
  autoload :AssemblyScriptDependencyManager,
53
53
  Project.project_filepath('layers/infrastructure/assemblyscript_dependency_manager')
54
+ autoload :AssemblyScriptTaskRunner, Project.project_filepath('layers/infrastructure/assemblyscript_task_runner')
54
55
  autoload :AssemblyScriptTsConfig, Project.project_filepath('layers/infrastructure/assemblyscript_tsconfig')
55
- autoload :AssemblyScriptWasmBuilder,
56
- Project.project_filepath('layers/infrastructure/assemblyscript_wasm_builder')
57
56
  autoload :DependencyManager, Project.project_filepath('layers/infrastructure/dependency_manager')
58
57
  autoload :PushPackageRepository, Project.project_filepath('layers/infrastructure/push_package_repository')
59
58
  autoload :ExtensionPointRepository, Project.project_filepath('layers/infrastructure/extension_point_repository')
60
- autoload :ScriptBuilder, Project.project_filepath('layers/infrastructure/script_builder')
61
59
  autoload :ScriptRepository, Project.project_filepath('layers/infrastructure/script_repository')
62
60
  autoload :ScriptService, Project.project_filepath('layers/infrastructure/script_service')
61
+ autoload :TaskRunner, Project.project_filepath('layers/infrastructure/task_runner')
63
62
  autoload :TestSuiteRepository, Project.project_filepath('layers/infrastructure/test_suite_repository')
64
63
  end
65
64
  end
@@ -19,6 +19,7 @@ module Script
19
19
  language: project.language,
20
20
  extension_point_type: project.extension_point_type,
21
21
  script_name: project.script_name,
22
+ source_file: project.source_file,
22
23
  api_key: form.api_key,
23
24
  force: form.force
24
25
  )
@@ -5,11 +5,11 @@ module Script
5
5
  module Application
6
6
  class BuildScript
7
7
  class << self
8
- def call(ctx:, script:)
8
+ def call(ctx:, task_runner:, script:)
9
9
  return if CLI::UI::Frame.open(ctx.message('script.application.building')) do
10
10
  begin
11
11
  UI::StrictSpinner.spin(ctx.message('script.application.building_script')) do |spinner|
12
- build(script)
12
+ build(ctx, task_runner, script)
13
13
  spinner.update_title(ctx.message('script.application.built'))
14
14
  end
15
15
  true
@@ -25,16 +25,13 @@ module Script
25
25
 
26
26
  private
27
27
 
28
- def build(script)
29
- script_repo = Infrastructure::ScriptRepository.new
30
- script_builder = Infrastructure::ScriptBuilder.for(script)
31
- compiled_type = script_builder.compiled_type
28
+ def build(ctx, task_runner, script)
29
+ script_repo = Infrastructure::ScriptRepository.new(ctx: ctx)
32
30
  script_content = script_repo.with_temp_build_context do
33
- script_builder.build
31
+ task_runner.build
34
32
  end
35
-
36
- Infrastructure::PushPackageRepository.new
37
- .create_push_package(script, script_content, compiled_type)
33
+ Infrastructure::PushPackageRepository.new(ctx: ctx)
34
+ .create_push_package(script, script_content, task_runner.compiled_type)
38
35
  end
39
36
  end
40
37
  end
@@ -9,15 +9,15 @@ 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
- create_project(ctx, language, script_name, extension_point)
12
+ project = create_project(ctx, script_name, extension_point)
13
+ install_dependencies(ctx, language, script_name, extension_point, project)
13
14
  create_definition(ctx, language, extension_point, script_name)
14
15
  end
15
16
 
16
17
  private
17
18
 
18
- def create_project(ctx, language, script_name, extension_point)
19
- ScriptProject.create(script_name)
20
- ctx.root = File.join(ctx.root, script_name)
19
+ def create_project(ctx, script_name, extension_point)
20
+ ScriptProject.create(ctx, script_name)
21
21
  ScriptProject.write(
22
22
  ctx,
23
23
  project_type: :script,
@@ -25,17 +25,26 @@ module Script
25
25
  extension_point_type: extension_point.type,
26
26
  script_name: script_name
27
27
  )
28
+ ScriptProject.current
29
+ end
30
+
31
+ def install_dependencies(ctx, language, script_name, extension_point, project)
32
+ task_runner = Infrastructure::TaskRunner.for(ctx, language, script_name, project.source_file)
28
33
  ProjectDependencies
29
34
  .bootstrap(ctx: ctx, language: language, extension_point: extension_point, script_name: script_name)
30
35
  ProjectDependencies
31
- .install(ctx: ctx, language: language, extension_point: extension_point, script_name: script_name)
36
+ .install(ctx: ctx, task_runner: task_runner)
32
37
  end
33
38
 
34
39
  def create_definition(ctx, language, extension_point, script_name)
35
40
  script = nil
36
41
  UI::StrictSpinner.spin(ctx.message('script.create.creating')) do |spinner|
37
- script = Infrastructure::ScriptRepository.new.create_script(language, extension_point, script_name)
38
- Infrastructure::TestSuiteRepository.new.create_test_suite(script)
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)
39
48
  spinner.update_title(ctx.message('script.create.created'))
40
49
  end
41
50
  script
@@ -7,15 +7,14 @@ module Script
7
7
  dep_manager.bootstrap
8
8
  end
9
9
 
10
- def self.install(ctx:, language:, extension_point:, script_name:)
11
- dep_manager = Infrastructure::DependencyManager.for(ctx, language, extension_point, script_name)
10
+ def self.install(ctx:, task_runner:)
12
11
  CLI::UI::Frame.open(ctx.message('script.project_deps.checking_with_npm')) do
13
12
  begin
14
- if dep_manager.installed?
13
+ if task_runner.dependencies_installed?
15
14
  ctx.puts(ctx.message('script.project_deps.none_required'))
16
15
  else
17
16
  UI::StrictSpinner.spin(ctx.message('script.project_deps.installing')) do |spinner|
18
- dep_manager.install
17
+ task_runner.install_dependencies
19
18
  spinner.update_title(ctx.message('script.project_deps.installed'))
20
19
  end
21
20
  end
@@ -5,21 +5,23 @@ module Script
5
5
  module Application
6
6
  class PushScript
7
7
  class << self
8
- def call(ctx:, language:, extension_point_type:, script_name:, api_key:, force:)
9
- extension_point = ExtensionPoints.get(type: extension_point_type)
10
- script = Infrastructure::ScriptRepository.new.get_script(language, extension_point_type, script_name)
11
- ProjectDependencies
12
- .install(ctx: ctx, language: language, extension_point: extension_point, script_name: script_name)
13
- BuildScript.call(ctx: ctx, script: script)
14
- push_script(ctx, script, api_key, force)
8
+ def call(ctx:, language:, extension_point_type:, script_name:, source_file:, api_key:, force:)
9
+ script = Infrastructure::ScriptRepository.new(ctx: ctx).get_script(
10
+ language,
11
+ extension_point_type,
12
+ script_name
13
+ )
14
+ task_runner = Infrastructure::TaskRunner.for(ctx, language, script_name, source_file)
15
+ ProjectDependencies.install(ctx: ctx, task_runner: task_runner)
16
+ BuildScript.call(ctx: ctx, task_runner: task_runner, script: script)
17
+ push_script(ctx, task_runner, script, api_key, force)
15
18
  end
16
19
 
17
20
  private
18
21
 
19
- def push_script(ctx, script, api_key, force)
20
- compiled_type = Infrastructure::ScriptBuilder.for(script).compiled_type
21
- Infrastructure::PushPackageRepository.new
22
- .get_push_package(script, compiled_type)
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)
23
25
  .push(Infrastructure::ScriptService.new(ctx: ctx), api_key, force)
24
26
  ctx.puts(ctx.message('script.application.pushed'))
25
27
  end
@@ -16,30 +16,8 @@ module Script
16
16
  write_package_json
17
17
  end
18
18
 
19
- def installed?
20
- # Assuming if node_modules folder exist at root of script folder, all deps are installed
21
- Dir.exist?("node_modules")
22
- end
23
-
24
- def install
25
- check_node_version!
26
-
27
- output, status = @ctx.capture2e("npm", "install", "--no-audit", "--no-optional", "--loglevel error")
28
- raise Errors::DependencyInstallError, output unless status.success?
29
- end
30
-
31
19
  private
32
20
 
33
- def check_node_version!
34
- output, status = @ctx.capture2e("node", "--version")
35
- raise Errors::DependencyInstallError, output unless status.success?
36
-
37
- version = Semantic::Version.new(output[1..-1])
38
- unless version >= Semantic::Version.new("12.16.0")
39
- raise Errors::DependencyInstallError, "Node version must be >= v12.16.0 Current version: #{output}."
40
- end
41
- end
42
-
43
21
  def write_npmrc
44
22
  @ctx.system(
45
23
  'npm', '--userconfig', './.npmrc', 'config', 'set', '@shopify:registry', 'https://registry.npmjs.com'
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Infrastructure
6
+ class AssemblyScriptTaskRunner
7
+ BYTECODE_FILE = "%{name}.wasm"
8
+ SCRIPT_SDK_BUILD = "npx --no-install shopify-scripts-build --src=../%{source} --binary=#{BYTECODE_FILE} "\
9
+ "-- --lib=../node_modules --validate --optimize"
10
+
11
+ attr_reader :ctx, :script_name, :script_source_file
12
+
13
+ def initialize(ctx, script_name, script_source_file)
14
+ @ctx = ctx
15
+ @script_name = script_name
16
+ @script_source_file = script_source_file
17
+ end
18
+
19
+ def build
20
+ compile
21
+ bytecode
22
+ end
23
+
24
+ def compiled_type
25
+ "wasm"
26
+ end
27
+
28
+ def install_dependencies
29
+ check_node_version!
30
+
31
+ output, status = ctx.capture2e("npm", "install", "--no-audit", "--no-optional", "--loglevel error")
32
+ raise Errors::DependencyInstallError, output unless status.success?
33
+ end
34
+
35
+ def dependencies_installed?
36
+ # Assuming if node_modules folder exist at root of script folder, all deps are installed
37
+ ctx.exist?("node_modules")
38
+ end
39
+
40
+ private
41
+
42
+ def check_node_version!
43
+ output, status = @ctx.capture2e("node", "--version")
44
+ raise Errors::DependencyInstallError, output unless status.success?
45
+
46
+ require 'semantic/semantic'
47
+ version = ::Semantic::Version.new(output[1..-1])
48
+ unless version >= ::Semantic::Version.new("12.16.0")
49
+ raise Errors::DependencyInstallError, "Node version must be >= v12.16.0. Current version: #{output.strip}."
50
+ end
51
+ end
52
+
53
+ def compile
54
+ out, status = ctx.capture2e(format(SCRIPT_SDK_BUILD, source: script_source_file, name: script_name))
55
+ raise Domain::Errors::ServiceFailureError, out unless status.success?
56
+ end
57
+
58
+ def bytecode
59
+ File.read(format(BYTECODE_FILE, name: script_name))
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -6,7 +6,6 @@ module Script
6
6
  module Errors
7
7
  class AppNotInstalledError < ScriptProjectError; end
8
8
  class AppScriptUndefinedError < ScriptProjectError; end
9
- class BuilderNotFoundError < ScriptProjectError; end
10
9
  class BuildError < ScriptProjectError; end
11
10
  class DependencyError < ScriptProjectError; end
12
11
  class DependencyInstallError < ScriptProjectError; end
@@ -32,6 +31,7 @@ module Script
32
31
  class ShopAuthenticationError < ScriptProjectError; end
33
32
  class ShopScriptConflictError < ScriptProjectError; end
34
33
  class ShopScriptUndefinedError < ScriptProjectError; end
34
+ class TaskRunnerNotFoundError < ScriptProjectError; end
35
35
  end
36
36
  end
37
37
  end
@@ -4,6 +4,9 @@ module Script
4
4
  module Layers
5
5
  module Infrastructure
6
6
  class PushPackageRepository
7
+ include SmartProperties
8
+ property! :ctx, accepts: ShopifyCli::Context
9
+
7
10
  def create_push_package(script, script_content, compiled_type)
8
11
  build_file_path = file_path(script.name, compiled_type)
9
12
  write_to_path(build_file_path, script_content)
@@ -34,8 +37,8 @@ module Script
34
37
  private
35
38
 
36
39
  def write_to_path(path, content)
37
- FileUtils.mkdir_p(File.dirname(path))
38
- File.write(path, content)
40
+ ctx.mkdir_p(File.dirname(path))
41
+ ctx.write(path, content)
39
42
  end
40
43
 
41
44
  def file_path(script_name, compiled_type)
@@ -4,10 +4,13 @@ module Script
4
4
  module Layers
5
5
  module Infrastructure
6
6
  class ScriptRepository
7
+ include SmartProperties
8
+ property! :ctx, accepts: ShopifyCli::Context
9
+
7
10
  BOOTSTRAP_SRC = "npx --no-install shopify-scripts-bootstrap src %{src_base}"
8
11
 
9
12
  def create_script(language, extension_point, script_name)
10
- FileUtils.mkdir_p(src_base)
13
+ ctx.mkdir_p(src_base)
11
14
  out, status = CLI::Kit::System.capture2e(format(BOOTSTRAP_SRC, src_base: src_base))
12
15
  raise Domain::Errors::ServiceFailureError, out unless status.success?
13
16
 
@@ -33,13 +36,13 @@ module Script
33
36
  def with_temp_build_context
34
37
  prev_dir = Dir.pwd
35
38
  temp_dir = "#{project_base}/temp"
36
- FileUtils.mkdir_p(temp_dir)
37
- Dir.chdir(temp_dir)
38
- FileUtils.cp_r("#{src_base}/.", ".")
39
+ ctx.mkdir_p(temp_dir)
40
+ ctx.chdir(temp_dir)
41
+ ctx.cp_r("#{src_base}/.", ".")
39
42
  yield
40
43
  ensure
41
- Dir.chdir(prev_dir)
42
- FileUtils.rm_rf(temp_dir)
44
+ ctx.chdir(prev_dir)
45
+ ctx.rm_rf(temp_dir)
43
46
  end
44
47
 
45
48
  def relative_path_to_src
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Script
4
+ module Layers
5
+ module Infrastructure
6
+ class TaskRunner
7
+ TASK_RUNNERS = {
8
+ "ts" => Infrastructure::AssemblyScriptTaskRunner,
9
+ }
10
+
11
+ def self.for(ctx, language, script_name, script_source_file)
12
+ raise Errors::TaskRunnerNotFoundError unless TASK_RUNNERS[language]
13
+ TASK_RUNNERS[language].new(ctx, script_name, script_source_file)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -6,6 +6,9 @@ module Script
6
6
  module Layers
7
7
  module Infrastructure
8
8
  class TestSuiteRepository
9
+ include SmartProperties
10
+ property! :ctx, accepts: ShopifyCli::Context
11
+
9
12
  ASPECT_DTS_FILENAME = "as-pect.d.ts"
10
13
  ASPECT_DTS_FILE_CONTENTS = "/// <reference types=\"@as-pect/assembly/types/as-pect\" />"
11
14
  BOOTSTRAP_TEST = "npx --no-install shopify-scripts-bootstrap test %{test_base}"
@@ -14,8 +17,8 @@ module Script
14
17
  # Remove this once we have a test suite for js
15
18
  return unless script.language == "ts"
16
19
 
17
- FileUtils.mkdir_p(test_base)
18
- FileUtils.copy(aspect_config_template(script.language), "#{test_base}/as-pect.config.js")
20
+ ctx.mkdir_p(test_base)
21
+ ctx.cp(aspect_config_template(script.language), "#{test_base}/as-pect.config.js")
19
22
  out, status = CLI::Kit::System.capture2e(format(BOOTSTRAP_TEST, test_base: test_base))
20
23
  raise Domain::Errors::ServiceFailureError, out unless status.success?
21
24
 
@@ -46,7 +49,7 @@ module Script
46
49
  end
47
50
 
48
51
  def relative_path_to_source_dir
49
- src_path_from_root = ScriptRepository.new.relative_path_to_src
52
+ src_path_from_root = ScriptRepository.new(ctx: ctx).relative_path_to_src
50
53
  Pathname.new(src_path_from_root).relative_path_from(test_dir)
51
54
  end
52
55
 
@@ -3,14 +3,28 @@
3
3
  module Script
4
4
  class ScriptProject < ShopifyCli::Project
5
5
  SUPPORTED_LANGUAGES = %w(ts)
6
+ SOURCE_DIR = "src"
6
7
 
7
8
  attr_reader :extension_point_type, :script_name, :language
8
9
 
9
- def initialize(dir)
10
- super(dir)
10
+ def initialize(*args)
11
+ super
11
12
  @extension_point_type = lookup_config('extension_point_type')
12
13
  @script_name = lookup_config('script_name')
13
14
  @language = 'ts'
15
+ ShopifyCli::Core::Monorail.metadata = {
16
+ "script_name" => @script_name,
17
+ "extension_point_type" => @extension_point_type,
18
+ "language" => @language,
19
+ }
20
+ end
21
+
22
+ def source_file
23
+ "#{SOURCE_DIR}/#{file_name}"
24
+ end
25
+
26
+ def file_name
27
+ "script.#{language}"
14
28
  end
15
29
 
16
30
  private
@@ -21,16 +35,15 @@ module Script
21
35
  end
22
36
 
23
37
  class << self
24
- def create(dir)
25
- raise Errors::ScriptProjectAlreadyExistsError, dir if Dir.exist?(dir)
26
-
27
- FileUtils.mkdir_p(dir)
28
- Dir.chdir(dir)
38
+ def create(ctx, dir)
39
+ raise Errors::ScriptProjectAlreadyExistsError, dir if ctx.exist?(dir)
40
+ ctx.mkdir_p(dir)
41
+ ctx.chdir(dir)
29
42
  end
30
43
 
31
44
  def cleanup(ctx:, script_name:, root_dir:)
32
- Dir.chdir(root_dir)
33
- ctx.rm_r("#{root_dir}/#{script_name}") if Dir.exist?("#{root_dir}/#{script_name}")
45
+ ctx.chdir(root_dir)
46
+ ctx.rm_r("#{root_dir}/#{script_name}") if ctx.exist?("#{root_dir}/#{script_name}")
34
47
  end
35
48
  end
36
49
  end
@@ -32,6 +32,8 @@ module ShopifyCli
32
32
  )
33
33
  ctx.debug(resp)
34
34
  resp
35
+ rescue API::APIRequestServerError, API::APIRequestUnexpectedError
36
+ ctx.puts(ctx.message('core.api.error.internal_server_error'))
35
37
  end
36
38
 
37
39
  protected
@@ -131,6 +131,47 @@ module ShopifyCli
131
131
  File.write(ctx_path(fname), content)
132
132
  end
133
133
 
134
+ # will change directories and update the root, the filepath is relative to the command root unless absolute
135
+ #
136
+ # #### Parameters
137
+ # * `path` - the file path to a directory, relative to the context root to remove from the FS
138
+ #
139
+ def chdir(path)
140
+ Dir.chdir(ctx_path(path))
141
+ self.root = ctx_path(path)
142
+ end
143
+
144
+ # checks if a directory exists, the filepath is relative to the command root unless absolute
145
+ #
146
+ # #### Parameters
147
+ # * `path` - the file path to a directory, relative to the context root to remove from the FS
148
+ #
149
+ def exist?(path)
150
+ Dir.exist?(ctx_path(path))
151
+ end
152
+
153
+ # will recursively copy a directory from the FS, the filepath is relative to the command
154
+ # root unless absolute
155
+ #
156
+ # #### Parameters
157
+ # * `from` - the path of the original file
158
+ # * `to` - the destination path
159
+ #
160
+ def cp_r(from, to)
161
+ FileUtils.cp_r(ctx_path(from), ctx_path(to))
162
+ end
163
+
164
+ # will copy a directory from the FS, the filepath is relative to the command
165
+ # root unless absolute
166
+ #
167
+ # #### Parameters
168
+ # * `from` - the path of the original file
169
+ # * `to` - the destination path
170
+ #
171
+ def cp(from, to)
172
+ FileUtils.cp(ctx_path(from), ctx_path(to))
173
+ end
174
+
134
175
  # will rename a file from one place to another, relative to the command root
135
176
  # unless the path is absolute.
136
177
  #
@@ -162,6 +203,16 @@ module ShopifyCli
162
203
  FileUtils.rm_r(ctx_path(fname))
163
204
  end
164
205
 
206
+ # will force remove a directory from the FS, the filepath is relative to the command
207
+ # root unless absolute
208
+ #
209
+ # #### Parameters
210
+ # * `fname` - the file path to a directory, relative to the context root to remove from the FS
211
+ #
212
+ def rm_rf(fname)
213
+ FileUtils.rm_rf(ctx_path(fname))
214
+ end
215
+
165
216
  # will create a directory, recursively if it does not exist. So if you create
166
217
  # a directory `foo/bar/dun`, this will also create the directories `foo` and
167
218
  # `foo/bar` if they do not exist. The path will be made relative to the command
@@ -46,10 +46,10 @@ module ShopifyCli
46
46
  if Dir.exist?(dest)
47
47
  ctx.abort(ctx.message('core.git.error.directory_exists'))
48
48
  else
49
- CLI::UI::Frame.open(ctx.message('core.git.cloning', dest)) do
49
+ success_message = ctx.message('core.git.cloned', dest)
50
+ CLI::UI::Frame.open(ctx.message('core.git.cloning', repository, dest), success_text: success_message) do
50
51
  clone_progress('clone', '--single-branch', repository, dest, ctx: ctx)
51
52
  end
52
- ctx.done(ctx.message('core.git.cloned', dest))
53
53
  end
54
54
  end
55
55
 
@@ -121,19 +121,23 @@ module ShopifyCli
121
121
  def clone_progress(*git_command, ctx:)
122
122
  CLI::UI::Progress.progress do |bar|
123
123
  msg = []
124
- success = ctx.system('git', *git_command, '--progress') do |_out, err|
125
- if err.strip.start_with?('Receiving objects:')
126
- percent = (err.match(/Receiving objects:\s+(\d+)/)[1].to_f / 100).round(2)
124
+ require 'open3'
125
+
126
+ success = Open3.popen3('git', *git_command, '--progress') do |_stdin, _stdout, stderr, thread|
127
+ while (line = stderr.gets)
128
+ next unless line.strip.start_with?('Receiving objects:')
129
+ percent = (line.match(/Receiving objects:\s+(\d+)/)[1].to_f / 100).round(2)
127
130
  bar.tick(set_percent: percent)
128
131
  next
129
132
  end
130
- msg << err
133
+
134
+ msg << stderr
135
+ thread.value
131
136
  end.success?
132
- unless success
133
- ctx.abort(msg.join("\n"))
134
- end
137
+
138
+ ctx.abort(msg.join("\n")) unless success
135
139
  bar.tick(set_percent: 1.0)
136
- true
140
+ success
137
141
  end
138
142
  end
139
143
  end
@@ -60,8 +60,8 @@ module ShopifyCli
60
60
  no_commits_made: "No git commits have been made. Please make at least one commit.",
61
61
  },
62
62
 
63
- cloning: "Cloning into %s...",
64
- cloned: "Cloned into %s",
63
+ cloning: "Cloning %s into %s...",
64
+ cloned: "{{v}} Cloned into %s",
65
65
  },
66
66
 
67
67
  help: {
@@ -154,6 +154,12 @@ module ShopifyCli
154
154
  },
155
155
  },
156
156
 
157
+ api: {
158
+ error: {
159
+ internal_server_error: '{{red:{{x}} An unexpected error occurred on Shopify.}}',
160
+ },
161
+ },
162
+
157
163
  populate: {
158
164
  options: {
159
165
  header: "{{bold:{{cyan:%s}} options:}}",
@@ -1,3 +1,3 @@
1
1
  module ShopifyCli
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
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: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-24 00:00:00.000000000 Z
11
+ date: 2020-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -229,15 +229,15 @@ files:
229
229
  - lib/project_types/script/layers/domain/push_package.rb
230
230
  - lib/project_types/script/layers/domain/script.rb
231
231
  - lib/project_types/script/layers/infrastructure/assemblyscript_dependency_manager.rb
232
+ - lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb
232
233
  - lib/project_types/script/layers/infrastructure/assemblyscript_tsconfig.rb
233
- - lib/project_types/script/layers/infrastructure/assemblyscript_wasm_builder.rb
234
234
  - lib/project_types/script/layers/infrastructure/dependency_manager.rb
235
235
  - lib/project_types/script/layers/infrastructure/errors.rb
236
236
  - lib/project_types/script/layers/infrastructure/extension_point_repository.rb
237
237
  - lib/project_types/script/layers/infrastructure/push_package_repository.rb
238
- - lib/project_types/script/layers/infrastructure/script_builder.rb
239
238
  - lib/project_types/script/layers/infrastructure/script_repository.rb
240
239
  - lib/project_types/script/layers/infrastructure/script_service.rb
240
+ - lib/project_types/script/layers/infrastructure/task_runner.rb
241
241
  - lib/project_types/script/layers/infrastructure/test_suite_repository.rb
242
242
  - lib/project_types/script/messages/messages.rb
243
243
  - lib/project_types/script/script_project.rb
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Script
4
- module Layers
5
- module Infrastructure
6
- class AssemblyScriptWasmBuilder
7
- BYTECODE_FILE = "%{name}.wasm"
8
- SCRIPT_SDK_BUILD = "npx --no-install shopify-scripts-build --src=../%{source} --binary=#{BYTECODE_FILE} "\
9
- "-- --lib=../node_modules --validate --optimize"
10
-
11
- attr_reader :script
12
-
13
- def initialize(script)
14
- @script = script
15
- end
16
-
17
- def build
18
- compile
19
- bytecode
20
- end
21
-
22
- def compiled_type
23
- "wasm"
24
- end
25
-
26
- private
27
-
28
- def compile
29
- out, status = CLI::Kit::System.capture2e(format(SCRIPT_SDK_BUILD, source: script.id, name: script.name))
30
- raise Domain::Errors::ServiceFailureError, out unless status.success?
31
- end
32
-
33
- def bytecode
34
- File.read(format(BYTECODE_FILE, name: script.name))
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Script
4
- module Layers
5
- module Infrastructure
6
- class NoopBuilder
7
- def initialize(script)
8
- @script = script
9
- end
10
-
11
- def build
12
- File.read(@script.filename)
13
- end
14
-
15
- def compiled_type
16
- @script.language
17
- end
18
- end
19
-
20
- class ScriptBuilder
21
- COMPILERS = {
22
- "ts" => Infrastructure::AssemblyScriptWasmBuilder,
23
- "js" => Infrastructure::NoopBuilder,
24
- "json" => Infrastructure::NoopBuilder,
25
- }
26
-
27
- def self.for(script)
28
- raise Errors::BuilderNotFoundError unless COMPILERS[script.language]
29
- COMPILERS[script.language].new(script)
30
- end
31
- end
32
- end
33
- end
34
- end