blufin-lib 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1987fd9c5b7b8590adc63c9179ce7eb8d398fb3
4
- data.tar.gz: 5064081160441c67b7bbe48f369688a9430c85c8
3
+ metadata.gz: c350615237fa3cabca9a833d125de66452839e90
4
+ data.tar.gz: d70bb123eb4a18d56bfea947fb364f168cd2c546
5
5
  SHA512:
6
- metadata.gz: e7e9b674320a55992ae41b263bdaf9bcd4e8e5eeba2a821708640e876682f05f4b9209407eb79941955c0b95d2d9ad59b36ff19a096dc8568294b1bf9a61958a
7
- data.tar.gz: db2bf6c32f4f9e27e06861633dd49b7a12972181860d01674470bd8314e18e421c587ca31b4bf6f0169f72dd3b768a1171eb468a3738902b6a22b1fcc887886b
6
+ metadata.gz: 9d1e4e53208fc09a65f92be9c70c57230fa787044f3fd9bbb373ac2a66cfcb18615de185acf198fc23b2b27a05c9b93d290d926bfb075dcefcbff2f0a71a28c6
7
+ data.tar.gz: d0526fbe1e4076ce2f228cb05c92048360fda5f600027f1dec0e7a3439b83756d5c6897a1a767e800abd4ca45b70267596f28ba79c0a8c77d644261f6912c884
@@ -16,7 +16,9 @@ module Blufin
16
16
  autoload :Projects, 'core/projects'
17
17
  autoload :Routes, 'core/routes'
18
18
  autoload :Scanner, 'scan/scanner'
19
+ autoload :ScannerError, 'scan/scanner_error'
19
20
  autoload :ScannerJava, 'scan/scanner_java'
21
+ autoload :ScannerJs, 'scan/scanner_js'
20
22
  autoload :ScannerVue, 'scan/scanner_vue'
21
23
  autoload :Strings, 'core/strings'
22
24
  autoload :Terminal, 'core/terminal'
@@ -327,6 +327,10 @@ module Blufin
327
327
  # @return Array
328
328
  def self.get_files_in_dir(path, only_with_extension = nil)
329
329
  raise RuntimeError, "Expected String, instead got: #{path.class}" unless path.is_a?(String)
330
+ unless only_with_extension.nil?
331
+ raise RuntimeError, "Expected String, instead got: #{path.class}" unless only_with_extension.is_a?(String)
332
+ raise RuntimeError, 'only_with_extension must be alphanumeric & lowercase (no periods)' unless only_with_extension =~ /[a-z0-9]/
333
+ end
330
334
  path = "/#{Blufin::Strings.remove_surrounding_slashes(File.expand_path(path))}"
331
335
  raise RuntimeError, "Directory doesn't exist: #{path}" unless path_exists(path)
332
336
  files = Dir.glob("#{path}/**/*.#{only_with_extension.nil? ? '*' : only_with_extension}")
@@ -3,6 +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
+ SCHEMA_FILE_QUASARRC = "#{Blufin::Base::get_base_path}#{Blufin::Base::OPT_PATH}/schema/projects-quasarrc.yml"
6
7
  SCRIPT_RUN = 'run'
7
8
  SCRIPT_TEST = 'test'
8
9
  SCRIPT_BUILD = 'build'
@@ -33,7 +34,11 @@ module Blufin
33
34
  WORKER = 'Worker'
34
35
  LAMBDA = 'Lambda'
35
36
  UI = 'UI' # TODO - Probably need to extend this to every type of UI.
36
- QUASAR = 'Quasar'
37
+ TRANSIENT_DATA = 'TransientData'
38
+ QUASARRC = '.quasarrc'
39
+ QUASAR_JS = 'JsPath'
40
+ QUASAR_JS_TESTS = 'JsPathTests'
41
+ QUASAR_ROUTES_FILE = 'RoutesFile'
37
42
  ROUTES_FILE = 'RoutesFile'
38
43
  TITLE = 'Title'
39
44
  ALIAS = 'Alias'
@@ -115,10 +120,10 @@ module Blufin
115
120
  def self.get_projects_as_array(types: nil)
116
121
  projects_arr = []
117
122
  if types.nil?
118
- validate_type(project_type, project_id)
119
123
  projects_arr = @@projects_arr
120
124
  else
121
125
  types = [types] unless types.is_a?(Array)
126
+ types.each { |type| raise RuntimeError, "Invalid type: #{type}" unless VALID_TYPES.include?(type) }
122
127
  @@projects_arr.each { |project| projects_arr << project if types.include?(project[TYPE]) }
123
128
  end
124
129
  projects_arr
@@ -299,227 +304,234 @@ module Blufin
299
304
  return if Blufin::Files::is_empty(source_file)
300
305
  # Otherwise, validate file.
301
306
  document, errors = Blufin::Config::validate_file(source_file, SCHEMA_FILE)
