spell_craft 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 337df1b211ee709a6ce91e2ffdeb96301c2aa9453e2a141da3435673d0c3b3da
4
- data.tar.gz: d533542e00a753c14d70678bd732a66cc5354a2550babce1b3830c64d8c0f86a
3
+ metadata.gz: '092e3be07d884e6207f4f0c0cf93157609fddd1e62218514f927cccd58275dfe'
4
+ data.tar.gz: c641a6d3b418b14b03da93af53489c6f0a235cc96373968c33d618b3c1efbfc6
5
5
  SHA512:
6
- metadata.gz: 8d7efc88b0a6f666e66f83ebf80a7541b8a837e007c7c2cc3f97df638c5a95dd0b57c182ebc3d3b0db8bd89119e2480d53f7ccb941ea226f1544c22e85788fe4
7
- data.tar.gz: 391c4897bdcfd0b3a5311af8e8b57fb51208b15e6fbc9ff56c34294417678bbf50799ed68fec89572c177af3b7d85b944a30cb6a80805ab5bcbe987ad12e7d05
6
+ metadata.gz: cea8a072a79286eb5bd74b6555c491a6578ac5545a78f191b6689824e0d1261f850a5a34ecfdb721a68cc71c16589496b4eaa7f5f537c60a088ebbf5636cbeb5
7
+ data.tar.gz: 59472374d88a467c8827e2ccb6617f861f76a7093a324adaf8972687a4ba6b3ef974e803e88e998e06b5e367f652724627d679e28a5f6c1ac4d270f2e1084652
data/bin/spell_craft ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sorbet-runtime'
4
+ require "dry/cli"
5
+
6
+ require_relative '../config/application'
7
+
8
+ Dry::CLI.new(Cmd::Cli).call
@@ -4,7 +4,7 @@
4
4
  require 'zeitwerk'
5
5
  require 'pathname'
6
6
 
7
- root = Pathname('.')
7
+ root = Pathname('/Users/cherryramatis/Repos/spell_craft')
8
8
 
9
9
  loader = Zeitwerk::Loader.new
10
10
 
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
- install_deps if pry
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
- puts 'Hello world'
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
- puts 'installing deps'
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
@@ -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.0'
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']
@@ -17,9 +17,13 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.required_ruby_version = '>= 3.2.0'
19
19
 
20
+ spec.files = Dir['LICENSE', 'README.md', 'spell_craft.gemspec', 'config/**/*', 'lib/**/*']
21
+
20
22
  spec.require_paths = ['lib']
21
- spec.files = Dir['LICENSE', 'README.md', 'spell_craft.gemspec', 'main.rb', 'config/**/*', 'lib/**/*']
23
+ spec.executables = ['spell_craft']
22
24
 
25
+ spec.add_dependency 'dry-cli', '~> 1.0'
23
26
  spec.add_dependency 'sorbet-runtime', '~> 0.5.11026'
27
+
24
28
  spec.metadata['rubygems_mfa_required'] = 'true'
25
29
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spell_craft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
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-18 00:00:00.000000000 Z
11
+ date: 2023-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: sorbet-runtime
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -26,17 +40,21 @@ dependencies:
26
40
  version: 0.5.11026
27
41
  description: Yet another code generator to make you type less stuff
28
42
  email:
29
- executables: []
43
+ executables:
44
+ - spell_craft
30
45
  extensions: []
31
46
  extra_rdoc_files: []
32
47
  files:
33
48
  - LICENSE
34
49
  - README.md
50
+ - bin/spell_craft
35
51
  - config/application.rb
36
52
  - lib/cmd/add/repl.rb
37
53
  - lib/cmd/cli.rb
38
54
  - lib/cmd/version.rb
39
- - main.rb
55
+ - lib/utils/file_system.rb
56
+ - lib/utils/gem.rb
57
+ - lib/utils/shell.rb
40
58
  - spell_craft.gemspec
41
59
  homepage: https://github.com/cherryramatisdev/spell_craft.git
42
60
  licenses:
data/main.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
- # typed: true
3
-
4
- require 'sorbet-runtime'
5
- require "dry/cli"
6
-
7
- require_relative 'config/application'
8
-
9
- Dry::CLI.new(Cmd::Cli).call