js_dependency 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +25 -3
- data/lib/js_dependency/extract_import_path.rb +7 -7
- data/lib/js_dependency/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20217229c2c7f845d05b400f356240d4e2db4d46f9b4d1fc6662868bc1bac372
|
4
|
+
data.tar.gz: d74ccf10be4764621ff17bc2700c56b8947263b5dc35bccaab49101df90eea59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a842902a4bf0331ea00352315682bf4efb8ac6891dfa2fcfedff0d5ecdfada5d8cf1240ebc6e02a5f8b8ac8a6df54d85c47e4140ac581601d43dbb7a16f3fb2d
|
7
|
+
data.tar.gz: 919130f6a767b0dc51533cacee935c810da0a8460ab74e86536704fea8614289fa45025c8b3d9edd62a48782bc463e632256b3c9868f849bcb93cf006859c035
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
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.
|
4
4
|
|
5
|
-
|
5
|
+
Analyze import dependency of JavaScript code and export mermaid format.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -15,8 +15,30 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
15
15
|
$ gem install js_dependency
|
16
16
|
|
17
17
|
## Usage
|
18
|
+
If your javascript code is in `./src` and `./src/App.vue` is in the directory, you can analyze `./src/App.vue` dependency like this:
|
18
19
|
|
19
|
-
|
20
|
+
```ruby
|
21
|
+
require 'js_dependency'
|
22
|
+
|
23
|
+
|
24
|
+
src_path = './src' # Root folder.
|
25
|
+
target_path = './src/App.vue' # Target file that you want to analyze.
|
26
|
+
child_analyze_level = 2 # Output level of child dependency.
|
27
|
+
parent_analyze_level = 2 # Output level of parent dependency.
|
28
|
+
output_path = './mermaid.txt' # Optional. Output file path
|
29
|
+
alias_paths = {'@' => '/src' } # Optional. Alias path.
|
30
|
+
|
31
|
+
# mermaid出力実行
|
32
|
+
JsDependency.export_mermaid(
|
33
|
+
src_path,
|
34
|
+
target_path,
|
35
|
+
child_analyze_level: child_analyze_level,
|
36
|
+
parent_analyze_level: parent_analyze_level,
|
37
|
+
output_path: output_path,
|
38
|
+
alias_paths: alias_paths)
|
39
|
+
```
|
40
|
+
|
41
|
+
See `./mermaid.txt` of `output_path` for the result.
|
20
42
|
|
21
43
|
## Development
|
22
44
|
|
@@ -26,7 +48,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
26
48
|
|
27
49
|
## Contributing
|
28
50
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/junara/js_dependency. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/js_dependency/blob/main/CODE_OF_CONDUCT.md).
|
30
52
|
|
31
53
|
## License
|
32
54
|
|
@@ -12,11 +12,11 @@ module JsDependency
|
|
12
12
|
def call
|
13
13
|
str = @str
|
14
14
|
# import defaultExport from 'module-name';
|
15
|
-
paths = str.gsub(/import\s+\S+\s+from\s+"([^
|
15
|
+
paths = str.gsub(/import\s+\S+\s+from\s+"([^"]+)"/).with_object([]) { |_, list| list << Regexp.last_match(1) }
|
16
16
|
paths += str.gsub(/import\s+\S+\s+from\s+'([^']+)'/).with_object([]) { |_, list| list << Regexp.last_match(1) }
|
17
17
|
|
18
18
|
# import * as name from \"module-name\";
|
19
|
-
paths += str.gsub(/import\s+\S+\s+as\s+\S+\s+from\s+"([^
|
19
|
+
paths += str.gsub(/import\s+\S+\s+as\s+\S+\s+from\s+"([^"]+)"/).with_object([]) do |_, list|
|
20
20
|
list << Regexp.last_match(1)
|
21
21
|
end
|
22
22
|
paths += str.gsub(/import\s+\S+\s+as\s+\S+\s+from\s+'([^']+)'/).with_object([]) do |_, list|
|
@@ -28,7 +28,7 @@ module JsDependency
|
|
28
28
|
# import { export1 , export2 } from "module-name";
|
29
29
|
# import { foo , bar } from "module-name/path/to/specific/un-exported/file";
|
30
30
|
# import { export1 , export2 as alias2 , [...] } from "module-name";
|
31
|
-
paths += str.gsub(/import\s+\{\s+.+\s+\}\s+from\s+"([^
|
31
|
+
paths += str.gsub(/import\s+\{\s+.+\s+\}\s+from\s+"([^"]+)"/).with_object([]) do |_, list|
|
32
32
|
list << Regexp.last_match(1)
|
33
33
|
end
|
34
34
|
paths += str.gsub(/import\s+\{\s+.+\s+\}\s+from\s+'([^']+)'/).with_object([]) do |_, list|
|
@@ -36,7 +36,7 @@ module JsDependency
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# import defaultExport, { export1 [ , [...] ] } from "module-name";
|
39
|
-
paths += str.gsub(/import\s+\S+,\s+\{\s+.+\s+\}\s+from\s+"([^
|
39
|
+
paths += str.gsub(/import\s+\S+,\s+\{\s+.+\s+\}\s+from\s+"([^"]+)"/).with_object([]) do |_, list|
|
40
40
|
list << Regexp.last_match(1)
|
41
41
|
end
|
42
42
|
paths += str.gsub(/import\s+\S+,\s+\{\s+.+\s+\}\s+from\s+'([^']+)'/).with_object([]) do |_, list|
|
@@ -44,7 +44,7 @@ module JsDependency
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# import defaultExport, * as name from "module-name";
|
47
|
-
paths += str.gsub(/import\s+\S+,\s+.+\s+as\s+\S+\s+from\s+"([^
|
47
|
+
paths += str.gsub(/import\s+\S+,\s+.+\s+as\s+\S+\s+from\s+"([^"]+)"/).with_object([]) do |_, list|
|
48
48
|
list << Regexp.last_match(1)
|
49
49
|
end
|
50
50
|
paths += str.gsub(/import\s+\S+,\s+.+\s+as\s+\S+\s+from\s+'([^']+)'/).with_object([]) do |_, list|
|
@@ -52,7 +52,7 @@ module JsDependency
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# import "module-name";
|
55
|
-
paths += str.gsub(/import\s+"([^
|
55
|
+
paths += str.gsub(/import\s+"([^"]+)"/).with_object([]) do |_, list|
|
56
56
|
list << Regexp.last_match(1)
|
57
57
|
end
|
58
58
|
paths += str.gsub(/import\s+'([^']+)'/).with_object([]) do |_, list|
|
@@ -60,7 +60,7 @@ module JsDependency
|
|
60
60
|
end
|
61
61
|
|
62
62
|
# var promise = import("module-name");
|
63
|
-
paths += str.gsub(/import\("([^
|
63
|
+
paths += str.gsub(/import\("([^"]+)"\)/).with_object([]) do |_, list|
|
64
64
|
list << Regexp.last_match(1)
|
65
65
|
end
|
66
66
|
paths += str.gsub(/import\('([^']+)'\)/).with_object([]) do |_, list|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js_dependency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- junara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pathname
|