js_dependency 0.3.6 → 0.3.9

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
  SHA256:
3
- metadata.gz: 201aa2538971ea1e938c32236410e2b31ada21abbcd9f90141b84b08b132e7bb
4
- data.tar.gz: fd6c9eb934ea1f884f885e0bce39c989ab2536a10faa33f900bcc95418f41fa6
3
+ metadata.gz: e6ac19bdd54aa746f7e5f40bb7cf8c92660eb8384c074347734f8e484d60d878
4
+ data.tar.gz: a5f4a090fec3d3a4af1c8a8b5747efc830f8f92c4f29dce852e91348c0d867c6
5
5
  SHA512:
6
- metadata.gz: 0641c8506997b0bf21e4ec9cede06096fbc9b523e8e4e39954bb4a63eb73d551772945efa73c7e1098b0481cf70b0fc87eb291140f57db6b7599901b958a1b78
7
- data.tar.gz: c0c38b6e23cb29d54a40009aba2290543d9706366eb45a092cbbd4e47817972e161e0830bbc51081e76bbd85899247d02bf851345030126c715e2e4e6e2d6e8e
6
+ metadata.gz: '0902a104039ef853937b3d1739ec0f1fe249d17f7428d23457124e66b16003a8f7a3136ceefb14a6f3122c99bfcbeeeec0f77d589066f6e0956d95e11b36b963'
7
+ data.tar.gz: 746f673194445bf43f180a2ec650bd2530795e9966e8cc6a35f5bb55d37ff8688187ceaff41475117bd166d6a788624a3bbb63555b52901231a5d46dace1f4dd
data/.rubocop_todo.yml CHANGED
@@ -1,47 +1,42 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-08-11 04:37:50 UTC using RuboCop version 1.34.1.
3
+ # on 2022-08-11 15:14:43 UTC using RuboCop version 1.34.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 5
9
+ # Offense count: 3
10
10
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
11
11
  Metrics/AbcSize:
12
- Max: 42
13
-
14
- # Offense count: 1
15
- # Configuration parameters: CountComments, CountAsOne.
16
- Metrics/ClassLength:
17
- Max: 129
12
+ Max: 33
18
13
 
19
- # Offense count: 5
14
+ # Offense count: 3
20
15
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
21
16
  Metrics/CyclomaticComplexity:
22
- Max: 18
17
+ Max: 19
23
18
 
24
- # Offense count: 9
19
+ # Offense count: 8
25
20
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
26
21
  Metrics/MethodLength:
27
- Max: 26
22
+ Max: 19
28
23
 
29
24
  # Offense count: 3
30
25
  # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
31
26
  Metrics/ParameterLists:
32
27
  Max: 9
33
28
 
34
- # Offense count: 5
29
+ # Offense count: 3
35
30
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
36
31
  Metrics/PerceivedComplexity:
37
- Max: 19
32
+ Max: 20
38
33
 
39
34
  # Offense count: 1
40
35
  Style/MultilineBlockChain:
41
36
  Exclude:
42
37
  - 'lib/js_dependency/mermaid/root.rb'
43
38
 
44
- # Offense count: 4
39
+ # Offense count: 8
45
40
  # This cop supports safe autocorrection (--autocorrect).
46
41
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
47
42
  # URISchemes: http, https
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.9] - 2022-08-12
4
+
5
+ - Add alias_paths options of hash.
6
+
7
+ ## [0.3.8] - 2022-08-11
8
+
9
+ - `.js_dependecy.yaml` is arrowed for configuration file name.
10
+ - Refactor codes.
11
+ - Add test codes.
12
+
13
+ ## [0.3.7] - 2022-08-11
14
+
15
+ - If target is index.js, orphan include in analysis.
16
+
3
17
  ## [0.3.6] - 2022-08-11
4
18
 
5
19
  - Add src path in script tag for create index.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- js_dependency (0.3.6)
4
+ js_dependency (0.3.9)
5
5
  pathname
6
6
  thor
7
7
  yaml
data/README.md CHANGED
@@ -56,6 +56,7 @@ parent_analyze_level -> -p
56
56
  name_level -> -n
57
57
  output_path -> -o
58
58
  exclude -> -e
59
+ alias_paths -> -a
59
60
  ```
60
61
 
61
62
  #### Export Mermaid Format
@@ -63,31 +64,31 @@ exclude -> -e
63
64
  ##### Single target path
64
65
 
65
66
  ```shell
