lit-cli 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lit +1 -1
- data/lib/config.rb +10 -7
- data/lib/lit_cli.rb +26 -9
- data/lib/lit_pry.rb +88 -49
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7edc257dc260a2ad0eccff8e71eff6217b0e89fde2acd7ea127500cefc58afb
|
4
|
+
data.tar.gz: 9f0726175f5f79794f96694e18bae016a819bffe66fed34226ad4ffa694adc1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 323f05467ab8cfa3c23d51fae4a738be4382e7a8d5bad44d9d9a2efc0376d6c139ee970792b35a9749226b913e308556209592d2ffb87318c14a6e6ae272d5b0
|
7
|
+
data.tar.gz: facde086d4de3198fbfef692367d4cb31be51e26445ea6527d4f31c6084872e3283d8d43c2c43569b33ac879c7ff764ab2c3281a593474eb6ba46d0829744991
|
data/bin/lit
CHANGED
data/lib/config.rb
CHANGED
@@ -33,12 +33,12 @@ module LitCLI
|
|
33
33
|
def initialize()
|
34
34
|
|
35
35
|
@statuses = {
|
36
|
-
:info => { icon: "ℹ", color: :blue },
|
37
|
-
:pass => { icon: "✔", color: :green },
|
38
|
-
:warn => { icon: "⚠", color: :yellow },
|
39
|
-
:fail => { icon: "⨯", color: :red },
|
40
|
-
:error => { icon: "!", color: :red },
|
41
|
-
:debug => { icon: "?", color: :purple },
|
36
|
+
:info => { icon: "ℹ", color: :blue, styles: [:upcase] },
|
37
|
+
:pass => { icon: "✔", color: :green, styles: [:upcase] },
|
38
|
+
:warn => { icon: "⚠", color: :yellow, styles: [:upcase] },
|
39
|
+
:fail => { icon: "⨯", color: :red, styles: [:upcase] },
|
40
|
+
:error => { icon: "!", color: :red, styles: [:upcase] },
|
41
|
+
:debug => { icon: "?", color: :purple, styles: [:upcase] },
|
42
42
|
}
|
43
43
|
|
44
44
|
@types = nil
|
@@ -70,7 +70,10 @@ module LitCLI
|
|
70
70
|
|
71
71
|
# Override config from command line.
|
72
72
|
def cli_configure()
|
73
|
-
|
73
|
+
|
74
|
+
# Enable lit via the command line.
|
75
|
+
@enabled = true if ENV['LIT_ENABLED'].to_i >= (Time.now.to_i() - 1)
|
76
|
+
return unless @enabled
|
74
77
|
|
75
78
|
# Convert flag string to hash.
|
76
79
|
flags = {}
|
data/lib/lit_cli.rb
CHANGED
@@ -12,41 +12,58 @@ module LitCLI
|
|
12
12
|
if @@config.enabled
|
13
13
|
return if LitCLI.filter_status? status
|
14
14
|
return if LitCLI.filter_type? type
|
15
|
+
|
15
16
|
LitCLI.render(message, status, type, context)
|
17
|
+
|
16
18
|
LitCLI.step()
|
19
|
+
yield if block_given?
|
20
|
+
|
17
21
|
LitCLI.delay()
|
18
22
|
end
|
19
23
|
end
|
20
24
|
alias 🔥 lit
|
21
25
|
|
22
26
|
def self.render(message, status, type, context)
|
23
|
-
|
27
|
+
output = "🔥"
|
24
28
|
|
25
29
|
# Time.
|
26
30
|
time = LitCLI.format(Time.now().strftime("%k:%M"), color: :cyan)
|
27
|
-
|
31
|
+
output << " #{time}"
|
28
32
|
|
29
33
|
# Status.
|
30
34
|
config = @@config.statuses[status]
|
31
|
-
|
35
|
+
output << LitCLI.format(" #{config[:icon]} #{status.to_s}", config)
|
32
36
|
|
33
37
|
# Type.
|
34
38
|
if !@@config.types.nil? && @@config.types.has_key?(type)
|
35
39
|
config = @@config.types[type]
|
36
40
|
if config.has_key? :icon
|
37
|
-
|
41
|
+
output << LitCLI.format(" #{config[:icon]} #{type.to_s}", config)
|
38
42
|
else
|
39
|
-
|
43
|
+
output << LitCLI.format(" #{type.to_s}", config)
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
47
|
# Context.
|
44
|
-
|
48
|
+
output << LitCLI.format(" #{context}", styles: [:bold, :dim])
|
45
49
|
|
46
50
|
# Message.
|
47
|
-
|
51
|
+
while message.start_with?('^')
|
52
|
+
message.delete_prefix!('^').strip!
|
53
|
+
unless @@config.status || @@config.type
|
54
|
+
output = "\n" + output
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
while message.start_with?('>')
|
59
|
+
message.delete_prefix!('>').strip!
|
60
|
+
unless @@config.status || @@config.type
|
61
|
+
output = ' ' + output
|
62
|
+
end
|
63
|
+
end
|
48
64
|
|
49
|
-
|
65
|
+
output << " #{message}"
|
66
|
+
puts output
|
50
67
|
end
|
51
68
|
|
52
69
|
def self.step()
|
@@ -145,7 +162,7 @@ module LitCLI
|
|
145
162
|
def self.configure()
|
146
163
|
yield(@@config)
|
147
164
|
|
148
|
-
# Override config from command line.
|
165
|
+
# Override config from flags on command line.
|
149
166
|
@@config.cli_configure()
|
150
167
|
end
|
151
168
|
|
data/lib/lit_pry.rb
CHANGED
@@ -1,70 +1,109 @@
|
|
1
1
|
# Only override kernel methods when Lit's @step flag is true.
|
2
2
|
if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
# TODO: Investigate RubyGems `require` before overriding.
|
6
|
+
# SEE: https://github.com/ruby/ruby/blob/v2_6_3/lib/rubygems/core_ext/kernel_require.rb
|
7
|
+
|
3
8
|
module Kernel
|
4
9
|
|
5
|
-
|
6
|
-
filename = relative_path
|
10
|
+
@@lit_processed_paths = Set.new
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
absolute_path.pop
|
12
|
+
def require_relative relative_path, current_directory = nil
|
13
|
+
return false if relative_path.nil?
|
11
14
|
|
12
|
-
#
|
13
|
-
if relative_path.start_with?('
|
14
|
-
|
15
|
-
|
15
|
+
# Handle absolute path.
|
16
|
+
if relative_path.start_with?('/') && File.exist?(relative_path)
|
17
|
+
absolute_path = relative_path.split('/')
|
18
|
+
file_name = absolute_path.pop
|
19
|
+
# Handle relative path.
|
20
|
+
else
|
21
|
+
# Get directory of the file that called this file.
|
22
|
+
if current_directory.nil?
|
23
|
+
absolute_path = caller_locations.first.absolute_path.split('/')
|
24
|
+
absolute_path.pop
|
25
|
+
else
|
26
|
+
absolute_path = current_directory.split('/')
|
27
|
+
end
|
28
|
+
|
29
|
+
# When path is current directory.
|
30
|
+
if relative_path.start_with?('./')
|
31
|
+
relative_path.delete_prefix! './'
|
32
|
+
end
|
33
|
+
|
34
|
+
# When path is parent directory.
|
35
|
+
while relative_path.start_with?('../')
|
36
|
+
relative_path.delete_prefix! '../'
|
37
|
+
absolute_path.pop
|
38
|
+
end
|
39
|
+
|
40
|
+
# When path contains child directories.
|
41
|
+
if relative_path.split('/').count > 1
|
42
|
+
# Add child directories to absolute path and remove from relative path.
|
43
|
+
child_path = relative_path.split('/')
|
44
|
+
relative_path = child_path.pop
|
45
|
+
child_path.each do |dir|
|
46
|
+
absolute_path << dir
|
47
|
+
end
|
48
|
+
end
|
16
49
|
|
17
|
-
|
18
|
-
while relative_path.start_with?('../')
|
19
|
-
relative_path.delete_prefix! '../'
|
20
|
-
absolute_path.pop
|
50
|
+
file_name = relative_path
|
21
51
|
end
|
22
52
|
|
23
53
|
# Append default extension.
|
24
|
-
unless
|
25
|
-
|
54
|
+
unless file_name.end_with? '.rb'
|
55
|
+
file_name << '.rb'
|
26
56
|
end
|
27
57
|
|
28
|
-
|
58
|
+
file_path = File.join(absolute_path.join('/'), file_name)
|
29
59
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
new_lines
|
34
|
-
|
35
|
-
|
36
|
-
|
60
|
+
unless @@lit_processed_paths.include? file_path
|
61
|
+
@@lit_processed_paths.add file_path
|
62
|
+
|
63
|
+
new_lines = ''
|
64
|
+
line_count = 0
|
65
|
+
new_lines_count = 0
|
66
|
+
|
67
|
+
File.foreach(file_path) do |line|
|
68
|
+
line_count = line_count + 1
|
69
|
+
|
70
|
+
# Pass current directory into the next file's requires.
|
71
|
+
if line.strip.start_with? 'require_relative '
|
72
|
+
line = line.strip + ", '#{absolute_path.join('/')}'\n"
|
73
|
+
new_lines << line
|
74
|
+
# Add pry binding on each lit method.
|
75
|
+
elsif lit_line = Kernel.add_lit_binding(line)
|
76
|
+
new_lines << lit_line
|
77
|
+
else
|
78
|
+
new_lines << line
|
79
|
+
end
|
37
80
|
end
|
81
|
+
|
82
|
+
eval(new_lines, get_binding(__dir__ = absolute_path), file_path)
|
83
|
+
|
84
|
+
return true
|
85
|
+
# Path has already been required.
|
86
|
+
else
|
87
|
+
return false
|
38
88
|
end
|
89
|
+
end
|
39
90
|
|
40
|
-
|
91
|
+
def get_binding(__dir__)
|
92
|
+
# Don't go to this binding when Pry session activated.
|
93
|
+
# The variables have already been evaluated by eval(). NEEDS CONFIRMATION.
|
94
|
+
# Setting file_path in eval() negates this fix but will keep just in case.
|
95
|
+
return binding unless LitCLI.is_prying?
|
41
96
|
end
|
42
97
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# #p File.dirname(File.realpath(__FILE__))
|
51
|
-
# #p File.realpath(__FILE__)
|
52
|
-
#
|
53
|
-
# # Split client-side and server-side code.
|
54
|
-
# new_lines = []
|
55
|
-
# binding_line = "binding.pry if LitCLI.is_prying?"
|
56
|
-
#
|
57
|
-
# # Add pry binding beneath each lit message.
|
58
|
-
# p path
|
59
|
-
# File.foreach(path) do |line|
|
60
|
-
# new_lines << line
|
61
|
-
# if line.strip.start_with? 'lit "'
|
62
|
-
# new_lines << binding_line
|
63
|
-
# end
|
64
|
-
# end
|
65
|
-
#
|
66
|
-
# eval(new_lines.join)
|
67
|
-
# end
|
98
|
+
def self.add_lit_binding(line)
|
99
|
+
['lit ', 'lit(', '🔥 ', '🔥(', '🔥'].each do |needle|
|
100
|
+
if line.strip.start_with? needle
|
101
|
+
args = line.strip.delete_prefix(needle).delete_suffix(")").chomp
|
102
|
+
return "lit(#{args}) { binding.pry if LitCLI.is_prying?; @@is_prying = false } \n"
|
103
|
+
end
|
104
|
+
end
|
68
105
|
|
106
|
+
false
|
107
|
+
end
|
69
108
|
end
|
70
109
|
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.
|
4
|
+
version: 0.7.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-
|
11
|
+
date: 2021-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|