instrumental-components 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7203f1cfb2dc60741b2d32e8809ad7ff62e697147f7baec3fcab6f45a1ad16c8
4
+ data.tar.gz: 2201c5c0f9c44ff8936ee0b98d09a00563105742e2bc3fa20d2732ca04162edd
5
+ SHA512:
6
+ metadata.gz: 9b01288d0e5760371151256075d4c79c36ac58c93f7778fc16f9be0ea802ddaa886c876cbbb80a290d81fe059da6ee9f1ebdca8e224e46336c32ef82eae5ae59
7
+ data.tar.gz: 662f70f580696eb3b01774df1906b1225b7e16db8fe180789ea7ffa1ac295fe8c242d1107d13bf2c6cb7e74b7f6ae75c02c36f723a3f541e0c92a0e8fe80f86d
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'instrumental-components'
4
+ require 'optparse'
5
+
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: install-instrumental --license_key=LICENSE_KEY --email=EMAIL"
9
+
10
+ opts.on("--license_key=LICENSE_KEY", "License key for Instrumental Components") do |key|
11
+ options[:license_key] = key
12
+ end
13
+
14
+ opts.on("--email=EMAIL", "Email associated with your Instrumental.dev account") do |email|
15
+ options[:email] = email
16
+ end
17
+ end.parse!
18
+
19
+ unless options[:license_key] && options[:email]
20
+ puts "Error: Both --license_key and --email are required"
21
+ exit 1
22
+ end
23
+
24
+ installer = InstrumentalComponents::Installer.new(options[:license_key], options[:email])
25
+ installer.install
@@ -0,0 +1,129 @@
1
+ require 'open-uri'
2
+ require 'fileutils'
3
+ require 'json'
4
+ require 'dotenv'
5
+
6
+ module InstrumentalComponents
7
+ class Installer
8
+ def initialize(license_key, email)
9
+ @license_key = license_key
10
+ @email = email
11
+ end
12
+
13
+ def install
14
+ puts "šŸ“„ Downloading the latest version of Instrumental Components..."
15
+
16
+ begin
17
+ # Load .env file if it exists
18
+ Dotenv.load if File.exist?('.env')
19
+
20
+ # Download the latest version of the gem
21
+ download_gem
22
+
23
+ puts "šŸ“¦ Installing the gem on your system..."
24
+ install_gem
25
+
26
+ puts "šŸ“ Updating Gemfile..."
27
+ update_gemfile
28
+
29
+ puts ""
30
+ puts "Running 'bundle install'..."
31
+ run_bundle_install
32
+
33
+ puts ""
34
+ puts "šŸš€ Running the Instrumental Components installer..."
35
+ run_installer
36
+
37
+ puts ""
38
+ rescue => e
39
+ # Display the error message sent by the logic in instrumental.dev's API
40
+ puts "\nāŒ #{e.message}"
41
+ exit(1)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def download_gem
48
+ # For local development, set INSTRUMENTAL_DOMAIN=http://localhost:3000 in .env
49
+ # This allows testing against a local server while developing the gem
50
+ domain = ENV['INSTRUMENTAL_DOMAIN'] || 'https://instrumental.dev'
51
+ unless 'https://instrumental.dev' == domain
52
+ puts "Using domain: #{domain}" # Confirm that we're in local development mode
53
+ end
54
+
55
+ # This API endpoint on instrumental.dev will return the latest version of the gem and
56
+ # save it in the root of the project under the filename, instrumental-components-library-latest.gem
57
+ gem_url = "#{domain}/gem_downloads/instrumental-components-library-latest.gem?token=#{@license_key}&email=#{@email}"
58
+
59
+ begin
60
+ response = URI.open(gem_url)
61
+ # Check if the response is JSON (indicating an error)
62
+ content_type = response.content_type
63
+ if content_type&.include?('application/json')
64
+ error_data = JSON.parse(response.read)
65
+ raise error_data['error'] || 'Authentication failed'
66
+ end
67
+
68
+ # If not JSON, it's the gem file - proceed with saving
69
+ File.open('instrumental-components-library-latest.gem', 'wb') do |file|
70
+ file.write(response.read)
71
+ end
72
+ rescue OpenURI::HTTPError => e
73
+ if e.io.status[0] == '401' || e.io.status[0] == '403' || e.io.status[0] == '404'
74
+ # Try to parse the error message from the response
75
+ begin
76
+ error_data = JSON.parse(e.io.read)
77
+ raise error_data['error']
78
+ rescue JSON::ParserError
79
+ raise "Server returned #{e.io.status[0]} status code"
80
+ end
81
+ else
82
+ raise "Error downloading gem: #{e.message}"
83
+ end
84
+ rescue JSON::ParserError
85
+ # If JSON parsing fails, it's likely the gem file - proceed with saving
86
+ File.open('instrumental-components-library-latest.gem', 'wb') do |file|
87
+ file.write(response.read)
88
+ end
89
+ end
90
+ end
91
+
92
+ def install_gem
93
+ system("gem install ./instrumental-components-library-latest.gem --silent --no-document")
94
+ FileUtils.rm('instrumental-components-library-latest.gem')
95
+ end
96
+
97
+ def update_gemfile
98
+ gemfile_path = 'Gemfile'
99
+ return unless File.exist?(gemfile_path)
100
+
101
+ gemfile_content = File.read(gemfile_path)
102
+
103
+ unless gemfile_content.include?("gem 'instrumental-components-library'")
104
+ if gemfile_content.include?("group :development")
105
+ # Add to existing development group
106
+ gemfile_content.gsub!(/group :development\s+do/) do |match|
107
+ "#{match}\n gem 'instrumental-components-library'"
108
+ end
109
+ else
110
+ # Create new development group
111
+ gemfile_content += "\n\ngroup :development do\n gem 'instrumental-components-library'\nend\n"
112
+ end
113
+
114
+ File.write(gemfile_path, gemfile_content)
115
+ puts "āœ… gem 'instrumental-components-library' has been added to the development group in your Gemfile."
116
+ else
117
+ puts "āœ… gem 'instrumental-components-library' is already in your Gemfile."
118
+ end
119
+ end
120
+
121
+ def run_bundle_install
122
+ system("bundle install")
123
+ end
124
+
125
+ def run_installer
126
+ system("rails g instrumental:install --license-key #{@license_key} --email #{@email}")
127
+ end
128
+ end
129
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instrumental-components
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Casel
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-05-11 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: open-uri
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: dotenv
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ description: The official installer for the Instrumental Components Library (instrumental.dev)
41
+ email:
42
+ - support@instrumental.dev
43
+ executables:
44
+ - install-instrumental
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/install-instrumental
49
+ - lib/instrumental-components.rb
50
+ homepage: https://instrumental.dev
51
+ licenses:
52
+ - Nonstandard
53
+ metadata: {}
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.6.5
69
+ specification_version: 4
70
+ summary: A simple installer for Instrumental Components
71
+ test_files: []