cobra_commander 0.1.2 → 0.2.0

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: 3a7c678173bc6ebeace6286a78b7bd0268c74300
4
- data.tar.gz: 784e159d2a26d02842dce69296578bde9df37345
3
+ metadata.gz: c08e78acc81afe93b06677fe59da88133927cd5a
4
+ data.tar.gz: 060cc5c2e75fdd9d85d9686cb9d34f23e2b60eba
5
5
  SHA512:
6
- metadata.gz: 3ff4cb4752fdcb18429da501d8dd9eac5c98f6f6a330a122ceafd1d5b2815639b65d3c0634be6b60e9e00d0a6a13eb4d603ca648cee57e38170e99168925a918
7
- data.tar.gz: 904df2c43fbccb55a5002e0e83e4baa9fe237e8f46bbf24088fe6b3a7e1b82304fff7e2cb0a72e55f8da68e78f3b40d4155e70dba62c5194ced18ec78cfd8862
6
+ metadata.gz: 1b9341d5b477afc484ff76eff6eab70efa90ff26e9ff4df804737ecc36db2d5b4bd0d2644565226b2d46e8db69919aa70880c48a35b1138ed272a5b832d78258
7
+ data.tar.gz: 953c630c3f7751ad8306f8098e3bf815f0d79d57931c2b23cafdfd6e70bf5d9a0a535bc9799e3bb591226b1df28bfb68256f7c29884bab455fc4ab167578bd68
data/.gitignore CHANGED
@@ -9,4 +9,7 @@
9
9
  /pkg/
10
10
  /spec/examples.txt
11
11
  /spec/reports/
