shopify-cli 0.9.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +3 -0
  3. data/CHANGELOG.md +26 -0
  4. data/{LICENSE.md → LICENSE} +0 -0
  5. data/RELEASING.md +51 -0
  6. data/Rakefile +1 -6
  7. data/docs/_config.yml +3 -0
  8. data/docs/_data/nav.yml +9 -0
  9. data/docs/getting-started/index.md +5 -40
  10. data/docs/getting-started/install/index.md +39 -0
  11. data/docs/getting-started/migrate/index.md +63 -0
  12. data/docs/getting-started/uninstall/index.md +37 -0
  13. data/docs/getting-started/upgrade/index.md +37 -0
  14. data/docs/index.md +5 -6
  15. data/lib/project_types/extension/cli.rb +2 -1
  16. data/lib/project_types/extension/commands/tunnel.rb +1 -1
  17. data/lib/project_types/extension/forms/register.rb +2 -3
  18. data/lib/project_types/extension/graphql/get_app_by_api_key.graphql +9 -0
  19. data/lib/project_types/extension/tasks/converters/app_converter.rb +27 -0
  20. data/lib/project_types/extension/tasks/get_app.rb +22 -0
  21. data/lib/project_types/extension/tasks/get_apps.rb +1 -6
  22. data/lib/project_types/node/forms/create.rb +3 -54
  23. data/lib/project_types/node/messages/messages.rb +1 -12
  24. data/lib/project_types/rails/forms/create.rb +3 -52
  25. data/lib/project_types/rails/messages/messages.rb +0 -11
  26. data/lib/project_types/script/cli.rb +5 -5
  27. data/lib/project_types/script/commands/create.rb +5 -4
  28. data/lib/project_types/script/commands/push.rb +1 -0
  29. data/lib/project_types/script/errors.rb +1 -0
  30. data/lib/project_types/script/forms/create.rb +8 -4
  31. data/lib/project_types/script/layers/application/build_script.rb +7 -10
  32. data/lib/project_types/script/layers/application/create_script.rb +16 -14
  33. data/lib/project_types/script/layers/application/project_dependencies.rb +3 -9
  34. data/lib/project_types/script/layers/application/push_script.rb +13 -11
  35. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +106 -0
  36. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +64 -0
  37. data/lib/project_types/script/layers/infrastructure/errors.rb +2 -2
  38. data/lib/project_types/script/layers/infrastructure/project_creator.rb +23 -0
  39. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +5 -2
  40. data/lib/project_types/script/layers/infrastructure/script_repository.rb +7 -37
  41. data/lib/project_types/script/layers/infrastructure/task_runner.rb +18 -0
  42. data/lib/project_types/script/messages/messages.rb +5 -6
  43. data/lib/project_types/script/script_project.rb +22 -9
  44. data/lib/project_types/script/templates/ts/as-pect.d.ts +1 -0
  45. data/lib/project_types/script/ui/error_handler.rb +5 -0
  46. data/lib/shopify-cli/admin_api.rb +1 -2
  47. data/lib/shopify-cli/admin_api/populate_resource_command.rb +10 -1
  48. data/lib/shopify-cli/api.rb +2 -0
  49. data/lib/shopify-cli/context.rb +51 -0
  50. data/lib/shopify-cli/core/entry_point.rb +6 -0
  51. data/lib/shopify-cli/core/finalize.rb +13 -0
  52. data/lib/shopify-cli/git.rb +14 -10
  53. data/lib/shopify-cli/messages/messages.rb +22 -2
  54. data/lib/shopify-cli/packager.rb +17 -25
  55. data/lib/shopify-cli/tasks.rb +1 -0
  56. data/lib/shopify-cli/tasks/select_org_and_shop.rb +77 -0
  57. data/lib/shopify-cli/tunnel.rb +33 -1
  58. data/lib/shopify-cli/version.rb +1 -1
  59. data/shopify-cli.gemspec +3 -5
  60. data/vendor/deps/cli-ui/REVISION +1 -1
  61. data/vendor/deps/cli-ui/lib/cli/ui.rb +52 -11
  62. data/vendor/deps/cli-ui/lib/cli/ui/color.rb +11 -7
  63. data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +34 -21
  64. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +107 -149
  65. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +99 -0
  66. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +119 -0
  67. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +158 -0
  68. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +112 -0
  69. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +9 -15
  70. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +47 -0
  71. data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +9 -7
  72. data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +39 -14
  73. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +62 -44
  74. data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +7 -2
  75. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +23 -3
  76. data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +34 -10
  77. data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +12 -7
  78. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +26 -16
  79. data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +3 -3
  80. data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +75 -0
  81. data/vendor/deps/cli-ui/lib/cli/ui/widgets/base.rb +27 -0
  82. data/vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb +61 -0
  83. metadata +30 -13
  84. data/lib/project_types/extension/features/tunnel_url.rb +0 -20
  85. data/lib/project_types/script/layers/infrastructure/assemblyscript_dependency_manager.rb +0 -73
  86. data/lib/project_types/script/layers/infrastructure/assemblyscript_wasm_builder.rb +0 -39
  87. data/lib/project_types/script/layers/infrastructure/dependency_manager.rb +0 -36
  88. data/lib/project_types/script/layers/infrastructure/script_builder.rb +0 -34
  89. data/lib/project_types/script/layers/infrastructure/test_suite_repository.rb +0 -59
  90. data/vendor/deps/cli-ui/lib/cli/ui/box.rb +0 -15
