Class: Extension::Tasks::FindPackageFromJson

Inherits:
ShopifyCLI::Task show all
Includes:
SmartProperties
Defined in:
lib/project_types/extension/tasks/find_package_from_json.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(package_name, **config) ⇒ Object



11
12
13
# File 'lib/project_types/extension/tasks/find_package_from_json.rb', line 11

def self.call(package_name, **config)
  new(**config).call(package_name)
end

Instance Method Details

#call(package_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/project_types/extension/tasks/find_package_from_json.rb', line 15

def call(package_name)
  ShopifyCLI::Result.success(resolve_package_json(package_name))
    .then { |file| File.read(file) }
    .then { |file| JSON.parse(file) }
    .then { |file| file.dig("version") }
    .then { |version| return Models::NpmPackage.new(name: package_name, version: version) }
    .unwrap do |error|
      context.debug(error)
      context.abort(context.message("errors.module_not_found", package_name))
    end
end