lib/js_dependency.rb in js_dependency-0.3.4 vs lib/js_dependency.rb in js_dependency-0.3.5
- old
+ new
@@ -3,10 +3,14 @@
require_relative "js_dependency/version"
require_relative "js_dependency/index_creator"
require_relative "js_dependency/mermaid/root"
require_relative "js_dependency/cli"
require_relative "js_dependency/target_pathname"
+require_relative "js_dependency/mermaid/target_pathname"
+require_relative "js_dependency/source_analysis/leave"
+require_relative "js_dependency/source_analysis/orphan"
+require_relative "js_dependency/pathname_utility"
require "pathname"
module JsDependency
class Error < StandardError; end
@@ -17,10 +21,26 @@
def self.export_index(src_path, alias_paths: nil, excludes: nil)
JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths, excludes: excludes)
end
# @param [String] src_path
+ # @param [Hash, nil] alias_paths
+ # @return [Array<String>]
+ def self.leave(src_path, alias_paths: nil)
+ index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths)
+ JsDependency::SourceAnalysis::Leave.new(index, src_path).call
+ end
+
+ # @param [String] src_path
+ # @param [Hash, nil] alias_paths
+ # @return [Array<String>]
+ def self.orphan(src_path, alias_paths: nil)
+ index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths)
+ JsDependency::SourceAnalysis::Orphan.new(index, src_path).call
+ end
+
+ # @param [String] src_path
# @param [Array<String>] target_paths
# @param [String] orientation
# @param [Hash, nil] alias_paths
# @param [Integer] child_analyze_level
# @param [Integer] parent_analyze_level
@@ -33,14 +53,14 @@
index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths, excludes: excludes)
nodes = []
styles = []
target_paths.each do |target_path|
- target_pathname = JsDependency::TargetPathname.new(target_path)
- styles += [target_pathname.mermaid_style(src_path)]
+ styles += [JsDependency::Mermaid::TargetPathname.new(target_path).mermaid_style(src_path)]
mermaid_root = JsDependency::Mermaid::Root.new(orientation)
+ target_pathname = JsDependency::TargetPathname.new(target_path)
target_pathname.each_parent_path(parent_analyze_level, index) do |parent_path, child_path|
mermaid_root.add(parent_path, child_path)
end
target_pathname.each_child_path(child_analyze_level, index) do |parent_path, child_path|
@@ -70,11 +90,11 @@
paths = []
target_pathname.each_parent_path(parent_analyze_level, index) do |parent_path, _child_path|
paths << parent_path
end
output = paths.uniq.sort.map do |path|
- Pathname.new(path).exist? ? Pathname.new(path).relative_path_from(Pathname.new(src_path).realpath.to_s).to_s : Pathname.new(path).to_s
+ JsDependency::PathnameUtility.relative_path_or_external_path(path, src_path)
end
output_pathname&.write(output.sort.join("\n"))
output
end
@@ -94,10 +114,10 @@
paths = []
target_pathname.each_child_path(child_analyze_level, index) do |_parent_path, child_path|
paths << child_path
end
output = paths.uniq.sort.map do |path|
- Pathname.new(path).exist? ? Pathname.new(path).relative_path_from(Pathname.new(src_path).realpath.to_s).to_s : Pathname.new(path).to_s
+ JsDependency::PathnameUtility.relative_path_or_external_path(path, src_path)
end
output_pathname&.write(output.sort.join("\n"))
output
end
end