spell_craft 0.1.1 → 0.1.2
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/config/application.rb +1 -1
- data/lib/cmd/add/repl.rb +68 -4
- data/lib/utils/file_system.rb +20 -0
- data/lib/utils/gem.rb +16 -0
- data/lib/utils/shell.rb +13 -0
- data/spell_craft.gemspec +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '092e3be07d884e6207f4f0c0cf93157609fddd1e62218514f927cccd58275dfe'
|
4
|
+
data.tar.gz: c641a6d3b418b14b03da93af53489c6f0a235cc96373968c33d618b3c1efbfc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cea8a072a79286eb5bd74b6555c491a6578ac5545a78f191b6689824e0d1261f850a5a34ecfdb721a68cc71c16589496b4eaa7f5f537c60a088ebbf5636cbeb5
|
7
|
+
data.tar.gz: 59472374d88a467c8827e2ccb6617f861f76a7093a324adaf8972687a4ba6b3ef974e803e88e998e06b5e367f652724627d679e28a5f6c1ac4d270f2e1084652
|
data/config/application.rb
CHANGED
data/lib/cmd/add/repl.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# typed: true
|
3
3
|
|
4
|
+
require 'dry/monads/all'
|
5
|
+
require 'async'
|
6
|
+
|
4
7
|
module Cmd
|
5
8
|
module Add
|
6
9
|
class Repl < Dry::CLI::Command
|
10
|
+
include Dry::Monads
|
7
11
|
extend T::Sig
|
8
12
|
|
9
13
|
desc 'Allow adding configuration for REPL support on the current application, being either pry or irb'
|
@@ -13,17 +17,77 @@ module Cmd
|
|
13
17
|
option :pry, type: :boolean, default: false,
|
14
18
|
desc: 'Enable the code generator to assume Pry as the REPL of choice'
|
15
19
|
|
20
|
+
IRB_TEMPLATE = <<~CONTENT
|
21
|
+
#!/usr/bin/env ruby
|
22
|
+
|
23
|
+
# frozen_string_literal: true
|
24
|
+
|
25
|
+
require 'irb'
|
26
|
+
IRB.start
|
27
|
+
CONTENT
|
28
|
+
|
29
|
+
PRY_TEMPLATE = <<~CONTENT
|
30
|
+
#!/usr/bin/env ruby
|
31
|
+
|
32
|
+
require 'pry-reload'
|
33
|
+
require 'pry'
|
34
|
+
Pry.start
|
35
|
+
CONTENT
|
36
|
+
|
37
|
+
class ConfigType < T::Enum
|
38
|
+
enums do
|
39
|
+
IRB = new
|
40
|
+
PRY = new
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
16
44
|
def call(irb:, pry:)
|
17
|
-
|
45
|
+
if pry
|
46
|
+
response = install_deps
|
47
|
+
|
48
|
+
if response.failure?
|
49
|
+
# TODO: make this better with red message maybe.
|
50
|
+
puts response.failure[:message]
|
51
|
+
return
|
52
|
+
end
|
53
|
+
end
|
18
54
|
|
19
|
-
|
55
|
+
write_config(type: ConfigType::IRB) if irb
|
56
|
+
write_config(type: ConfigType::PRY) if pry
|
20
57
|
end
|
21
58
|
|
22
59
|
private
|
23
60
|
|
24
|
-
sig { void }
|
61
|
+
sig { params(type: ConfigType).void }
|
62
|
+
def write_config(type:)
|
63
|
+
case type
|
64
|
+
when ConfigType::IRB
|
65
|
+
Utils::FileSystem.create_directory_if_not_exist('bin')
|
66
|
+
|
67
|
+
File.write('bin/console', IRB_TEMPLATE)
|
68
|
+
when ConfigType::PRY
|
69
|
+
Utils::FileSystem.create_directory_if_not_exist('bin')
|
70
|
+
|
71
|
+
File.write('bin/console', PRY_TEMPLATE)
|
72
|
+
|
73
|
+
File.chmod(0o755, 'bin/console')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
sig { returns(T.any(Result::Success, Result::Failure)) }
|
25
78
|
def install_deps
|
26
|
-
|
79
|
+
unless File.exist?('Gemfile') || Utils::Shell.binary_exists?('bundle')
|
80
|
+
return Result::Failure.new({ message: 'Gemfile don\'t exist or the bundle gem is not available' })
|
81
|
+
end
|
82
|
+
|
83
|
+
return Result::Success.new(true) if Utils::Gem.exists?('pry') || Utils::Gem.exists?('pry-reload')
|
84
|
+
|
85
|
+
Async do
|
86
|
+
system('bundle add pry')
|
87
|
+
system('bundle add pry-reload')
|
88
|
+
end
|
89
|
+
|
90
|
+
Result::Success.new(true)
|
27
91
|
end
|
28
92
|
end
|
29
93
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
module Utils
|
5
|
+
class FileSystem
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
sig { params(name: String).returns(T::Boolean) }
|
9
|
+
def self.create_directory_if_not_exist(name)
|
10
|
+
return true if File.directory?(name)
|
11
|
+
|
12
|
+
begin
|
13
|
+
Dir.mkdir(name)
|
14
|
+
true
|
15
|
+
rescue SystemCallError
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/utils/gem.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
module Utils
|
5
|
+
class Gem
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
sig { params(name: String).returns(T::Boolean) }
|
9
|
+
def self.exists?(name)
|
10
|
+
gemfile_content = File.read('Gemfile')
|
11
|
+
|
12
|
+
pattern = /gem\s+['"]#{name}['"]/
|
13
|
+
!gemfile_content.scan(pattern).empty?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/utils/shell.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
module Utils
|
5
|
+
class Shell
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
sig { params(binary: String).returns(T::Boolean) }
|
9
|
+
def self.binary_exists?(binary)
|
10
|
+
File.executable?(File.join(ENV.fetch('PATH', '').split(':'), binary))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spell_craft.gemspec
CHANGED
@@ -8,7 +8,7 @@ $LOAD_PATH.unshift(config) unless $LOAD_PATH.include?(config)
|
|
8
8
|
|
9
9
|
Gem::Specification.new do |spec|
|
10
10
|
spec.name = 'spell_craft'
|
11
|
-
spec.version = '0.1.
|
11
|
+
spec.version = '0.1.2'
|
12
12
|
spec.summary = 'Yet another code generator to make you type less stuff'
|
13
13
|
spec.description = 'Yet another code generator to make you type less stuff'
|
14
14
|
spec.authors = ['Cherry Ramatis']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spell_craft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cherry Ramatis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-cli
|
@@ -52,6 +52,9 @@ files:
|
|
52
52
|
- lib/cmd/add/repl.rb
|
53
53
|
- lib/cmd/cli.rb
|
54
54
|
- lib/cmd/version.rb
|
55
|
+
- lib/utils/file_system.rb
|
56
|
+
- lib/utils/gem.rb
|
57
|
+
- lib/utils/shell.rb
|
55
58
|
- spell_craft.gemspec
|
56
59
|
homepage: https://github.com/cherryramatisdev/spell_craft.git
|
57
60
|
licenses:
|