Class: Depec::Target::Node
- Inherits:
-
Base
- Object
- Base
- Depec::Target::Node
show all
- Defined in:
- lib/depec/target/node.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#node_version_file ⇒ String
7
8
9
|
# File 'lib/depec/target/node.rb', line 7
def node_version_file
File.join(@dir, '.node-version')
end
|
#npm_version(npm) ⇒ String
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/depec/target/node.rb', line 57
def npm_version(npm)
return unless File.exists?(yarn_lock)
version_line = false
File.open(yarn_lock) do |f|
f.each_line do |line|
return line.match(/version \"(?<version>.*)\"/)[:version] if version_line
version_line = true if line.match?(/^#{npm}@/)
end
end
return nil
end
|
#package_json ⇒ String
14
15
16
|
# File 'lib/depec/target/node.rb', line 14
def package_json
File.join(@dir, 'package.json')
end
|
#used? ⇒ Boolean
28
29
30
|
# File 'lib/depec/target/node.rb', line 28
def used?
File.exists?(package_json)
end
|
#version ⇒ String
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/depec/target/node.rb', line 35
def version
if File.exists?(node_version_file)
File.open(node_version_file) { |f| return f.gets.strip }
elsif File.exists?(package_json)
engine_section = false
File.open(package_json) do |f|
f.each_line do |line|
engine_section = true if line.include?('"engines"')
if engine_section && line.include?('"node"')
return line.match(/"node": "(?<version>.*)"/)[:version]
end
end
end
return nil
end
end
|
#yarn_lock ⇒ String
21
22
23
|
# File 'lib/depec/target/node.rb', line 21
def yarn_lock
File.join(@dir, 'yarn.lock')
end
|