Module: JsDependency
- Defined in:
- lib/js_dependency.rb,
lib/js_dependency/cli.rb,
lib/js_dependency/version.rb,
lib/js_dependency/mermaid/root.rb,
lib/js_dependency/index_creator.rb,
lib/js_dependency/cli_utils/yaml.rb,
lib/js_dependency/report/markdown.rb,
lib/js_dependency/target_pathname.rb,
lib/js_dependency/cli_utils/config.rb,
lib/js_dependency/pathname_utility.rb,
lib/js_dependency/mermaid/nodes_link.rb,
lib/js_dependency/replace_path_alias.rb,
lib/js_dependency/source_analysis/leave.rb,
lib/js_dependency/source_analysis/orphan.rb,
lib/js_dependency/mermaid/target_pathname.rb,
lib/js_dependency/extractor/extract_src_path.rb,
lib/js_dependency/extractor/extract_script_tag.rb,
lib/js_dependency/extractor/extract_import_path.rb
Defined Under Namespace
Modules: CliUtils, Extractor, Mermaid, PathnameUtility, Report, SourceAnalysis Classes: Cli, Error, IndexCreator, ReplacePathAlias, TargetPathname
Constant Summary collapse
- VERSION =
"0.4.1"
Class Method Summary collapse
- .children(src_path, target_path, alias_paths: nil, child_analyze_level: 1, output_path: nil, excludes: nil) ⇒ Array<Pathname>
- .export_index(src_path, alias_paths: nil, excludes: nil) ⇒ Hash
- .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, exclude_output_names: []) ⇒ String
- .export_mermaid(src_path, target_paths, orientation: "LR", alias_paths: nil, child_analyze_level: 1, parent_analyze_level: 1, name_level: 1, output_path: nil, excludes: nil) ⇒ String
- .leave(src_path, alias_paths: nil) ⇒ Array<String>
- .orphan(src_path, alias_paths: nil, exclude_output_names: []) ⇒ Array<String>
- .parents(src_path, target_path, alias_paths: nil, parent_analyze_level: 1, output_path: nil, excludes: nil) ⇒ Array<Pathname>
Class Method Details
.children(src_path, target_path, alias_paths: nil, child_analyze_level: 1, output_path: nil, excludes: nil) ⇒ Array<Pathname>
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/js_dependency.rb', line 116 def self.children(src_path, target_path, alias_paths: nil, child_analyze_level: 1, output_path: nil, excludes: nil) output_pathname = Pathname.new(output_path) if output_path index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths, excludes: excludes) target_pathname = JsDependency::TargetPathname.new(target_path) 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| JsDependency::PathnameUtility.relative_path_or_external_path(path, src_path) end output_pathname&.write(output.sort.join("\n")) output end |
.export_index(src_path, alias_paths: nil, excludes: nil) ⇒ Hash
24 25 26 |
# File 'lib/js_dependency.rb', line 24 def self.export_index(src_path, alias_paths: nil, excludes: nil) JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths, excludes: excludes) end |
.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, exclude_output_names: []) ⇒ String
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/js_dependency.rb', line 143 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, 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 |
.export_mermaid(src_path, target_paths, orientation: "LR", alias_paths: nil, child_analyze_level: 1, parent_analyze_level: 1, name_level: 1, output_path: nil, excludes: nil) ⇒ String
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/js_dependency.rb', line 58 def self.export_mermaid(src_path, target_paths, orientation: "LR", alias_paths: nil, child_analyze_level: 1, parent_analyze_level: 1, name_level: 1, output_path: nil, excludes: nil) output_pathname = Pathname.new(output_path) if output_path index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths, excludes: excludes) nodes = [] styles = [] target_paths.each do |target_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| mermaid_root.add(parent_path, child_path) end nodes += mermaid_root.export_nodes(name_level: name_level, src_path: src_path) end output = "#{(["flowchart LR"] + nodes.uniq + styles.uniq).join("\n")}\n" output_pathname&.write(output) output end |
.leave(src_path, alias_paths: nil) ⇒ Array<String>
31 32 33 34 |
# File 'lib/js_dependency.rb', line 31 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 |
.orphan(src_path, alias_paths: nil, exclude_output_names: []) ⇒ Array<String>
39 40 41 42 43 44 45 46 |
# File 'lib/js_dependency.rb', line 39 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.filter do |path| exclude_output_names.none? do |name| path.include?(name) end end end |
.parents(src_path, target_path, alias_paths: nil, parent_analyze_level: 1, output_path: nil, excludes: nil) ⇒ Array<Pathname>
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/js_dependency.rb', line 92 def self.parents(src_path, target_path, alias_paths: nil, parent_analyze_level: 1, output_path: nil, excludes: nil) output_pathname = Pathname.new(output_path) if output_path index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths, excludes: excludes) target_pathname = JsDependency::TargetPathname.new(target_path) 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| JsDependency::PathnameUtility.relative_path_or_external_path(path, src_path) end output_pathname&.write(output.sort.join("\n")) output end |