12
+ /spec/fixtures/app/node_modules/
13
+ /spec/fixtures/app/node_manifest/node_modules/
14
+ /spec/fixtures/app/components/*/node_modules/
12
15
  /tmp/
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## Unreleased
4
+
5
+ ## Version 0.2.0 - 2017-09-01
6
+
7
+ ### Added
8
+
9
+ * Track javascript components via package.json links. PR [#10](https://github.com/powerhome/cobra_commander/pull/10)
10
+
11
+ * Alphabetize dependencies in `ls` & `changes` output. PR [#10](https://github.com/powerhome/cobra_commander/pull/10)
12
+
13
+ * Add component type to `changes` output. PR [#10](https://github.com/powerhome/cobra_commander/pull/10)
14
+
3
15
  ## Version 0.1.2 - 2017-05-08
4
16
 
5
17
  ### Fixed
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Code Climate](https://img.shields.io/codeclimate/github/powerhome/cobra_commander.svg)](https://codeclimate.com/github/powerhome/cobra_commander)
7
7
  [![Gemnasium](https://img.shields.io/gemnasium/powerhome/cobra_commander.svg)](https://gemnasium.com/github.com/powerhome/cobra_commander)
8
8
 
9
- Tools for working with Component Based Rails Apps (see http://shageman.github.io/cbra.info/). Includes tools for graphing the components of an app and their relationships, as well as selectively testing components based on changes made.
9
+ Tools for working with Component Based Rails Apps (see http://shageman.github.io/cbra.info/). Includes tools for graphing both Ruby and Javascript components in an application and their relationships, as well as selectively testing components based on changes made.
10
10
 
11
11
  ## Installation
12
12
 
@@ -6,22 +6,29 @@ module CobraCommander
6
6
  attr_reader :directly, :transitively
7
7
 
8
8
  def initialize(tree, changes, path)
9
+ @tree = tree
9
10
  @changes = changes
10
11
  @path = path
11
- @transitively = Set.new
12
- @directly = Set.new
13
- find_dependencies(tree)
14
- @transitively.delete(name: UMBRELLA_APP_NAME, path: @path)
12
+ run!
15
13
  end
16
14
 
17
15
  def needs_testing
18
- @needs_testing ||= (@directly + @transitively).map! do |component|
16
+ @needs_testing ||= all_affected.map! do |component|
19
17
  File.join(component[:path], "test.sh")
20
18
  end
21
19
  end
22
20
 
23
21
  private
24
22
 
23
+ def run!
24
+ @transitively = Set.new
25
+ @directly = Set.new
26
+ find_dependencies(@tree)
27
+ @transitively.delete(name: UMBRELLA_APP_NAME, path: @path, type: @tree[:type])
28
+ @transitively = @transitively.to_a.sort_by { |h| h[:name] }
29
+ @directly = @directly.to_a.sort_by { |h| h[:name] }
30
+ end
31
+
25
32
  def find_dependencies(parent_component)
26
33
  parent_component[:dependencies].each do |component|
27
34
  add_if_changed(component)
@@ -37,5 +44,9 @@ module CobraCommander
37
44
  end
38
45
  end
39
46
  end
47
+
48
+ def all_affected
49
+ (@directly + @transitively).uniq.sort_by { |h| h[:path] }
50
+ end
40
51
  end
41
52
  end
@@ -63,13 +63,13 @@ module CobraCommander
63
63
 
64
64
  def directly_affected_components
65
65
  puts "<<< Directly affected components >>>"
66
- @affected.directly.each { |component| puts component[:name] }
66
+ @affected.directly.each { |component| puts display(component) }
67
67
  puts blank_line
68
68
  end
69
69
 
70
70
  def transitively_affected_components
71
71
  puts "<<< Transitively affected components >>>"
72
- @affected.transitively.each { |component| puts component[:name] }
72
+ @affected.transitively.each { |component| puts display(component) }
73
73
  puts blank_line
74
74
  end
75
75
 
@@ -78,6 +78,10 @@ module CobraCommander
78
78
  @affected.needs_testing.each { |script| puts script }
79
79
  end
80
80
 
81
+ def display(component)
82
+ "#{component[:name]} - #{component[:type]}"
83
+ end
84
+
81
85
  def blank_line
82
86
  ""
83
87
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "json"
4
+
3
5
  module CobraCommander
4
6
  # Representation of the tree of components and their dependencies
5
7
  class ComponentTree
@@ -8,50 +10,122 @@ module CobraCommander
8
10
  end
9
11
 
10
12
  def to_h
11
- GemComponentTree.new(UMBRELLA_APP_NAME, @root_path).to_h
13
+ Tree.new(UMBRELLA_APP_NAME, @root_path).to_h
12
14
  end
13
15
 
14
- # Represents a tree of gem components with dependencies extracted via Bundler
15
- class GemComponentTree
16
+ # Generates component tree
17
+ class Tree
16
18
  def initialize(name, path, ancestry = Set.new)
17
19
  @name = name
18
20
  @root_path = path
19
21
  @ancestry = ancestry
22
+ @ruby = Ruby.new(path)
23
+ @js = Js.new(path)
24
+ @type = type_of_component
20
25
  end
21
26
 
22
27
  def to_h
23
28
  {
24
29
  name: @name,
25
30
  path: @root_path,
31
+ type: @type,
26
32
  ancestry: @ancestry,
27
- dependencies: component_dependencies.map(&method(:dep_representation)),
33
+ dependencies: dependencies.map(&method(:dep_representation)),
28
34
  }
29
35
  end
30
36
 
31
37
  private
32
38
 
33
- def gemfile_path
34
- File.join(@root_path, "Gemfile")
39
+ def type_of_component
40
+ return "Ruby & JS" if @ruby.gem? && @js.node?
41
+ return "Ruby" if @ruby.gem?
42
+ return "JS" if @js.node?
35
43
  end
36
44
 
37
- def gemfile_lock_path
38
- File.join(@root_path, "Gemfile.lock")
45
+ def dependencies
46
+ @deps ||= begin
47
+ deps = @ruby.dependencies + @js.dependencies
48
+ deps.sort_by { |dep| dep[:name] }
49
+ end
39
50
  end
40
51
 
41
- def bundler_definition
42
- ::Bundler::Definition.build(gemfile_path, gemfile_lock_path, nil)
52
+ def dep_representation(dep)
53
+ full_path = File.expand_path(File.join(@root_path, dep[:path]))
54
+ ancestry = @ancestry + [{ name: @name, path: @root_path, type: @type }]
55
+ self.class.new(dep[:name], full_path, ancestry).to_h
43
56
  end
44
57
 
45
- def component_dependencies
46
- bundler_definition.dependencies.select do |dep|
47
- dep.source&.is_a_path? && dep.source.path.to_s != "."
58
+ # Calculates ruby dependencies
59
+ class Ruby
60
+ def initialize(root_path)
61
+ @root_path = root_path
62
+ end
63
+
64
+ def dependencies
65
+ @deps ||= begin
66
+ return [] unless gem?
67
+ gems = bundler_definition.dependencies.select do |dep|
68
+ dep.source&.is_a_path? && dep.source.path.to_s != "."
69
+ end
70
+ format(gems)
71
+ end
72
+ end
73
+
74
+ def format(deps)
75
+ deps.map do |dep|
76
+ path = File.join(dep.source.path, dep.name)
77
+ { name: dep.name, path: path }
78
+ end
79
+ end
80
+
81
+ def gem?
82
+ @gem ||= File.exist?(gemfile_path)
83
+ end
84
+
85
+ def bundler_definition
86
+ ::Bundler::Definition.build(gemfile_path, gemfile_lock_path, nil)
87
+ end
88
+
89
+ def gemfile_path
90
+ File.join(@root_path, "Gemfile")
91
+ end
92
+
93
+ def gemfile_lock_path
94
+ File.join(@root_path, "Gemfile.lock")
48
95
  end
49
96
  end
50
97
 
51
- def dep_representation(dep)
52
- path = File.expand_path(File.join(@root_path, dep.source.path, dep.name))
53
- ancestry = @ancestry + [{ name: @name, path: @root_path }]
54
- self.class.new(dep.name, path, ancestry).to_h
98
+ # Calculates js dependencies
99
+ class Js
100
+ def initialize(root_path)
101
+ @root_path = root_path
102
+ end
103
+
104
+ def dependencies
105
+ @deps ||= begin
106
+ return [] unless node?
107
+ json = JSON.parse(File.read(package_json_path))
108
+ format(json["dependencies"])
109
+ end
110
+ end
111
+
112
+ def format(deps)
113
+ return [] if deps.nil?
114
+ linked_deps = deps.select { |_, v| v.start_with? "link:" }
115
+ linked_deps.map do |_, v|
116
+ relational_path = v.split("link:")[1]
117
+ dep_name = relational_path.split("/")[-1]
118
+ { name: dep_name, path: relational_path }
119
+ end
120
+ end
121
+
122
+ def node?
123
+ @node ||= File.exist?(package_json_path)
124
+ end
125
+
126
+ def package_json_path
127
+ File.join(@root_path, "package.json")
128
+ end
55
129
  end
56
130
  end
57
131
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CobraCommander
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cobra_commander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Langfeld
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-05-08 00:00:00.000000000 Z
12
+ date: 2017-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  requirements: []
195
195
  rubyforge_project:
196
- rubygems_version: 2.5.2
196
+ rubygems_version: 2.6.13
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Tools for working with Component Based Rails Apps