js_dependency 0.1.1 → 0.2.0

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: 20217229c2c7f845d05b400f356240d4e2db4d46f9b4d1fc6662868bc1bac372
4
- data.tar.gz: d74ccf10be4764621ff17bc2700c56b8947263b5dc35bccaab49101df90eea59
3
+ metadata.gz: 1c3c24ad458ab62df198ebb779c5a9142a7bff0aee92bb95a9bc88061192045c
4
+ data.tar.gz: e9d6e041aee4a8df90c3ebc850474f2c8f6ad808ac07368fdfc8bec009a7b463
5
5
  SHA512:
6
- metadata.gz: a842902a4bf0331ea00352315682bf4efb8ac6891dfa2fcfedff0d5ecdfada5d8cf1240ebc6e02a5f8b8ac8a6df54d85c47e4140ac581601d43dbb7a16f3fb2d
7
- data.tar.gz: 919130f6a767b0dc51533cacee935c810da0a8460ab74e86536704fea8614289fa45025c8b3d9edd62a48782bc463e632256b3c9868f849bcb93cf006859c035
6
+ metadata.gz: 2fdda6bc1addc027df2fcfdb802bd5fa2c413422e80bf7c89d99532cc0bdff1fd47fed2c17fdfb675662b5ea8fc545235e0764a804db67d1e8a49ebf66f76c19
7
+ data.tar.gz: 38923fd2655a8c60b2e844df0075256eb1e8bbb7d92bd07cc9330551846fbd730f3a7e1f75ac2a8a93f680c6beff8eafcec10f2b407f9a69c4df78ab160aad2d
@@ -0,0 +1,8 @@
1
+ src_path: ./src
2
+ target_path: ./src/App.vue
3
+ child_analyze_level: 2
4
+ parent_analyze_level: 2
5
+ name_level: 1
6
+ output_path: ./mermaid.txt
7
+ alias_paths:
8
+ "@": ./src
data/.rubocop_todo.yml CHANGED
@@ -1,26 +1,41 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-07-18 12:42:10 UTC using RuboCop version 1.31.2.
3
+ # on 2022-07-19 16:03:39 UTC using RuboCop version 1.31.2.
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: 3
9
+ # Offense count: 6
10
10
  # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
11
11
  Metrics/AbcSize:
12
- Max: 20
12
+ Max: 30
13
13
 
14
14
  # Offense count: 3
15
+ # Configuration parameters: IgnoredMethods.
16
+ Metrics/CyclomaticComplexity:
17
+ Max: 13
18
+
19
+ # Offense count: 8
15
20
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
16
21
  Metrics/MethodLength:
17
- Max: 17
22
+ Max: 20
23
+
24
+ # Offense count: 1
25
+ # Configuration parameters: CountComments, CountAsOne.
26
+ Metrics/ModuleLength:
27
+ Max: 112
18
28
 
19
29
  # Offense count: 1
20
30
  # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
21
31
  Metrics/ParameterLists:
22
32
  Max: 8
23
33
 
34
+ # Offense count: 3
35
+ # Configuration parameters: IgnoredMethods.
36
+ Metrics/PerceivedComplexity:
37
+ Max: 13
38
+
24
39
  # Offense count: 1
25
40
  # This cop supports safe autocorrection (--autocorrect).
26
41
  Style/IfUnlessModifier:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2022-07-19
4
+
5
+ - Add CLI interface.
6
+
3
7
  ## [0.1.1] - 2022-07-19
4
8
 
5
9
  - Bug fix of double quotation mark.
data/Gemfile.lock CHANGED
@@ -1,8 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- js_dependency (0.1.1)
4
+ js_dependency (0.2.0)
5
5
  pathname
6
+ thor
7
+ yaml
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
@@ -74,11 +76,13 @@ GEM
74
76
  simplecov_json_formatter (~> 0.1)
75
77
  simplecov-html (0.12.3)
76
78
  simplecov_json_formatter (0.1.4)
79
+ thor (1.2.1)
77
80
  trollop (2.9.10)
78
81
  unicode-display_width (2.2.0)
79
82
  unparser (0.6.5)
80
83
  diff-lcs (~> 1.3)
81
84
  parser (>= 3.1.0)
85
+ yaml (0.2.0)
82
86
  yarn (0.1.1)
83
87
  parslet (>= 1.2)