302
- if errors && !errors.empty?
303
- errors_output = []
304
- errors.each { |e|
305
- errors_output << "[#{e.path}] #{e.message}"
306
- }
307
- Blufin::Terminal::error("Your configuration file is invalid. Please fix: #{Blufin::Terminal::format_directory(source_file)}", errors)
308
- else
309
- begin
310
- file_parsed = YAML.load_file(source_file)
311
- rescue => e
312
- Blufin::Terminal::error("Failed to parse config file: #{Blufin::Terminal::format_directory(source_file)}", e.message)
313
- end
314
-
315
- # Buffer script(s).
316
- [RUN_SCRIPTS, TEST_SCRIPTS, BUILD_SCRIPTS].each do |script_type|
317
- if file_parsed.has_key?(script_type)
318
- if file_parsed[script_type].is_a?(Array)
319
- script_key = script_key_mapper(script_type)
320
- @@scripts[script_key] = {} unless @@scripts.has_key?(script_key)
321
- file_parsed[script_type].each do |script|
322
- script_id = script[ID]
323
- # Throw error if duplicate script is found for type.
324
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight("#{script_type} - #{script_id}")} \xe2\x80\x94 Duplicate script found: #{Blufin::Terminal::format_invalid(script_id)}") if @@scripts[script_key].has_key?(script_id)
325
- @@scripts[script_key][script_id] = script
326
- # Check that if script is AWS, it doesn't have --region or --profile flag.
327
- if script.has_key?(COMMANDS)
328
- script[COMMANDS].each do |command|
329
- if command.strip =~ /^aws/i
330
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight("#{script_type} - #{script_id}")} \xe2\x80\x94 AWS scripts cannot have: #{Blufin::Terminal::format_invalid('--region')} flag.", command) if command =~ /\s--region\s/
331
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight("#{script_type} - #{script_id}")} \xe2\x80\x94 AWS scripts cannot have: #{Blufin::Terminal::format_invalid('--profile')} flag.", command) if command =~ /\s--profile\s/
332
- end
307
+ display_parse_errors_if_any(errors, source_file)
308
+ projects_yml = parse_yml(source_file)
309
+ # Buffer script(s).
310
+ [RUN_SCRIPTS, TEST_SCRIPTS, BUILD_SCRIPTS].each do |script_type|
311
+ if projects_yml.has_key?(script_type)
312
+ if projects_yml[script_type].is_a?(Array)
313
+ script_key = script_key_mapper(script_type)
314
+ @@scripts[script_key] = {} unless @@scripts.has_key?(script_key)
315
+ projects_yml[script_type].each do |script|
316
+ script_id = script[ID]
317
+ # Throw error if duplicate script is found for type.
318
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight("#{script_type} - #{script_id}")} \xe2\x80\x94 Duplicate script found: #{Blufin::Terminal::format_invalid(script_id)}") if @@scripts[script_key].has_key?(script_id)
319
+ @@scripts[script_key][script_id] = script
320
+ # Check that if script is AWS, it doesn't have --region or --profile flag.
321
+ if script.has_key?(COMMANDS)
322
+ script[COMMANDS].each do |command|
323
+ if command.strip =~ /^aws/i
324
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight("#{script_type} - #{script_id}")} \xe2\x80\x94 AWS scripts cannot have: #{Blufin::Terminal::format_invalid('--region')} flag.", command) if command =~ /\s--region\s/
325
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight("#{script_type} - #{script_id}")} \xe2\x80\x94 AWS scripts cannot have: #{Blufin::Terminal::format_invalid('--profile')} flag.", command) if command =~ /\s--profile\s/
333
326
  end
334
327
  end
335
328
  end
336
329
  end
337
330
  end
338
331
  end
332
+ end
339
333
 
