spell_craft 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '092e3be07d884e6207f4f0c0cf93157609fddd1e62218514f927cccd58275dfe'
4
- data.tar.gz: c641a6d3b418b14b03da93af53489c6f0a235cc96373968c33d618b3c1efbfc6
3
+ metadata.gz: cfb94192846d3309c224e6512046f4031c66198d903f3745adce62ded95aeeb9
4
+ data.tar.gz: 27820fe9ab3ecf5d985c4232e7d780584fc001a71ad9290f7d839e09d1a36e6a
5
5
  SHA512:
6
- metadata.gz: cea8a072a79286eb5bd74b6555c491a6578ac5545a78f191b6689824e0d1261f850a5a34ecfdb721a68cc71c16589496b4eaa7f5f537c60a088ebbf5636cbeb5
7
- data.tar.gz: 59472374d88a467c8827e2ccb6617f861f76a7093a324adaf8972687a4ba6b3ef974e803e88e998e06b5e367f652724627d679e28a5f6c1ac4d270f2e1084652
6
+ metadata.gz: 7b6d6a5bd7bc8a8e42fd8da1e9fadeb38ae579197ca63c8489aef379c62d57ff1c591037d0c01cbca42093211e45462ab5afb038f2b2b415b5bd441d003cd5f6
7
+ data.tar.gz: 0e03842cfb8946170a0fef437eb78edab24c4ebc7d1e2e3e3fbff4eb70a28159a2b704ff89f6db10de42c12d3c02fb7c796e91e49c2642cb20580e46d199c693
data/README.md CHANGED
@@ -11,6 +11,11 @@ In the future, this project should enable configuration of [dry-rb](https://dry-
11
11
  ## Commands
12
12
 
13
13
  - [ ] `add`: A branch to add configurations
14
- - [ ] `repl`: This command should prompt to choose from IRB or pry and add correct configuration to `bin/console`, for pry it should install common extensions like pry reload and pry rescue.
15
- - [ ] `autoload`: This command should add the configuration necessary to use zeitwerk on the current project.
14
+ - [ ] `repl`: This command should prompt to choose from IRB or pry and add correct configuration to `bin/console`, for pry it should install common extensions like pry reload and pry rescue. `(PS: This should support rails)`
15
+ - [x] `autoload`: This command should add the configuration necessary to use zeitwerk on the current project.
16
+ - [ ] `type_checking`: This command should add the configuration necessary to use sorbet on the current project. `(PS: This should support rails)`
16
17
  - [ ] `remove`: A branch to remove configurations
18
+
19
+ ## Future plans
20
+
21
+ - Add support for third party generators to be plugged in?
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ require 'async'
5
+
6
+ module Cmd
7
+ module Add
8
+ class Autoload < Dry::CLI::Command
9
+ extend T::Sig
10
+
11
+ desc 'Allow adding configuration for Autoloading and autorequiring on the current application, being either plain zeitwerk or dry-system + zeitwerk'
12
+
13
+ option :dry_system, type: :boolean, default: false,
14
+ desc: 'Enable the code generator to assume dry-system + zeitwerk configuration'
15
+
16
+ ZEITWERK_TEMPLATE = <<~CONTENT
17
+ # frozen_string_literal: true
18
+
19
+ require 'zeitwerk'
20
+ require 'pathname'
21
+
22
+ root = Pathname('.')
23
+
24
+ loader = Zeitwerk::Loader.new
25
+
26
+ loader.push_dir(root.join('lib').realpath)
27
+ loader.push_dir(root.join('config').realpath)
28
+
29
+ loader.setup
30
+ CONTENT
31
+
32
+ DRY_SYSTEM_TEMPLATE = <<~CONTENT
33
+ # frozen_string_literal: true
34
+
35
+ require 'dry/system'
36
+
37
+ # Application configure all the paths to be autoloaded and auto injectable.
38
+ class Application < Dry::System::Container
39
+ configure do |config|
40
+ config.root = Pathname('.')
41
+
42
+ config.component_dirs.loader = Dry::System::Loader::Autoloading
43
+
44
+ config.component_dirs.add 'lib'
45
+ config.component_dirs.add 'config'
46
+ end
47
+ end
48
+
49
+ loader = Zeitwerk::Loader.new
50
+ loader.push_dir(Application.config.root.join('lib').realpath)
51
+ loader.push_dir(Application.config.root.join('config').realpath)
52
+ loader.setup
53
+ CONTENT
54
+
55
+ class DepsType < T::Enum
56
+ enums do
57
+ DRY_SYSTEM = new
58
+ ZEITWERK = new
59
+ end
60
+ end
61
+
62
+ sig { params(dry_system: T::Boolean).void }
63
+ def call(dry_system:)
64
+ return puts 'Could not locate Gemfile' unless Utils::Gem.gemfile_exist?
65
+
66
+ Utils::FileSystem.create_directory_if_not_exist('config')
67
+
68
+ if dry_system
69
+ File.write('config/application.rb', DRY_SYSTEM_TEMPLATE)
70
+
71
+ install_deps(DepsType::DRY_SYSTEM)
72
+ end
73
+
74
+ return if dry_system
75
+
76
+ File.write('config/application.rb', ZEITWERK_TEMPLATE)
77
+
78
+ install_deps(DepsType::ZEITWERK)
79
+ end
80
+
81
+ private
82
+
83
+ sig { params(type: DepsType).void }
84
+ def install_deps(type)
85
+ if Utils::Gem.exists?('dry-system') || Utils::Gem.exists?('zeitwerk') || Utils::Gem.exists?('dry-auto_inject')
86
+ return
87
+ end
88
+
89
+ pkgs = T.let(['zeitwerk'], T::Array[String])
90
+
91
+ pkgs.push('dry-system', 'dry-auto_inject') if type == DepsType::DRY_SYSTEM
92
+
93
+ Async do
94
+ pkgs.each do |pkg|
95
+ system("bundle add #{pkg}")
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
data/lib/cmd/add/repl.rb CHANGED
@@ -41,6 +41,7 @@ module Cmd
41
41
  end
42
42
  end
43
43
 
44
+ sig { params(irb: T::Boolean, pry: T::Boolean).void }
44
45
  def call(irb:, pry:)
45
46
  if pry
46
47
  response = install_deps
@@ -76,8 +77,10 @@ module Cmd
76
77
 
77
78
  sig { returns(T.any(Result::Success, Result::Failure)) }
78
79
  def install_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' })
80
+ return Result::Failure.new({ message: 'Could not locate Gemfile' }) unless Utils::Gem.gemfile_exist?
81
+
82
+ unless Utils::Shell.binary_exists?('bundle')
83
+ return Result::Failure.new({ message: 'Could not locate bundle gem' })
81
84
  end
82
85
 
83
86
  return Result::Success.new(true) if Utils::Gem.exists?('pry') || Utils::Gem.exists?('pry-reload')
data/lib/cmd/cli.rb CHANGED
@@ -8,6 +8,7 @@ module Cmd
8
8
  register 'version', Version, aliases: ['v', '-v', '--version']
9
9
  register 'add', aliases: ['a'] do |prefix|
10
10
  prefix.register 'repl', Add::Repl
11
+ prefix.register 'autoload', Add::Autoload
11
12
  end
12
13
  end
13
14
  end
data/lib/cmd/version.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: true
3
3
 
4
+ require 'rubygems'
5
+
4
6
  module Cmd
5
7
  class Version < Dry::CLI::Command
6
8
  desc 'Print version'
7
9
 
8
10
  def call
9
- puts '0.0.1'
11
+ puts Gem::Specification.load('spell_craft.gemspec').version
10
12
  end
11
13
  end
12
14
  end
data/lib/utils/gem.rb CHANGED
@@ -12,5 +12,10 @@ module Utils
12
12
  pattern = /gem\s+['"]#{name}['"]/
13
13
  !gemfile_content.scan(pattern).empty?
14
14
  end
15
+
16
+ sig { returns(T::Boolean) }
17
+ def self.gemfile_exist?
18
+ File.exist?('Gemfile')
19
+ end
15
20
  end
16
21
  end
data/lib/utils/shell.rb CHANGED
@@ -8,6 +8,11 @@ module Utils
8
8
  sig { params(binary: String).returns(T::Boolean) }
9
9
  def self.binary_exists?(binary)
10
10
  File.executable?(File.join(ENV.fetch('PATH', '').split(':'), binary))
11
+ path_dirs = ENV.fetch('PATH', '').split(File::PATH_SEPARATOR)
12
+
13
+ !path_dirs.find do |dir|
14
+ File.exist?(File.join(dir, binary)) && !File.directory?(File.join(dir, binary))
15
+ end.nil?
11
16
  end
12
17
  end
13
18
  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.2'
11
+ spec.version = '0.1.3'
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.2
4
+ version: 0.1.3
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-21 00:00:00.000000000 Z
11
+ date: 2023-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -49,6 +49,7 @@ files:
49
49
  - README.md
50
50
  - bin/spell_craft
51
51
  - config/application.rb
52
+ - lib/cmd/add/autoload.rb
52
53
  - lib/cmd/add/repl.rb
53
54
  - lib/cmd/cli.rb
54
55
  - lib/cmd/version.rb