blufin-lib 1.8.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blufin-lib.rb +1 -3
- data/lib/core/aws.rb +49 -6
- data/lib/core/config.rb +1 -1
- data/lib/core/files.rb +48 -13
- data/lib/core/git.rb +11 -1
- data/lib/core/projects.rb +45 -30
- data/lib/scan/scanner_error.rb +14 -5
- data/lib/scan/scanner_java.rb +92 -2
- data/lib/scan/scanner_js.rb +1 -7
- data/lib/scan/scanner_js_tests.rb +34 -0
- data/lib/scan/scanner_vue.rb +16 -2
- data/lib/version.rb +1 -1
- data/opt/schema/codegen.yml +47 -0
- metadata +5 -8
- data/lib/generate/generate_base.rb +0 -47
- data/lib/generate/generate_ui_routes.rb +0 -230
- data/lib/scan/scanner.rb +0 -41
- data/opt/schema/projects-quasarrc.yml +0 -8
- data/opt/schema/routes.yml +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c18b8e80ef480a5dad4b4ce1d23d8c357ef41144
|
4
|
+
data.tar.gz: 3ac8da0829f69021888397ad1c8879d3ae7f48e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3527a65e1fba07c5915007e4b2925e01bf183eecbbde9e8087e99bf8ac43bf731b1a50577d589828c21220942e9dd6f9c8b13aeab95af1a06b5777ff4eec357
|
7
|
+
data.tar.gz: 743bba3db7bcc1cd51c4cd43b14fe94e55394e60b7586b6959c2766804043800c5f76ced3cc5fb987198cf57dfb0565cb2c90f3e3a4a9a87750fe994a6e5f9f8
|
data/lib/blufin-lib.rb
CHANGED
@@ -7,18 +7,16 @@ module Blufin
|
|
7
7
|
autoload :Constants, 'core/constants'
|
8
8
|
autoload :DateTimeUtils, 'core/datetime_utils'
|
9
9
|
autoload :Files, 'core/files'
|
10
|
-
autoload :GenerateBase, 'generate/generate_base'
|
11
|
-
autoload :GenerateUiRoutes, 'generate/generate_ui_routes'
|
12
10
|
autoload :Git, 'core/git'
|
13
11
|
autoload :Image, 'core/image'
|
14
12
|
autoload :Network, 'core/network'
|
15
13
|
autoload :Numbers, 'core/numbers'
|
16
14
|
autoload :Projects, 'core/projects'
|
17
15
|
autoload :Routes, 'core/routes'
|
18
|
-
autoload :Scanner, 'scan/scanner'
|
19
16
|
autoload :ScannerError, 'scan/scanner_error'
|
20
17
|
autoload :ScannerJava, 'scan/scanner_java'
|
21
18
|
autoload :ScannerJs, 'scan/scanner_js'
|
19
|
+
autoload :ScannerJsTests, 'scan/scanner_js_tests'
|
22
20
|
autoload :ScannerVue, 'scan/scanner_vue'
|
23
21
|
autoload :Strings, 'core/strings'
|
24
22
|
autoload :Terminal, 'core/terminal'
|
data/lib/core/aws.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Blufin
|
2
2
|
|
3
|
-
|
3
|
+
class AWS
|
4
|
+
|
5
|
+
FILE_AWS_CONFIG = File.expand_path('~/.aws/config')
|
6
|
+
FILE_AWS_CREDENTIALS = File.expand_path('~/.aws/credentials')
|
4
7
|
|
5
8
|
S3_EXCLUDE = "--exclude '.DS_Store' --exclude '*/.DS_Store' --exclude '*.icloud' --exclude '*/*.icloud'"
|
6
9
|
|
@@ -62,14 +65,18 @@ module Blufin
|
|
62
65
|
else
|
63
66
|
return tmp_location if Blufin::Files::file_exists(tmp_location) && use_cache
|
64
67
|
end
|
68
|
+
# Get profile name.
|
69
|
+
profile_name = profile.nil? ? App::AWSProfile::get_profile_name : " --profile #{profile}"
|
65
70
|
begin
|
66
71
|
# Clear out all (possibly stale) files.
|
67
|
-
|
68
|
-
|
69
|
-
system("rm #{tmp_location}")
|
70
|
-
Blufin::Files::
|
72
|
+
puts
|
73
|
+
raise RuntimeError unless Blufin::Terminal::execute_proc("Wiping temp-data: #{Blufin::Terminal::format_directory(tmp_location)}", Proc.new {
|
74
|
+
system("rm -rf #{tmp_location}") if file.nil? && Blufin::Files::path_exists(tmp_location)
|
75
|
+
system("rm #{tmp_location}") if !file.nil? && Blufin::Files::file_exists(tmp_location)
|
76
|
+
Blufin::Files::create_directory(tmp_location) if file.nil?
|
77
|
+
true
|
71
78
|
}, verbose: true)
|
72
|
-
raise RuntimeError unless Blufin::Terminal::execute("aws s3 cp s3://#{bucket_name}#{bucket_path_s3} #{tmp_location} --recursive --region #{region}#{
|
79
|
+
raise RuntimeError unless Blufin::Terminal::execute("aws s3 cp s3://#{bucket_name}#{bucket_path_s3} #{tmp_location}#{file.nil? ? ' --recursive' : ''} --region #{region}#{profile_name}", verbose: true)[0]
|
73
80
|
tmp_location
|
74
81
|
rescue
|
75
82
|
system("rm -rf #{tmp_location}") if file.nil?
|
@@ -79,6 +86,42 @@ module Blufin
|
|
79
86
|
|
80
87
|
end
|
81
88
|
|
89
|
+
# Checks if AWS credentials exist. Does nothing if on EC2.
|
90
|
+
# @return Array (of errors).
|
91
|
+
def self.get_aws_credentials(profile)
|
92
|
+
credentials = nil
|
93
|
+
errors = []
|
94
|
+
if Blufin::Files::file_exists(FILE_AWS_CREDENTIALS)
|
95
|
+
credentials = Blufin::AWSCredentials.new
|
96
|
+
config = Blufin::Files::file_exists(FILE_AWS_CONFIG) ? ParseConfig.new(FILE_AWS_CONFIG) : nil
|
97
|
+
credentials_parsed = ParseConfig.new(FILE_AWS_CREDENTIALS)
|
98
|
+
unless credentials_parsed.params[profile].nil?
|
99
|
+
# Currently not used/required (but here just in case).
|
100
|
+
unless config.nil? || config.params[profile].nil?
|
101
|
+
credentials.region = config.params[profile]['region'] unless config.params[profile]['region'].nil?
|
102
|
+
credentials.output = config.params[profile]['output'] unless config.params[profile]['output'].nil?
|
103
|
+
|
104
|
+
end
|
105
|
+
credentials.aws_key = credentials_parsed.params[profile]['aws_access_key_id'] unless credentials_parsed.params[profile]['aws_access_key_id'].nil?
|
106
|
+
credentials.aws_secret = credentials_parsed.params[profile]['aws_secret_access_key'] unless credentials_parsed.params[profile]['aws_secret_access_key'].nil?
|
107
|
+
end
|
108
|
+
errors << "aws-cli error. Cannot find #{profile}: #{Blufin::Terminal::format_invalid('aws_access_key_id')} in: #{Blufin::Terminal::format_directory(FILE_AWS_CREDENTIALS)}" if credentials.aws_key.nil?
|
109
|
+
errors << "aws-cli error. Cannot find #{profile}: #{Blufin::Terminal::format_invalid('aws_secret_access_key')} in: #{Blufin::Terminal::format_directory(FILE_AWS_CREDENTIALS)}" if credentials.aws_secret.nil?
|
110
|
+
else
|
111
|
+
# Returns 'yes' if running on EC2 instance, 'no' if not.
|
112
|
+
unless `#{App::Opt::get_base_path}/#{App::Opt::OPT_PATH}/shell/ec2-check`.to_s.gsub("\n", '') =~ /yes/i
|
113
|
+
errors << "aws-cli error. Cannot find file: #{Blufin::Terminal::format_invalid(FILE_AWS_CREDENTIALS)}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
return credentials, errors
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
class AWSCredentials
|
122
|
+
|
123
|
+
attr_accessor :region, :output, :aws_key, :aws_secret
|
124
|
+
|
82
125
|
end
|
83
126
|
|
84
127
|
end
|
data/lib/core/config.rb
CHANGED
@@ -56,7 +56,7 @@ module Blufin
|
|
56
56
|
begin
|
57
57
|
schema_file_parsed = YAML.load_file(schema_file)
|
58
58
|
rescue => e
|
59
|
-
Blufin::Terminal::error("Failed to schema
|
59
|
+
Blufin::Terminal::error("Failed to parse schema file: #{Blufin::Terminal::format_directory(schema_file)}", e.message)
|
60
60
|
end
|
61
61
|
validator = Kwalify::Validator.new(schema_file_parsed)
|
62
62
|
begin
|
data/lib/core/files.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'parseconfig'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'digest/sha1'
|
3
5
|
|
4
6
|
module Blufin
|
5
7
|
|
@@ -11,11 +13,12 @@ module Blufin
|
|
11
13
|
# Same as write_file() but for Java files. If arrange_imports = TRUE (default) it
|
12
14
|
# will sort the import statements in the same order as IntelliJ would.
|
13
15
|
# @return String
|
14
|
-
def self.write_file_java(path_and_file, array_of_lines, auto_generated = JAVA_AUTO_GENERATED_EVERY_RUN)
|
16
|
+
def self.write_file_java(path_and_file, array_of_lines, auto_generated = JAVA_AUTO_GENERATED_EVERY_RUN, test_annotations = true)
|
15
17
|
raise RuntimeError, "Expected String, instead got: #{path_and_file.class}" unless path_and_file.is_a?(String)
|
16
|
-
auto_generated_valid = [JAVA_AUTO_GENERATED_EVERY_RUN, JAVA_AUTO_GENERATED_ONCE]
|
18
|
+
auto_generated_valid = [nil, JAVA_AUTO_GENERATED_EVERY_RUN, JAVA_AUTO_GENERATED_ONCE]
|
17
19
|
raise RuntimeError, "Expected .java file, instead got: #{path_and_file}" unless path_and_file =~ /\.java\z/
|
18
|
-
raise RuntimeError, "auto_generated must be one of the following: #{auto_generated_valid.join(', ')}" unless auto_generated_valid.include?(auto_generated)
|
20
|
+
raise RuntimeError, "auto_generated must be one of the following: #{auto_generated_valid.join(', ')}" unless auto_generated.nil? || auto_generated_valid.include?(auto_generated)
|
21
|
+
raise RuntimeError, "Expected Boolean, instead got: #{test_annotations.class}" unless !!test_annotations == test_annotations
|
19
22
|
package = nil
|
20
23
|
import_statements_one = []
|
21
24
|
import_statements_two = []
|
@@ -31,9 +34,9 @@ module Blufin
|
|
31
34
|
previous_was_blank = true if line.strip == ''
|
32
35
|
next
|
33
36
|
end
|
34
|
-
if package.nil? && line.strip =~ /^package\s+[A-Za-z0-9\._-]
|
37
|
+
if package.nil? && line.strip =~ /^package\s+[A-Za-z0-9\._-]+;(\s*#.*)?$/
|
35
38
|
# Get package.
|
36
|
-
raise RuntimeError, "Package has a hyphen in it \xe2\x86\x92 \x1B[38;5;184m#{line.strip}\x1B[0m. When this file's contents were generated you forgot a .gsub() statement to replace it." if line.strip =~ /-/
|
39
|
+
raise RuntimeError, "Package has a hyphen in it \xe2\x86\x92 \x1B[38;5;184m#{line.strip}\x1B[0m. When this file's contents were generated you forgot a .gsub() statement to replace it." if line.gsub(/(\s*#.*)?$/, '').strip =~ /-/
|
37
40
|
package = line.strip
|
38
41
|
next
|
39
42
|
elsif line.strip =~ /^import\s+[A-Za-z0-9\.*_-]+;$/ || line.strip =~ /^import\s+static\s+[A-Za-z0-9\.*_-]+;$/
|
@@ -43,22 +46,22 @@ module Blufin
|
|
43
46
|
next
|
44
47
|
elsif !contents.any? && line.strip =~ /^@(.)+$/
|
45
48
|
annotations_one << line.strip
|
46
|
-
elsif !contents.any? && line.strip =~ /^(public|private|protected)\s+.*(class|enum)\s+.*\{
|
49
|
+
elsif !contents.any? && line.strip =~ /^(public|private|protected)\s+.*(class|enum)\s+.*\{(\s*\})?$/
|
47
50
|
contents << line.strip
|
48
51
|
next
|
49
52
|
end
|
50
53
|
end
|
51
54
|
raise RuntimeError, "Couldn't parse content for: #{path_and_file}" unless contents.any?
|
52
55
|
# Add @AutoGenerated + @TestNotRequired stuff.
|
53
|
-
import_statements_one << 'import org.blufin.base.annotations.AutoGenerated;'
|
54
|
-
import_statements_one << 'import org.blufin.base.annotations.TestNotRequired;'
|
55
|
-
import_statements_one << 'import org.blufin.base.annotations.helper.ON;'
|
56
|
+
import_statements_one << 'import org.blufin.base.annotations.AutoGenerated;' unless auto_generated.nil?
|
57
|
+
import_statements_one << 'import org.blufin.base.annotations.TestNotRequired;' if test_annotations
|
58
|
+
import_statements_one << 'import org.blufin.base.annotations.helper.ON;' unless auto_generated.nil?
|
56
59
|
annotations_one.each do |annotation|
|
57
60
|
next if %w(@TestNotRequired @AutoGenerated @AutoGenerated(ON.EVERY_RUN) @AutoGenerated(ON.CREATION_ONLY)).include?(annotation)
|
58
61
|
annotations_two << annotation
|
59
62
|
end
|
60
|
-
annotations_two << '@TestNotRequired'
|
61
|
-
annotations_two << ((auto_generated == JAVA_AUTO_GENERATED_EVERY_RUN) ? '@AutoGenerated(ON.EVERY_RUN)' : '@AutoGenerated(ON.CREATION_ONLY)')
|
63
|
+
annotations_two << '@TestNotRequired' if test_annotations
|
64
|
+
annotations_two << ((auto_generated == JAVA_AUTO_GENERATED_EVERY_RUN) ? '@AutoGenerated(ON.EVERY_RUN)' : '@AutoGenerated(ON.CREATION_ONLY)') unless auto_generated.nil?
|
62
65
|
annotations_two.uniq!
|
63
66
|
import_statements_one.uniq!
|
64
67
|
import_statements_one.sort!
|
@@ -157,9 +160,31 @@ module Blufin
|
|
157
160
|
return self.write_file(path_and_file, final_contents)
|
158
161
|
end
|
159
162
|
|
163
|
+
# Writes a file (but only if content has changed).
|
164
|
+
# Returns true if file was overwritten, false if not.
|
165
|
+
# @return boolean
|
166
|
+
def self.write_file_if_changed(path_and_file, array_of_lines, write_empty_trailing_line: false)
|
167
|
+
raise RuntimeError, "Expected String, instead got: #{path_and_file.class}" unless path_and_file.is_a?(String)
|
168
|
+
raise RuntimeError, "Expected Array, instead got: #{array_of_lines.class}" unless array_of_lines.is_a?(Array)
|
169
|
+
# If file does not exist, writes it regardless and returns TRUE.
|
170
|
+
unless Blufin::Files::file_exists(path_and_file)
|
171
|
+
Blufin::Files::write_file(path_and_file, array_of_lines, write_empty_trailing_line: write_empty_trailing_line)
|
172
|
+
return true
|
173
|
+
end
|
174
|
+
tmp_file = "/tmp/#{Blufin::Strings::random_string(2)}.txt"
|
175
|
+
Blufin::Files::write_file(tmp_file, array_of_lines, write_empty_trailing_line: write_empty_trailing_line)
|
176
|
+
target_file_hash = Digest::SHA1.hexdigest Blufin::Arrays::convert_line_array_to_string(Blufin::Files::read_file(path_and_file)).gsub(/\s/, '')
|
177
|
+
tmp_file_hash = Digest::SHA1.hexdigest Blufin::Arrays::convert_line_array_to_string(Blufin::Files::read_file(tmp_file)).gsub(/\s/, '')
|
178
|
+
if target_file_hash != tmp_file_hash
|
179
|
+
FileUtils.mv(tmp_file, path_and_file)
|
180
|
+
return true
|
181
|
+
end
|
182
|
+
false
|
183
|
+
end
|
184
|
+
|
160
185
|
# Write an "Array of Lines" to a file -- overwrites file if exists!
|
161
186
|
# @return String
|
162
|
-
def self.write_file(path_and_file, array_of_lines)
|
187
|
+
def self.write_file(path_and_file, array_of_lines, write_empty_trailing_line: false)
|
163
188
|
raise RuntimeError, "Expected String, instead got: #{path_and_file.class}" unless path_and_file.is_a?(String)
|
164
189
|
path_and_file = File.expand_path(path_and_file)
|
165
190
|
# If this comes in as a string, convert it to an Array of lines.
|
@@ -174,7 +199,7 @@ module Blufin
|
|
174
199
|
File.open(path_and_file, 'w') { |file|
|
175
200
|
array_of_lines.each_with_index do |line, index|
|
176
201
|
if index == array_of_lines.size - 1
|
177
|
-
file.write("#{line}")
|
202
|
+
file.write("#{line}") if line.to_s.strip != '' || write_empty_trailing_line
|
178
203
|
else
|
179
204
|
file.write("#{line}\n")
|
180
205
|
end
|
@@ -373,6 +398,7 @@ module Blufin
|
|
373
398
|
# Proxy function for the above.
|
374
399
|
# @return void
|
375
400
|
def self.create_path(path)
|
401
|
+
raise RuntimeError, "Expected String, instead got: #{path.class}" unless path.is_a?(String)
|
376
402
|
create_directory(path)
|
377
403
|
end
|
378
404
|
|
@@ -394,6 +420,7 @@ module Blufin
|
|
394
420
|
# Returns TRUE if file is empty. Ignores spaces and new-line characters.
|
395
421
|
# @return bool
|
396
422
|
def self.is_empty(path_and_file)
|
423
|
+
raise RuntimeError, "Expected String, instead got: #{path_and_file.class}" unless path_and_file.is_a?(String)
|
397
424
|
Blufin::Files::read_file(path_and_file).each do |line|
|
398
425
|
line.strip!
|
399
426
|
return false if line != ''
|
@@ -401,6 +428,14 @@ module Blufin
|
|
401
428
|
true
|
402
429
|
end
|
403
430
|
|
431
|
+
# Returns TRUE if path_and_file is a file, FALSE if it's a directory.
|
432
|
+
# File does not need to exist.
|
433
|
+
# @return bool
|
434
|
+
def self.is_file(path_and_file)
|
435
|
+
raise RuntimeError, "Expected String, instead got: #{path_and_file.class}" unless path_and_file.is_a?(String)
|
436
|
+
path_and_file =~ /\.[a-z0-9]{1,10}$/i ? true : false
|
437
|
+
end
|
438
|
+
|
404
439
|
private
|
405
440
|
|
406
441
|
# Creates path (if not exists) and deletes file (if exists).
|
data/lib/core/git.rb
CHANGED
@@ -218,13 +218,23 @@ module Blufin
|
|
218
218
|
exists = false
|
219
219
|
Blufin::Terminal::execute_proc("Checking #{type} exists: #{Blufin::Terminal::format_highlight(btc)} \x1B[38;5;246m\xe2\x86\x92 \x1B[38;5;240m#{File.expand_path(path)}\x1B[0m", Proc.new {
|
220
220
|
run('git fetch -p', path, verbose: false) if run_git_fetch
|
221
|
-
|
221
|
+
case type
|
222
|
+
when 'branch'
|
223
|
+
cmd = "git branch -r | grep #{btc}"
|
224
|
+
when 'tag'
|
225
|
+
cmd = "git tag | grep #{btc}"
|
226
|
+
when 'commit'
|
227
|
+
cmd = "git log | grep \"commit #{btc}\""
|
228
|
+
else
|
229
|
+
raise RuntimeError, "Unhandled type: #{type}"
|
230
|
+
end
|
222
231
|
res = Blufin::Terminal::execute(cmd, path, capture: true, verbose: false)
|
223
232
|
res.each do |line|
|
224
233
|
next if line.nil? || line.strip == ''
|
225
234
|
case type
|
226
235
|
when 'branch'
|
227
236
|
line = line.gsub(/^\*\s?/, '')
|
237
|
+
line = line.gsub(/^\s*origin\//, '')
|
228
238
|
when 'commit'
|
229
239
|
line = line.gsub(/^commit\s?/, '')
|
230
240
|
when 'tag'
|
data/lib/core/projects.rb
CHANGED
@@ -3,7 +3,7 @@ module Blufin
|
|
3
3
|
class Projects
|
4
4
|
|
5
5
|
SCHEMA_FILE = "#{Blufin::Base::get_base_path}#{Blufin::Base::OPT_PATH}/schema/projects.yml"
|
6
|
-
|
6
|
+
SCHEMA_FILE_CODEGEN = "#{Blufin::Base::get_base_path}#{Blufin::Base::OPT_PATH}/schema/codegen.yml"
|
7
7
|
SCRIPT_RUN = 'run'
|
8
8
|
SCRIPT_TEST = 'test'
|
9
9
|
SCRIPT_BUILD = 'build'
|
@@ -35,11 +35,16 @@ module Blufin
|
|
35
35
|
LAMBDA = 'Lambda'
|
36
36
|
UI = 'UI' # TODO - Probably need to extend this to every type of UI.
|
37
37
|
TRANSIENT_DATA = 'TransientData'
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
CODEGEN = 'codegen'
|
39
|
+
CG_API_SIMPLE = 'ApiSimple'
|
40
|
+
CG_QUASAR = 'Quasar'
|
41
|
+
CG_QUASAR_ROOT = 'Root'
|
42
|
+
CG_QUASAR_PAGES = 'PathPages'
|
43
|
+
CG_QUASAR_PAGES_IGNORE = 'PathPagesIgnore'
|
44
|
+
CG_QUASAR_API_DOCS_FILE = 'ApiDocsFile'
|
45
|
+
CG_QUASAR_JS = 'JsPath'
|
46
|
+
CG_QUASAR_TESTS = 'JsPathTests'
|
47
|
+
CG_QUASAR_ROUTES_FILE = 'RoutesFile'
|
43
48
|
TITLE = 'Title'
|
44
49
|
ALIAS = 'Alias'
|
45
50
|
DOMAIN = 'Domain'
|
@@ -86,7 +91,7 @@ module Blufin
|
|
86
91
|
# Takes a Hash that needs to have a 'Projects' key.
|
87
92
|
# This can come from both .awx.yml['Profiles'] or .blufin.yml (root).
|
88
93
|
# @return void
|
89
|
-
def initialize(projects)
|
94
|
+
def initialize(projects, profile = nil)
|
90
95
|
raise RuntimeError, 'Cannot run Blufin::Projects.new() more than once.' if !@@projects.nil? || !@@scripts.nil?
|
91
96
|
raise RuntimeError, "Need either a Local or S3Bucket key, found neither: #{projects.keys}" unless projects.has_key?(LOCAL) || projects.has_key?('S3Bucket')
|
92
97
|
@@projects = {}
|
@@ -98,15 +103,12 @@ module Blufin
|
|
98
103
|
# Validate the source file against the expected schema.
|
99
104
|
process_source_file(source_file)
|
100
105
|
elsif projects.has_key?('S3Bucket')
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
raise RuntimeError, 'Reading projects.yml from S3 is not yet implemented!'
|
107
|
-
|
106
|
+
# Throw an error if we don't have an AWS Profile.
|
107
|
+
Blufin::Terminal::error("Your configuration is getting #{Blufin::Terminal::format_highlight('projects.yml')} from S3, but you have no AWS Profile set.") if profile.nil?
|
108
|
+
s3 = projects['S3Bucket']
|
109
|
+
tmp_path = Blufin::AWS::download_s3_data(s3['Name'], s3['Path'], file: s3['File'], profile: profile, region: s3['Region'], use_cache: true)
|
110
|
+
process_source_file(tmp_path)
|
108
111
|
end
|
109
|
-
|
110
112
|
end
|
111
113
|
|
112
114
|
# Gets Project(s) -- as a nested hash with -> [PROJECT][PROJECT_ID] as the keys.
|
@@ -117,14 +119,16 @@ module Blufin
|
|
117
119
|
|
118
120
|
# Gets Project(s) -- but in a single array.
|
119
121
|
# @return Array
|
120
|
-
def self.get_projects_as_array(types: nil)
|
122
|
+
def self.get_projects_as_array(group: nil, types: nil)
|
121
123
|
projects_arr = []
|
122
|
-
|
123
|
-
projects_arr = @@projects_arr
|
124
|
-
else
|
124
|
+
unless types.nil?
|
125
125
|
types = [types] unless types.is_a?(Array)
|
126
126
|
types.each { |type| raise RuntimeError, "Invalid type: #{type}" unless VALID_TYPES.include?(type) }
|
127
|
-
|
127
|
+
end
|
128
|
+
@@projects_arr.each do |project|
|
129
|
+
next if !group.nil? && group != project[PROJECT]
|
130
|
+
next if !types.nil? && !types.include?(project[TYPE])
|
131
|
+
projects_arr << project
|
128
132
|
end
|
129
133
|
projects_arr
|
130
134
|
end
|
@@ -291,7 +295,7 @@ module Blufin
|
|
291
295
|
Blufin::Terminal::error('No projects found.') unless array_of_projects.any?
|
292
296
|
return array_of_projects[0] if array_of_projects.length == 1
|
293
297
|
projects = []
|
294
|
-
array_of_projects.each { |project| projects << {:text => project[PROJECT_ID], :value => project} }
|
298
|
+
array_of_projects.each { |project| projects << { :text => project[PROJECT_ID], :value => project } }
|
295
299
|
Blufin::Terminal::prompt_select('Select project:', projects)
|
296
300
|
end
|
297
301
|
|
@@ -379,6 +383,18 @@ module Blufin
|
|
379
383
|
project_name = project[PROJECT]
|
380
384
|
project_type = project[TYPE]
|
381
385
|
validate_type(project_type, project_id)
|
386
|
+
|
387
|
+
@codegen_file = "#{Blufin::Projects::get_project_path(project_id, project: project)}/.#{CODEGEN}/#{CODEGEN}.yml"
|
388
|
+
|
389
|
+
if [TYPE_API_SIMPLE, TYPE_QUASAR].include?(project_type)
|
390
|
+
# Validate (and parse) .codegen/codegen.yml.
|
391
|
+
Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Missing file: #{Blufin::Terminal::format_directory(@codegen_file)}", 'This file needs to exist.', true) unless Blufin::Files::file_exists(@codegen_file)
|
392
|
+
# Parse .codegen/codegen.yml
|
393
|
+
document, errors = Blufin::Config::validate_file(@codegen_file, SCHEMA_FILE_CODEGEN)
|
394
|
+
display_parse_errors_if_any(errors, @codegen_file)
|
395
|
+
@codegen_yml = parse_yml(@codegen_file)
|
396
|
+
end
|
397
|
+
|
382
398
|
# Validate Script(s).
|
383
399
|
[RUN, TEST, BUILD].each do |script_type|
|
384
400
|
if project.has_key?(script_type)
|
@@ -448,6 +464,12 @@ module Blufin
|
|
448
464
|
Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Property not supported: #{Blufin::Terminal::format_invalid(API)}", "This property is only allowed for project(s) with type: #{API}", true) if project.has_key?(API)
|
449
465
|
end
|
450
466
|
|
467
|
+
# Validate ApiSimple property.
|
468
|
+
if project_type == TYPE_API_SIMPLE
|
469
|
+
Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Missing property #{Blufin::Terminal::format_highlight(CG_API_SIMPLE)} in: #{Blufin::Terminal::format_directory(@codegen_file)}", "This property is required for project(s) with type: #{TYPE_API_SIMPLE}", true) unless @codegen_yml.has_key?(CG_API_SIMPLE)
|
470
|
+
project[TRANSIENT_DATA] = @codegen_yml[CG_API_SIMPLE]
|
471
|
+
end
|
472
|
+
|
451
473
|
# Validate Lambda property.
|
452
474
|
if project_type == TYPE_LAMBDA
|
453
475
|
# Make sure we have the Lambda property.
|
@@ -473,15 +495,8 @@ module Blufin
|
|
473
495
|
|
474
496
|
# Validate Quasar property.
|
475
497
|
if project_type == TYPE_QUASAR
|
476
|
-
#
|
477
|
-
|
478
|
-
Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Missing file: #{Blufin::Terminal::format_directory(quasarrc_file)}", 'This file needs to exist.', true) unless Blufin::Files::file_exists(quasarrc_file)
|
479
|
-
# Parse .quasarrc
|
480
|
-
document, errors = Blufin::Config::validate_file(quasarrc_file, SCHEMA_FILE_QUASARRC)
|
481
|
-
display_parse_errors_if_any(errors, quasarrc_file)
|
482
|
-
quasarrc_yml = parse_yml(quasarrc_file)
|
483
|
-
# Add it to the project object as transient data.
|
484
|
-
project[TRANSIENT_DATA] = quasarrc_yml
|
498
|
+
Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Missing property #{Blufin::Terminal::format_highlight(CG_QUASAR)} in: #{Blufin::Terminal::format_directory(@codegen_file)}", "This property is required for project(s) with type: #{TYPE_QUASAR}", true) unless @codegen_yml.has_key?(CG_QUASAR)
|
499
|
+
project[TRANSIENT_DATA] = @codegen_yml[CG_QUASAR]
|
485
500
|
end
|
486
501
|
|
487
502
|
# Validate upstream/downstream Libs(s).
|
data/lib/scan/scanner_error.rb
CHANGED
@@ -14,12 +14,12 @@ module Blufin
|
|
14
14
|
# Initialize a ScannerError object.
|
15
15
|
# @return void
|
16
16
|
def initialize(file, line, line_number, message)
|
17
|
-
raise RuntimeError, "File does not exist: #{file}" unless Blufin::Files::file_exists(file)
|
18
|
-
raise RuntimeError, "Line number must be positive integer, got: #{line_number}"
|
17
|
+
raise RuntimeError, "File does not exist: #{file}" unless Blufin::Files::file_exists(file) unless file.nil?
|
18
|
+
raise RuntimeError, "Line number must be positive integer, got: #{line_number}" if !line_number.nil? && line_number.to_s !~ /^\d+$/
|
19
19
|
raise RuntimeError, 'Message cannot be nil or blank.' if message.nil? || message.strip == ''
|
20
|
-
self.file = file
|
21
|
-
self.line = line
|
22
|
-
self.line_number = line_number.to_s
|
20
|
+
self.file = file.nil? ? "\xe2\x80\x94" : file
|
21
|
+
self.line = line.nil? ? "\xe2\x80\x94" : line
|
22
|
+
self.line_number = line_number.nil? ? "\xe2\x80\x94" : line_number.to_s
|
23
23
|
self.message = message
|
24
24
|
end
|
25
25
|
|
@@ -27,6 +27,7 @@ module Blufin
|
|
27
27
|
# @return void
|
28
28
|
def self.output_cli(errors, clear_screen = true)
|
29
29
|
raise RuntimeError, "Expected Array, instead got: #{errors.class}" unless errors.is_a?(Array)
|
30
|
+
return unless errors.any?
|
30
31
|
system('clear') if clear_screen
|
31
32
|
puts if clear_screen
|
32
33
|
@files = {}
|
@@ -39,6 +40,7 @@ module Blufin
|
|
39
40
|
puts " #{highlight_filename(file)}"
|
40
41
|
table(:border => false) do
|
41
42
|
wildcard_width = Blufin::Terminal::get_terminal_width - 120
|
43
|
+
wildcard_width = 1 if wildcard_width < 0
|
42
44
|
message_width = 100
|
43
45
|
row do
|
44
46
|
column('', :width => 2, :color => HEADER_COLOR)
|
@@ -59,6 +61,7 @@ module Blufin
|
|
59
61
|
end
|
60
62
|
puts
|
61
63
|
end
|
64
|
+
exit 1
|
62
65
|
end
|
63
66
|
|
64
67
|
# Takes a file like '/Users/Albert/Repos/eworldes/fmm/client/src/js/app/overlays.js' and highlights 'overlays.js'
|
@@ -70,6 +73,12 @@ module Blufin
|
|
70
73
|
"\x1B[48;5;233m \x1B[38;5;240m#{fs.join('/')}/\x1B[38;5;202m#{fl} \x1B[0m"
|
71
74
|
end
|
72
75
|
|
76
|
+
# Add an error.
|
77
|
+
# @return Object
|
78
|
+
def self.add_error(file, message, line = nil, line_number = nil)
|
79
|
+
Blufin::ScannerError.new(file, line, line_number, message)
|
80
|
+
end
|
81
|
+
|
73
82
|
end
|
74
83
|
|
75
84
|
end
|
data/lib/scan/scanner_java.rb
CHANGED
@@ -2,6 +2,12 @@ module Blufin
|
|
2
2
|
|
3
3
|
class ScannerJava
|
4
4
|
|
5
|
+
# TODO NOW - RENAME THESE
|
6
|
+
TYPE_CLASS = 'type_class'
|
7
|
+
TYPE_CLASS_ABSTRACT = 'type_class_abstract'
|
8
|
+
TYPE_ENUM = 'type_enum'
|
9
|
+
TYPE_INTERFACE = 'type_interface'
|
10
|
+
|
5
11
|
# Scan Java code.
|
6
12
|
# @return void
|
7
13
|
def self.scan(path)
|
@@ -9,9 +15,93 @@ module Blufin
|
|
9
15
|
# Check path exists.
|
10
16
|
Blufin::Terminal::error("Path does not exist: #{Blufin::Terminal::format_invalid(path)}") unless Blufin::Files::path_exists(path)
|
11
17
|
|
12
|
-
|
13
|
-
|
18
|
+
@data = {}
|
19
|
+
@errors = []
|
20
|
+
|
21
|
+
# Get all file(s) in path.
|
22
|
+
Blufin::Files::get_files_in_dir(path, 'java').each do |file|
|
23
|
+
data, errors = scan_file(file)
|
24
|
+
@data[file] = data
|
25
|
+
@errors.concat(errors)
|
26
|
+
end
|
27
|
+
|
28
|
+
return @data, @errors
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
# Scans a file.
|
33
|
+
# @return void
|
34
|
+
def self.scan_file(file)
|
35
|
+
raise RuntimeError, "File not found: #{file}" unless Blufin::Files::file_exists(file)
|
36
|
+
data = {}
|
37
|
+
errors = []
|
38
|
+
fs = file.split('/')
|
39
|
+
data[:class] = fs[fs.length - 1].gsub(/\.java\s*$/i, '')
|
40
|
+
@line_number = 0
|
41
|
+
|
42
|
+
Blufin::Files::read_file(file).each do |line|
|
43
|
+
|
44
|
+
begin
|
45
|
+
|
46
|
+
@line = line.gsub("\n", '')
|
47
|
+
@line_number += 1
|
48
|
+
|
49
|
+
# Get the type of class this is.
|
50
|
+
class_type = get_java_class_type
|
51
|
+
unless class_type.nil?
|
52
|
+
data[:class_type] = class_type
|
53
|
+
next
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
if @line =~ /^\s*@RestController\s*$/
|
58
|
+
data[:controller] = true
|
59
|
+
next
|
60
|
+
elsif @line =~ /^\s*@RequestMapping\(".+"\)$/
|
61
|
+
rm = @line.gsub(/^\s*@RequestMapping\("/, '').gsub(/"\)$/, '')
|
62
|
+
# Skip the custom 404 error handler mapping.
|
63
|
+
next if rm == '${server.error.path:${error.path:/error}}'
|
64
|
+
raise RuntimeError, 'Cannot have annotation @RequestMapping before (or without) @RestController.' unless data[:controller]
|
14
65
|
|
66
|
+
# TODO NOW - Continue here.
|
67
|
+
# TODO NOW - Need an example of every possible end-point in TestController.
|
68
|
+
|
69
|
+
data[:request_mapping] = rm
|
70
|
+
|
71
|
+
elsif !data[:class_type].nil? && @line =~ /^\s*.*\s+(public|protected|private)\s+[A-Za-z]+\s+[A-Za-z0-9]+\s*\(.*\)\s*\{?\}?\s*$/
|
72
|
+
|
73
|
+
# TODO - REMOVE
|
74
|
+
# puts "\x1B[38;5;154m#{@line}\x1B[0m"
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
rescue RuntimeError => e
|
79
|
+
errors << Blufin::ScannerError.new(file, @line, @line_number, e.message)
|
80
|
+
next
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
return data, errors
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
# Gets the Java class TYPE.
|
92
|
+
# @return void
|
93
|
+
def self.get_java_class_type
|
94
|
+
if @line =~ /\Apublic class\s/ || @line =~ /\Apublic final class\s/
|
95
|
+
return TYPE_CLASS
|
96
|
+
elsif @line =~ /\Aclass\s/ || @line =~ /\Afinal class\s/
|
97
|
+
raise RuntimeError, "Class in file is not public: #{@line}"
|
98
|
+
elsif @line =~ /\Apublic abstract class/
|
99
|
+
return TYPE_CLASS_ABSTRACT
|
100
|
+
elsif @line =~ /\Apublic enum/
|
101
|
+
return TYPE_ENUM
|
102
|
+
elsif @line =~ /\Apublic interface/
|
103
|
+
return TYPE_INTERFACE
|
104
|
+
end
|
15
105
|
end
|
16
106
|
|
17
107
|
end
|
data/lib/scan/scanner_js.rb
CHANGED
@@ -31,7 +31,7 @@ module Blufin
|
|
31
31
|
@data[@file] = {}
|
32
32
|
@data[@file][:methods] = {}
|
33
33
|
|
34
|
-
@
|
34
|
+
@line = nil
|
35
35
|
@line_number = 0
|
36
36
|
@params = nil
|
37
37
|
@docs = nil
|
@@ -64,13 +64,7 @@ module Blufin
|
|
64
64
|
@params = {}
|
65
65
|
# Extract method data.
|
66
66
|
parse_method_definition(@line)
|
67
|
-
|
68
67
|
@docs = nil
|
69
|
-
else
|
70
|
-
|
71
|
-
# TODO - REMOVE
|
72
|
-
# puts line unless @docs_active || @method_active
|
73
|
-
|
74
68
|
end
|
75
69
|
|
76
70
|
# If we're inside a comment.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class ScannerJsTests
|
4
|
+
|
5
|
+
# Scan Javascript (test) code.
|
6
|
+
# @return void
|
7
|
+
def self.scan(path)
|
8
|
+
|
9
|
+
# Check path exists.
|
10
|
+
Blufin::Terminal::error("Path does not exist: #{Blufin::Terminal::format_invalid(path)}") unless Blufin::Files::path_exists(path)
|
11
|
+
|
12
|
+
@data = {}
|
13
|
+
@errors = []
|
14
|
+
|
15
|
+
# Get all file(s) in path.
|
16
|
+
Blufin::Files::get_files_in_dir(path, 'js').each { |file| scan_file(file) }
|
17
|
+
|
18
|
+
return @data, @errors
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Scans a file.
|
25
|
+
# @return void
|
26
|
+
def self.scan_file(file)
|
27
|
+
|
28
|
+
# TODO NOW - FINISH THIS!
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/scan/scanner_vue.rb
CHANGED
@@ -9,11 +9,25 @@ module Blufin
|
|
9
9
|
# Check path exists.
|
10
10
|
Blufin::Terminal::error("Path does not exist: #{Blufin::Terminal::format_invalid(path)}") unless Blufin::Files::path_exists(path)
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
@data = {}
|
13
|
+
@errors = []
|
14
|
+
|
15
|
+
# Get all file(s) in path.
|
16
|
+
Blufin::Files::get_files_in_dir(path, 'vue').each { |file| scan_file(file) }
|
17
|
+
|
18
|
+
return @data, @errors
|
14
19
|
|
15
20
|
end
|
16
21
|
|
22
|
+
private
|
23
|
+
|
24
|
+
# Scans a file.
|
25
|
+
# @return void
|
26
|
+
def self.scan_file(file)
|
27
|
+
|
28
|
+
# TODO NOW - FINISH THIS!
|
29
|
+
|
30
|
+
end
|
17
31
|
|
18
32
|
end
|
19
33
|
|
data/lib/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
BLUFIN_LIB_VERSION = '
|
1
|
+
BLUFIN_LIB_VERSION = '2.0.0'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
type: map
|
2
|
+
mapping:
|
3
|
+
ApiSimple:
|
4
|
+
type: map
|
5
|
+
mapping:
|
6
|
+
Package:
|
7
|
+
required: true
|
8
|
+
pattern: /^[a-z0-9\.\-]+$/
|
9
|
+
ControllerPath:
|
10
|
+
required: true
|
11
|
+
pattern: /^[a-z0-9\-\/]+$/
|
12
|
+
ServicePath:
|
13
|
+
required: true
|
14
|
+
pattern: /^[a-z0-9\-\/]+$/
|
15
|
+
Lambda:
|
16
|
+
type: map
|
17
|
+
mapping:
|
18
|
+
ChangeMe:
|
19
|
+
type: bool
|
20
|
+
Quasar:
|
21
|
+
type: map
|
22
|
+
mapping:
|
23
|
+
Root:
|
24
|
+
required: true
|
25
|
+
pattern: /^[a-z0-9\-\/]+$/
|
26
|
+
PathPages:
|
27
|
+
required: true
|
28
|
+
pattern: /^[a-z0-9\-\/]+$/
|
29
|
+
PathPagesIgnore:
|
30
|
+
type: seq
|
31
|
+
sequence:
|
32
|
+
- type: str
|
33
|
+
ApiDocsFile:
|
34
|
+
required: true
|
35
|
+
pattern: /^[a-z0-9\-\.\/]+$/
|
36
|
+
JsDocsFile:
|
37
|
+
required: true
|
38
|
+
pattern: /^[a-z0-9\-\.\/]+$/
|
39
|
+
JsPath:
|
40
|
+
required: true
|
41
|
+
pattern: /^[a-z0-9\-\/]+$/
|
42
|
+
JsPathTests:
|
43
|
+
required: true
|
44
|
+
pattern: /^[a-z0-9\-\/]+$/
|
45
|
+
RoutesFile:
|
46
|
+
required: true
|
47
|
+
pattern: /^[a-z0-9\-\.\/]+$/
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blufin-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Albert Rannetsperger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -149,17 +149,14 @@ files:
|
|
149
149
|
- lib/core/validate.rb
|
150
150
|
- lib/core/versioning.rb
|
151
151
|
- lib/core/yml.rb
|
152
|
-
- lib/generate/generate_base.rb
|
153
|
-
- lib/generate/generate_ui_routes.rb
|
154
|
-
- lib/scan/scanner.rb
|
155
152
|
- lib/scan/scanner_error.rb
|
156
153
|
- lib/scan/scanner_java.rb
|
157
154
|
- lib/scan/scanner_js.rb
|
155
|
+
- lib/scan/scanner_js_tests.rb
|
158
156
|
- lib/scan/scanner_vue.rb
|
159
157
|
- lib/version.rb
|
160
|
-
- opt/schema/
|
158
|
+
- opt/schema/codegen.yml
|
161
159
|
- opt/schema/projects.yml
|
162
|
-
- opt/schema/routes.yml
|
163
160
|
- opt/shell/ec2-check
|
164
161
|
homepage: https://github.com/alb3rtuk
|
165
162
|
licenses:
|
@@ -181,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
178
|
version: '0'
|
182
179
|
requirements: []
|
183
180
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.5.
|
181
|
+
rubygems_version: 2.5.2.3
|
185
182
|
signing_key:
|
186
183
|
specification_version: 4
|
187
184
|
summary: Blufin Lib
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Blufin
|
2
|
-
|
3
|
-
class GenerateBase
|
4
|
-
|
5
|
-
OUTPUT_GENERATE = 'generated'
|
6
|
-
OUTPUT_SKIP = 'exists'
|
7
|
-
|
8
|
-
# Standardized output for code-generation.
|
9
|
-
# @return void
|
10
|
-
def self.output(message, type)
|
11
|
-
|
12
|
-
case type
|
13
|
-
when OUTPUT_GENERATE
|
14
|
-
puts "\x1B[38;5;231m\x1B[48;5;55m Generated \x1B[0m \xe2\x86\x92 \x1B[38;5;182m#{message}\x1B[0m"
|
15
|
-
when OUTPUT_SKIP
|
16
|
-
puts " \x1B[38;5;246m\x1B[48;5;234m Skipping \x1B[0m \xe2\x86\x92 \x1B[38;5;240m#{message}\x1B[0m"
|
17
|
-
else
|
18
|
-
raise "Unrecognized output type: #{type}"
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
# Display errors/warnings after code generation, if any.
|
24
|
-
# This method currently terminates with a 1 exit code if errors/warnings occurred, 0 if not.
|
25
|
-
# @return void
|
26
|
-
def self.exit_code_generation(errors, warnings)
|
27
|
-
|
28
|
-
if warnings.any?
|
29
|
-
Blufin::Terminal::warning('Please fix the following warnings(s):', nil, false)
|
30
|
-
warnings.each { |warning| puts " #{warning}" }
|
31
|
-
puts
|
32
|
-
end
|
33
|
-
|
34
|
-
if errors.any?
|
35
|
-
Blufin::Terminal::error('Please fix the following error(s):', nil, false)
|
36
|
-
errors.each { |error| puts " #{error}" }
|
37
|
-
puts
|
38
|
-
exit 1
|
39
|
-
end
|
40
|
-
|
41
|
-
return errors.any? || warnings.any? ? 1 : 0
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
@@ -1,230 +0,0 @@
|
|
1
|
-
module Blufin
|
2
|
-
|
3
|
-
class GenerateUiRoutes
|
4
|
-
|
5
|
-
SCHEMA_FILE = "#{Blufin::Base::get_base_path}#{Blufin::Base::OPT_PATH}/schema/routes.yml"
|
6
|
-
HOME_TERM = 'dashboard'
|
7
|
-
PAGES_ROOT = 'PagesRoot'
|
8
|
-
PAGES_404 = 'Pages404'
|
9
|
-
ROUTES_FILE = 'RoutesFile'
|
10
|
-
IGNORE = 'Ignore'
|
11
|
-
ROUTES = 'Routes'
|
12
|
-
PARENT = 'Parent'
|
13
|
-
PATH = 'Path'
|
14
|
-
NAME = 'Name'
|
15
|
-
ICON = 'Icon'
|
16
|
-
LAYOUT = 'Layout'
|
17
|
-
ROOT_PATH = 'RootPath'
|
18
|
-
INVISIBLE = 'Invisible'
|
19
|
-
CHILDREN = 'Children'
|
20
|
-
|
21
|
-
|
22
|
-
# Generates routes in the UI.
|
23
|
-
# @return void
|
24
|
-
def self.run(project)
|
25
|
-
raise RuntimeError, "Expected project type to be: #{Blufin::Projects::TYPE_QUASAR}, instead got: #{project[Blufin::Projects::TYPE]}" unless project[Blufin::Projects::TYPE] == Blufin::Projects::TYPE_QUASAR
|
26
|
-
@errors = []
|
27
|
-
@warnings = []
|
28
|
-
@files = []
|
29
|
-
@files_to_create = []
|
30
|
-
root_path_seen = nil
|
31
|
-
begin
|
32
|
-
@output = <<TEMPLATE
|
33
|
-
const routes = [
|
34
|
-
{
|
35
|
-
TEMPLATE
|
36
|
-
project_path = Blufin::Projects::get_project_path(project[Blufin::Projects::PROJECT_ID], true)
|
37
|
-
routes_file = "#{project_path}/#{project[Blufin::Projects::TRANSIENT_DATA][Blufin::Projects::QUASAR_ROUTES_FILE]}"
|
38
|
-
routes_yml = Blufin::Yml::read_file(routes_file, SCHEMA_FILE)
|
39
|
-
target_file = "#{project_path}/src/#{Blufin::Strings::remove_surrounding_slashes(routes_yml[ROUTES_FILE])}"
|
40
|
-
pages_root = routes_yml[PAGES_ROOT]
|
41
|
-
pages_not_found = routes_yml[PAGES_404]
|
42
|
-
path_pages_ignore = []
|
43
|
-
path_to_pages = "#{project_path}/src/#{pages_root}"
|
44
|
-
|
45
|
-
# Add ignore path(s) -- if exists.
|
46
|
-
routes_yml[IGNORE].each { |ignore_path| path_pages_ignore << "#{Blufin::Strings::remove_surrounding_slashes(ignore_path)}" } if routes_yml.has_key?(IGNORE)
|
47
|
-
|
48
|
-
# Loop Routes.
|
49
|
-
routes = routes_yml[ROUTES]
|
50
|
-
routes.each_with_index do |route, idx|
|
51
|
-
|
52
|
-
# Make sure we have a route.
|
53
|
-
@errors << "You have an empty route in: #{Blufin::Terminal::format_directory(routes_file)}" if route.nil? || !route.any?
|
54
|
-
|
55
|
-
# Validate order of keys (in route).
|
56
|
-
expected = {
|
57
|
-
PARENT => true,
|
58
|
-
CHILDREN => false
|
59
|
-
}
|
60
|
-
Blufin::Validate::assert_valid_keys(expected, route.keys, routes_file)
|
61
|
-
|
62
|
-
# Validate order of keys (in parent).
|
63
|
-
expected = {
|
64
|
-
LAYOUT => true,
|
65
|
-
PATH => true,
|
66
|
-
NAME => false,
|
67
|
-
ICON => false,
|
68
|
-
ROOT_PATH => false,
|
69
|
-
INVISIBLE => false,
|
70
|
-
}
|
71
|
-
Blufin::Validate::assert_valid_keys(expected, route[PARENT].keys, routes_file)
|
72
|
-
|
73
|
-
comma = route.has_key?(CHILDREN) ? ',' : nil
|
74
|
-
parent_path = route[PARENT][PATH]
|
75
|
-
layout = route[PARENT][LAYOUT]
|
76
|
-
invisible = nil
|
77
|
-
|
78
|
-
# The prefix that gets added to all (parent) error messages.
|
79
|
-
parent_error_prefix = "Parent path: #{Blufin::Terminal::format_highlight("/#{parent_path}")} \xe2\x80\x94 "
|
80
|
-
|
81
|
-
# Make sure path and layout are all lowercase.
|
82
|
-
@errors << "#{parent_error_prefix}Everything must be lowercase, found: #{Blufin::Terminal::format_invalid(parent_path)}" if route[PARENT][PATH].downcase != parent_path
|
83
|
-
@errors << "#{parent_error_prefix}Everything must be lowercase, found: #{Blufin::Terminal::format_invalid(layout)}" if route[PARENT][LAYOUT].downcase != layout
|
84
|
-
|
85
|
-
# Validate name/icon properties based on whether this route is visible or not.
|
86
|
-
if route[PARENT].has_key?(INVISIBLE) && route[PARENT][INVISIBLE]
|
87
|
-
invisible = "\n invisible: true,"
|
88
|
-
# Validate we don't have name/icon when invisible.
|
89
|
-
[NAME, ICON].each { |taboo_key| @errors << "#{parent_error_prefix}When #{Blufin::Terminal::format_action(INVISIBLE)} is set, cannot have property: #{Blufin::Terminal::format_invalid(taboo_key)}" if route[PARENT].has_key?(taboo_key) }
|
90
|
-
else
|
91
|
-
# Validate we have name/icon when NOT invisible.
|
92
|
-
[NAME, ICON].each { |required_key| @errors << "#{parent_error_prefix}Missing property: #{Blufin::Terminal::format_invalid(required_key)}" unless route[PARENT].has_key?(required_key) }
|
93
|
-
end
|
94
|
-
|
95
|
-
# Make sure the RootPath hasn't already been seen.
|
96
|
-
if route[PARENT].has_key?(ROOT_PATH)
|
97
|
-
@errors << "Found multiple routes with a #{Blufin::Terminal::format_highlight(ROOT_PATH)} flag: #{Blufin::Terminal::format_invalid(root_path_seen)}, #{Blufin::Terminal::format_invalid(route[PARENT][PATH])}" unless root_path_seen.nil?
|
98
|
-
root_path_seen = parent_path
|
99
|
-
end
|
100
|
-
|
101
|
-
@output += <<TEMPLATE
|
102
|
-
path: '/#{route[PARENT].has_key?(ROOT_PATH) && route[PARENT][ROOT_PATH] ? nil : parent_path}',
|
103
|
-
sectionName: '#{route[PARENT][NAME]}',
|
104
|
-
sectionIcon: '#{route[PARENT][ICON]}',#{invisible}
|
105
|
-
component: () => import('./../#{layout}')#{comma}
|
106
|
-
TEMPLATE
|
107
|
-
file = "#{pages_root}/#{parent_path}/index.vue"
|
108
|
-
prefix = parent_path == HOME_TERM ? 'dashboard/' : nil
|
109
|
-
process_file(file, project_path)
|
110
|
-
if route.has_key?(CHILDREN)
|
111
|
-
@output += <<TEMPLATE
|
112
|
-
children: [
|
113
|
-
{
|
114
|
-
path: '',
|
115
|
-
component: () => import('./../#{file}')
|
116
|
-
},
|
117
|
-
TEMPLATE
|
118
|
-
# Loop Children.
|
119
|
-
children = route[CHILDREN]
|
120
|
-
children.each_with_index do |child, idx|
|
121
|
-
comma = idx == children.length - 1 ? nil : ','
|
122
|
-
file = "#{pages_root}/#{parent_path}/#{child[PATH]}.vue"
|
123
|
-
disabled = child.has_key?('Disabled') && child['Disabled'] ? "\n disabled: true," : nil
|
124
|
-
@errors << "#{parent_error_prefix}Everything must be lowercase, found: #{Blufin::Terminal::format_invalid(child[PATH])}" if child[PATH].downcase != child[PATH]
|
125
|
-
process_file(file, project_path)
|
126
|
-
@output += <<TEMPLATE
|
127
|
-
{
|
128
|
-
path: '#{prefix}#{child[PATH]}',
|
129
|
-
name: '#{child[NAME]}',#{disabled}
|
130
|
-
component: () => import('./../#{file}')
|
131
|
-
}#{comma}
|
132
|
-
TEMPLATE
|
133
|
-
end
|
134
|
-
@output += " ]\n"
|
135
|
-
end
|
136
|
-
|
137
|
-
if idx == routes.length - 1
|
138
|
-
@output += <<TEMPLATE
|
139
|
-
}
|
140
|
-
TEMPLATE
|
141
|
-
else
|
142
|
-
@output += <<TEMPLATE
|
143
|
-
},
|
144
|
-
{
|
145
|
-
TEMPLATE
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
@output += <<TEMPLATE
|
150
|
-
];
|
151
|
-
|
152
|
-
if (process.env.MODE !== 'ssr') {
|
153
|
-
routes.push({
|
154
|
-
path: '*',
|
155
|
-
component: () => import('./../#{pages_not_found}')
|
156
|
-
});
|
157
|
-
}
|
158
|
-
|
159
|
-
export default routes;
|
160
|
-
TEMPLATE
|
161
|
-
rescue => e
|
162
|
-
Blufin::Terminal::print_exception(e)
|
163
|
-
end
|
164
|
-
|
165
|
-
# Write the output to the file.
|
166
|
-
Blufin::Files::write_file(target_file, Blufin::Arrays::convert_string_to_line_array(@output))
|
167
|
-
|
168
|
-
# Output message.
|
169
|
-
Blufin::Terminal::info('Generating route file(s):') if @files_to_create.any?
|
170
|
-
|
171
|
-
# Write all the blank route files.
|
172
|
-
@files_to_create.each do |ftc|
|
173
|
-
if Blufin::Files::file_exists(ftc)
|
174
|
-
Blufin::GenerateBase::output(ftc, Blufin::GenerateBase::OUTPUT_SKIP)
|
175
|
-
else
|
176
|
-
Blufin::Files::write_file(ftc, Blufin::Arrays::convert_string_to_line_array(get_blank_file_content))
|
177
|
-
Blufin::GenerateBase::output(ftc, Blufin::GenerateBase::OUTPUT_GENERATE)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
puts if @files_to_create.any?
|
182
|
-
|
183
|
-
# Check for rogue files.
|
184
|
-
Blufin::Files::get_files_in_dir(path_to_pages).each do |file|
|
185
|
-
next if file =~ /#{path_to_pages}\/(#{path_pages_ignore.join('|')})\/[a-z0-9]/
|
186
|
-
unless @files_to_create.include?(file)
|
187
|
-
@warnings << "Found rogue file: #{Blufin::Terminal::format_invalid(file)}"
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
return @errors, @warnings
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
private
|
196
|
-
|
197
|
-
# Ensures that we're not defining a path twice.
|
198
|
-
# Creates file if not exists
|
199
|
-
# @return void
|
200
|
-
def self.process_file(file, project_path)
|
201
|
-
@errors << "Duplicate file: #{Blufin::Terminal::format_invalid(file)}" if @files.include?(file)
|
202
|
-
@files << file
|
203
|
-
@files_to_create << "#{project_path}/src/#{file}"
|
204
|
-
end
|
205
|
-
|
206
|
-
# Returns the contents of a blank file.
|
207
|
-
# @return string
|
208
|
-
def self.get_blank_file_content
|
209
|
-
<<TEMPLATE
|
210
|
-
<template>
|
211
|
-
<div>
|
212
|
-
<base-title h="5" :nudge-right="30" :nudge-up="10">{{ $route.name }}</base-title>
|
213
|
-
</div>
|
214
|
-
</template>
|
215
|
-
|
216
|
-
<script>
|
217
|
-
export default {
|
218
|
-
data() {
|
219
|
-
return {};
|
220
|
-
}
|
221
|
-
};
|
222
|
-
</script>
|
223
|
-
|
224
|
-
<style scoped type="text/scss" lang="scss"></style>
|
225
|
-
TEMPLATE
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
end
|
data/lib/scan/scanner.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Blufin
|
2
|
-
|
3
|
-
class Scanner
|
4
|
-
|
5
|
-
# Initialize the class.
|
6
|
-
# @return void
|
7
|
-
def self.scan(project_key)
|
8
|
-
|
9
|
-
@errors = []
|
10
|
-
@js_data = {}
|
11
|
-
|
12
|
-
Blufin::Projects::get_projects_as_array.each do |project|
|
13
|
-
if project[Blufin::Projects::PROJECT] == project_key
|
14
|
-
project_id = project[Blufin::Projects::PROJECT_ID]
|
15
|
-
project_type = project[Blufin::Projects::TYPE]
|
16
|
-
project_path = Blufin::Projects::get_project_path(project_id, true)
|
17
|
-
case project_type
|
18
|
-
when Blufin::Projects::TYPE_API_SIMPLE
|
19
|
-
when Blufin::Projects::TYPE_QUASAR
|
20
|
-
# Extract JS data.
|
21
|
-
if project.has_key?(Blufin::Projects::TRANSIENT_DATA) && project[Blufin::Projects::TRANSIENT_DATA].has_key?(Blufin::Projects::QUASAR_JS)
|
22
|
-
js_path = project[Blufin::Projects::TRANSIENT_DATA][Blufin::Projects::QUASAR_JS]
|
23
|
-
@js_data, errors = Blufin::ScannerJs::scan("#{project_path}/#{js_path}")
|
24
|
-
@errors.concat(errors)
|
25
|
-
end
|
26
|
-
else
|
27
|
-
raise RuntimeError, "Unsupported project type: #{project_type}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
return {
|
33
|
-
:js_data => @js_data,
|
34
|
-
:errors => @errors
|
35
|
-
}
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
data/opt/schema/routes.yml
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
type: map
|
2
|
-
mapping:
|
3
|
-
PagesRoot:
|
4
|
-
required: true
|
5
|
-
Pages404:
|
6
|
-
required: true
|
7
|
-
RoutesFile:
|
8
|
-
required: true
|
9
|
-
Ignore:
|
10
|
-
type: seq
|
11
|
-
sequence:
|
12
|
-
- type: str
|
13
|
-
Routes:
|
14
|
-
type: seq
|
15
|
-
required: true
|
16
|
-
sequence:
|
17
|
-
- type: map
|
18
|
-
mapping:
|
19
|
-
Parent:
|
20
|
-
type: map
|
21
|
-
required: true
|
22
|
-
mapping:
|
23
|
-
Layout:
|
24
|
-
required: true
|
25
|
-
Path:
|
26
|
-
required: true
|
27
|
-
Name:
|
28
|
-
Icon:
|
29
|
-
RootPath:
|
30
|
-
type: bool
|
31
|
-
Invisible:
|
32
|
-
type: bool
|
33
|
-
Children:
|
34
|
-
type: seq
|
35
|
-
sequence:
|
36
|
-
- type: map
|
37
|
-
required: true
|
38
|
-
mapping:
|
39
|
-
Path:
|
40
|
-
required: true
|
41
|
-
Name:
|
42
|
-
required: true
|
43
|
-
Disabled:
|
44
|
-
type: bool
|