lib/js_dependency.rb in js_dependency-0.3.14 vs lib/js_dependency.rb in js_dependency-0.3.15

- old
+ new

@@ -34,13 +34,17 @@ end # @param [String] src_path # @param [Hash, nil] alias_paths # @return [Array<String>] - def self.orphan(src_path, alias_paths: nil) + def self.orphan(src_path, alias_paths: nil, exclude_output_names: []) index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths) - JsDependency::SourceAnalysis::Orphan.new(index, src_path).call + JsDependency::SourceAnalysis::Orphan.new(index, src_path).call.filter do |path| + exclude_output_names.none? do |name| + path.include?(name) + end + end end # @param [String] src_path # @param [Array<String>] target_paths # @param [String] orientation @@ -135,22 +139,26 @@ # @param [String, nil] output_path # @param [Array, nil] excludes # @param [String, nil] identifier # @return [String] def self.export_markdown_report(src_path, target_paths, orientation: "LR", alias_paths: nil, child_analyze_level: 1, - parent_analyze_level: 1, name_level: 1, excludes: nil, identifier: nil) - mermaid_markdown = JsDependency.export_mermaid( - src_path, - target_paths, - orientation: orientation, - alias_paths: alias_paths, - child_analyze_level: child_analyze_level, - parent_analyze_level: parent_analyze_level, - name_level: name_level, - excludes: excludes - ) - - orphan_list = JsDependency.orphan(src_path, alias_paths: alias_paths) + parent_analyze_level: 1, name_level: 1, excludes: nil, identifier: nil, exclude_output_names: []) + permitted_target_paths = JsDependency::PathnameUtility.filter_js_files(target_paths) + mermaid_markdown = if target_paths.nil? || target_paths.empty? + nil + else + JsDependency.export_mermaid( + src_path, + permitted_target_paths, + orientation: orientation, + alias_paths: alias_paths, + child_analyze_level: child_analyze_level, + parent_analyze_level: parent_analyze_level, + name_level: name_level, + excludes: excludes + ) + end + orphan_list = JsDependency.orphan(src_path, alias_paths: alias_paths, exclude_output_names: exclude_output_names) JsDependency::Report::Markdown.new(orphan_list, mermaid_markdown, identifier: identifier).export end end