340
- # Buffer/validate project(s) stuff.
341
- file_parsed['Projects'].each do |project|
342
- project_id = project[PROJECT_ID]
343
- project_type = project[TYPE]
344
- if project_type == TYPE_MVN_LIB || TYPE_NPM_LIB
345
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Duplicate Library Project.", "A library with this ID (#{Blufin::Terminal::format_invalid(project_id)}) has already been registered.") if @@libs.keys.include?(project_id)
346
- @@libs[project_id] = project
347
- elsif project_type == TYPE_API || project_type == TYPE_API_SIMPLE
348
- [ALIAS, PROJECT_NAME, PROJECT_NAME_PASCAL_CASE, TITLE].each do |x|
349
- @@api_data[x] = [] unless @@api_data.has_key?(x) && @@api_data[x].is_a?(Array)
350
- property_value = project[API][x].strip.downcase
351
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Duplicate #{x} API Property.", "An API Property with this value (#{Blufin::Terminal::format_invalid(property_value)}) has already been registered.") if @@api_data[x].include?(property_value)
352
- @@api_data[x] << property_value
353
- end
334
+ # Buffer/validate project(s) stuff.
335
+ projects_yml['Projects'].each do |project|
336
+ project_id = project[PROJECT_ID]
337
+ project_type = project[TYPE]
338
+ if project_type == TYPE_MVN_LIB || TYPE_NPM_LIB
339
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Duplicate Library Project.", "A library with this ID (#{Blufin::Terminal::format_invalid(project_id)}) has already been registered.") if @@libs.keys.include?(project_id)
340
+ @@libs[project_id] = project
341
+ elsif project_type == TYPE_API || project_type == TYPE_API_SIMPLE
342
+ [ALIAS, PROJECT_NAME, PROJECT_NAME_PASCAL_CASE, TITLE].each do |x|
343
+ @@api_data[x] = [] unless @@api_data.has_key?(x) && @@api_data[x].is_a?(Array)
344
+ property_value = project[API][x].strip.downcase
345
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Duplicate #{x} API Property.", "An API Property with this value (#{Blufin::Terminal::format_invalid(property_value)}) has already been registered.") if @@api_data[x].include?(property_value)
346
+ @@api_data[x] << property_value
354
347
  end
355
348
  end
349
+ end
356
350
 
357
- used_ports = {}
351
+ used_ports = {}
358
352
 
359
- # Run through once quickly to populate critical objects (required for validation).
360
- file_parsed['Projects'].each do |project|
361
- @@project_names << project[PROJECT]
362
- @@project_ids << project[PROJECT_ID]
363
- end
353
+ # Run through once quickly to populate critical objects (required for validation).
354
+ projects_yml['Projects'].each do |project|
355
+ @@project_names << project[PROJECT]
356
+ @@project_ids << project[PROJECT_ID]
357
+ end
364
358
 
365
- # Loop (and validate) projects.
366
- file_parsed['Projects'].each do |project|
367
- # Validate keys are in specific order.
368
- expected = {
369
- PROJECT_ID => true,
370
- PROJECT => true,
371
- TYPE => true,
372
- REPOSITORY => true,
373
- UPSTREAM => false,
374
- DOWNSTREAM => false,
375
- RUN => false,
376
- TEST => false,
377
- BUILD => false,
378
- API => false,
379
- LAMBDA => false,
380
- UI => false,
381
- QUASAR => false,
382
- DEPLOYMENT => false,
383
- }
384
- Blufin::Validate::assert_valid_keys(expected, project.keys, source_file)
385
- project_id = project[PROJECT_ID]
386
- project_name = project[PROJECT]
387
- project_type = project[TYPE]
388
- validate_type(project_type, project_id)
389
- # Validate Script(s).
390
- [RUN, TEST, BUILD].each do |script_type|
391
- if project.has_key?(script_type)
392
- # Validate the LAMBDA functions don't need build scripts.
393
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Project type: #{Blufin::Terminal::format_highlight(TYPE_LAMBDA)} does not require #{Blufin::Terminal::format_invalid(script_type)} script(s).", 'This type of project does not support this.', true) if [BUILD].include?(script_type) && project_type == TYPE_LAMBDA
394
- if project[script_type].is_a?(Hash)
395
- script_key = script_key_mapper(script_type)
396
- valid_scripts = []
397
- valid_scripts = @@scripts[script_key].keys if @@scripts.has_key?(script_key)
398
- script = project[script_type]
399
- script_name = script['Script']
400
- unless valid_scripts.include?(script_name)
401
- error = valid_scripts.any? ? 'Valid values are:' : "There currently are no #{script_key} script(s) defined."
402
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 #{Blufin::Terminal::format_highlight(script_type)} \xe2\x80\x94 Invalid script reference: #{Blufin::Terminal::format_invalid(script_name)}. #{error}", valid_scripts)
403
- end
359
+ # Loop (and validate) projects.
360
+ projects_yml['Projects'].each do |project|
361
+ # Validate keys are in specific order.
362
+ expected = {
363
+ PROJECT_ID => true,
364
+ PROJECT => true,
365
+ TYPE => true,
366
+ REPOSITORY => true,
367
+ UPSTREAM => false,
368
+ DOWNSTREAM => false,
369
+ RUN => false,
370
+ TEST => false,
371
+ BUILD => false,
372
+ API => false,
373
+ LAMBDA => false,
374
+ UI => false,
375
+ DEPLOYMENT => false,
376
+ }
377
+ Blufin::Validate::assert_valid_keys(expected, project.keys, source_file)
378
+ project_id = project[PROJECT_ID]
379
+ project_name = project[PROJECT]
380
+ project_type = project[TYPE]
381
+ validate_type(project_type, project_id)
382
+ # Validate Script(s).
383
+ [RUN, TEST, BUILD].each do |script_type|
384
+ if project.has_key?(script_type)
385
+ # Validate the LAMBDA functions don't need build scripts.
386
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Project type: #{Blufin::Terminal::format_highlight(TYPE_LAMBDA)} does not require #{Blufin::Terminal::format_invalid(script_type)} script(s).", 'This type of project does not support this.', true) if [BUILD].include?(script_type) && project_type == TYPE_LAMBDA
387
+ if project[script_type].is_a?(Hash)
388
+ script_key = script_key_mapper(script_type)
389
+ valid_scripts = []
390
+ valid_scripts = @@scripts[script_key].keys if @@scripts.has_key?(script_key)
391
+ script = project[script_type]
392
+ script_name = script['Script']
393
+ unless valid_scripts.include?(script_name)
394
+ error = valid_scripts.any? ? 'Valid values are:' : "There currently are no #{script_key} script(s) defined."
395
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 #{Blufin::Terminal::format_highlight(script_type)} \xe2\x80\x94 Invalid script reference: #{Blufin::Terminal::format_invalid(script_name)}. #{error}", valid_scripts)
404
396
  end
405
397
  end
406
398
  end
399
+ end
407
400
 
408
- # Validate Repository property.
409
- if project.has_key?(REPOSITORY)
410
- if project[REPOSITORY].has_key?(LOCAL)
411
- repo_path = project[REPOSITORY][LOCAL]
412
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Repository path not found: #{Blufin::Terminal::format_invalid(repo_path)}") unless Blufin::Files::path_exists(repo_path)
401
+ # Validate Repository property.
402
+ if project.has_key?(REPOSITORY)
403
+ if project[REPOSITORY].has_key?(LOCAL)
404
+ repo_path = project[REPOSITORY][LOCAL]
405
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Repository path not found: #{Blufin::Terminal::format_invalid(repo_path)}") unless Blufin::Files::path_exists(repo_path)
413
406
 
414
- end
415
407
  end
408
+ end
416
409
 
417
- # Validate Deployment property.
418
- if project.has_key?(DEPLOYMENT)
419
- expected = {
420
- DEPLOYMENT_BUCKET => true,
421
- DEPLOYMENT_FILES => true
422
- }
423
- Blufin::Validate::assert_valid_keys(expected, project[DEPLOYMENT].keys, source_file)
424
- end
410
+ # Validate Deployment property.
411
+ if project.has_key?(DEPLOYMENT)
412
+ expected = {
413
+ DEPLOYMENT_BUCKET => true,
414
+ DEPLOYMENT_FILES => true
415
+ }
416
+ Blufin::Validate::assert_valid_keys(expected, project[DEPLOYMENT].keys, source_file)
417
+ end
425
418
 
426
- # Validate API property.
427
- if project_type == TYPE_API || project_type == TYPE_API_SIMPLE
428
- # Make sure we have the API property.
429
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Missing property: #{Blufin::Terminal::format_highlight(API)}", "This property is required for project(s) with type: #{API}", true) unless project.has_key?(API)
430
- # Validate keys are in specific order.
431
- expected = {
432
- TITLE => true,
433
- ALIAS => true,
434
- DOMAIN => true,
435
- PROJECT_NAME => true,
436
- PROJECT_NAME_PASCAL_CASE => true,
437
- PORTS => true
438
- }
439
- Blufin::Validate::assert_valid_keys(expected, project[API].keys, source_file)
440
- expected_ports = {
441
- API => true,
442
- SCHEDULER => true,
443
- WORKER => true
444
- }
445
- Blufin::Validate::assert_valid_keys(expected_ports, project[API][PORTS].keys, source_file)
446
- validate_ports([project[API][PORTS][API], project[API][PORTS][SCHEDULER], project[API][PORTS][WORKER]], project_id, used_ports)
447
- # Add ports to used_ports.
448
- used_ports[project[API][PORTS][API]] = project_id
449
- used_ports[project[API][PORTS][SCHEDULER]] = project_id
450
- used_ports[project[API][PORTS][WORKER]] = project_id
451
- @@apis = {} if @@apis.nil?
452
- @@apis[project[PROJECT_ID]] = project
453
- else
454
- # Make sure we DON'T have the API key.
455
- 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)
456
- end
419
+ # Validate API property.
420
+ if project_type == TYPE_API || project_type == TYPE_API_SIMPLE
421
+ # Make sure we have the API property.
422
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Missing property: #{Blufin::Terminal::format_highlight(API)}", "This property is required for project(s) with type: #{API}", true) unless project.has_key?(API)
423
+ # Validate keys are in specific order.
424
+ expected = {
425
+ TITLE => true,
426
+ ALIAS => true,
427
+ DOMAIN => true,
428
+ PROJECT_NAME => true,
429
+ PROJECT_NAME_PASCAL_CASE => true,
430
+ PORTS => true
431
+ }
432
+ Blufin::Validate::assert_valid_keys(expected, project[API].keys, source_file)
433
+ expected_ports = {
434
+ API => true,
435
+ SCHEDULER => true,
436
+ WORKER => true
437
+ }
438
+ Blufin::Validate::assert_valid_keys(expected_ports, project[API][PORTS].keys, source_file)
439
+ validate_ports([project[API][PORTS][API], project[API][PORTS][SCHEDULER], project[API][PORTS][WORKER]], project_id, used_ports)
440
+ # Add ports to used_ports.
441
+ used_ports[project[API][PORTS][API]] = project_id
442
+ used_ports[project[API][PORTS][SCHEDULER]] = project_id
443
+ used_ports[project[API][PORTS][WORKER]] = project_id
444
+ @@apis = {} if @@apis.nil?
445
+ @@apis[project[PROJECT_ID]] = project
446
+ else
447
+ # Make sure we DON'T have the API key.
448
+ 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
+ end
457
450
 
458
- # Validate Lambda property.
459
- if project_type == TYPE_LAMBDA
460
- # Make sure we have the Lambda property.
461
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Missing property: #{Blufin::Terminal::format_highlight(LAMBDA)}", "This property is required for project(s) with type: #{TYPE_LAMBDA}", true) unless project.has_key?(LAMBDA)
462
- # Validate keys are in specific order.
463
- expected = {
464
- TITLE => true,
465
- ALIAS => true,
466
- PORT => true,
467
- STAGES => true
468
- }
469
- Blufin::Validate::assert_valid_keys(expected, project[LAMBDA].keys, source_file)
470
- validate_ports([project[LAMBDA][PORT]], project_id, used_ports)
471
- # Add ports to used_ports.
472
- used_ports[project[LAMBDA][PORT]] = project_id
473
- @@lambdas = {} if @@lambdas.nil?
474
- Blufin::Terminal::error("Duplicate Lambda project: #{Blufin::Terminal::format_invalid(project[PROJECT_ID])}") if @@lambdas.has_key?(project[PROJECT_ID])
475
- @@lambdas[project[PROJECT_ID]] = project
476
- else
477
- # Make sure we DON'T have the Lambda key.
478
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Property not supported: #{Blufin::Terminal::format_invalid(LAMBDA)}", "This property is only allowed for project(s) with type: #{TYPE_LAMBDA}", true) if project.has_key?(LAMBDA)
479
- end
451
+ # Validate Lambda property.
452
+ if project_type == TYPE_LAMBDA
453
+ # Make sure we have the Lambda property.
454
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Missing property: #{Blufin::Terminal::format_highlight(LAMBDA)}", "This property is required for project(s) with type: #{TYPE_LAMBDA}", true) unless project.has_key?(LAMBDA)
455
+ # Validate keys are in specific order.
456
+ expected = {
457
+ TITLE => true,
458
+ ALIAS => true,
459
+ PORT => true,
460
+ STAGES => true
461
+ }
462
+ Blufin::Validate::assert_valid_keys(expected, project[LAMBDA].keys, source_file)
463
+ validate_ports([project[LAMBDA][PORT]], project_id, used_ports)
464
+ # Add ports to used_ports.
465
+ used_ports[project[LAMBDA][PORT]] = project_id
466
+ @@lambdas = {} if @@lambdas.nil?
467
+ Blufin::Terminal::error("Duplicate Lambda project: #{Blufin::Terminal::format_invalid(project[PROJECT_ID])}") if @@lambdas.has_key?(project[PROJECT_ID])
468
+ @@lambdas[project[PROJECT_ID]] = project
469
+ else
470
+ # Make sure we DON'T have the Lambda key.
471
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Property not supported: #{Blufin::Terminal::format_invalid(LAMBDA)}", "This property is only allowed for project(s) with type: #{TYPE_LAMBDA}", true) if project.has_key?(LAMBDA)
472
+ end
480
473
 
481
- # Validate Quasar property.
482
- if project_type == TYPE_QUASAR
483
- # Make sure we have the QUASAR property.
484
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Missing property: #{Blufin::Terminal::format_highlight(QUASAR)}", "This property is required for project(s) with type: #{TYPE_QUASAR}", true) unless project.has_key?(QUASAR)
485
- # Validate keys are in specific order.
486
- expected = {
487
- ROUTES_FILE => true
488
- }
489
- Blufin::Validate::assert_valid_keys(expected, project[QUASAR].keys, source_file)
490
- # Validate RoutesFile exists.
491
- routes_file = "#{Blufin::Projects::get_project_path(project_id, true, project: project)}/#{project[QUASAR][ROUTES_FILE]}"
492
- Blufin::Terminal::error("Cannot find #{Blufin::Terminal::format_highlight(ROUTES_FILE)}: #{Blufin::Terminal::format_directory(routes_file)}") unless Blufin::Files::file_exists(routes_file)
493
- else
494
- # Make sure we DON'T have the UI key.
495
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Property not supported: #{Blufin::Terminal::format_invalid(QUASAR)}", "This property is only allowed for project(s) with type: #{TYPE_QUASAR}", true) if project.has_key?(QUASAR)
496
- end
474
+ # Validate Quasar property.
475
+ if project_type == TYPE_QUASAR
476
+ # Check .quasarrc exists.
477
+ quasarrc_file = "#{Blufin::Projects::get_project_path(project_id, true, project: project)}/#{QUASARRC}"
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
485
+ end
497
486
 
498
- # Validate upstream/downstream Libs(s).
499
- [UPSTREAM, DOWNSTREAM].each do |stream|
500
- if project.has_key?(stream)
501
- project[stream].each do |library|
502
- case stream
503
- when UPSTREAM
504
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Unrecognized #{Blufin::Terminal::format_action(UPSTREAM)} library: #{Blufin::Terminal::format_invalid(library)}") unless @@libs.keys.include?(library)
505
- when DOWNSTREAM
506
- Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Unrecognized #{Blufin::Terminal::format_action(DOWNSTREAM)} library: #{Blufin::Terminal::format_invalid(library)}") unless @@project_ids.include?(library)
507
- else
508
- raise RuntimeError, "Unrecognized stream: #{stream}"
509
- end
487
+ # Validate upstream/downstream Libs(s).
488
+ [UPSTREAM, DOWNSTREAM].each do |stream|
489
+ if project.has_key?(stream)
490
+ project[stream].each do |library|
491
+ case stream
492
+ when UPSTREAM
493
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Unrecognized #{Blufin::Terminal::format_action(UPSTREAM)} library: #{Blufin::Terminal::format_invalid(library)}") unless @@libs.keys.include?(library)
494
+ when DOWNSTREAM
495
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight(project_id)} \xe2\x80\x94 Unrecognized #{Blufin::Terminal::format_action(DOWNSTREAM)} library: #{Blufin::Terminal::format_invalid(library)}") unless @@project_ids.include?(library)
496
+ else
497
+ raise RuntimeError, "Unrecognized stream: #{stream}"
510
498
  end
