justprep 0.1.0.2 → 1.2.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: b13b593435a5c49d2e2424322e870ff7827b23c09a663aee229fed96244a4ab2
4
- data.tar.gz: 34461b2ae7001c6bd742546ce08e772c0615a4e97509c35599f95a478473e4e2
3
+ metadata.gz: 7e0bc299adb71964c6298e1a195b380dd37c4cf716c2c58cb6ffab9320f74a5d
4
+ data.tar.gz: a22fcb32d3c7c5b516dade83e17670696ef0aa0619efcbb8c1361b580100b814
5
5
  SHA512:
6
- metadata.gz: 7acc2115979eb30d55d918032ebcccd635398f874a3088a3349b7a296372a14d890126fa667339fc3f75e7ef95763a0b555a22b5a0e6a2ef6f2b0395b9bd9974
7
- data.tar.gz: 942df7a303cab2dcf36c80e5c281e3b47f648f9a89fd6b0ecdc729abff08dd9aefcb032f383ec51ac66963271c3e54ffda428bcab11bed26574f1b965e1de394
6
+ metadata.gz: 9c2a9c4b7da6f3ad617f6799084808596c868a710dcb6a639dd742709c3aef18c414d32d654c3f74821d1d10af03c80f27414c0dd7007294b28b731d741eeb9b
7
+ data.tar.gz: 70b4bc355484300078eac81ec0ce5f450373346dd5809338f03ddaae83f1823f07bb39a8dfa76c67a043960805c14ad54830b036722e855ec62f766c2611bf6a
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- justprep (0.1.0)
4
+ justprep (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ bump (0.10.0)
9
10
  minitest (5.14.4)
10
11
  rake (13.0.4)
11
12
 
@@ -13,9 +14,10 @@ PLATFORMS
13
14
  x86_64-darwin-20
14
15
 
15
16
  DEPENDENCIES
17
+ bump
16
18
  justprep!
17
19
  minitest (~> 5.0)
18
20
  rake (~> 13.0)
19
21
 
20
22
  BUNDLED WITH
21
- 2.2.21
23
+ 2.2.24
data/README.md CHANGED
@@ -8,13 +8,7 @@ A pre-processor to the "just" command-line utility packaged as a Ruby Gem.
8
8
 
9
9
  ## Usage
10
10
 
11
- TODO: Write usage instructions here
12
-
13
- ## Development
14
-
15
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
16
-
17
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
11
+ See the top-level README.md file.
18
12
 
19
13
  ## Contributing
20
14
 
data/bin/justprep CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'justprep'
3
+ require_relative '../lib/justprep.rb'
4
4
 
5
- Justprep.execute
5
+ Justprep.new.execute
data/justfile ADDED
@@ -0,0 +1,29 @@
1
+ # github.com/MadBomber/justprep/**/ruby/justfile
2
+ #
3
+
4
+ set positional-arguments := true
5
+
6
+ # List available recipes
7
+ @help:
8
+ echo
9
+ echo "Available Recipes at"
10
+ echo `pwd`
11
+ echo "are:"
12
+ echo
13
+ just -l --list-prefix 'just ' --list-heading ''
14
+ echo
15
+
16
+ # Run the minitest examples on the Ruby code
17
+ test: build
18
+ rake test
19
+
20
+
21
+ # Build the current gem
22
+ @build:
23
+ rake clean clobber build
24
+
25
+
26
+ # Install the gem locally
27
+ @install:
28
+ rake install:local
29
+
data/justprep.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/justprep/version"
3
+ load "lib/justprep/common/constants.crb"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "justprep"
7
- spec.version = Justprep::VERSION
7
+ spec.version = VERSION
8
8
  spec.authors = ["Dewayne VanHoozer"]
9
9
  spec.email = ["dvanhoozer@gmail.com"]
10
10
 
@@ -39,6 +39,5 @@ Gem::Specification.new do |spec|
39
39
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
40
40
  end
41
41
 
42
- # Uncomment to register a new dependency of your gem
43
- # spec.add_dependency "example-gem", "~> 1.0"
42
+ spec.add_development_dependency 'bump'
44
43
  end
@@ -0,0 +1,5 @@
1
+ VERSION = "1.2.2"
2
+
3
+ JUSTPREP_FILENAME_IN = ENV.fetch("JUSTPREP_FILENAME_IN", "main.just")
4
+ JUSTPREP_FILENAME_OUT = ENV.fetch("JUSTPREP_FILENAME_OUT", "justfile")
5
+ JUSTPREP_KEYWORDS = ENV.fetch("JUSTPREP_KEYWORDS", "import include require with").split
@@ -0,0 +1,31 @@
1
+ # common/error_messages.crb
2
+
3
+ # Parameters:
4
+ # line_number .. Integer (zero-based index)
5
+ # a_line ....... String
6
+ #
7
+ # Returns:
8
+ # nil
9
+ #
10
+ def error_file_does_not_exist(line_number, a_line)
11
+ STDERR.puts
12
+ STDERR.puts "ERROR: File Does Not Exist"
13
+
14
+ # Crystal types thinks line_number can be nil or Int32
15
+ line_out = sprintf("% d ", line_number.nil? ? 0 : line_number)
16
+ STDERR.puts (" "*line_out.size)+"|"
17
+ STDERR.puts "#{line_out}| #{a_line}"
18
+ STDERR.print (" "*line_out.size)+"|"
19
+
20
+ x = a_line.index(" ")
21
+ begin_filename = x.nil? ? a_line.size + 2 : x + 2
22
+ end_filename = a_line.size
23
+ len_filename = end_filename - begin_filename + 1
24
+
25
+ len_filename = 13 if len_filename < 0
26
+
27
+ STDERR.puts (" "*begin_filename) + ("^"*len_filename)
28
+ STDERR.puts
29
+
30
+ return nil
31
+ end
@@ -0,0 +1,15 @@
1
+ # common/expand_file_path.crb
2
+
3
+ # use an external shell to expand system environment variables
4
+ def expand_file_path(a_path_string)
5
+ a_path_string = a_path_string.strip
6
+
7
+ if a_path_string.to_s.starts_with? "~"
8
+ a_path_string = "${HOME}" + a_path_string.to_s[1, a_path_string.to_s.size-1]
9
+ end
10
+
11
+ a_path_string = `echo "#{a_path_string}"`.chomp
12
+
13
+ return a_path_string
14
+ end
15
+
@@ -0,0 +1,24 @@
1
+ # common/handle_command_line_parameters.crb
2
+
3
+
4
+ # take care of ARGV
5
+ #
6
+ # Returns
7
+ # nil when there are no command line parameters
8
+ # otherwise it terminates the process
9
+ #
10
+ def handle_command_line_parameters
11
+ if ARGV.size > 0
12
+ ARGV.each do |param|
13
+ if "--version" == param
14
+ puts "jusrprep v#{VERSION} (#{IMPLEMENTATION})"
15
+ elsif ["-h", "--help"].includes?(param)
16
+ usage
17
+ else
18
+ STDERR.puts "justprep does not support: #{param}"
19
+ end
20
+ end
21
+
22
+ exit(1)
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ # common/just_find_it.crb
2
+
3
+ # look for first occurace of mainfile
4
+ # returns nil when none are found.
5
+ def just_find_it(here = FileUtils.pwd)
6
+ mainfile_path = here + "/" + JUSTPREP_FILENAME_IN
7
+ return mainfile_path if File.exists?(mainfile_path)
8
+
9
+ parts = here.to_s.split("/")
10
+ parts.pop
11
+
12
+ return nil if parts.empty?
13
+ return just_find_it(parts.join('/'))
14
+ end
@@ -0,0 +1,46 @@
1
+ # common/usage.crb
2
+
3
+ def usage
4
+ usage_text = "
5
+ justprep v#{VERSION} (#{IMPLEMENTATION})
6
+
7
+ A pre-processor to the just command line utility
8
+ By Dewayne VanHoozer <dvanhoozer@gmail.com>
9
+
10
+ USAGE:
11
+ justprep [flags] && just
12
+
13
+ FLAGS:
14
+ --version Shows the current version
15
+ -h, --help Displays this usage message
16
+
17
+ DESCRIPTION:
18
+ Looks for a file named #{JUSTPREP_FILENAME_IN} in the current
19
+ directory hierarchy. If found it replaces all lines that
20
+ have the keywords (#{JUSTPREP_KEYWORDS.join(", ")}) followed
21
+ by file path with the contents of the specified file.
22
+
23
+ SYSTEM ENVIRONMENT VARIABLES:
24
+ Default Value
25
+ JUSTPREP_FILENAME_IN .... main.just
26
+ JUSTPREP_FILENAME_OUT ... justfile
27
+ JUSTPREP_KEYWORDS ....... 'import include require with'
28
+
29
+ SUGGESTION:
30
+ Create an alias for your command shell. For example
31
+ alias jj='justprep && just'
32
+
33
+ THANKS TO:
34
+ Casey Rodarmor <casey@rodarmor.com>
35
+ for Just because just is just a handy utility with just an
36
+ odd name but an extreamly useful product. :)
37
+
38
+ Greg Lutostanski <greg.luto@gmail.com>
39
+ for the homebrew formula and the github actions to compile
40
+ a new Crystal release.
41
+
42
+ "
43
+ puts usage_text
44
+
45
+ return usage_text
46
+ end
@@ -0,0 +1,18 @@
1
+ # common/crystal_methods.rb
2
+
3
+ # Monkey oatch Ruby classes to match method names
4
+ # used by Crystal
5
+
6
+ # TODO: find other classes in which Ruby/Crystal differ
7
+
8
+ class Array
9
+ alias_method :includes?, :include?
10
+ end
11
+
12
+ class Pathname
13
+ alias_method :exists?, :exist?
14
+ end
15
+
16
+ class String
17
+ alias_method :starts_with?, :start_with?
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Justprep
4
- VERSION = "0.1.0.2"
4
+ VERSION = "1.0.2"
5
5
  end
data/lib/justprep.rb CHANGED
@@ -1,190 +1,116 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
  # warn_indent: true
4
-
5
4
  ##########################################################
6
- ###
7
- ## File: justprep/ruby/lib/justprep.rb
8
- ##
9
- ## Desc: A preprocessor for the "just" command line utility.
10
- ## It looks for keywords: import include require with
11
- ## followed by a file name or path.
12
- ##
13
- ## It looks for a file "main.just" in the current directory.
14
- ## If it does not exist, does nothing. Otherwise it reviews
15
- ## the file for the KEYWORDS. When found it inserts the
16
- ## content of the specified file into that position. The
17
- ## final text is written out to the "justfile" for processing
18
- ## with the "just" tool.
19
- ##
20
- ## The following system environment variable are supported:
21
- ##
22
- ## variable name default value
23
- ## --------------------- -------------
24
- ## JUSTPREP_FILENAME_IN ... main.just
25
- ## JUSTPREP_FILENAME_OUT ... justfile
26
- ## JUSTPREP_KEYWORDS ... 'import include require with'
27
- ##
28
- ## By: Dewayne VanHoozer (dvanhoozer@gmail.com)
5
+ # File: justprep.rb
6
+ # Desc: A preprocessor to "just" cli tool
7
+ # By: Dewayne VanHoozer (dvanhoozer@gmail.com)
8
+ #
9
+ # The following system environment variable are supported:
10
+ #
11
+ # variable name default value
12
+ # --------------------- -------------
13
+ # JUSTPREP_FILENAME_IN ... main.just
14
+ # JUSTPREP_FILENAME_OUT ... justfile
15
+ # JUSTPREP_KEYWORDS ... 'import include require with'
29
16
  #
30
17
 
31
- require "pathname"
32
- require_relative "justprep/version"
33
-
34
- module Justprep
35
- class << self
36
- JUSTPREP_FILENAME_IN = ENV.fetch('JUSTPREP_FILENAME_IN', 'main.just')
37
- JUSTPREP_FILENAME_OUT = ENV.fetch('JUSTPREP_FILENAME_OUT', 'justfile')
38
- JUSTPREP_KEYWORDS = ENV.fetch('JUSTPREP_KEYWORDS', 'import include require with').split
39
-
40
-
41
- # review the text looking for module references
42
- def find_modules(text)
43
- modules = []
44
-
45
- JUSTPREP_KEYWORDS.each do |keyword|
46
- modules << text.select{|x| x.start_with? "#{keyword} "}
47
- end
48
-
49
- return modules.flatten!
50
- end
51
-
18
+ IMPLEMENTATION = "Ruby"
52
19
 
53
- # somg;e-level inclusion
54
- def include_content_from(file_path)
55
- content = []
56
- content << "\n# >>> #{file_path}"
57
- content << file_path.readlines.map{|x| x.chomp} # TODO: support recursion??
58
- content << "# <<< #{file_path}\n"
20
+ require "fileutils"
21
+ require "pathname"
22
+ require_relative "justprep/crystal_methods"
59
23
 
60
- return content.flatten
24
+ # The common directory contains files which are usable in
25
+ # both the Ruby gem and compiled Crystal implementations
26
+ # The files have the extension ".crb"
27
+ #
28
+ COMMON_DIR = Pathname.new(__FILE__) + '../justprep/common'
29
+
30
+ # Loading these common methods as global kernel-level
31
+ load COMMON_DIR + "constants.crb"
32
+ load COMMON_DIR + "error_messages.crb"
33
+ load COMMON_DIR + "expand_file_path.crb"
34
+ load COMMON_DIR + "handle_command_line_parameters.crb"
35
+ load COMMON_DIR + "just_find_it.crb"
36
+ load COMMON_DIR + "usage.crb"
37
+
38
+ class Justprep
39
+ def initialize
40
+ handle_command_line_parameters # may terminate the process
61
41
  end
62
42
 
63
43
 
64
- # look for first occurace of mainfile
65
- def just_find_it(here=Pathname.pwd)
66
- mainfile = here + JUSTPREP_FILENAME_IN
67
- return mainfile if mainfile.exist?
68
- return nil if here == here.parent
69
- return just_find_it(here.parent)
70
- end
44
+ # single-level inclusion
45
+ def include_content_from(out_file, module_filename)
46
+ module_file = File.open(module_filename, "r")
71
47
 
48
+ out_file.puts "\n# >>> #{module_filename}"
72
49
 
73
- # use an external shell to expand system environment variables
74
- def expand_file_path(a_path_string)
75
- if a_path_string.start_with? '~'
76
- a_path_string = "${HOME}" + a_path_string[1, a_path_string.size-1]
50
+ module_file.readlines.each do |m_line|
51
+ out_file.write m_line
77
52
  end
78
53
 
79
- a_path_string = `echo "#{a_path_string}"`.chomp
54
+ out_file.puts "# <<< #{module_filename}\n"
80
55
 
81
- return a_path_string
82
- end
83
-
84
- # Print usage text
85
- def usage
86
- puts <<~EOS
87
- justprep v#{VERSION} (ruby)
88
- A pre-processor to the just command line utility
89
- By Dewayne VanHoozer <dvanhoozer@gmail.com>
90
-
91
- USAGE:
92
- justprep [flags] && just
93
-
94
- FLAGS:
95
- --version Shows the current version
96
- -h, --help Displays this usage message
97
-
98
- DESCRIPTION:
99
- Looks for a file named #{JUSTPREP_FILENAME_IN} in the current
100
- directory hierarchy. If found it replaces all lines that
101
- have the keywords (#{JUSTPREP_KEYWORDS.join(", ")}) followed
102
- by file path with the contents of the specified file.
103
-
104
- SYSTEM ENVIRONMENT VARIABLES:
105
- Default Value
106
- JUSTPREP_FILENAME_IN .... main.just
107
- JUSTPREP_FILENAME_OUT ... justfile
108
- JUSTPREP_KEYWORDS ....... 'import include require with'
109
-
110
- SUGGESTION:
111
- Create an alias for your command shell. For example
112
- alias jj='justprop && just'
113
-
114
- THANKS TO:
115
- Casey Rodarmor <casey@rodarmor.com>
116
- Just because just is just a handy utility with just an odd name. :)
117
-
118
- EOS
119
- end
120
-
121
-
122
- # take care of ARGV processing
123
- def handle_command_line_parameters
124
- if ARGV.size > 0
125
- ARGV.each do |param|
126
- if "--version" == param
127
- puts "jusrprep v#{VERSION} (ruby)"
128
- elsif ["-h", "--help"].include?(param)
129
- usage
130
- else
131
- STDERR.puts "justprep does not support: #{param}"
132
- exit(1)
133
- end
134
- end
135
- end
56
+ return nil
136
57
  end
137
58
 
138
59
 
139
60
  # Main function called from executable
140
61
  def execute
141
- handle_command_line_parameters
142
-
143
- mainfile = just_find_it
62
+ in_filename = just_find_it
144
63
 
145
- exit(0) if mainfile.nil?
64
+ if in_filename.nil?
65
+ STDERR.puts "WARNING: JUSTPREP_FILENAME_IN Not Found: #{JUSTPREP_FILENAME_IN}"
66
+ exit(0)
67
+ end
146
68
 
147
- basefile = mainfile.parent + JUSTPREP_FILENAME_OUT
69
+ out_filename = File.dirname(in_filename) + "/" + JUSTPREP_FILENAME_OUT
148
70
 
149
- text = mainfile.readlines.map{|x| x.chomp} # drop the line ending from each line
71
+ in_file = File.open(in_filename, "r")
72
+ out_file = File.open(out_filename, "w")
150
73
 
151
- modules = find_modules text
74
+ line_number = 0
152
75
 
153
- if modules.empty?
154
- basefile.write text
155
- exit(0)
156
- end
76
+ in_file.readlines.map{|x| x.chomp}.each do |a_line|
77
+ line_number += 1
157
78
 
158
- modules.each do |a_line|
159
- an_index = text.index a_line
160
- begin_filename = a_line.index(' ')
161
- module_filename = a_line[begin_filename, a_line.size - begin_filename].strip
79
+ parts = a_line.to_s.split(" ")
162
80
 
163
- if module_filename.empty?
164
- STDERR.puts "#{an_index}: #{a_line}"
165
- STDERR.puts "ERROR: No path/to/file was provided"
166
- next
81
+ if 0 == parts.size
82
+ out_file.puts
83
+ next
167
84
  end
168
85
 
169
- if module_filename.include?('~') || module_filename.include?('$')
170
- module_filename = expand_file_path(module_filename)
171
- end
86
+ # NOTE: Leading spaces are not allowed. The keywords
87
+ # MUST be complete left-justified.
88
+ #
89
+ if JUSTPREP_KEYWORDS.include?(parts.first.downcase)
90
+ out_file.puts "# #{a_line}"
91
+
92
+ glob_filename = expand_file_path(parts[1..parts.size].join(" "))
172
93
 
173
- module_path = Pathname.new(module_filename)
94
+ module_filenames = Dir.glob(glob_filename)
174
95
 
175
- if module_path.relative?
176
- module_path = mainfile.parent + module_path
96
+ if 0 == module_filenames.size
97
+ error_file_does_not_exist(line_number, a_line)
98
+ exit(1)
177
99
  end
178
100
 
179
- if module_path.exist?
180
- text[an_index] = include_content_from(module_path)
101
+ module_filenames.each do |module_filename|
102
+ if File.exist?(module_filename)
103
+ include_content_from(out_file, module_filename)
181
104
  else
182
- STDERR.puts "#{an_index}: #{a_line}"
183
- STDERR.puts "| ERROR: File Does Not Exist - #{module_path}"
105
+ error_file_does_not_exist(line_number, a_line)
106
+ exit(1)
107
+ end
184
108
  end
109
+ else
110
+ out_file.puts a_line
185
111
  end
112
+ end # in_file.readlines ...
186
113
 
187
- basefile.write text.flatten!.join "\n"
114
+ out_file.close
188
115
  end # def execute
189
- end # class << self
190
- end # module Justprep
116
+ end # class Justprep
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: justprep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.2
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-08 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bump
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: |
14
28
  allows a "justfile" to be auto-generated from a seperate source file
15
29
  that contains inclusionary keywords such as include, import, require
@@ -26,7 +40,6 @@ extensions: []
26
40
  extra_rdoc_files: []
27
41
  files:
28
42
  - ".gitignore"
29
- - CHANGELOG.md
30
43
  - Gemfile
31
44
  - Gemfile.lock
32
45
  - LICENSE.txt
@@ -34,8 +47,16 @@ files:
34
47
  - Rakefile
35
48
  - bin/justprep
36
49
  - bin/setup
50
+ - justfile
37
51
  - justprep.gemspec
38
52
  - lib/justprep.rb
53
+ - lib/justprep/common/constants.crb
54
+ - lib/justprep/common/error_messages.crb
55
+ - lib/justprep/common/expand_file_path.crb
56
+ - lib/justprep/common/handle_command_line_parameters.crb
57
+ - lib/justprep/common/just_find_it.crb
58
+ - lib/justprep/common/usage.crb
59
+ - lib/justprep/crystal_methods.rb
39
60
  - lib/justprep/version.rb
40
61
  - prototype.rb
41
62
  homepage: http://github.com/MadBomber/justprep/tree/main/ruby
@@ -58,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
79
  - !ruby/object:Gem::Version
59
80
  version: '0'
60
81
  requirements: []
61
- rubygems_version: 3.2.21
82
+ rubygems_version: 3.3.15
62
83
  signing_key:
63
84
  specification_version: 4
64
85
  summary: A pre-processor for the 'just' command line utility
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2021-07-07
4
-
5
- - Initial release