importmap-cli 0.1.0 → 0.4.0
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/bin/importmap +1 -0
- data/lib/importmap_cli/commands/add.rb +46 -15
- data/lib/importmap_cli/version.rb +1 -1
- metadata +2 -3
- data/sig/importmap/cli.rbs +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ba33fe0fd763e34d59b1a53f3b3c84d6e10e744b5fe96b7ee2ed46909cbb52c
|
4
|
+
data.tar.gz: a8e8e42b4fd7960755c27bd92647da3eedf46a909615942a6cf4c2d7f9bc2980
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab3302b8fadc198e50b0823340079c053bb27c4bd72be7027f9af98915c6f884353c565305529d4be20e633ddd272fd987eaa61fc6883e3af46f791c1a7cdf2
|
7
|
+
data.tar.gz: 0f9b9942236f35bf08a703f967f6696616f839a8c734acab16c68c86ec631c9e2638277f5639d96c0efa282b64aea289800df68d345ae1c19f33b6cc68f253d4
|
data/bin/importmap
CHANGED
@@ -16,6 +16,7 @@ module ImportmapCLI
|
|
16
16
|
desc 'add [*PACKAGES]', 'Pin new packages'
|
17
17
|
option :env, type: :string, aliases: :e, default: 'production'
|
18
18
|
option :from, type: :string, aliases: :f, default: 'jspm'
|
19
|
+
option :format, type: :string, repeatable: false
|
19
20
|
def add(*packages)
|
20
21
|
main.add(packages:, options:)
|
21
22
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'uri'
|
4
|
+
require 'yaml'
|
4
5
|
require 'json'
|
5
6
|
require 'net/http'
|
6
7
|
require 'fileutils'
|
@@ -13,8 +14,8 @@ module ImportmapCLI
|
|
13
14
|
RESOURCE_URL = URI('https://api.jspm.io/generate').freeze
|
14
15
|
|
15
16
|
def initialize(packages:, options:)
|
16
|
-
@
|
17
|
-
@
|
17
|
+
@options = Hash(options)
|
18
|
+
@packages = current_packages + packages
|
18
19
|
end
|
19
20
|
|
20
21
|
def run
|
@@ -27,27 +28,26 @@ module ImportmapCLI
|
|
27
28
|
FileUtils.mkdir_p("#{ImportmapCLI.current_dir}/vendor/javascript")
|
28
29
|
|
29
30
|
# ensure importmap.rb exists
|
30
|
-
unless File.exist?("#{ImportmapCLI.current_dir}
|
31
|
-
puts "[error] #{ImportmapCLI.current_dir}
|
31
|
+
unless File.exist?("#{ImportmapCLI.current_dir}#{filename}")
|
32
|
+
puts "[error] #{ImportmapCLI.current_dir}#{filename} file does not exist"
|
32
33
|
exit 1
|
33
34
|
end
|
34
35
|
|
35
|
-
|
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)
|
36
|
+
importmap_generated = build_importmap(payload)
|
37
|
+
File.write("#{ImportmapCLI.current_dir}#{filename}", importmap_generated)
|
46
38
|
end
|
47
39
|
end
|
48
40
|
|
49
41
|
private
|
50
42
|
|
43
|
+
def filename
|
44
|
+
@filename ||= "/config/importmap.#{file_extension}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_extension
|
48
|
+
@file_extension ||= Hash(@options).fetch('format', 'rb')
|
49
|
+
end
|
50
|
+
|
51
51
|
def same_filename?(package, filename)
|
52
52
|
"#{package.gsub('/', '--')}.js" == filename
|
53
53
|
end
|
@@ -56,6 +56,37 @@ module ImportmapCLI
|
|
56
56
|
url.scan(/@(\d+\.\d+.\d+)/)&.flatten&.first
|
57
57
|
end
|
58
58
|
|
59
|
+
def current_packages
|
60
|
+
file_content = File.read("#{ImportmapCLI.current_dir}#{filename}")
|
61
|
+
|
62
|
+
case file_extension
|
63
|
+
when 'json'
|
64
|
+
JSON.parse(file_content, symbolize_names: true).fetch(:imports, {}).keys
|
65
|
+
when 'yaml'
|
66
|
+
YAML.load(file_content).fetch(:imports, {}).keys
|
67
|
+
else
|
68
|
+
file_content.scan(/pin\s+['"](.+)['"],?.*/).flatten
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def build_importmap(payload)
|
73
|
+
case file_extension
|
74
|
+
when 'json'
|
75
|
+
JSON.pretty_generate(payload)
|
76
|
+
when 'yaml'
|
77
|
+
YAML.dump(payload)
|
78
|
+
else
|
79
|
+
importmap = ''
|
80
|
+
|
81
|
+
payload.fetch(:imports, {}).each do |package, url|
|
82
|
+
puts "[info] pinning #{package} to #{url}"
|
83
|
+
importmap += "#{importmap}\npin '#{package}', to: '#{url}' # #{package_version_from(url)}"
|
84
|
+
end
|
85
|
+
|
86
|
+
importmap
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
59
90
|
def request_body
|
60
91
|
{
|
61
92
|
'install' => Array(@packages),
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: importmap-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Vinciguerra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: importmap-cli is a command line tool to manage importmaps inpired from
|
14
14
|
importmap-rails gem
|
@@ -43,7 +43,6 @@ files:
|
|
43
43
|
- lib/importmap_cli/main.rb
|
44
44
|
- lib/importmap_cli/roles/http_resource.rb
|
45
45
|
- lib/importmap_cli/version.rb
|
46
|
-
- sig/importmap/cli.rbs
|
47
46
|
homepage: https://github.com/dvinciguerra/importmap-cli
|
48
47
|
licenses:
|
49
48
|
- MIT
|