Class: NeetoCompliance::NodeVersionVerifier
- Inherits:
-
Base
- Object
- Base
- NeetoCompliance::NodeVersionVerifier
show all
- Defined in:
- lib/neeto_compliance/verifiers/node_version_verifier.rb
Instance Method Summary
collapse
Methods inherited from Base
#app_is_exception?, #app_name, #apps_exception_list, #audit, #auto_correct!, #error_message, #print_description, #process, #verifier_name
Instance Method Details
#autofix_command ⇒ Object
80
81
82
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 80
def autofix_command
"#{update_semaphore_config_file}\n#{update_package_file}"
end
|
#autofix_suggestion ⇒ Object
17
18
19
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 17
def autofix_suggestion
@errors.join("\n").yellow
end
|
#check_node_step_added_to_semahore_config? ⇒ Boolean
58
59
60
61
62
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 58
def check_node_step_added_to_semahore_config?
semaphore_config = YAML.load(File.open(".semaphore/semaphore.yml").read, aliases: true)
semaphore_command = "sem-version node #{commons_node_version}"
semaphore_config["global_job_config"]["prologue"]["commands"].include?(semaphore_command)
end
|
#commons_node_version ⇒ Object
9
10
11
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 9
def commons_node_version
@_commons_node_version ||= File.open(commons_node_version_copy).read.chomp
end
|
#commons_node_version_copy ⇒ Object
68
69
70
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 68
def commons_node_version_copy
NeetoCompliance::NeetoCommons.path.join "common_files/.node-version"
end
|
#local_node_version ⇒ Object
5
6
7
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 5
def local_node_version
@_local_node_version ||= File.open(".node-version").read.chomp
end
|
#local_package_json_engines ⇒ Object
13
14
15
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 13
def local_package_json_engines
JSON.parse(open("package.json").read)["engines"]
end
|
#update_package_file ⇒ Object
72
73
74
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 72
def update_package_file
"perl -p -i -e 's/\"node\": \"#{local_node_version}\"/\"node\": \"#{commons_node_version}\"/g' package.json"
end
|
#update_semaphore_config_file ⇒ Object
76
77
78
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 76
def update_semaphore_config_file
"perl -p -i -e 's/sem-version node #{local_node_version}/sem-version node #{commons_node_version}/g' .semaphore/semaphore.yml"
end
|
#updated_node_version_file? ⇒ Boolean
50
51
52
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 50
def updated_node_version_file?
commons_node_version == File.open(".node-version").read.chomp
end
|
#updated_nvmrc_file? ⇒ Boolean
54
55
56
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 54
def updated_nvmrc_file?
commons_node_version == File.open(".nvmrc").read.chomp
end
|
#updated_package_file? ⇒ Boolean
64
65
66
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 64
def updated_package_file?
commons_node_version == local_package_json_engines["node"]
end
|
#valid? ⇒ Boolean
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/neeto_compliance/verifiers/node_version_verifier.rb', line 21
def valid?
@errors = []
unless updated_nvmrc_file?
@errors << "Update node version in .nvmrc to #{commons_node_version}"
end
unless updated_node_version_file?
@errors << "Update node version in .node-version to #{commons_node_version}"
end
unless check_node_step_added_to_semahore_config?
@errors << "Add node version to your semaphore.yml as shown below:
global_job_config:
prologue:
commands:
- checkout
- sem-version ruby 3.0.1
- sem-version node #{commons_node_version}
- sem-service start postgres 12.4
\n "
end
unless updated_package_file?
@errors << "Update node version in package.json to #{commons_node_version}"
end
@errors.length == 0
end
|