lit-cli 0.3.0 → 0.4.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lit_cli.rb +17 -9
  3. data/lib/lit_pry.rb +68 -0
  4. metadata +18 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7da20adf8c48a70324edea2bbd6fd0ecce700d5963062517dbc3a966aab086be
4
- data.tar.gz: f44d5c8433cfa2a640ea2d8785c742070d15ef5078fa131187c6a21c65bedec5
3
+ metadata.gz: 0ed5d7713a6943b0043bf26568c069dc4c0a647a8581dc48d7a88c05abb3b5de
4
+ data.tar.gz: 53c911d1424038fa5bb836dfc68f739514d53a62b91ed813dc506078d4c5742d
5
5
  SHA512:
6
- metadata.gz: b7cb6cf1c1095c166b91ad7b926b30fbb11635b31b2c54aeff776901f20c0ecfae54ebd2d03e88dc9b26a659c462692919cdd113989953e4f89367fa34cde7a0
7
- data.tar.gz: 7b9938c6416e365a966e91bd659a7448a6ff31fd40ded6427e586ea5277c4d08f575e2f484ee888e4b008bd13f4b814d6f398b1d96bfd4240aaba296cf36b458
6
+ metadata.gz: e75aab70ca6f9aac9258b68f289ca7efdaf24d8328030a7195c91e24ecd7828eaf32d42d7cee87acc6b1d188d2ef692969cc402055b1a98ed71bc5a0edf4632e
7
+ data.tar.gz: 0f88b27bcb0308d93b8e7ba223a91a11125faf4c29fdb600e3ff77a18a1526c1be51f5dc4c60e276f5b2a0aca2e91577a92e8f4ef85b6e6c233d80cab8c0a2c3
data/lib/lit_cli.rb CHANGED
@@ -1,21 +1,24 @@
1
+ require 'pry'
1
2
  require 'pastel'
2
3
  require 'config'
4
+ require 'lit_pry'
3
5
 
4
6
  module LitCLI
5
7
  @@pastel = Pastel.new
6
8
  @@config = Config.new
9
+ @@is_prying = false
7
10
 
8
11
  def lit(message, type = :info)
9
12
  if @@config.enabled
10
- return if filter? type
11
- render(type)
12
- step()
13
- delay()
13
+ return if LitCLI.filter? type
14
+ LitCLI.render(type)
15
+ LitCLI.step()
16
+ LitCLI.delay()
14
17
  end
15
18
  end
16
19
  alias 🔥 lit
17
20
 
18
- def render(type)
21
+ def self.render(type)
19
22
  type_config = @@config.types[type]
20
23
 
21
24
  time_text = LitCLI.colorize(Time.now().strftime("%k:%M"), :cyan)
@@ -27,15 +30,16 @@ module LitCLI
27
30
  puts message
28
31
  end
29
32
 
30
- def step()
33
+ def self.step()
31
34
  if @@config.step
32
- puts "🔥 PRESS ENTER:"
35
+ puts "🔥 Press ENTER to step or P to Pry:"
33
36
  input = gets.chomp
34
37
  binding while input == nil
38
+ @@is_prying = true if input.downcase == "p"
35
39
  end
36
40
  end
37
41
 
38
- def filter? type
42
+ def self.filter? type
39
43
  unless @@config.type.nil? || @@config.type.include?(type)
40
44
  return true
41
45
  end
@@ -43,12 +47,16 @@ module LitCLI
43
47
  false
44
48
  end
45
49
 
46
- def delay()
50
+ def self.delay()
47
51
  if @@config.delay > 0
48
52
  sleep(@@config.delay)
49
53
  end
50
54
  end
51
55
 
56
+ def self.is_prying?
57
+ @@config.step && @@is_prying
58
+ end
59
+
52
60
  def self.colorize(text, color)
53
61
  case color
54
62
  when :blue
data/lib/lit_pry.rb ADDED
@@ -0,0 +1,68 @@
1
+ # Only override kernel methods when Lit's @step flag is true.
2
+ if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
3
+ module Kernel
4
+
5
+ def require_relative relative_path
6
+ filename = relative_path
7
+
8
+ # Get directory of the file that called this file.
9
+ absolute_path = caller_locations.first.absolute_path.split('/')
10
+ absolute_path.pop
11
+
12
+ # When relative path is current directory.
13
+ if relative_path.start_with?('./')
14
+ filename = relative_path.delete_prefix! './'
15
+ end
16
+
17
+ # When relative path is parent directory.
18
+ while relative_path.start_with?('../')
19
+ relative_path.delete_prefix! '../'
20
+ absolute_path.pop
21
+ end
22
+
23
+ # Append default extension.
24
+ unless filename.end_with? '.rb'
25
+ filename << '.rb'
26
+ end
27
+
28
+ filepath = File.join(absolute_path.join('/'), relative_path)
29
+
30
+ # Add pry binding beneath each lit message.
31
+ new_lines = ''
32
+ File.foreach(filepath) do |line|
33
+ new_lines << line
34
+ if line.strip.start_with? 'lit "'
35
+ new_lines << "binding.pry if LitCLI.is_prying?\n"
36
+ new_lines << "@@is_prying = false\n"
37
+ end
38
+ end
39
+
40
+ eval(new_lines)
41
+ end
42
+
43
+ # TODO: Investigate RubyGems `require` before overriding.
44
+ # def require path
45
+ # absolute_path = File.join(Dir.pwd, path)
46
+ # #p "requiring #{absolute_path}"
47
+ # #p __dir__
48
+ # #p File.dirname(File.realpath(__FILE__))
49
+ # #p File.realpath(__FILE__)
50
+ #
51
+ # # Split client-side and server-side code.
52
+ # new_lines = []
53
+ # binding_line = "binding.pry if LitCLI.is_prying?"
54
+ #
55
+ # # Add pry binding beneath each lit message.
56
+ # p path
57
+ # File.foreach(path) do |line|
58
+ # new_lines << line
59
+ # if line.strip.start_with? 'lit "'
60
+ # new_lines << binding_line
61
+ # end
62
+ # end
63
+ #
64
+ # eval(new_lines.join)
65
+ # end
66
+
67
+ end
68
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lit-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maedi Prichard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-06 00:00:00.000000000 Z
11
+ date: 2021-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -24,7 +24,21 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: Console logs that are only visible after prefixing a process with `lit`
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Console logs that are only visible after prefixing commands with 'lit'.
28
42
  email: maediprichard@gmail.com
29
43
  executables:
30
44
  - lit
@@ -34,6 +48,7 @@ files:
34
48
  - bin/lit
35
49
  - lib/config.rb
36
50
  - lib/lit_cli.rb
51
+ - lib/lit_pry.rb
37
52
  homepage: https://reflekt.dev/lit
38
53
  licenses:
39
54
  - MPL-2.0