lumise 0.2.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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/exe/lumise +16 -0
  3. data/lib/lumise/cli.rb +31 -0
  4. data/lib/lumise/cli.rbi +28 -0
  5. data/lib/lumise/command.rb +8 -0
  6. data/lib/lumise/commands/rubocop.rb +56 -0
  7. data/lib/lumise/commands/rubocop.rbi +48 -0
  8. data/lib/lumise/commands.rb +36 -0
  9. data/lib/lumise/commands.rbi +30 -0
  10. data/lib/lumise/configurations.rb +16 -0
  11. data/lib/lumise/configurations.rbi +1 -0
  12. data/lib/lumise/error.rb +6 -0
  13. data/lib/lumise/l.rb +10 -0
  14. data/lib/lumise/l.rbi +10 -0
  15. data/lib/lumise/logger.rb +7 -0
  16. data/lib/lumise/services/commands/rubocop/repo_files.rb +56 -0
  17. data/lib/lumise/services/commands/rubocop/repo_files.rbi +51 -0
  18. data/lib/lumise/services/commands/rubocop/update_files.rb +87 -0
  19. data/lib/lumise/services/commands/rubocop/update_files.rbi +67 -0
  20. data/lib/lumise/services/commands/rubocop/update_gems.rb +64 -0
  21. data/lib/lumise/services/commands/rubocop/update_gems.rbi +47 -0
  22. data/lib/lumise/services/commands/rubocop/update_todo.rb +52 -0
  23. data/lib/lumise/services/commands/rubocop/update_todo.rbi +43 -0
  24. data/lib/lumise/templates/.git +1 -0
  25. data/lib/lumise/templates/README.md +70 -0
  26. data/lib/lumise/templates/rubocop/.rubocop +1 -0
  27. data/lib/lumise/templates/rubocop/.rubocop.yml +17 -0
  28. data/lib/lumise/templates/rubocop/.rubocop_global.yml +58 -0
  29. data/lib/lumise/templates/rubocop/.rubocop_local.yml +3 -0
  30. data/lib/lumise/templates/rubocop/.rubocop_project.yml +29 -0
  31. data/lib/lumise/templates/rubocop/.rubocop_raw.yml +16 -0
  32. data/lib/lumise/templates/rubocop/.rubocop_todo.yml +5 -0
  33. data/lib/lumise/version.rb +6 -0
  34. data/lib/lumise/which/curl.rb +46 -0
  35. data/lib/lumise/which/curl.rbi +36 -0
  36. data/lib/lumise.rb +45 -0
  37. data/lib/lumise.rbi +12 -0
  38. data/lib/warning.rb +10 -0
  39. data/lib/warning.rbi +8 -0
  40. metadata +187 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d82dc3a5d42d401ae1bc2bf483c99dd2bc592431
