importmap-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 57b42db4d7acbfe99f5958275e127e60bc63c7515a12a366f96f7cbbb88b05a2
4
+ data.tar.gz: 54592dce82bc7209398b75855d0ccf389081f3287127b61c15e83ae37daa88b4
5
+ SHA512:
6
+ metadata.gz: 8b771f63ff1a81741682695c3ac66533c14535eff28c195e8a7e515319bd485a226874771661fdcebca63de0d99a41b4cc80e7595321718a3556f92c0e1762af
7
+ data.tar.gz: 99e64d4f3e08e15523858bc6aa13a0e5b0a4ce806203d2328c4b24ed6f8b278f15113d5333351c8c190727fcc5e2a4b04149870ebbad822965662830c868665e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ inherit_from: .rubocop_todo.yml
3
+
4
+
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,22 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2024-01-16 14:20:52 UTC using RuboCop version 1.59.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 5
10
+ # This cop supports unsafe autocorrection (--autocorrect-all).
11
+ Lint/UselessAssignment:
12
+ Exclude:
13
+ - 'importmap'
14
+
15
+ # Offense count: 7
16
+ # This cop supports safe autocorrection (--autocorrect).
17
+ # Configuration parameters: EnforcedStyle.
18
+ # SupportedStyles: line_count_dependent, lambda, literal
19
+ Style/Lambda:
20
+ Exclude:
21
+ - 'importmap'
22
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-01-09
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at daniel.vinciguerra@bivee.com.br. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in importmap-cli.gemspec
6
+ gemspec
7
+
8
+ gem 'pry-byebug'
9
+ gem 'rake', '~> 13.0'
10
+ gem 'rspec', '~> 3.0'
11
+
12
+ group :development, :test do
13
+ gem 'rubocop-performance', require: false
14
+ gem 'rubocop-rspec', require: false
15
+
16
+ gem 'rubycritic', require: false
17
+ end
18
+
19
+ group :test do
20
+ gem 'simplecov', require: false
21
+ gem 'simplecov-console', require: false
22
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,182 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ importmap-cli (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.8.6)
10
+ public_suffix (>= 2.0.2, < 6.0)
11
+ ansi (1.5.0)
12
+ ast (2.4.2)
13
+ axiom-types (0.1.1)
14
+ descendants_tracker (~> 0.0.4)
15
+ ice_nine (~> 0.11.0)
16
+ thread_safe (~> 0.3, >= 0.3.1)
17
+ bigdecimal (3.1.5)
18
+ byebug (11.1.3)
19
+ coderay (1.1.3)
20
+ coercible (1.0.0)
21
+ descendants_tracker (~> 0.0.1)
22
+ concurrent-ruby (1.2.3)
23
+ descendants_tracker (0.0.4)
24
+ thread_safe (~> 0.3, >= 0.3.1)
25
+ diff-lcs (1.5.0)
26
+ docile (1.4.0)
27
+ dry-configurable (1.1.0)
28
+ dry-core (~> 1.0, < 2)
29
+ zeitwerk (~> 2.6)
30
+ dry-core (1.0.1)
31
+ concurrent-ruby (~> 1.0)
32
+ zeitwerk (~> 2.6)
33
+ dry-inflector (1.0.0)
34
+ dry-initializer (3.1.1)
35
+ dry-logic (1.5.0)
36
+ concurrent-ruby (~> 1.0)
37
+ dry-core (~> 1.0, < 2)
38
+ zeitwerk (~> 2.6)
39
+ dry-schema (1.13.3)
40
+ concurrent-ruby (~> 1.0)
41
+ dry-configurable (~> 1.0, >= 1.0.1)
42
+ dry-core (~> 1.0, < 2)
43
+ dry-initializer (~> 3.0)
44
+ dry-logic (>= 1.4, < 2)
45
+ dry-types (>= 1.7, < 2)
46
+ zeitwerk (~> 2.6)
47
+ dry-types (1.7.2)
48
+ bigdecimal (~> 3.0)
49
+ concurrent-ruby (~> 1.0)
50
+ dry-core (~> 1.0)
51
+ dry-inflector (~> 1.0)
52
+ dry-logic (~> 1.4)
53
+ zeitwerk (~> 2.6)
54
+ erubi (1.12.0)
55
+ flay (2.13.1)
56
+ erubi (~> 1.10)
57
+ path_expander (~> 1.0)
58
+ ruby_parser (~> 3.0)
59
+ sexp_processor (~> 4.0)
60
+ flog (4.8.0)
61
+ path_expander (~> 1.0)
62
+ ruby_parser (~> 3.1, > 3.1.0)
63
+ sexp_processor (~> 4.8)
64
+ ice_nine (0.11.2)
65
+ json (2.7.1)
66
+ language_server-protocol (3.17.0.3)
67
+ launchy (2.5.2)
68
+ addressable (~> 2.8)
69
+ method_source (1.0.0)
70
+ parallel (1.24.0)
71
+ parser (3.2.2.4)
72
+ ast (~> 2.4.1)
73
+ racc
74
+ path_expander (1.1.1)
75
+ pry (0.14.2)
76
+ coderay (~> 1.1)
77
+ method_source (~> 1.0)
78
+ pry-byebug (3.10.1)
79
+ byebug (~> 11.0)
80
+ pry (>= 0.13, < 0.15)
81
+ public_suffix (5.0.4)
82
+ racc (1.7.3)
83
+ rainbow (3.1.1)
84
+ rake (13.1.0)
85
+ reek (6.2.0)
86
+ dry-schema (~> 1.13.0)
87
+ parser (~> 3.2.0)
88
+ rainbow (>= 2.0, < 4.0)
89
+ rexml (~> 3.1)
90
+ regexp_parser (2.9.0)
91
+ rexml (3.2.6)
92
+ rspec (3.12.0)
93
+ rspec-core (~> 3.12.0)
94
+ rspec-expectations (~> 3.12.0)
95
+ rspec-mocks (~> 3.12.0)
96
+ rspec-core (3.12.2)
97
+ rspec-support (~> 3.12.0)
98
+ rspec-expectations (3.12.3)
99
+ diff-lcs (>= 1.2.0, < 2.0)
100
+ rspec-support (~> 3.12.0)
101
+ rspec-mocks (3.12.6)
102
+ diff-lcs (>= 1.2.0, < 2.0)
103
+ rspec-support (~> 3.12.0)
104
+ rspec-support (3.12.1)
105
+ rubocop (1.59.0)
106
+ json (~> 2.3)
107
+ language_server-protocol (>= 3.17.0)
108
+ parallel (~> 1.10)
109
+ parser (>= 3.2.2.4)
110
+ rainbow (>= 2.2.2, < 4.0)
111
+ regexp_parser (>= 1.8, < 3.0)
112
+ rexml (>= 3.2.5, < 4.0)
113
+ rubocop-ast (>= 1.30.0, < 2.0)
114
+ ruby-progressbar (~> 1.7)
115
+ unicode-display_width (>= 2.4.0, < 3.0)
116
+ rubocop-ast (1.30.0)
117
+ parser (>= 3.2.1.0)
118
+ rubocop-capybara (2.20.0)
119
+ rubocop (~> 1.41)
120
+ rubocop-factory_bot (2.25.1)
121
+ rubocop (~> 1.41)
122
+ rubocop-performance (1.20.2)
123
+ rubocop (>= 1.48.1, < 2.0)
124
+ rubocop-ast (>= 1.30.0, < 2.0)
125
+ rubocop-rspec (2.26.1)
126
+ rubocop (~> 1.40)
127
+ rubocop-capybara (~> 2.17)
128
+ rubocop-factory_bot (~> 2.22)
129
+ ruby-progressbar (1.13.0)
130
+ ruby_parser (3.21.0)
131
+ racc (~> 1.5)
132
+ sexp_processor (~> 4.16)
133
+ rubycritic (4.9.0)
134
+ flay (~> 2.13)
135
+ flog (~> 4.7)
136
+ launchy (>= 2.5.2)
137
+ parser (>= 3.2.2.1)
138
+ rainbow (~> 3.1.1)
139
+ reek (~> 6.0, < 7.0)
140
+ rexml
141
+ ruby_parser (~> 3.20)
142
+ simplecov (>= 0.22.0)
143
+ tty-which (~> 0.5.0)
144
+ virtus (~> 2.0)
145
+ sexp_processor (4.17.1)
146
+ simplecov (0.22.0)
147
+ docile (~> 1.1)
148
+ simplecov-html (~> 0.11)
149
+ simplecov_json_formatter (~> 0.1)
150
+ simplecov-console (0.9.1)
151
+ ansi
152
+ simplecov
153
+ terminal-table
154
+ simplecov-html (0.12.3)
155
+ simplecov_json_formatter (0.1.4)
156
+ terminal-table (3.0.2)
157
+ unicode-display_width (>= 1.1.1, < 3)
158
+ thread_safe (0.3.6)
159
+ tty-which (0.5.0)
160
+ unicode-display_width (2.5.0)
161
+ virtus (2.0.0)
162
+ axiom-types (~> 0.1)
163
+ coercible (~> 1.0)
164
+ descendants_tracker (~> 0.0, >= 0.0.3)
165
+ zeitwerk (2.6.12)
166
+
167
+ PLATFORMS
168
+ ruby
169
+
170
+ DEPENDENCIES
171
+ importmap-cli!
172
+ pry-byebug
173
+ rake (~> 13.0)
174
+ rspec (~> 3.0)
175
+ rubocop-performance
176
+ rubocop-rspec
177
+ rubycritic
178
+ simplecov
179
+ simplecov-console
180
+
181
+ BUNDLED WITH
182
+ 2.4.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Daniel Vinciguerra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Importmap::Cli
2
+
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/importmap/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'importmap-cli'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install importmap-cli
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dvinciguerra/importmap-cli. 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/dvinciguerra/importmap-cli/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Importmap::Cli project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dvinciguerra/importmap-cli/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/importmap ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
5
+
6
+ require 'thor'
7
+ require 'importmap_cli'
8
+
9
+ module ImportmapCLI
10
+ # importmap cli application class
11
+ class App < Thor
12
+ def self.exit_on_failure?
13
+ false
14
+ end
15
+
16
+ desc 'add [*PACKAGES]', 'Pin new packages'
17
+ option :env, type: :string, aliases: :e, default: 'production'
18
+ option :from, type: :string, aliases: :f, default: 'jspm'
19
+ def add(*packages)
20
+ main.add(packages:, options:)
21
+ end
22
+
23
+ desc 'remove [*PACKAGES]', 'Unpin existing packages'
24
+ option :env, type: :string, aliases: :e, default: 'production'
25
+ option :from, type: :string, aliases: :f, default: 'jspm'
26
+ def remove(*packages)
27
+ main.remove(packages:, options:)
28
+ end
29
+
30
+ desc 'json', 'Show importmap in json format'
31
+ def json
32
+ main.json
33
+ end
34
+
35
+ desc 'audit', 'Run a security audit'
36
+ def audit
37
+ main.audit
38
+ end
39
+
40
+ desc 'outdated', 'Check for outdated packages'
41
+ def outdated
42
+ main.outdated
43
+ end
44
+
45
+ desc 'update', 'Update outdated package pins'
46
+ def update
47
+ main.update
48
+ end
49
+
50
+ desc 'packages', 'Print out packages with version numbers'
51
+ def packages
52
+ main.packages
53
+ end
54
+
55
+ private
56
+
57
+ def main
58
+ ImportmapCLI::Main.new
59
+ end
60
+ end
61
+ end
62
+
63
+ ImportmapCLI::App.start
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/importmap_cli/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'importmap-cli'
7
+ spec.version = ImportmapCLI::VERSION
8
+ spec.authors = ['Daniel Vinciguerra']
9
+ spec.email = ['daniel.vinciguerra@bivee.com.br']
10
+
11
+ spec.summary = 'importmap-cli is a command line tool to manage importmaps inpired from importmap-rails gem'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/dvinciguerra/importmap-cli'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.0.0'
16
+
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = 'bin'
29
+ spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, check out our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ spec.metadata['rubygems_mfa_required'] = 'true'
38
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'json'
5
+ require 'net/http'
6
+ require 'fileutils'
7
+
8
+ module ImportmapCLI
9
+ module Commands
10
+ class Add < BaseCommand
11
+ include ImportmapCLI::Roles::HttpResource
12
+
13
+ RESOURCE_URL = URI('https://api.jspm.io/generate').freeze
14
+
15
+ def initialize(packages:, options:)
16
+ @packages = packages
17
+ @options = options
18
+ end
19
+
20
+ def run
21
+ response = http_post(RESOURCE_URL, request_body)
22
+
23
+ http_status?(response, 200) do
24
+ payload = parse_importmap(response)
25
+
26
+ # ensure vendor directory exists
27
+ FileUtils.mkdir_p("#{ImportmapCLI.current_dir}/vendor/javascript")
28
+
29
+ # ensure importmap.rb exists
30
+ unless File.exist?("#{ImportmapCLI.current_dir}/config/importmap.rb")
31
+ puts "[error] #{ImportmapCLI.current_dir}/config/importmap.rb file does not exist"
32
+ exit 1
33
+ end
34
+
35
+ @importmap = File.read("#{ImportmapCLI.current_dir}/config/importmap.rb")
36
+
37
+ payload.fetch(:imports, {}).each do |package, url|
38
+ puts "[info] pinning #{package} to #{url}"
39
+
40
+ unless @importmap.match?(/^pin\s+['"]#{package}["']/)
41
+ @importmap = "#{@importmap}\npin '#{package}', to: '#{url}' # #{package_version_from(url)}"
42
+ end
43
+ end
44
+
45
+ File.write("#{ImportmapCLI.current_dir}/config/importmap.rb", @importmap)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def same_filename?(package, filename)
52
+ "#{package.gsub('/', '--')}.js" == filename
53
+ end
54
+
55
+ def package_version_from(url)
56
+ url.scan(/@(\d+\.\d+.\d+)/)&.flatten&.first
57
+ end
58
+
59
+ def request_body
60
+ {
61
+ 'install' => Array(@packages),
62
+ 'flattenScope' => true,
63
+ 'env' => ['browser', 'module', @options[:env]],
64
+ 'provider' => @options[:from].to_s
65
+ }.to_json
66
+ end
67
+
68
+ def parse_importmap(response)
69
+ JSON.parse(response.body, symbolize_names: true).fetch(:map, {})
70
+ rescue StandardError
71
+ puts '[error] unexpected error parsing importmap'
72
+ exit(1)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImportmapCLI
4
+ module Commands
5
+ class Audit
6
+ def run
7
+ pp [:audit]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImportmapCLI
4
+ module Commands
5
+ # Base class for all commands
6
+ class BaseCommand
7
+ protected
8
+
9
+ def current_dir
10
+ ImportmapCLI.current_dir
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImportmapCLI
4
+ module Commands
5
+ # Class that generates importmap in json format
6
+ class Json < BaseCommand
7
+ def run
8
+ # ensure importmap.rb exists
9
+ unless File.exist?("#{ImportmapCLI.current_dir}/config/importmap.rb")
10
+ puts "[error] #{ImportmapCLI.current_dir}/config/importmap.rb file does not exist"
11
+ exit 1
12
+ end
13
+
14
+ imports = {}
15
+
16
+ importmap_each_pin do |_line, matcher|
17
+ package, url = matcher.values_at(:package, :url)
18
+
19
+ imports.update(package => url)
20
+ end
21
+
22
+ puts JSON.pretty_generate({ imports: imports })
23
+ end
24
+
25
+ private
26
+
27
+ def importmap_each_pin(&block)
28
+ File.readlines("#{ImportmapCLI.current_dir}/config/importmap.rb").each do |line|
29
+ line.chomp!
30
+ next if line.empty? || !line.match(/^pin\s+["'](?<package>.*)['"],\s+to:\s+["'](?<url>.*)['"]/)
31
+
32
+ block.call(line, Regexp.last_match)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImportmapCLI
4
+ module Commands
5
+ class Outdated
6
+ def run
7
+ pp [:outdated]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImportmapCLI
4
+ module Commands
5
+ class Packages
6
+ def run
7
+ pp [:packages]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImportmapCLI
4
+ module Commands
5
+ class Remove
6
+ def initialize(packages:, options:)
7
+ @packages = packages
8
+ @options = options
9
+ end
10
+
11
+ def run
12
+ pp [:unpin, @packages, @options]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImportmapCLI
4
+ module Commands
5
+ class Update
6
+ def run
7
+ pp [:update]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'importmap_cli/commands/base_command'
4
+ require 'importmap_cli/commands/add'
5
+ require 'importmap_cli/commands/remove'
6
+ require 'importmap_cli/commands/json'
7
+ require 'importmap_cli/commands/audit'
8
+ require 'importmap_cli/commands/outdated'
9
+ require 'importmap_cli/commands/update'
10
+ require 'importmap_cli/commands/packages'
11
+
12
+ module ImportmapCLI
13
+ # adr cli main command line entry point class
14
+ class Main
15
+ def add(packages:, options:)
16
+ Commands::Add.new(packages:, options:).run
17
+ end
18
+
19
+ def remove(packages:, options:)
20
+ Commands::Remove.new(packages:, options:).run
21
+ end
22
+
23
+ def json
24
+ Commands::Json.new.run
25
+ end
26
+
27
+ def audit
28
+ Commands::Audit.new.run
29
+ end
30
+
31
+ def outdated
32
+ Commands::Outdated.new.run
33
+ end
34
+
35
+ def update
36
+ Commands::Update.new.run
37
+ end
38
+
39
+ def packages
40
+ Commands::Packages.new.run
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ module ImportmapCLI
6
+ module Roles
7
+ # role that inject behaviour for http resources
8
+ module HttpResource
9
+ protected
10
+
11
+ # performe a http post request
12
+ def http_post(url, body, headers = { 'Content-Type' => 'application/json' })
13
+ Net::HTTP.post(url, body, headers)
14
+ rescue StandardError => e
15
+ raise HTTPError, "[error] unexpected transport error (#{e.class}: #{e.message})"
16
+ end
17
+
18
+ # check http status code and performa a block
19
+ def http_status?(response, code, &block)
20
+ block.call if response.code == code.to_s
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImportmapCLI
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.expand_path('./', __dir__))
4
+
5
+ require 'logger'
6
+ require 'fileutils'
7
+
8
+ require 'importmap_cli/version'
9
+ require 'importmap_cli/roles/http_resource'
10
+ require 'importmap_cli/main'
11
+
12
+ # adr cli root module
13
+ module ImportmapCLI
14
+ class Error < StandardError; end
15
+
16
+ CURRENT_DIR = FileUtils.pwd.freeze
17
+
18
+ class << self
19
+ # application logger
20
+ def logger
21
+ @logger ||= Logger.new($stdout)
22
+ end
23
+
24
+ # current directory
25
+ def current_dir
26
+ ImportmapCLI::CURRENT_DIR
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ module Importmap
2
+ module Cli
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: importmap-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Vinciguerra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: importmap-cli is a command line tool to manage importmaps inpired from
14
+ importmap-rails gem
15
+ email:
16
+ - daniel.vinciguerra@bivee.com.br
17
+ executables:
18
+ - importmap
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".rubocop_todo.yml"
25
+ - CHANGELOG.md
26
+ - CODE_OF_CONDUCT.md
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - bin/importmap
33
+ - importmap-cli.gemspec
34
+ - lib/importmap_cli.rb
35
+ - lib/importmap_cli/commands/add.rb
36
+ - lib/importmap_cli/commands/audit.rb
37
+ - lib/importmap_cli/commands/base_command.rb
38
+ - lib/importmap_cli/commands/json.rb
39
+ - lib/importmap_cli/commands/outdated.rb
40
+ - lib/importmap_cli/commands/packages.rb
41
+ - lib/importmap_cli/commands/remove.rb
42
+ - lib/importmap_cli/commands/update.rb
43
+ - lib/importmap_cli/main.rb
44
+ - lib/importmap_cli/roles/http_resource.rb
45
+ - lib/importmap_cli/version.rb
46
+ - sig/importmap/cli.rbs
47
+ homepage: https://github.com/dvinciguerra/importmap-cli
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/dvinciguerra/importmap-cli
52
+ source_code_uri: https://github.com/dvinciguerra/importmap-cli
53
+ rubygems_mfa_required: 'true'
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.4.22
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: importmap-cli is a command line tool to manage importmaps inpired from importmap-rails
73
+ gem
74
+ test_files: []