Sha256: e379edb941d47b5bea349d05e390a45deea7eda750d17cdab348a0d0ac988c8f

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Script
  class ScriptProject < ShopifyCli::Project
    SUPPORTED_LANGUAGES = %w(ts)
    SOURCE_DIR = "src"

    attr_reader :extension_point_type, :script_name, :language

    def initialize(*args)
      super
      @extension_point_type = lookup_config('extension_point_type')
      @script_name = lookup_config('script_name')
      @language = 'ts'
      ShopifyCli::Core::Monorail.metadata = {
        "script_name" => @script_name,
        "extension_point_type" => @extension_point_type,
        "language" => @language,
      }
    end

    def source_file
      "#{SOURCE_DIR}/#{file_name}"
    end

    def file_name
      "script.#{language}"
    end

    private

    def lookup_config(key)
      raise Errors::InvalidContextError, key unless config.key?(key)
      config[key]
    end

    class << self
      def create(ctx, dir)
        raise Errors::ScriptProjectAlreadyExistsError, dir if ctx.exist?(dir)
        ctx.mkdir_p(dir)
        ctx.chdir(dir)
      end

      def cleanup(ctx:, script_name:, root_dir:)
        ctx.chdir(root_dir)
        ctx.rm_r("#{root_dir}/#{script_name}") if ctx.exist?("#{root_dir}/#{script_name}")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shopify-cli-1.0.1 lib/project_types/script/script_project.rb
shopify-cli-1.0.0 lib/project_types/script/script_project.rb
shopify-cli-0.9.3 lib/project_types/script/script_project.rb
shopify-cli-0.9.2 lib/project_types/script/script_project.rb