Sha256: 6e5cc3966fe63da6813fd40db0f4f02d4ef0768bddbbf66d9f18e493e5661adf

Contents?: true

Size: 1.55 KB

Versions: 20

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module Extension
  module Features
    class ArgoSetup
      include SmartProperties

      GIT_DIRECTORY = '.git'
      SCRIPTS_DIRECTORY = 'scripts'

      property! :git_template, accepts: String
      property! :dependency_checks, default: []

      def call(directory_name, identifier, context)
        steps = [
          ArgoSetupSteps.check_dependencies(dependency_checks),
          ArgoSetupSteps.clone_template(git_template),
          ArgoSetupSteps.install_dependencies,
          ArgoSetupSteps.initialize_project,
        ]

        install_result = run_install_steps(context, steps, identifier, directory_name)

        cleanup(context, install_result, directory_name)
        install_result
      end

      def run_install_steps(context, steps, identifier, directory_name)
        system = ShopifyCli::JsSystem.new(ctx: context)

        steps.inject(true) do |success, setup_step|
          success && setup_step.call(context, identifier, directory_name, system)
        end
      end

      def cleanup(context, install_result, directory_name)
        install_result ? cleanup_template(context) : cleanup_on_failure(context, directory_name)
      end

      def cleanup_template(context)
        context.rm_r(GIT_DIRECTORY)
        context.rm_r(SCRIPTS_DIRECTORY)
      rescue Errno::ENOENT => e
        context.debug(e)
      end

      def cleanup_on_failure(context, directory_name)
        FileUtils.rm_r(directory_name) if Dir.exist?(directory_name)
      rescue Errno::ENOENT => e
        context.debug(e)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
shopify-cli-1.6.0 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.5.0 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.4.1 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.4.0 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.3.1 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.3.0 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.2.0 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.1.2 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.1.1 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.1.0 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.0.5 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.0.4 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.0.3 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.0.2 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.0.1 lib/project_types/extension/features/argo_setup.rb
shopify-cli-1.0.0 lib/project_types/extension/features/argo_setup.rb
shopify-cli-0.9.3 lib/project_types/extension/features/argo_setup.rb
shopify-cli-0.9.2 lib/project_types/extension/features/argo_setup.rb
shopify-cli-0.9.1 lib/project_types/extension/features/argo_setup.rb
shopify-cli-0.9.0 lib/project_types/extension/features/argo_setup.rb