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.3.14"

Class Method Summary collapse

Class Method Details

.children(src_path, target_path, alias_paths: nil, child_analyze_level: 1, output_path: nil, excludes: nil) ⇒ Array<Pathname>

Parameters:

  • src_path (String)
  • target_path (String)
  • orientation (String)
  • alias_paths (Hash, nil) (defaults to: nil)
  • child_analyze_level (Integer) (defaults to: 1)
  • output_path (String, nil) (defaults to: nil)
  • excludes (Array, nil) (defaults to: nil)

Returns:

  • (Array<Pathname>)


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/js_dependency.rb', line 112

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

Parameters:

  • src_path (String)
  • alias_paths (Hash, nil) (defaults to: nil)
  • excludes (Array, nil) (defaults to: nil)

Returns:

  • (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) ⇒ String

Parameters:

  • src_path (String)
  • target_paths (Array<String>)
  • orientation (String) (defaults to: "LR")
  • alias_paths (Hash, nil) (defaults to: nil)
  • child_analyze_level (Integer) (defaults to: 1)
  • parent_analyze_level (Integer) (defaults to: 1)
  • name_level (Integer) (defaults to: 1)
  • output_path (String, nil)
  • excludes (Array, nil) (defaults to: nil)
  • identifier (String, nil) (defaults to: nil)

Returns:

  • (String)


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/js_dependency.rb', line 139

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)

  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

Parameters:

  • src_path (String)
  • target_paths (Array<String>)
  • orientation (String) (defaults to: "LR")
  • alias_paths (Hash, nil) (defaults to: nil)
  • child_analyze_level (Integer) (defaults to: 1)
  • parent_analyze_level (Integer) (defaults to: 1)
  • name_level (Integer) (defaults to: 1)
  • output_path (String, nil) (defaults to: nil)
  • excludes (Array, nil) (defaults to: nil)

Returns:

  • (String)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/js_dependency.rb', line 54

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>

Parameters:

  • src_path (String)
  • alias_paths (Hash, nil) (defaults to: nil)

Returns:

  • (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) ⇒ Array<String>

Parameters:

  • src_path (String)
  • alias_paths (Hash, nil) (defaults to: nil)

Returns:

  • (Array<String>)


39
40
41
42
# File 'lib/js_dependency.rb', line 39

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

.parents(src_path, target_path, alias_paths: nil, parent_analyze_level: 1, output_path: nil, excludes: nil) ⇒ Array<Pathname>

Parameters:

  • src_path (String)
  • target_path (String)
  • orientation (String)
  • alias_paths (Hash, nil) (defaults to: nil)
  • parent_analyze_level (Integer) (defaults to: 1)
  • output_path (String, nil) (defaults to: nil)
  • excludes (Array, nil) (defaults to: nil)

Returns:

  • (Array<Pathname>)


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/js_dependency.rb', line 88

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