4
+ data.tar.gz: 3ee4e2003df33f6e899476ee8c79b2cb565fc678
5
+ SHA512:
6
+ metadata.gz: 032b661e3f4e3d87e8cbe7aca8c3271c00682fd7c7d0acdefeec896f0551e3f059ebc3c1c46ca511df93b489cc956abe4a84c9535425aa892d005740c2a66979
7
+ data.tar.gz: 3ff36cbaba6e560e538f1375a620585f5d84c8f098fceef515193af3f773703a19c344a0d291548518ae50652462197f18757f7af1c8a510dc39718b67cba8a7
data/exe/lumise ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/lumise'
5
+
6
+ Signal.trap('INT') do
7
+ warn("\n#{caller.join("\n")}: interrupted")
8
+ exit(1)
9
+ end
10
+
11
+ begin
12
+ Lumise::CLI.start
13
+ rescue Lumise::CLI::Error => e
14
+ puts "ERROR: #{e.message}"
15
+ exit 1
16
+ end
data/lib/lumise/cli.rb ADDED
@@ -0,0 +1,31 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ class CLI < Thor
6
+ Error = Class.new(StandardError)
7
+
8
+ desc 'version', 'lumise version'
9
+ def version
10
+ $stdout.puts "v#{Lumise::VERSION}"
11
+ end
12
+ map %w[--version -v] => :version
13
+
14
+ desc 'rubocop', 'Set up rubocop'
15
+ method_option :help, aliases: '-h', type: :boolean,
16
+ desc: 'Display usage information'
17
+ def rubocop(*)
18
+ if options[:help]
19
+ invoke :help, ['rubocop']
20
+ else
21
+ execute_rubocop
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def execute_rubocop
28
+ Lumise::Commands::Rubocop.new(options).execute
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ class CLI < Thor
6
+ sig do
7
+ params(
8
+ mappings: T::Hash[T.untyped, T.untyped]
9
+ ).void
10
+ end
11
+ def self.map(mappings)
12
+ end
13
+
14
+ sig { void }
15
+ def version
16
+ end
17
+
18
+ sig { params(arr: T.untyped).void }
19
+ def rubocop(*arr)
20
+ end
21
+
22
+ private
23
+
24
+ sig { void }
25
+ def execute_rubocop
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ class Command
6
+ include Commands
7
+ end
8
+ end
@@ -0,0 +1,56 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module Commands
6
+ class Rubocop < Lumise::Command
7
+ include L
8
+
9
+ def initialize(_options)
10
+ verify_dependencies
11
+ @plugins = set_plugins
12
+ rescue Which::Curl::CurlError
13
+ logger.error 'Please install curl'
14
+ end
15
+
16
+ attr_reader :plugins
17
+
18
+ def execute
19
+ update_gems
20
+ create_files
21
+ update_todo
22
+ end
23
+
24
+ private
25
+
26
+ def set_plugins
27
+ l.plugins || prompt_plugins
28
+ end
29
+
30
+ def verify_dependencies
31
+ Which::Curl.call
32
+ end
33
+
34
+ def prompt_plugins
35
+ choices = %w[performance rails rspec sorbet]
36
+
37
+ prompt.multi_select 'Which plugins are you using?' do |menu|
38
+ menu.default 1, 3
39
+ menu.choices choices
40
+ end
41
+ end
42
+
43
+ def update_gems
44
+ UpdateGems.call plugins: plugins
45
+ end
46
+
47
+ def create_files
48
+ UpdateFiles.call plugins: plugins
49
+ end
50
+
51
+ def update_todo
52
+ UpdateTodo.call plugins: plugins
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,48 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module Commands
6
+ class Rubocop < Lumise::Command
7
+ include L
8
+
9
+ sig { params(_options: T.untyped).void }
10
+ def initialize(_options)
11
+ @plugins = T.let nil, T::Array[String]
12
+ end
13
+
14
+ sig { returns T::Array[String] }
15
+ attr_reader :plugins
16
+
17
+ sig { void }
18
+ def execute
19
+ end
20
+
21
+ private
22
+
23
+ sig { returns T::Array[String] }
24
+ def set_plugins
25
+ end
26
+
27
+ sig { void }
28
+ def verify_dependencies
29
+ end
30
+
31
+ sig { returns T::Array[String] }
32
+ def prompt_plugins
33
+ end
34
+
35
+ sig { void }
36
+ def update_gems
37
+ end
38
+
39
+ sig { void }
40
+ def create_files
41
+ end
42
+
43
+ sig { void }
44
+ def update_todo
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,36 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require 'tty-command'
5
+ require 'tty-file'
6
+ require 'tty-logger'
7
+ require 'tty-prompt'
8
+ require 'tty-which'
9
+
10
+ module Lumise
11
+ module Commands
12
+ def command(options)
13
+ TTY::Command.new(options)
14
+ end
15
+
16
+ def generator
17
+ TTY::File
18
+ end
19
+
20
+ def logger
21
+ TTY::Logger.new
22
+ end
23
+
24
+ def prompt(**options)
25
+ TTY::Prompt.new(options)
26
+ end
27
+
28
+ def which(cmd)
29
+ TTY::Which.which(cmd)
30
+ end
31
+
32
+ def exec_exist?(cmd)
33
+ TTY::Which.exist?(cmd)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module Commands
6
+ sig { params(options: T.untyped).returns(TTY::Command) }
7
+ def command(options)
8
+ end
9
+
10
+ sig { returns(T.class_of(TTY::File)) }
11
+ def generator
12
+ end
13
+
14
+ sig { returns(TTY::Logger) }
15
+ def logger
16
+ end
17
+
18
+ sig { params(options: T::Hash[T.untyped, T.untyped]).returns TTY::Prompt }
19
+ def prompt(**options)
20
+ end
21
+
22
+ sig { params(cmd: String).returns T::Array[String] }
23
+ def which(cmd)
24
+ end
25
+
26
+ sig { params(cmd: String).returns T::Boolean }
27
+ def exec_exist?(cmd)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ class Configurations < T::Struct
6
+ include Singleton
7
+
8
+ prop :force, T::Boolean, default: false
9
+ prop :plugins, T.nilable(T::Array[String])
10
+ prop :repo, T.nilable(String)
11
+ prop :branch, T.nilable(String)
12
+ prop :update_gems, T.nilable(T::Boolean)
13
+ prop :update_files, T.nilable(T::Boolean)
14
+ prop :update_todo, T.nilable(T::Boolean)
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ # typed: strong
@@ -0,0 +1,6 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ class Error < StandardError; end
6
+ end
data/lib/lumise/l.rb ADDED
@@ -0,0 +1,10 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module L
6
+ def l
7
+ Lumise::Configurations.instance
8
+ end
9
+ end
10
+ end
data/lib/lumise/l.rbi ADDED
@@ -0,0 +1,10 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module L
6
+ sig { returns Configurations }
7
+ def l
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ class Logger < TTY::Logger
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module Commands
6
+ class Rubocop < Lumise::Command
7
+ class RepoFiles
8
+ include Commands
9
+ include L
10
+
11
+ def self.call
12
+ new.call
13
+ end
14
+
15
+ def call
16
+ remove_tmp_lumise
17
+ recreate_tmp_lumise
18
+ clone_repo_onto_tmp_lumise
19
+ rubocop_files
20
+ end
21
+
22
+ private
23
+
24
+ def rubocop_files
25
+ Dir['tmp/lumise/rubocop/**/{*,.*}']
26
+ end
27
+
28
+ def clone_repo_onto_tmp_lumise
29
+ command(printer: :null).run(git_clone_command) do |_out, err|
30
+ logger.info err.force_encoding(Encoding::UTF_8)
31
+ end
32
+ end
33
+
34
+ def git_clone_command
35
+ "git clone --single-branch --branch #{branch} #{repo} tmp/lumise"
36
+ end
37
+
38
+ def repo
39
+ T.must(l.repo)
40
+ end
41
+
42
+ def branch
43
+ l.branch || 'master'
44
+ end
45
+
46
+ def recreate_tmp_lumise
47
+ command(printer: :quiet).run('mkdir -p tmp/lumise')
48
+ end
49
+
50
+ def remove_tmp_lumise
51
+ command(printer: :quiet).run('rm -rf tmp/lumise')
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,51 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module Commands
6
+ class Rubocop < Lumise::Command
7
+ class RepoFiles
8
+ include Commands
9
+ include L
10
+
11
+ sig { returns T::Array[String] }
12
+ def self.call
13
+ end
14
+
15
+ sig { returns T::Array[String] }
16
+ def call
17
+ end
18
+
19
+ private
20
+
21
+ sig { returns T::Array[String] }
22
+ def rubocop_files
23
+ end
24
+
25
+ sig { void }
26
+ def clone_repo_onto_tmp_lumise
27
+ end
28
+
29
+ sig { returns String }
30
+ def git_clone_command
31
+ end
32
+
33
+ sig { returns String }
34
+ def repo
35
+ end
36
+
37
+ sig { returns String }
38
+ def branch
39
+ end
40
+
41
+ sig { void }
42
+ def recreate_tmp_lumise
43
+ end
44
+
45
+ sig { void }
46
+ def remove_tmp_lumise
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,87 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module Commands
6
+ class Rubocop < Lumise::Command
7
+ class UpdateFiles
8
+ include Commands
9
+ include L
10
+
11
+ def self.call(plugins:)
12
+ new(plugins: plugins).send :perform
13
+ end
14
+
15
+ def initialize(plugins:)
16
+ @plugins = plugins
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :plugins
22
+
23
+ def perform
24
+ if yes?
25
+ files.each do |file|
26
+ parse_template file
27
+ end
28
+ end
29
+ end
30
+
31
+ def parse_template(file)
32
+ generator.create_file File.basename(file), mustacho(file),
33
+ force: l.force
34
+ end
35
+
36
+ def mustacho(file)
37
+ Mustache.render File.read(file),
38
+ require: plugins?, plugins: plugins_list,
39
+ rspec: plugins.include?('rspec'),
40
+ sorbet: plugins.include?('sorbet')
41
+ end
42
+
43
+ def plugins_list
44
+ plugins.map do |plugin|
45
+ " - rubocop-#{plugin}"
46
+ end.join("\n")
47
+ rescue NoMethodError
48
+ []
49
+ end
50
+
51
+ def files
52
+ if l.repo
53
+ repo_files
54
+ else
55
+ template_files
56
+ end
57
+ end
58
+
59
+ def template_files
60
+ Dir[templates_path + '**/{*,.*}'].reject do |file|
61
+ file.scan(/\.$/).first
62
+ end
63
+ end
64
+
65
+ def repo_files
66
+ RepoFiles.call
67
+ end
68
+
69
+ def templates_path
70
+ File.expand_path('../../../templates/rubocop', __dir__)
71
+ end
72
+
73
+ def plugins?
74
+ !plugins&.first.nil?
75
+ end
76
+
77
+ def yes?
78
+ if l.update_files.nil?
79
+ prompt.yes? 'Update .rubocop files?', suffix: 'Yeah/nah'
80
+ else
81
+ l.update_files
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,67 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module Commands
6
+ class Rubocop < Lumise::Command
7
+ class UpdateFiles
8
+ include Commands
9
+ include L
10
+
11
+ sig { params(plugins: T::Array[String]).void }
12
+ def self.call(plugins:)
13
+ end
14
+
15
+ sig { params(plugins: T::Array[String]).void }
16
+ def initialize(plugins:)
17
+ @plugins = plugins
18
+ end
19
+
20
+ private
21
+
22
+ sig { returns T::Array[String] }
23
+ attr_reader :plugins
24
+
25
+ sig { void }
26
+ def perform
27
+ end
28
+
29
+ sig { params(file: T.any(String, Pathname)).void }
30
+ def parse_template(file)
31
+ end
32
+
33
+ sig { params(file: T.any(File, String, Pathname)).returns String }
34
+ def mustacho(file)
35
+ end
36
+
37
+ sig { returns T.any(T::Array[T.untyped], String) }
38
+ def plugins_list
39
+ end
40
+
41
+ sig { returns(T::Array[String]) }
42
+ def files
43
+ end
44
+
45
+ sig { returns T::Array[String] }
46
+ def template_files
47
+ end
48
+
49
+ sig { returns T::Array[String] }
50
+ def repo_files
51
+ end
52
+
53
+ sig { returns(String) }
54
+ def templates_path
55
+ end
56
+
57
+ sig { returns(T::Boolean) }
58
+ def plugins?
59
+ end
60
+
61
+ sig { returns(T::Boolean) }
62
+ def yes?
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,64 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module Commands
6
+ class Rubocop < Lumise::Command
7
+ class UpdateGems
8
+ include Commands
9
+ include L
10
+
11
+ def self.call(plugins:)
12
+ new(plugins: plugins).send :perform
13
+ end
14
+
15
+ def initialize(plugins:)
16
+ @plugins = plugins
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :plugins
22
+
23
+ def perform
24
+ if yes?
25
+ logger.info "#Running #{bundle_update_command}"
26
+ bundle_update
27
+ end
28
+ end
29
+
30
+ def bundle_update
31
+ command(printer: :quiet).run(bundle_update_command)
32
+ rescue TTY::Command::ExitError, StandardError => e
33
+ # Could not find gem 'rubocop'.
34
+ #
35
+ # Could not locate Gemfile
36
+ #
37
+ # This Bundle hasn't been installed yet. Run `bundle install` to
38
+ # update and install the bundled gems.
39
+
40
+ logger.error e.message
41
+ exit 1
42
+ end
43
+
44
+ def yes?
45
+ if l.update_gems.nil?
46
+ prompt.yes? 'Update rubocop gems?', suffix: 'Yeah/nah'
47
+ else
48
+ l.update_gems
49
+ end
50
+ end
51
+
52
+ def bundle_update_command
53
+ "bundle update --conservative rubocop #{gems}"
54
+ end
55
+
56
+ def gems
57
+ plugins.map do |plugin|
58
+ 'rubocop-' + plugin
59
+ end.join(' ')
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,47 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ module Lumise
5
+ module Commands
6
+ class Rubocop < Lumise::Command
7
+ class UpdateGems
8
+ include Commands
9
+ include L
10
+
11
+ sig { params(plugins: T::Array[String]).void }
12
+ def self.call(plugins:)
13
+ end
14
+
15
+ sig { params(plugins: T::Array[String]).void }
16
+ def initialize(plugins:)
17
+ @plugins = plugins
18
+ end
19
+
20
+ private
21
+
22
+ sig { returns T::Array[String] }
23
+ attr_reader :plugins
24
+
25
+ sig { void }
26
+ def perform
27
+ end
28
+
29
+ sig { void }
30
+ def bundle_update
31
+ end
32
+
33
+ sig { returns T::Boolean }
34
+ def yes?
35
+ end
36
+
37
+ sig { returns String }
38
+ def bundle_update_command
39
+ end
40
+
41
+ sig { returns String }
42
+ def gems
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end