asdf-discover 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 62237375363e82aebaa954b482acd3c16109b208ad48b976bdd0fe6eef9ab946
4
+ data.tar.gz: 6cbe4ccee4b08822b75c8e854acc5488ec5204106f6a69d3eb56f7a4456f318b
5
+ SHA512:
6
+ metadata.gz: b4834888adce95eba59ac70dcffde7778a0d367aa9f624ef6d5c1873348af089b6e26eb4cc316087f45c7e1cda77233c7d7476982fcb791d93b5b337eaecdf29
7
+ data.tar.gz: 9958fb09d33896bccd1333912085baffb4b47970c38db51331fa179d7ed81b51bac0afcc6f8edf5103bd6ba99aa811f84f40121f4fdc2caba3d157b62dcc825f
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,42 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+
7
+ Layout/FirstArrayElementIndentation:
8
+ EnforcedStyle: consistent
9
+
10
+ Layout/MultilineMethodCallIndentation:
11
+ EnforcedStyle: indented
12
+
13
+ Metrics/BlockLength:
14
+ Exclude:
15
+ - "Rakefile"
16
+ - "**/*.rake"
17
+ - "spec/**/*.rb"
18
+
19
+ RSpec/ExampleLength:
20
+ Max: 15
21
+
22
+ RSpec/FactoryBot/CreateList:
23
+ Enabled: false
24
+
25
+ RSpec/MultipleExpectations:
26
+ Max: 5
27
+
28
+ Style/FrozenStringLiteralComment:
29
+ Enabled: false
30
+
31
+ Style/StringLiterals:
32
+ Enabled: true
33
+ EnforcedStyle: double_quotes
34
+
35
+ Style/SymbolArray:
36
+ Enabled: false
37
+
38
+ Style/TrailingCommaInArrayLiteral:
39
+ EnforcedStyleForMultiline: comma
40
+
41
+ Style/WordArray:
42
+ EnforcedStyle: brackets
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [version] - yyyy-mm-dd
11
+
12
+ ### Added
13
+ ### Changed
14
+ ### Deprecated
15
+ ### Fixed
16
+ ### Removed
17
+ ### Security
18
+
19
+ ## [Unreleased]
20
+
21
+ ## [1.0] - 2020-10-02
22
+
23
+ ### Added
24
+
25
+ * Support for nodejs from .node-version, .nvmrc
26
+ * Support for ruby from .ruby-version, .rvmrc
27
+ * Support for golang from go.mod
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in asdf-discover.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Jason Schweier
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.
@@ -0,0 +1,65 @@
1
+ # asdf-discover
2
+
3
+ A gem that provides an executable to populate [asdf](http://asdf-vm.com/)'s `.tool-versions` file.
4
+
5
+ ## Changelog
6
+
7
+ [Changelog](./CHANGELOG.md) following https://keepachangelog.com
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ $ gem install asdf-discover
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Run `asdf-discover` in a project directory.
18
+
19
+ ## Languages / Versions Discovered
20
+
21
+ | Lanuage | File |
22
+ |---------|---------------|
23
+ | Go | go.mod |
24
+ | Ruby | .ruby-version |
25
+ | Ruby | .rvmrc |
26
+ | node.js | .nvmrc |
27
+ | node.js | .node-version |
28
+
29
+ ## TODO
30
+
31
+ * If a version comes from multiple sources, list them all (currently displays the first found)
32
+ * There seems to be 2 ways to find a version:
33
+ * The contents of a file (e.g. .ruby-version)
34
+ * A line in a file (e.g. go.mod)
35
+
36
+ Consider a DSL for adding more:
37
+
38
+ ```ruby
39
+ class GoMod
40
+ include Asdf::Searcher
41
+
42
+ scan_file "go.mod", for: /go ([0-9.]+)$/
43
+ end
44
+
45
+ class DotRubyVersion
46
+ include Asdf::Searcher
47
+
48
+ file_contents ".ruby-version"
49
+ end
50
+ ```
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bundle install`.
55
+ Then, run `rake spec` to run the tests.
56
+
57
+ You can run the binary locally with: `ruby -Ilib ./exe/asdf-discover path/to/directory`
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jmks/asdf-discover.
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:rubocop)
7
+
8
+ task default: [:spec, :rubocop]
@@ -0,0 +1,31 @@
1
+ require_relative "lib/asdf_discover/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "asdf-discover"
5
+ spec.version = AsdfDiscover::VERSION
6
+ spec.authors = ["Jason Schweier"]
7
+ spec.email = ["jason.schweier@gmail.com"]
8
+
9
+ spec.summary = %(Simple command to discover what should be in ASDF's .tool-versions file)
10
+ spec.homepage = "https://github.com/jmks/asdf-discover"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/jmks/asdf-discover"
16
+ # spec.metadata["changelog_uri"] = "https://github.com/jmks/asdf-discover/CHANGELOG.md"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "pry-byebug"
29
+ spec.add_development_dependency "rubocop", "~> 1.0"
30
+ spec.add_development_dependency "rubocop-rspec", "~> 1.0"
31
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "asdf/discover"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "asdf_discover"
4
+ require "fileutils"
5
+
6
+ FileUtils.cd(ARGV.first) if ARGV.first
7
+
8
+ if File.exist?(AsdfDiscover::TOOL_VERSIONS)
9
+ puts "#{AsdfDiscover::TOOL_VERSIONS} already exists!"
10
+ exit(1)
11
+ end
12
+
13
+ result = AsdfDiscover.search
14
+
15
+ unless result.any?
16
+ puts "No tool versions found!"
17
+ exit(1)
18
+ end
19
+
20
+ unless result.consistent?
21
+ result.conflicts.each do |conflict|
22
+ puts "Discovered multiple versions for #{conflict.tool}:"
23
+ conflict.sources.each do |source|
24
+ puts " - #{source.version} from #{source.source}"
25
+ end
26
+ puts
27
+ end
28
+ puts "You should manually reconcile which version to use"
29
+ puts ".tool-versions will include all versions discovered"
30
+ puts "asdf, by default, will use the first entry"
31
+ end
32
+
33
+ File.open(AsdfDiscover::TOOL_VERSIONS, "w") do |f|
34
+ result.tool_versions.each do |tool_version|
35
+ f.puts "#{tool_version.tool} #{tool_version.version} # from #{tool_version.source}"
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ require "asdf_discover/result"
2
+ require "asdf_discover/search_result"
3
+ require "asdf_discover/searchers/dot_node_version"
4
+ require "asdf_discover/searchers/dot_ruby_version"
5
+ require "asdf_discover/searchers/gemfile"
6
+ require "asdf_discover/searchers/go_mod"
7
+ require "asdf_discover/searchers/nvmrc"
8
+ require "asdf_discover/version"
9
+
10
+ # Namespace for the gem
11
+ module AsdfDiscover
12
+ TOOL_VERSIONS = ".tool-versions".freeze
13
+
14
+ def self.add_searcher(*searchers)
15
+ @searchers ||= []
16
+ @searchers.concat(searchers)
17
+ end
18
+
19
+ def self.search
20
+ found = @searchers
21
+ .map(&:new)
22
+ .map(&:call)
23
+ .select(&:found?)
24
+
25
+ SearchResult.new(found)
26
+ end
27
+
28
+ add_searcher Searchers::DotNodeVersion
29
+ add_searcher Searchers::DotRubyVersion
30
+ add_searcher Searchers::Gemfile
31
+ add_searcher Searchers::GoMod
32
+ add_searcher Searchers::Nvmrc
33
+ end
@@ -0,0 +1,18 @@
1
+ module AsdfDiscover
2
+ # The result of a search by a Searcher.
3
+ # A result is either Found or NotFound.
4
+
5
+ # A result that was found.
6
+ Found = Struct.new(:tool, :version, :source) do
7
+ def found?
8
+ true
9
+ end
10
+ end
11
+
12
+ # A nil result
13
+ class NotFound
14
+ def self.found?
15
+ false
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ module AsdfDiscover
2
+ # Amalgamated results from Searchers.
3
+ # Contains the data required to display warnings and write the .tool-versions file.
4
+ class SearchResult
5
+ Conflict = Struct.new(:tool, :sources)
6
+
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def consistent?
12
+ conflicts.none?
13
+ end
14
+
15
+ def conflicts
16
+ @conflicts ||= find_conflicts
17
+ end
18
+
19
+ def tool_versions
20
+ @tool_versions ||= collect_tool_versions
21
+ end
22
+
23
+ def any?
24
+ @results.any?
25
+ end
26
+
27
+ private
28
+
29
+ def find_conflicts
30
+ @results
31
+ .group_by(&:tool)
32
+ .filter { |_tool, matches| matches.map(&:version).uniq.length != 1 }
33
+ .map { |tool, matches| Conflict.new(tool, matches) }
34
+ end
35
+
36
+ def collect_tool_versions
37
+ @results
38
+ .sort_by { |e| [e.tool, e.version] }
39
+ .uniq { |e| [e.tool, e.version] }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ module AsdfDiscover
2
+ # A Searcher responds to #call and returns a AsdfDiscover::Result
3
+ class Searcher
4
+ # call should return either Found or NotFound
5
+ def call
6
+ raise "implement me"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module AsdfDiscover
2
+ module Searchers
3
+ # Searches in .node-version
4
+ class DotNodeVersion
5
+ NODE_VERSION = ".node-version".freeze
6
+
7
+ def call
8
+ return NotFound unless File.exist?(NODE_VERSION)
9
+
10
+ version = File.read(NODE_VERSION).chomp
11
+
12
+ Found.new("nodejs", version, NODE_VERSION)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module AsdfDiscover
2
+ module Searchers
3
+ # Searches in .ruby-version
4
+ class DotRubyVersion
5
+ RUBY_VERSION_FILE = ".ruby-version".freeze
6
+
7
+ def call
8
+ return NotFound unless File.exist?(RUBY_VERSION_FILE)
9
+
10
+ version = File.read(RUBY_VERSION_FILE).chomp
11
+
12
+ Found.new("ruby", version, RUBY_VERSION_FILE)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module AsdfDiscover
2
+ module Searchers
3
+ # Searches for a Ruby version in a Gemfile
4
+ class Gemfile
5
+ GEMFILE = "Gemfile".freeze
6
+
7
+ def call
8
+ return NotFound unless File.exist?(GEMFILE)
9
+
10
+ File.open(GEMFILE, "r").each_line do |line|
11
+ return Found.new("ruby", Regexp.last_match(1), GEMFILE) if line =~ /ruby ['"]([0-9.]+)['"]$/
12
+ end
13
+
14
+ NotFound
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module AsdfDiscover
2
+ module Searchers
3
+ # Searches for a Go version in the go.mod file
4
+ class GoMod
5
+ GO_MOD = "go.mod".freeze
6
+
7
+ def call
8
+ return NotFound unless File.exist?(GO_MOD)
9
+
10
+ File.open(GO_MOD, "r").each_line do |line|
11
+ return Found.new("golang", Regexp.last_match(1), GO_MOD) if line =~ /go ([0-9.]+)$/
12
+ end
13
+
14
+ NotFound
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module AsdfDiscover
2
+ module Searchers
3
+ # Searches in .nvmrc
4
+ class Nvmrc
5
+ NVMRC = ".nvmrc".freeze
6
+
7
+ def call
8
+ return NotFound unless File.exist?(NVMRC)
9
+
10
+ version = File.read(NVMRC).chomp
11
+
12
+ Found.new("nodejs", version, NVMRC)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module AsdfDiscover
2
+ VERSION = "1.0.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asdf-discover
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Schweier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description:
70
+ email:
71
+ - jason.schweier@gmail.com
72
+ executables:
73
+ - asdf-discover
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".rubocop.yml"
80
+ - ".travis.yml"
81
+ - CHANGELOG.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - asdf-discover.gemspec
87
+ - bin/console
88
+ - bin/setup
89
+ - exe/asdf-discover
90
+ - lib/asdf_discover.rb
91
+ - lib/asdf_discover/result.rb
92
+ - lib/asdf_discover/search_result.rb
93
+ - lib/asdf_discover/searcher.rb
94
+ - lib/asdf_discover/searchers/dot_node_version.rb
95
+ - lib/asdf_discover/searchers/dot_ruby_version.rb
96
+ - lib/asdf_discover/searchers/gemfile.rb
97
+ - lib/asdf_discover/searchers/go_mod.rb
98
+ - lib/asdf_discover/searchers/nvmrc.rb
99
+ - lib/asdf_discover/version.rb
100
+ homepage: https://github.com/jmks/asdf-discover
101
+ licenses:
102
+ - MIT
103
+ metadata:
104
+ homepage_uri: https://github.com/jmks/asdf-discover
105
+ source_code_uri: https://github.com/jmks/asdf-discover
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 2.6.0
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.1.4
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Simple command to discover what should be in ASDF's .tool-versions file
125
+ test_files: []