class Spud::TaskRunners::PackageJSON::Task
Attributes
name[R]
Public Class Methods
new(driver, name, command, scripts)
click to toggle source
# File lib/spud/task_runners/package.json/task.rb, line 47 def initialize(driver, name, command, scripts) @driver = driver @name = name @command = command @scripts = scripts end
tasks(driver)
click to toggle source
# File lib/spud/task_runners/package.json/task.rb, line 19 def self.tasks(driver) if File.exist?('package.lock') if `command -v npm`.empty? puts 'package.json detected, but no installation of `npm` exists. Skipping npm...' return [] else command = 'npm' end elsif File.exist?('yarn.lock') if `command -v yarn`.empty? puts 'package.json detected, but no installation of `yarn` exists. Skipping yarn...' return [] else command = 'yarn' end else return [] end source = File.read('package.json') contents = JSON.parse(source) scripts = contents['scripts'] return [] unless scripts scripts.keys.map { |name| new(driver, name, command, scripts) } end
Public Instance Methods
details()
click to toggle source
# File lib/spud/task_runners/package.json/task.rb, line 65 def details %({ "#{name}": "#{@scripts[name]}" }) end
invoke(ordered, named)
click to toggle source
# File lib/spud/task_runners/package.json/task.rb, line 55 def invoke(ordered, named) system("#{@command} run #{name}") end
source()
click to toggle source
# File lib/spud/task_runners/package.json/task.rb, line 60 def source 'package.json' end