@@ -2,20 +2,14 @@ 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
- def self.install(ctx:, language:, extension_point:, script_name:)
11
- dep_manager = Infrastructure::DependencyManager.for(ctx, language, extension_point, script_name)
5
+ def self.install(ctx:, task_runner:)
12
6
  CLI::UI::Frame.open(ctx.message('script.project_deps.checking_with_npm')) do
13
7
  begin
14
- if dep_manager.installed?
8
+ if task_runner.dependencies_installed?
15
9
  ctx.puts(ctx.message('script.project_deps.none_required'))
16
10
  else
17
11
  UI::StrictSpinner.spin(ctx.message('script.project_deps.installing')) do |spinner|
18
- dep_manager.install
12
+ task_runner.install_dependencies
19
13
  spinner.update_title(ctx.message('script.project_deps.installed'))
20
14
  end
21
15
  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
@@ -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.0.1",
90
+ "assemblyscript": "^0.12.0"
91
+ },
92
+ "scripts": {
93
+ "test": "asp --config test/as-pect.config.js --summary --verbose"
94
+ },
95
+ "engines": {
96
+ "node": ">=12.16"
97
+ }
98
+ }
99
+ HERE
100
+
101
+ ctx.write("package.json", package_json)
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -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,9 +6,7 @@ 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
- class DependencyError < ScriptProjectError; end
12
10
  class DependencyInstallError < ScriptProjectError; end
13
11
  class ForbiddenError < ScriptProjectError; end
14
12
  class GraphqlError < ScriptProjectError
@@ -18,6 +16,7 @@ module Script
18
16
  super("GraphQL failed with errors: #{errors}")
19
17
  end
20
18
  end
19
+ class ProjectCreatorNotFoundError < ScriptProjectError; end
21
20
  class ScriptRepushError < ScriptProjectError
22
21
  attr_reader :api_key
23
22
  def initialize(api_key)
@@ -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
@@ -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
@@ -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,22 +4,8 @@ module Script
4
4
  module Layers
5
5
  module Infrastructure
6
6
  class ScriptRepository