511
499
  end
512
500
  end
501
+ end
513
502
 
514
- @@projects[project_name] = {} unless @@projects.has_key?(project_name)
515
- Blufin::Terminal::error("Duplicate project ID: #{Blufin::Terminal::format_invalid(project_id)}") if @@projects[project_name].has_key?(project_id)
516
- @@projects[project_name][project_id] = project
517
- @@projects_arr << project
503
+ @@projects[project_name] = {} unless @@projects.has_key?(project_name)
504
+ Blufin::Terminal::error("Duplicate project ID: #{Blufin::Terminal::format_invalid(project_id)}") if @@projects[project_name].has_key?(project_id)
505
+ @@projects[project_name][project_id] = project
506
+ @@projects_arr << project
518
507
 
519
- end
520
- @@project_names.uniq!
521
- @@project_names.sort!
522
508
  end
509
+ @@project_names.uniq!
510
+ @@project_names.sort!
511
+ end
512
+
513
+ # Standardized way of displaying YML Parser (Kwalify) errors.
514
+ # Script will terminate in this method.
515
+ # @return void
516
+ def display_parse_errors_if_any(errors, source_file)
517
+ if errors && !errors.empty?
518
+ errors_output = []
519
+ errors.each { |e|
520
+ errors_output << "[#{e.path}] #{e.message}"
521
+ }
522
+ Blufin::Terminal::error("Your configuration file is invalid. Please fix: #{Blufin::Terminal::format_directory(source_file)}", errors)
523
+ end
524
+ end
525
+
526
+ # Parses a YML file, bombs-out if something fails.
527
+ # @return Hash
528
+ def parse_yml(source_file)
529
+ begin
530
+ file_parsed = YAML.load_file(source_file)
531
+ rescue => e
532
+ Blufin::Terminal::error("Failed to parse config file: #{Blufin::Terminal::format_directory(source_file)}", e.message)
533
+ end
534
+ file_parsed
523
535
  end
