Sha256: 680c2fdef0be7e0e489a3223ece30bf51c5f2bc580dfd214eac889c80c4367f6

Contents?: true

Size: 1.81 KB

Versions: 12

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

require "shopify_cli"

module Script
  module Layers
    module Application
      class CreateScript
        class << self
          def call(ctx:, language:, script_name:, extension_point_type:)
            extension_point = ExtensionPoints.get(type: extension_point_type)
            project = setup_project(ctx, script_name, extension_point)
            project_creator = Infrastructure::ProjectCreator
              .for(ctx, language, extension_point, script_name, project.directory)
            install_dependencies(ctx, language, script_name, project.source_file, project_creator)
            bootstrap(ctx, project.source_path, project_creator)
            project
          end

          private

          def setup_project(ctx, script_name, extension_point)
            ScriptProject.create(ctx, script_name)
            ScriptProject.write(
              ctx,
              project_type: :script,
              organization_id: nil, # TODO: can you provide this at creation
              extension_point_type: extension_point.type,
              script_name: script_name
            )
            ScriptProject.current
          end

          def install_dependencies(ctx, language, script_name, source_file, project_creator)
            task_runner = Infrastructure::TaskRunner.for(ctx, language, script_name, source_file)
            project_creator.setup_dependencies
            ProjectDependencies.install(ctx: ctx, task_runner: task_runner)
          end

          def bootstrap(ctx, source_path, project_creator)
            UI::StrictSpinner.spin(ctx.message('script.create.creating')) do |spinner|
              project_creator.bootstrap
              spinner.update_title(ctx.message('script.create.created', source_path))
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
shopify-cli-1.5.0 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.4.1 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.4.0 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.3.1 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.3.0 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.2.0 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.1.2 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.1.1 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.1.0 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.0.5 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.0.4 lib/project_types/script/layers/application/create_script.rb
shopify-cli-1.0.3 lib/project_types/script/layers/application/create_script.rb