Class: Spud::TaskRunners::PackageJSON::Task
- Extended by:
- T::Sig
- Defined in:
- lib/spud/task_runners/package.json/task.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #details ⇒ Object
- #filename ⇒ Object
-
#initialize(driver, name, command, scripts) ⇒ Task
constructor
A new instance of Task.
- #invoke(ordered, named) ⇒ Object
Methods inherited from Task
Constructor Details
#initialize(driver, name, command, scripts) ⇒ Task
Returns a new instance of Task.
46 47 48 49 50 51 |
# File 'lib/spud/task_runners/package.json/task.rb', line 46 def initialize(driver, name, command, scripts) @driver = driver @name = name @command = command @scripts = scripts end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/spud/task_runners/package.json/task.rb', line 15 def name @name end |
Class Method Details
.tasks(driver) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/spud/task_runners/package.json/task.rb', line 18 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') json = JSON.parse(source) scripts = json['scripts'] return [] unless scripts scripts.keys.map { |name| new(driver, name, command, scripts) } end |
Instance Method Details
#details ⇒ Object
64 65 66 |
# File 'lib/spud/task_runners/package.json/task.rb', line 64 def details %({ "#{name}": "#{@scripts[name]}" }) end |
#filename ⇒ Object
59 60 61 |
# File 'lib/spud/task_runners/package.json/task.rb', line 59 def filename 'package.json' end |
#invoke(ordered, named) ⇒ Object
54 55 56 |
# File 'lib/spud/task_runners/package.json/task.rb', line 54 def invoke(ordered, named) system("#{@command} run #{name}") end |