7
- BOOTSTRAP_SRC = "npx --no-install shopify-scripts-bootstrap src %{src_base}"
8
-
9
- def create_script(language, extension_point, script_name)
10
- FileUtils.mkdir_p(src_base)
11
- out, status = CLI::Kit::System.capture2e(format(BOOTSTRAP_SRC, src_base: src_base))
12
- raise Domain::Errors::ServiceFailureError, out unless status.success?
13
-
14
- write_tsconfig if language == "ts"
15
-
16
- Domain::Script.new(
17
- script_id(language),
18
- script_name,
19
- extension_point.type,
20
- language
21
- )
22
- end
7
+ include SmartProperties
8
+ property! :ctx, accepts: ShopifyCli::Context
23
9
 
24
10
  def get_script(language, extension_point_type, script_name)
25
11
  source_file_path = src_code_file(language)
@@ -33,13 +19,13 @@ module Script
33
19
  def with_temp_build_context
34
20
  prev_dir = Dir.pwd
35
21
  temp_dir = "#{project_base}/temp"
36
- FileUtils.mkdir_p(temp_dir)
37
- Dir.chdir(temp_dir)
38
- FileUtils.cp_r("#{src_base}/.", ".")
22
+ ctx.mkdir_p(temp_dir)
23
+ ctx.chdir(temp_dir)
24
+ ctx.cp_r("#{src_base}/.", ".")
39
25
  yield
40
26
  ensure
41
- Dir.chdir(prev_dir)
42
- FileUtils.rm_rf(temp_dir)
27
+ ctx.chdir(prev_dir)
28
+ ctx.rm_rf(temp_dir)
43
29
  end
44
30
 
45
31
  def relative_path_to_src
@@ -48,18 +34,6 @@ module Script
48
34
 
49
35
  private
50
36
 
51
- def write_sdk(extension_point_type, language, sdk_types)
52
- return unless language == "ts"
53
- File.write(sdk_types_file(extension_point_type, language), sdk_types)
54
- end
55
-
56
- def write_tsconfig
57
- AssemblyScriptTsConfig
58
- .new(dir_to_write_in: relative_path_to_src)
59
- .with_extends_assemblyscript_config(relative_path_to_node_modules: ".")
60
- .write
61
- end
62
-
63
37
  def project_base
64
38
  ScriptProject.current.directory
65
39
  end
@@ -79,10 +53,6 @@ module Script
79
53
  def file_name(language)
80
54
  "script.#{language}"
81
55
  end
82
-
83
- def sdk_types_file(extension_point_type, language)
84
- "#{src_base}/#{extension_point_type}.#{language}"
85
- end
86
56
  end
87
57
  end
88
58
  end
@@ -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
@@ -18,8 +18,12 @@ module Script
18
18
  invalid_context_cause: "Your .shopify-cli.yml file is not correct.",
19
19
  invalid_context_help: "See https://help.shopify.com",
20
20
 
21
+ invalid_script_name_cause: "Invalid script name.",
22
+ invalid_script_name_help: "Replace or remove unsupported characters. Valid characters "\
23
+ "are numbers, letters, hyphens, or underscores.",
24
+
21
25
  no_existing_apps_cause: "You don't have any apps.",
22
- no_existing_apps_help: "Please create an app with {{command:shopify create}} or"\
26
+ no_existing_apps_help: "Please create an app with {{command:shopify create}} or "\
23
27
  "visit https://partners.shopify.com/.",
24
28
 
25
29
  no_existing_orgs_cause: "You don't have any partner organizations.",
@@ -169,11 +173,6 @@ module Script
169
173
  create: {
170
174
  select_extension_point: "Which extension point do you want to use?",
171
175
  script_name: "Script Name",
172
-
173
- error: {
174
- invalid_name: "Invalid script name: replace or remove unsupported characters. Valid "\
175
- "characters are numbers, letters, spaces, hyphens, or underscores.",
176
- },
177
176
  },
178
177
  script_form: {
179
178
  ask_app_api_key_default: "Which app do you want this script to belong to?",
@@ -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