66
- js_dependency -s ./src -t ./src/App.vue -o ./mermaid.txt -c 2 -p 2 -n 1
67
+ js_dependency -s ./src -t ./src/App.vue -o ./mermaid.txt -c 2 -p 2 -n 1 -a @:./pages
67
68
  ```
68
69
 
69
70
  ##### Multiple target paths
70
71
 
71
72
  ```shell
72
- js_dependency -s ./src -t ./src/App.vue ./src/components/Sub.vue -o ./mermaid.txt -c 2 -p 2 -n 1
73
+ js_dependency -s ./src -t ./src/App.vue ./src/components/Sub.vue -o ./mermaid.txt -c 2 -p 2 -n 1 -a @:./pages
73
74
  ```
74
75
 
75
- ##### Exclude path which iclude exclude words `-e` from output
76
+ ##### Exclude path which include exclude words `-e` from output
76
77
 
77
78
  ```shell
78
- js_dependency -s ./src -t ./src/App.vue -o ./mermaid.txt -c 2 -p 2 -n 1 -e excludeWord1 excludeWord2
79
+ js_dependency -s ./src -t ./src/App.vue -o ./mermaid.txt -c 2 -p 2 -n 1 -e excludeWord1 excludeWord2 -a @:./pages
79
80
  ```
80
81
 
81
82
  #### Export parents components list
82
83
 
83
84
  ```shell
84
- js_dependency parents -s ./src -t ./src/App.vue -o ./parents.txt -p 2
85
+ js_dependency parents -s ./src -t ./src/App.vue -o ./parents.txt -p 2 -a @:./pages
85
86
  ```
86
87
 
87
88
  #### Export children components list
88
89
 
89
90
  ```shell
90
- js_dependency childrent -s ./src -t ./src/App.vue -o ./children.txt -c 2
91
+ js_dependency childrent -s ./src -t ./src/App.vue -o ./children.txt -c 2 -a @:./pages
91
92
  ```
92
93
 
93
94
  #### Export orphan components list
@@ -95,7 +96,7 @@ js_dependency childrent -s ./src -t ./src/App.vue -o ./children.txt -c 2
95
96
  Components that are not used in other components.
96
97
 
97
98
  ```shell
98
- js_dependency orphan -s ./src
99
+ js_dependency orphan -s ./src -a @:./pages
99
100
  ```
100
101
 
101
102
  #### Export left components list
@@ -103,7 +104,7 @@ js_dependency orphan -s ./src
103
104
  Components that do not import other components.
104
105
 
105
106
  ```shell