524
536
 
525
537
  # Validate project type.
@@ -4,6 +4,20 @@ module Blufin
4
4
 
5
5
  SCHEMA_FILE = "#{Blufin::Base::get_base_path}#{Blufin::Base::OPT_PATH}/schema/routes.yml"
6
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
+
7
21
 
8
22
  # Generates routes in the UI.
9
23
  # @return void
@@ -13,36 +27,87 @@ module Blufin
13
27
  @warnings = []
14
28
  @files = []
15
29
  @files_to_create = []
30
+ root_path_seen = nil
16
31
  begin
17
32
  @output = <<TEMPLATE
18
33
  const routes = [
19
34
  {
20
35
  TEMPLATE
21
36
  project_path = Blufin::Projects::get_project_path(project[Blufin::Projects::PROJECT_ID], true)
22
- routes_file = "#{project_path}/#{project[Blufin::Projects::QUASAR][Blufin::Projects::ROUTES_FILE]}"
37
+ routes_file = "#{project_path}/#{project[Blufin::Projects::TRANSIENT_DATA][Blufin::Projects::QUASAR_ROUTES_FILE]}"
23
38
  routes_yml = Blufin::Yml::read_file(routes_file, SCHEMA_FILE)
24
- target_file = "#{project_path}/src/#{Blufin::Strings::remove_surrounding_slashes(routes_yml['RoutesFile'])}"
25
- layout = routes_yml['Layout']
26
- pages_root = routes_yml['PagesRoot']
27
- pages_not_found = routes_yml['Pages404']
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]
28
42
  path_pages_ignore = []
29
43
  path_to_pages = "#{project_path}/src/#{pages_root}"
44
+
30
45
  # Add ignore path(s) -- if exists.
31
- routes_yml['Ignore'].each { |ignore_path| path_pages_ignore << "#{Blufin::Strings::remove_surrounding_slashes(ignore_path)}" } if routes_yml.has_key?('Ignore')
32
- routes = routes_yml['Routes']
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]
33
50
  routes.each_with_index do |route, idx|