84
88
  rack (>= 1.3)
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![codecov](https://codecov.io/gh/junara/js_dependency/branch/main/graph/badge.svg?token=GRdbS1xqUa)](https://codecov.io/gh/junara/js_dependency)
2
+
1
3
  # JsDependency
2
4
 
3
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/js_dependency`. To experiment with that code, run `bin/console` for an interactive prompt.
@@ -15,6 +17,41 @@ If bundler is not being used to manage dependencies, install the gem by executin
15
17
  $ gem install js_dependency
16
18
 
17
19
  ## Usage
20
+ ### By Command Line
21
+
22
+ Configuration file is `./.js_dependency.yml`. This file includes parameters for the analysis.
23
+
24
+ ```yaml
25
+ src_path: ./src # Root folder
26
+ target_path: ./src/App.vue # Target file tha you want to analyze
27
+ child_analyze_level: 2 # Output level of child analyze
28
+ parent_analyze_level: 2 # Output level of parent analyze
29
+ name_level: 1 # Output name level
30
+ output_path: ./mermaid.txt # Output file path
31
+ alias_paths: # Alias path
32
+ "@": ./src
33
+ ```
34
+
35
+ #### Export Mermaid Format
36
+
37
+ ```shell
38
+ js_dependency -s ./src -t ./src/App.vue -o ./mermaid.txt -c 2 -p 2 -n 1
39
+ ```
40
+
41
+ #### Export parents components list
42
+
43
+ ```shell
44
+ js_dependency parents -s ./src -t ./src/App.vue -o ./parents.txt -p 2
45
+ ```
46
+
47
+ #### Export children components list
48
+
49
+ ```shell
50
+ js_dependency childrent -s ./src -t ./src/App.vue -o ./children.txt -c 2
51
+ ```
52
+
53
+
54
+ ### By ruby code
18
55
  If your javascript code is in `./src` and `./src/App.vue` is in the directory, you can analyze `./src/App.vue` dependency like this:
19
56
 
20
57
  ```ruby
data/exe/js_dependency ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "js_dependency"
5
+
6
+ JsDependency::Cli.start(ARGV)
@@ -31,7 +31,8 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_dependency "pathname"
34
-
34
+ spec.add_dependency "thor"
35
+ spec.add_dependency "yaml"
35
36
  spec.add_development_dependency "rspec"
36
37
  spec.add_development_dependency "rspec-parameterized"
37
38
  spec.add_development_dependency "rubocop"
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "yaml"
5
+
6
+ module JsDependency
7
+ class Cli < Thor
8
+ default_command :export_mermaid
9
+
10
+ desc "export_mermaid", "Output mermaid flowchart string."
11
+ option :src_path, type: :string, aliases: "-s", desc: "Root folder."
12
+ option :target_path, type: :string, 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
+ def export_mermaid
18
+ pathname = Pathname.new(".js_dependency.yml")
19
+ args = {}
20
+ args = YAML.safe_load(pathname.read) if pathname.exist?
21
+
22
+ src_path = options[:src_path] || args["src_path"]
23
+ target_path = options[:target_path] || args["target_path"]
24
+ child_analyze_level = options[:child_analyze_level] || args["child_analyze_level"] || 2
25
+ parent_analyze_level = options[:parent_analyze_level] || args["parent_analyze_level"] || 2
26
+ output_path = options[:output_path] || args["output_path"] || nil
27
+ alias_paths = args["alias_paths"] || nil
28
+ name_level = options[:name_level] || args["name_level"] || 1
29
+
30
+ str = JsDependency.export_mermaid(
31
+ src_path,
32
+ target_path,
33
+ child_analyze_level: child_analyze_level,
34
+ parent_analyze_level: parent_analyze_level,
35
+ output_path: output_path,
36
+ alias_paths: alias_paths,
37
+ name_level: name_level
38
+ )
39
+
40
+ puts str
41
+ end
42
+
43
+ desc "parents", "export parents list"
44
+ option :src_path, type: :string, aliases: "-s", desc: "Root folder."
45
+ option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
46
+ option :output_path, type: :string, aliases: "-o", desc: "Output file path"
47
+ option :parent_analyze_level, type: :numeric, aliases: "-p", desc: "Output level of parent dependency"
48
+ def parents
49
+ pathname = Pathname.new(".js_dependency.yml")
50
+ args = {}
51
+ args = YAML.safe_load(pathname.read) if pathname.exist?
52
+
53
+ src_path = options[:src_path] || args["src_path"]
54
+ target_path = options[:target_path] || args["target_path"]
55
+ parent_analyze_level = options[:parent_analyze_level] || args["parent_analyze_level"] || 1
56
+ output_path = options[:output_path] || args["output_path"] || nil
57
+ alias_paths = args["alias_paths"] || nil
58
+
59
+ str = JsDependency.parents(
60
+ src_path,
61
+ target_path,
62
+ parent_analyze_level: parent_analyze_level,
63
+ output_path: output_path,
64
+ alias_paths: alias_paths
65
+ ).sort.uniq.join("\n")
66
+
67
+ puts str
68
+ end
69
+
70
+ desc "children", "export children list"
71
+ option :src_path, type: :string, aliases: "-s", desc: "Root folder."
72
+ option :target_path, type: :string, aliases: "-t", desc: "Target file that you want to analyze."
73
+ option :output_path, type: :string, aliases: "-o", desc: "Output file path"
74
+ option :child_analyze_level, type: :numeric, aliases: "-c", desc: "Output level of child dependency"
75
+ def children
76
+ pathname = Pathname.new(".js_dependency.yml")
77
+ args = {}
78
+ args = YAML.safe_load(pathname.read) if pathname.exist?
79
+
80
+ src_path = options[:src_path] || args["src_path"]
81
+ target_path = options[:target_path] || args["target_path"]
82
+ child_analyze_level = options[:child_analyze_level] || args["child_analyze_level"] || 1
83
+ output_path = options[:output_path] || args["output_path"] || nil
84
+ alias_paths = args["alias_paths"] || nil
85
+
86
+ str = JsDependency.children(
87
+ src_path,
88
+ target_path,
89
+ child_analyze_level: child_analyze_level,
90
+ output_path: output_path,
91
+ alias_paths: alias_paths
92
+ ).sort.uniq.join("\n")
93
+
94
+ puts str
95
+ end
96
+ end
97
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsDependency
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/js_dependency.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "js_dependency/version"
4
4
  require_relative "js_dependency/index_creator"
5
5
  require_relative "js_dependency/mermaid/root"
6
+ require_relative "js_dependency/cli"
6
7
  require "pathname"
7
8
 
8
9
  module JsDependency
@@ -42,6 +43,42 @@ module JsDependency
42
43
  output
43
44
  end
44
45
 
46
+ def self.parents(src_path, target_path, alias_paths: nil, parent_analyze_level: 1, output_path: nil)
47
+ output_pathname = Pathname.new(output_path) if output_path
48
+ index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths)
49
+
50
+ target_pathname = if Pathname.new(target_path).relative? && Pathname.new(target_path).exist?
51
+ Pathname.new(target_path).realpath
52
+ else
53
+ Pathname.new(target_path)
54
+ end
55
+ list = []
56
+ parents_paths(target_pathname, parent_analyze_level, index) do |parent_path, _child_path|
57
+ list << parent_path
58
+ end
59
+ output = list.uniq
60
+ output_pathname&.write(output)
61
+ output
62
+ end
63
+
64
+ def self.children(src_path, target_path, alias_paths: nil, child_analyze_level: 1, output_path: nil)
65
+ output_pathname = Pathname.new(output_path) if output_path
66
+ index = JsDependency::IndexCreator.call(src_path, alias_paths: alias_paths)
67
+
68
+ target_pathname = if Pathname.new(target_path).relative? && Pathname.new(target_path).exist?
69
+ Pathname.new(target_path).realpath
70
+ else
71
+ Pathname.new(target_path)
72
+ end
73
+ list = []
74
+ children_paths(target_pathname, child_analyze_level, index) do |_parent_path, child_path|
75
+ list << child_path
76
+ end
77
+ output = list.uniq
78
+ output_pathname&.write(output)
79
+ output
80
+ end
81
+
45
82
  # @param [String] target_path
46
83
  # @param [Hash] index
47
84
  # @return [Array]
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - junara
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yaml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rspec
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -111,10 +139,12 @@ dependencies:
111
139
  description: Analyze dependency using import for JavaScript.
112
140
  email:
113
141
  - jun5araki@gmail.com
114
- executables: []
142
+ executables:
143
+ - js_dependency
115
144
  extensions: []
116
145
  extra_rdoc_files: []
117
146
  files:
147
+ - ".js_dependency.yml.sample"
118
148
  - ".rspec"
119
149
  - ".rubocop.yml"
120
150
  - ".rubocop_todo.yml"
@@ -125,8 +155,10 @@ files:
125
155
  - LICENSE.txt
126
156
  - README.md
127
157
  - Rakefile
158
+ - exe/js_dependency
128
159
  - js_dependency.gemspec
129
160
  - lib/js_dependency.rb
161
+ - lib/js_dependency/cli.rb
130
162
  - lib/js_dependency/extract_import_path.rb
131
163
  - lib/js_dependency/extract_script_tag.rb
132
164
  - lib/js_dependency/index_creator.rb