106
- js_dependency leave -s ./src
107
+ js_dependency leave -s ./src -a @:./pages
107
108
  ```
108
109
 
109
110
  ### By ruby code
@@ -8,152 +8,96 @@ module JsDependency
8
8
  default_command :export_mermaid
9
9
 
10
10
  desc "export_mermaid", "Output mermaid flowchart string."
11
- option :src_path, type: :string, aliases: "-s", desc: "Root folder."
12
- option :target_paths, type: :array, aliases: "-t", desc: "Target file that you want to analyze."
13
- option :output_path, type: :string, aliases: "-o", desc: "Output file path"
14
- option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
15
- option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
16
- option :name_level, type: :numeric, aliases: "-n", desc: "Output name level"
17
- option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
11
+ method_option :src_path, type: :string, aliases: "-s", desc: "Root folder."
12
+ method_option :target_paths, type: :array, aliases: "-t", desc: "Target file that you want to analyze."
13
+ method_option :output_path, type: :string, aliases: "-o", desc: "Output file path"
14
+ method_option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
15
+ method_option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
16
+ method_option :name_level, type: :numeric, aliases: "-n", desc: "Output name level"
17
+ method_option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
18
+ method_option :alias_paths, type: :hash, aliases: "-a", desc: "Alias paths by hash format."
18
19
 
19
20
  def export_mermaid
20
- pathname = Pathname.new(".js_dependency.yml")
21
- args = {}
22
- args = YAML.safe_load(pathname.read) if pathname.exist?
23
-
24
- src_path = options[:src_path] || args["src_path"]
25
- target_paths = options[:target_paths] || (args["target_path"].is_a?(String) ? [args["target_path"]] : args["target_path"])
26
- child_analyze_level = options[:child_analyze_level] || args["child_analyze_level"] || 2
27
- parent_analyze_level = options[:parent_analyze_level] || args["parent_analyze_level"] || 2
28
- output_path = options[:output_path] || args["output_path"] || nil
29
- alias_paths = args["alias_paths"] || nil
30
- name_level = options[:name_level] || args["name_level"] || 1
31
- excludes = if options[:excludes]&.length&.positive?
32
- options[:excludes]
33
- elsif args["excludes"]
34
- args["excludes"]
35
- end
36
-
37
- str = JsDependency.export_mermaid(
38
- src_path,
39
- target_paths,
40
- child_analyze_level: child_analyze_level,
41
- parent_analyze_level: parent_analyze_level,
42
- output_path: output_path,
43
- alias_paths: alias_paths,
44
- name_level: name_level,
45
- excludes: excludes
21
+ args = JsDependency::CliUtils::Yaml.new.args
22
+ config = JsDependency::CliUtils::Config.new(options, args)
23
+ puts JsDependency.export_mermaid(
24
+ config.src_path,
25
+ config.target_paths,
26
+ child_analyze_level: config.child_analyze_level,
27
+ parent_analyze_level: config.parent_analyze_level,
28
+ output_path: config.output_path,
29
+ alias_paths: config.alias_paths,
30
+ name_level: config.name_level,
31
+ excludes: config.excludes
46
32
  )
47
-
48
- puts str
49
33
  end
50
34
 
51
35
  desc "parents", "export parents list"
52
- option :src_path, type: :string, aliases: "-s", desc: "Root folder."
53
- option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
54
- option :output_path, type: :string, aliases: "-o", desc: "Output file path"
55
- option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
56
- option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
36
+ method_option :src_path, type: :string, aliases: "-s", desc: "Root folder."
37
+ method_option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
38
+ method_option :output_path, type: :string, aliases: "-o", desc: "Output file path"
39
+ method_option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
40
+ method_option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
41
+ method_option :alias_paths, type: :hash, aliases: "-a", desc: "Alias paths by hash format."
57
42
 
58
43
  def parents
59
- pathname = Pathname.new(".js_dependency.yml")
60
- args = {}
61
- args = YAML.safe_load(pathname.read) if pathname.exist?
62
-
63
- src_path = options[:src_path] || args["src_path"]
64
- target_path = options[:target_path] || args["target_path"]
65
- parent_analyze_level = options[:parent_analyze_level] || args["parent_analyze_level"] || 1
66
- output_path = options[:output_path] || args["output_path"] || nil
67
- alias_paths = args["alias_paths"] || nil
68
- excludes = if options[:excludes]&.length&.positive?
69
- options[:excludes]
70
- elsif args["excludes"]
71
- args["excludes"]
72
- end
73
-
74
- str = JsDependency.parents(
75
- src_path,
76
- target_path,
77
- parent_analyze_level: parent_analyze_level,
78
- output_path: output_path,
79
- alias_paths: alias_paths,
80
- excludes: excludes
44
+ args = JsDependency::CliUtils::Yaml.new.args
45
+ config = JsDependency::CliUtils::Config.new(options, args)
46
+ puts JsDependency.parents(
47
+ config.src_path,
48
+ config.target_path,
49
+ parent_analyze_level: config.parent_analyze_level,
50
+ output_path: config.output_path,
51
+ alias_paths: config.alias_paths,
52
+ excludes: config.excludes
81
53
  ).join("\n")
82
-
83
- puts str
84
54
  end
85
55
 
86
56
  desc "children", "export children list"
87
- option :src_path, type: :string, aliases: "-s", desc: "Root folder."
88
- option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
89
- option :output_path, type: :string, aliases: "-o", desc: "Output file path"
90
- option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
91
- option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
57
+ method_option :src_path, type: :string, aliases: "-s", desc: "Root folder."
58
+ method_option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
59
+ method_option :output_path, type: :string, aliases: "-o", desc: "Output file path"
60
+ method_option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
61
+ method_option :excludes, type: :array, aliases: "-e", desc: "Exclude the word that is included in the path"
62
+ method_option :alias_paths, type: :hash, aliases: "-a", desc: "Alias paths by hash format."
92
63
 
93
64
  def children
94
- pathname = Pathname.new(".js_dependency.yml")
95
- args = {}
96
- args = YAML.safe_load(pathname.read) if pathname.exist?
97
-
98
- src_path = options[:src_path] || args["src_path"]
99
- target_path = options[:target_path] || args["target_path"]
100
- child_analyze_level = options[:child_analyze_level] || args["child_analyze_level"] || 1
101
- output_path = options[:output_path] || args["output_path"] || nil
102
- alias_paths = args["alias_paths"] || nil
103
- excludes = if options[:excludes]&.length&.positive?
104
- options[:excludes]
105
- elsif args["excludes"]
106
- args["excludes"]
107
- end
108
-
109
- str = JsDependency.children(
110
- src_path,
111
- target_path,
112
- child_analyze_level: child_analyze_level,
113
- output_path: output_path,
114
- alias_paths: alias_paths,
115
- excludes: excludes
65
+ args = JsDependency::CliUtils::Yaml.new.args
66
+ config = JsDependency::CliUtils::Config.new(options, args)
67
+ puts JsDependency.children(
68
+ config.src_path,
69
+ config.target_path,
70
+ child_analyze_level: config.child_analyze_level,
71
+ output_path: config.output_path,
72
+ alias_paths: config.alias_paths,
73
+ excludes: config.excludes
116
74
  ).join("\n")
117
-
118
- puts str
119
75
  end
120
76
 
121
77
  desc "orphan", "export components than is not depended by others"
122
- option :src_path, type: :string, aliases: "-s", desc: "Root folder."
78
+ method_option :src_path, type: :string, aliases: "-s", desc: "Root folder."
79
+ method_option :alias_paths, type: :hash, aliases: "-a", desc: "Alias paths by hash format."
123
80
 
124
81
  def orphan
125
- pathname = Pathname.new(".js_dependency.yml")
126
- args = {}
127
- args = YAML.safe_load(pathname.read) if pathname.exist?
128
-
129
- src_path = options[:src_path] || args["src_path"]
130
- alias_paths = args["alias_paths"] || nil
131
-
132
- str = JsDependency.orphan(
133
- src_path,
134
- alias_paths: alias_paths
82
+ args = JsDependency::CliUtils::Yaml.new.args
83
+ config = JsDependency::CliUtils::Config.new(options, args)
84
+ puts JsDependency.orphan(
85
+ config.src_path,
86
+ alias_paths: config.alias_paths
135
87
  ).join("\n")
136
-
137
- puts str
138
88
  end
139
89
 
140
90
  desc "leave", "export components than is not depended by others"
141
- option :src_path, type: :string, aliases: "-s", desc: "Root folder."
91
+ method_option :src_path, type: :string, aliases: "-s", desc: "Root folder."
92
+ method_option :alias_paths, type: :hash, aliases: "-a", desc: "Alias paths by hash format."
142
93
 
143
94
  def leave
144
- pathname = Pathname.new(".js_dependency.yml")
145
- args = {}
146
- args = YAML.safe_load(pathname.read) if pathname.exist?
147
-
148
- src_path = options[:src_path] || args["src_path"]
149
- alias_paths = args["alias_paths"] || nil
150
-
151
- str = JsDependency.leave(
152
- src_path,
153
- alias_paths: alias_paths
95
+ args = JsDependency::CliUtils::Yaml.new.args
96
+ config = JsDependency::CliUtils::Config.new(options, args)
97
+ puts JsDependency.leave(
98
+ config.src_path,
99
+ alias_paths: config.alias_paths
154
100
  ).join("\n")
155
-
156
- puts str
157
101
  end
158
102
 
159
103
  desc "version", "show version"
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsDependency
4
+ module CliUtils
5
+ class Config
6
+ attr_reader :src_path, :target_paths, :target_path, :child_analyze_level, :parent_analyze_level, :output_path,
7
+ :alias_paths, :name_level, :excludes
8
+
9
+ # @param [Hash] options
10
+ # @param [Hash] args
11
+ def initialize(options, args)
12
+ @src_path = options[:src_path] || args[:src_path]
13
+ @target_paths = options[:target_paths] || (args[:target_path].is_a?(String) ? [args[:target_path]] : args[:target_path])
14
+ @target_path = options[:target_path] || args[:target_path]
15
+ @child_analyze_level = options[:child_analyze_level] || args[:child_analyze_level] || 2
16
+ @parent_analyze_level = options[:parent_analyze_level] || args[:parent_analyze_level] || 2
17
+ @output_path = options[:output_path] || args[:output_path] || nil
18
+ @alias_paths = options[:alias_paths] || args[:alias_paths] || {}
19
+ @name_level = options[:name_level] || args[:name_level] || 1
20
+ @excludes = if options[:excludes]&.length&.positive?
21
+ options[:excludes]
22
+ elsif args[:excludes]
23
+ args[:excludes]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsDependency
4
+ module CliUtils
5
+ class Yaml
6
+ attr_reader :args,
7
+ :dir_path
8
+
9
+ # @param [String, nil] dir_path
10
+ def initialize(dir_path: nil)
11
+ @dir_path = dir_path || Dir.pwd
12
+ pathname = config_pathname
13
+ @args = if pathname.nil?
14
+ {}
15
+ else
16
+ symbolize_keys(YAML.safe_load(pathname.read))
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ # @return [Pathname, nil]
23
+ def config_pathname
24
+ dir_pathname = Pathname.new(@dir_path)
25
+ pathname = nil
26
+ %w[.js_dependency.yml .js_dependency.yaml].each do |path|
27
+ pathname = (dir_pathname + path) if (dir_pathname + path).exist?
28
+ end
29
+ pathname
30
+ end
31
+
32
+ # @param [Hash] hash
33
+ # @return [Hash]
34
+ def symbolize_keys(hash)
35
+ hash.transform_keys(&:to_sym)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -30,11 +30,9 @@ module JsDependency
30
30
  # @param [String] target_path
31
31
  # @return [TrueClass, FalseClass]
32
32
  def orphan?(target_path)
33
- target_pathname = JsDependency::TargetPathname.new(target_path)
34
- paths = []
35
- target_pathname.each_parent_path(1, @index) do |parent_path, _child_path|
36
- paths << parent_path
37
- end
33
+ paths = parent_paths(target_path)
34
+ paths += dir_parent_paths(target_path) if target_path.include?("index.js")
35
+
38
36
  paths.size.zero?
39
37
  end
40
38
 
@@ -44,6 +42,30 @@ module JsDependency
44
42
  def relative_path_or_external_path(path, src_path)
45
43
  JsDependency::PathnameUtility.relative_path_or_external_path(path, src_path)
46
44
  end
45
+
46
+ # Parent paths.
47
+ # @param [String] target_path
48
+ # @return [Array<String>]
49
+ def parent_paths(target_path)
50
+ target_pathname = JsDependency::TargetPathname.new(target_path)
51
+ paths = []
52
+ target_pathname.each_parent_path(1, @index) do |parent_path, _child_path|
53
+ paths << parent_path
54
+ end
55
+ paths
56
+ end
57
+
58
+ # Directory parent paths.
59
+ # @param [String] target_path
60
+ # @return [Array<String>]
61
+ def dir_parent_paths(target_path)
62
+ paths = []
63
+ target_pathname_dir = JsDependency::TargetPathname.new(Pathname.new(target_path).dirname.to_s)
64
+ target_pathname_dir.each_parent_path(1, @index) do |parent_path, _child_path|
65
+ paths << parent_path
66
+ end
67
+ paths
68
+ end
47
69
  end
48
70
  end
49
71
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsDependency
4
- VERSION = "0.3.6"
4
+ VERSION = "0.3.9"
5
5
  end
data/lib/js_dependency.rb CHANGED
@@ -9,6 +9,8 @@ require_relative "js_dependency/mermaid/target_pathname"
9
9
  require_relative "js_dependency/source_analysis/leave"
10
10
  require_relative "js_dependency/source_analysis/orphan"
11
11
  require_relative "js_dependency/pathname_utility"
12
+ require_relative "js_dependency/cli_utils/yaml"
13
+ require_relative "js_dependency/cli_utils/config"
12
14
  require "pathname"
13
15
 
14
16
  module JsDependency
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_dependency
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - junara
@@ -159,6 +159,8 @@ files:
159
159
  - js_dependency.gemspec
160
160
  - lib/js_dependency.rb
161
161
  - lib/js_dependency/cli.rb
162
+ - lib/js_dependency/cli_utils/config.rb
163
+ - lib/js_dependency/cli_utils/yaml.rb
162
164
  - lib/js_dependency/extractor/extract_import_path.rb
163
165
  - lib/js_dependency/extractor/extract_script_tag.rb
164
166
  - lib/js_dependency/extractor/extract_src_path.rb