34
- comma = route.has_key?('Children') ? ',' : nil
35
- parent_path = route['Parent']['Path']
36
- @output += <<TEMPLATE
37
- path: '/#{route['Parent'].has_key?('RootPath') && route['Parent']['RootPath'] ? nil : parent_path}',
38
- sectionName: '#{route['Parent']['Name']}',
39
- sectionIcon: '#{route['Parent']['Icon']}',
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}
40
105
  component: () => import('./../#{layout}')#{comma}
41
106
  TEMPLATE
42
- file = parent_path == HOME_TERM ? "#{pages_root}/#{parent_path}/#{HOME_TERM}.vue" : "#{pages_root}/#{parent_path}/#{parent_path}-#{HOME_TERM}.vue"
107
+ file = "#{pages_root}/#{parent_path}/index.vue"
43
108
  prefix = parent_path == HOME_TERM ? 'dashboard/' : nil
44
109
  process_file(file, project_path)
45
- if route.has_key?('Children')
110
+ if route.has_key?(CHILDREN)
46
111
  @output += <<TEMPLATE
47
112
  children: [
48
113
  {
@@ -50,16 +115,18 @@ TEMPLATE
50
115
  component: () => import('./../#{file}')
51
116
  },
52
117
  TEMPLATE
53
- children = route['Children']
118
+ # Loop Children.
119
+ children = route[CHILDREN]
54
120
  children.each_with_index do |child, idx|
55
121
  comma = idx == children.length - 1 ? nil : ','
56
- file = "#{pages_root}/#{parent_path}/#{child['Path']}.vue"
122
+ file = "#{pages_root}/#{parent_path}/#{child[PATH]}.vue"
57
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]
58
125
  process_file(file, project_path)
59
126
  @output += <<TEMPLATE
60
127
  {
61
- path: '#{prefix}#{child['Path']}',
62
- name: '#{child['Name']}',#{disabled}
128
+ path: '#{prefix}#{child[PATH]}',
129
+ name: '#{child[NAME]}',#{disabled}
63
130
  component: () => import('./../#{file}')
64
131
  }#{comma}
65
132
  TEMPLATE
@@ -115,7 +182,7 @@ TEMPLATE
115
182
 
116
183
  # Check for rogue files.
117
184
  Blufin::Files::get_files_in_dir(path_to_pages).each do |file|
118
- next if file =~ /#{path_to_pages}\/(#{path_pages_ignore.join('|')})/
185
+ next if file =~ /#{path_to_pages}\/(#{path_pages_ignore.join('|')})\/[a-z0-9]/
119
186
  unless @files_to_create.include?(file)
120
187
  @warnings << "Found rogue file: #{Blufin::Terminal::format_invalid(file)}"
121
188
  end
@@ -131,7 +198,7 @@ TEMPLATE
131
198
  # Creates file if not exists
132
199
  # @return void
133
200
  def self.process_file(file, project_path)
134
- Blufin::Terminal::error("Duplicate file: #{Blufin::Terminal::format_invalid(file)}", 'Your configuration would produce a duplicate file. Please fix.') if @files.include?(file)
201
+ @errors << "Duplicate file: #{Blufin::Terminal::format_invalid(file)}" if @files.include?(file)
135
202
  @files << file
136
203
  @files_to_create << "#{project_path}/src/#{file}"
137
204
  end
@@ -146,12 +213,10 @@ TEMPLATE
146
213
  </div>
147
214
  </template>
148
215
 
149
- <script type="text/ecmascript-6">
216
+ <script>
150
217
  export default {
151
218
  data() {
152
- return {
153
- test: this.$route.path
154
- };
219
+ return {};
155
220
  }
156
221
  };
157
222
  </script>
@@ -4,28 +4,35 @@ module Blufin
4
4
 
5
5
  # Initialize the class.
6
6
  # @return void
7
- def initialize(java_path: nil, vue_path: nil)
8
-
9
- scan_java(java_path) unless java_path.nil?
10
- scan_vue(vue_path) unless vue_path.nil?
11
-
12
- end
13
-
14
- private
15
-
16
- # Scan Java code.
17
- # @return void
18
- def scan_java(path)
19
-
20
- Blufin::ScannerJava::scan(path)
21
-
22
- end
23
-
24
- # Scan Vue code.
25
- # @return void
26
- def scan_vue(path)
27
-
28
- Blufin::ScannerVue::scan(path)
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
+ }
29
36
 
30
37
  end
31
38
 
@@ -0,0 +1,75 @@
1
+ module Blufin
2
+
3
+ class ScannerError
4
+
5
+ attr_accessor :file, :line, :line_number, :error_type, :message
6
+
7
+ HEADER_COLOR = 240
8
+ LINE_COLOR = 184
9
+ ERROR_COLOR = 196
10
+ CODE_COLOR = 102
11
+
12
+ extend Columnist
13
+
14
+ # Initialize a ScannerError object.
15
+ # @return void
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}" unless line_number.to_s =~ /^\d+$/
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
23
+ self.message = message
24
+ end
25
+
26
+ # Static method to output the errors to Terminal.
27
+ # @return void
28
+ def self.output_cli(errors, clear_screen = true)
29
+ raise RuntimeError, "Expected Array, instead got: #{errors.class}" unless errors.is_a?(Array)
30
+ system('clear') if clear_screen
31
+ puts if clear_screen
32
+ @files = {}
33
+ errors.each do |error|
34
+ file = error.file
35
+ @files[file] = [] unless @files.has_key?(file)
36
+ @files[file] << error
37
+ end
38
+ @files.each do |file, inner_errors|
39
+ puts " #{highlight_filename(file)}"
40
+ table(:border => false) do
41
+ wildcard_width = Blufin::Terminal::get_terminal_width - 120
42
+ message_width = 100
43
+ row do
44
+ column('', :width => 2, :color => HEADER_COLOR)
45
+ column('-' * 5, :width => 5, :color => HEADER_COLOR)
46
+ column('-' * message_width, :width => message_width, :color => HEADER_COLOR)
47
+ column('-' * wildcard_width, :width => wildcard_width, :color => HEADER_COLOR)
48
+ column('', :width => 2, :color => HEADER_COLOR)
49
+ end
50
+ inner_errors.each do |error|
51
+ row do
52
+ column('')
53
+ column(error.line_number[0..5].ljust(5, ' '), :color => LINE_COLOR)
54
+ column(error.message[0..message_width], :color => ERROR_COLOR)
55
+ column(error.line.strip[0..wildcard_width], :color => CODE_COLOR)
56
+ column('')
57
+ end
58
+ end
59
+ end
60
+ puts
61
+ end
62
+ end
63
+
64
+ # Takes a file like '/Users/Albert/Repos/eworldes/fmm/client/src/js/app/overlays.js' and highlights 'overlays.js'
65
+ # @return string
66
+ def self.highlight_filename(file)
67
+ raise RuntimeError, "Expected String, instead got: #{file.class}" unless file.is_a?(String)
68
+ fs = file.split('/')
69
+ fl = fs.pop
70
+ "\x1B[48;5;233m \x1B[38;5;240m#{fs.join('/')}/\x1B[38;5;202m#{fl} \x1B[0m"
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,184 @@
1
+ module Blufin
2
+
3
+ class ScannerJs
4
+
5
+ DATA_TYPES = %w(string number boolean array object *)
6
+
7
+ # Scan Javascript code.
8
+ # @return void
9
+ def self.scan(path)
10
+
11
+ # Check path exists.
12
+ Blufin::Terminal::error("Path does not exist: #{Blufin::Terminal::format_invalid(path)}") unless Blufin::Files::path_exists(path)
13
+
14
+ @data = {}
15
+ @errors = []
16
+
17
+ # Get all file(s) in path.
18
+ Blufin::Files::get_files_in_dir(path, 'js').each { |file| scan_file(file) }
19
+
20
+ return @data, @errors
21
+
22
+ end
23
+
24
+ private
25
+
26
+ # Scans a file.
27
+ # @return void
28
+ def self.scan_file(file)
29
+
30
+ @file = file
31
+ @data[@file] = {}
32
+ @data[@file][:methods] = {}
33
+
34
+ @liner = nil
35
+ @line_number = 0
36
+ @params = nil
37
+ @docs = nil
38
+ @docs_active = false
39
+ @method_active = false
40
+
41
+ Blufin::Files::read_file(file).each do |line|
42
+
43
+ begin
44
+
45
+ @line = line.gsub("\n", '')
46
+ @line_number += 1
47
+
48
+ if @line =~ /^\s*\/+\s*\w.*$/ # // some comment
49
+ parse_comment(@line)
50
+ elsif @line =~ /^\s*\/\*+\s*.*$/ # /** OR *
51
+ @docs = {}
52
+ @docs_active = true
53
+ elsif @line =~ /^\s{4}\w+\s*(:\s*function)?\(.*\)\s*\{\s*(\}|\},)?\s*$/
54
+ # clear() {}
55
+ # clear() {},
56
+ # clear(key) {
57
+ # clear(key, value) {
58
+ # clear(key, value = null) {
59
+ # set: function() {
60
+ # set: function(key) {
61
+ # set: function(key, value) {
62
+ # set: function(key, value = null) {
63
+ @method_active = true
64
+ @params = {}
65
+ # Extract method data.
66
+ parse_method_definition(@line)
67
+
68
+ @docs = nil
69
+ else
70
+
71
+ # TODO - REMOVE
72
+ # puts line unless @docs_active || @method_active
73
+
74
+ end
75
+
76
+ # If we're inside a comment.
77
+ parse_comment(@line) if @docs_active
78
+
79
+ # Break out of comment ( ... */)
80
+ @docs_active = false if @line =~ /^.*\*+\/\s*$/
81
+
82
+ # Break out of method ( ... } OR }, )
83
+ @method_active = false if @line =~ /^\s{4}(\}|\},)\s*$/ || @line =~ /^\s{4}\w+\s*(:\s*function)?\(.*\)\s*\{\s*(\}|\},)\s*$/
84
+
85
+ rescue RuntimeError => e
86
+ @errors << Blufin::ScannerError.new(file, @line, @line_number, e.message)
87
+ next
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+
94
+ # Parses comments.
95
+ # @return void
96
+ def self.parse_comment(line)
97
+ if line =~ /^\s*\/\*+\s*.*$/
98
+ # /** OR *
99
+ return
100
+ elsif line =~ /^\s*\/+\s*\w.*$/
101
+ # // some comment
102
+ return
103
+ elsif line =~ /^\s*\*\/\s*$/
104
+ # */
105
+ return
106
+ elsif line =~ /^\s*\*+\s*[A-Za-z0-9].*$/
107
+ # * some comment
108
+ @docs[:description] = [] if @docs[:description].nil?
109
+ @docs[:description] << line.gsub(/^\s*\*\s*/, '').strip
110
+ elsif line =~ /^\s*\*+\s*@param\s*\{(\w|\*)+\}*.+$/
111
+ # * @param {string} parent - The parent key.
112
+ ls = line.gsub(/^\s*\*+\s*@param\s+/, '').split(' ')
113
+ type = extract_type(ls[0])
114
+ param_name = ls[1]
115
+ hyphen = ls[2]
116
+ description = ls.drop(3).join(' ')
117
+ raise RuntimeError, "Duplicate parameter: #{param_name}" if @docs[:params].is_a?(Hash) && @docs[:params].has_key?(param_name)
118
+ raise RuntimeError, "Expected hyphen after parameter name. IE: {#{type}} #{param_name} - ..." if ls.length > 2 && hyphen != '-'
119
+ @docs[:params] = {} if @docs[:params].nil?
120
+ @docs[:params][param_name] = {}
121
+ @docs[:params][param_name][:type] = type
122
+ @docs[:params][param_name][:description] = description
123
+ elsif line =~ /^\s*\*+\s*@returns\s+\{(\w|\*)+\}.*$/
124
+ # * @returns {boolean}
125
+ raise RuntimeError, 'Multiple return statement(s).' if @docs.has_key?(:return)
126
+ ls = line.gsub(/^\s*\*+\s*@returns\s+/, '').split(' ')
127
+ @docs[:return] = nil
128
+ @docs[:return] = extract_type(ls[0], true) if ls.any?
129
+ else
130
+ raise RuntimeError, 'Something is wrong with this line, it failed to parse.'
131
+ end
132
+ end
133
+
134
+ # Parses the 1st line of a method and extracts information about the parameters.
135
+ # @return void
136
+ def self.parse_method_definition(line)
137
+ method_name = line.strip.gsub(/\(.*$/, '')
138
+ method_private = method_name =~ /^_/ ? true : false
139
+ raise RuntimeError, "Duplicate method: #{method_name}" if @data[@file][:methods].keys.include?(method_name)
140
+ matches = line.match(/\(.*\)/)
141
+ raise RuntimeError, 'Unable to extract method parameters.' unless matches.length == 1
142
+ params = matches[0].strip.gsub(/^\(/, '').gsub(/\)$/, '')
143
+ params = params.split(',')
144
+ params.each do |param|
145
+ param.strip!
146
+ if param =~ /\w+\s*=\s*\w+/
147
+ ps = param.split('=')
148
+ raise RuntimeError, "Expected exactly one equal (=) sign, got: #{ps.length - 1}" unless ps.length == 2
149
+ param_extracted = ps[0].strip
150
+ raise RuntimeError, "Duplicate parameter: #{param_extracted}" if @params.has_key?(param_extracted)
151
+ @params[param_extracted] = {:default => ps[1].strip}
152
+ elsif param =~ /\w+/
153
+ raise RuntimeError, "Duplicate parameter: #{param}" if @params.has_key?(param)
154
+ @params[param] = {}
155
+ else
156
+ raise RuntimeError, "Unrecognized parameter: #{param}"
157
+ end
158
+ end
159
+ @docs = {:params => {}} unless @docs.is_a?(Hash)
160
+ @docs[:params] = {} unless @docs[:params].is_a?(Hash)
161
+ @data[@file][:methods][method_name] = {
162
+ :line => @line,
163
+ :line_number => @line_number,
164
+ :docs => @docs,
165
+ :params => @params,
166
+ :private => method_private
167
+ }
168
+ end
169
+
170
+ # Attempts to extract 'string' from something like '{string}'.
171
+ # Will throw Error if anything isn't right.
172
+ # @return string
173
+ def self.extract_type(string, allow_void = false)
174
+ types = DATA_TYPES
175
+ types << 'void' if allow_void
176
+ type = string.gsub(/^\{/, '').gsub(/\}$/, '')
177
+ raise RuntimeError, "Unrecognized data type: #{type}" unless types.include?(type.downcase)
178
+ raise RuntimeError, "Data types must be lowercase, found: #{type}" if type.downcase != 'array' && type != type.downcase
179
+ type
180
+ end
181
+
182
+ end
183
+
184
+ end
@@ -1 +1 @@
1
- BLUFIN_LIB_VERSION = '1.8.1'
1
+ BLUFIN_LIB_VERSION = '1.8.2'
@@ -0,0 +1,8 @@
1
+ type: map
2
+ mapping:
3
+ JsPath:
4
+ required: true
5
+ JsPathTests:
6
+ required: true
7
+ RoutesFile:
8
+ required: true
@@ -146,11 +146,6 @@ mapping:
146
146
  required: yes
147
147
  sequence:
148
148
  - type: str
149
- Quasar:
150
- type: map
151
- mapping:
152
- RoutesFile:
153
- required: yes
154
149
  UI:
155
150
  type: map
156
151
  mapping:
@@ -1,7 +1,5 @@
1
1
  type: map
2
2
  mapping:
3
- Layout:
4
- required: true
5
3
  PagesRoot:
6
4
  required: true
7
5
  Pages404:
@@ -22,14 +20,16 @@ mapping:
22
20
  type: map
23
21
  required: true
24
22
  mapping:
23
+ Layout:
24
+ required: true
25
25
  Path:
26
26
  required: true
27
27
  Name:
28
- required: true
29
28
  Icon:
30
- required: true
31
29
  RootPath:
32
30
  type: bool
31
+ Invisible:
32
+ type: bool
33
33
  Children:
34
34
  type: seq
35
35
  sequence:
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: 1.8.1
4
+ version: 1.8.2
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-13 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -152,9 +152,12 @@ files:
152
152
  - lib/generate/generate_base.rb
153
153
  - lib/generate/generate_ui_routes.rb
154
154
  - lib/scan/scanner.rb
155
+ - lib/scan/scanner_error.rb
155
156
  - lib/scan/scanner_java.rb
157
+ - lib/scan/scanner_js.rb
156
158
  - lib/scan/scanner_vue.rb
157
159
  - lib/version.rb
160
+ - opt/schema/projects-quasarrc.yml
158
161
  - opt/schema/projects.yml
159
162
  - opt/schema/routes.yml
160
163
  - opt/shell/ec2-check
@@ -178,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
181
  version: '0'
179
182
  requirements: []
180
183
  rubyforge_project:
181
- rubygems_version: 2.5.2.3
184
+ rubygems_version: 2.5.1
182
185
  signing_key:
183
186
  specification_version: 4
184
187
  summary: Blufin Lib