justprep 0.1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e35c0a964ffac9ceb3a2020aba78022a34f8b4b904a04edf7165e4ea7effc2d2
4
+ data.tar.gz: 8de618079e948c4288e7dbf93a3d89cc8aff9320e63b930b5558822a9ed209d2
5
+ SHA512:
6
+ metadata.gz: 49278e4ea5e0d3e245d85f8c2bfc95d9e6d33923a59d90494685ce007fe73c9524133f7704816338ab98a5de85d6ad1ecf63f3cb10f03971a9097de7e60ecef7
7
+ data.tar.gz: 73a4b132c311e2030704c05269a7f766d7b4521adebc62c68d83de8593dd15e6141cd23f2c2555b3d1b15ce3412da3c8ea697022764dda6e4b11eacda749f167
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-07-07
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in justprep.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ justprep (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.14.4)
10
+ rake (13.0.4)
11
+
12
+ PLATFORMS
13
+ x86_64-darwin-20
14
+
15
+ DEPENDENCIES
16
+ justprep!
17
+ minitest (~> 5.0)
18
+ rake (~> 13.0)
19
+
20
+ BUNDLED WITH
21
+ 2.2.21
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Dewayne VanHoozer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Justprep
2
+
3
+ A pre-processor to the "just" command-line utility packaged as a Ruby Gem.
4
+
5
+ ## Installation
6
+
7
+ $ gem install justprep
8
+
9
+ ## Usage
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).
18
+
19
+ ## Contributing
20
+
21
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/justprep.
22
+
23
+ ## License
24
+
25
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/justprep ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'justprep'
4
+
5
+ Justprep.execute
data/bin/setup ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle install
4
+
5
+ # Assumes 'which' is available
6
+ just=`which just`
7
+ brew=`which brew`
8
+
9
+ if [[ "x" == "x$just" ]] ; then
10
+ echo
11
+ echo "The 'just' command line utility is not installed."
12
+ if [[ "x" != "x%brew" ]] ; then
13
+ echo "To install it do this:"
14
+ echo " brew install just"
15
+ else
16
+ echo "Use your favorite package manager to install 'just'"
17
+ fi
18
+ echo
19
+ fi
data/justprep.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/justprep/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "justprep"
7
+ spec.version = Justprep::VERSION
8
+ spec.authors = ["Dewayne VanHoozer"]
9
+ spec.email = ["dvanhoozer@gmail.com"]
10
+
11
+ spec.summary = "A pre-processor for the 'just' command line utility"
12
+ spec.description = <<~EOS
13
+ allows a "justfile" to be auto-generated from a seperate source file
14
+ that contains inclusionary keywords such as include, import, require
15
+ and with. These keywords are followed by a path to a file. If the
16
+ file exists, the contents of the file are inserted into the file
17
+ at the position of the keyword command. After all keywords have
18
+ been process a new "justfile" is created which can then be used by
19
+ the 'just' tool.
20
+ EOS
21
+
22
+ spec.homepage = "http://github.com/MadBomber/justprep/tree/main/ruby"
23
+ spec.license = "MIT"
24
+ spec.required_ruby_version = ">= 2.4.0"
25
+
26
+ spec.metadata["allowed_push_host"] = ""
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
32
+ end
33
+
34
+ spec.bindir = "bin"
35
+ spec.executables = ["justprep"]
36
+ spec.require_paths = ["lib"]
37
+
38
+ if spec.respond_to?(:metadata)
39
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
40
+ end
41
+
42
+ # Uncomment to register a new dependency of your gem
43
+ # spec.add_dependency "example-gem", "~> 1.0"
44
+ end
data/lib/justprep.rb ADDED
@@ -0,0 +1,192 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ # warn_indent: true
4
+
5
+ ##########################################################
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)
29
+ #
30
+
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
+
52
+
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"
59
+
60
+ return content.flatten
61
+ end
62
+
63
+
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
71
+
72
+
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]
77
+ end
78
+
79
+ a_path_string = `echo "#{a_path_string}"`.chomp
80
+
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
136
+ end
137
+
138
+
139
+ # Main function called from executable
140
+ def execute
141
+ handle_command_line_parameters
142
+
143
+ mainfile = just_find_it
144
+
145
+ exit(0) if mainfile.nil?
146
+
147
+ basefile = mainfile.parent + JUSTPREP_FILENAME_OUT
148
+
149
+ text = mainfile.readlines.map{|x| x.chomp} # drop the line ending from each line
150
+
151
+ modules = find_modules text
152
+
153
+ if modules.empty?
154
+ basefile.write text
155
+ exit(0)
156
+ end
157
+
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
162
+
163
+ if module_filename.empty?
164
+ STDERR.puts "#{an_index}: #{a_line}"
165
+ STDERR.puts "ERROR: No path/to/file was provided"
166
+ next
167
+ end
168
+
169
+ if module_filename.include?('~') || module_filename.include?('$')
170
+ module_filename = expand_file_path(module_filename)
171
+ end
172
+
173
+ module_path = Pathname.new(module_filename)
174
+
175
+ if module_path.relative?
176
+ module_path = mainfile.parent + module_path
177
+ end
178
+
179
+ if module_path.exist?
180
+ text[an_index] = include_content_from(module_path)
181
+ else
182
+ STDERR.puts "#{an_index}: #{a_line}"
183
+ STDERR.puts "| ERROR: File Does Not Exist - #{module_path}"
184
+ end
185
+ end
186
+
187
+ basefile.write text.flatten!.join "\n"
188
+ end # def execute
189
+ end # class << self
190
+ end # module Justprep
191
+
192
+ Justprep.execute
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Justprep
4
+ VERSION = "0.1.0.1"
5
+ end
data/prototype.rb ADDED
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # frozen_string_literal: true
4
+ # warn_indent: true
5
+ ##########################################################
6
+ ###
7
+ ## File: justprep.rb
8
+ ## Desc: A preprocessor for justfiles using "main.just"
9
+ ## Looks for keywords: import include require with
10
+ ## followed by a file name or path.
11
+ ##
12
+ ## It looks for a file "main.just" in the current directory.
13
+ ## If it does not exist, does nothing. Otherwise it reviews
14
+ ## the file for the KEYWORDS. When found it inserts the
15
+ ## content of the specified file into that position. The
16
+ ## final text is written out to the "justfile" for processing
17
+ ## with the "just" tool.
18
+ ##
19
+ ## There is NO ERROR checking. including file names/paths
20
+ ## are assume to have to space characters.
21
+ ##
22
+ ## By: Dewayne VanHoozer (dvanhoozer@gmail.com)
23
+ #
24
+
25
+ KEYWORDS = %w[ import include require with ]
26
+ BASEFILE = 'justfile'
27
+ MAINFILE = 'main.just'
28
+
29
+ require 'pathname'
30
+
31
+ ######################################################
32
+ # Local methods
33
+
34
+ # review the text looking for module references
35
+ def find_modules(text)
36
+ modules = []
37
+
38
+ KEYWORDS.each do |keyword|
39
+ modules << text.select{|x| x.start_with? "#{keyword} "}
40
+ end
41
+
42
+ return modules.flatten!
43
+ end
44
+
45
+
46
+ # somg;e-level inclusion
47
+ def include_content_from(file_path)
48
+ content = []
49
+ content << "\n# >>> #{file_path}"
50
+ content << file_path.readlines.map{|x| x.chomp} # TODO: support recursion??
51
+ content << "# <<< #{file_path}\n"
52
+
53
+ return content.flatten
54
+ end
55
+
56
+
57
+ # look for first occurace of mainfile
58
+ def just_find_it(here=Pathname.pwd)
59
+ mainfile = here + MAINFILE
60
+ return mainfile if mainfile.exist?
61
+ return nil if here == here.parent
62
+ return just_find_it(here.parent)
63
+ end
64
+
65
+
66
+ # use an external shell to expand system environment variables
67
+ def expand_file_path(a_path_string)
68
+ if a_path_string.start_with? '~'
69
+ a_path_string = "${HOME}" + a_path_string[1, a_path_string.size-1]
70
+ end
71
+
72
+ a_path_string = `echo "#{a_path_string}"`.chomp
73
+
74
+ return a_path_string
75
+ end
76
+
77
+
78
+ ######################################################
79
+ # Main
80
+
81
+ mainfile = just_find_it
82
+
83
+ exit(0) if mainfile.nil?
84
+
85
+ basefile = mainfile.parent + BASEFILE
86
+
87
+ text = mainfile.readlines.map{|x| x.chomp} # drop the line ending from each line
88
+
89
+ modules = find_modules text
90
+
91
+ if modules.empty?
92
+ basefile.write text
93
+ exit(0)
94
+ end
95
+
96
+ modules.each do |a_line|
97
+ an_index = text.index a_line
98
+ begin_filename = a_line.index(' ')
99
+ module_filename = a_line[begin_filename, a_line.size - begin_filename].strip
100
+
101
+ if module_filename.empty?
102
+ STDERR.puts "#{an_index}: #{a_line}"
103
+ STDERR.puts "ERROR: No path/to/file was provided"
104
+ next
105
+ end
106
+
107
+ if module_filename.include?('~') || module_filename.include?('$')
108
+ module_filename = expand_file_path(module_filename)
109
+ end
110
+
111
+ module_path = Pathname.new(module_filename)
112
+
113
+ if module_path.relative?
114
+ module_path = mainfile.parent + module_path
115
+ end
116
+
117
+ if module_path.exist?
118
+ text[an_index] = include_content_from(module_path)
119
+ else
120
+ STDERR.puts "#{an_index}: #{a_line}"
121
+ STDERR.puts "| ERROR: File Does Not Exist - #{module_path}"
122
+ end
123
+ end
124
+
125
+ basefile.write text.flatten!.join "\n"
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: justprep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dewayne VanHoozer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ allows a "justfile" to be auto-generated from a seperate source file
15
+ that contains inclusionary keywords such as include, import, require
16
+ and with. These keywords are followed by a path to a file. If the
17
+ file exists, the contents of the file are inserted into the file
18
+ at the position of the keyword command. After all keywords have
19
+ been process a new "justfile" is created which can then be used by
20
+ the 'just' tool.
21
+ email:
22
+ - dvanhoozer@gmail.com
23
+ executables:
24
+ - justprep
25
+ extensions: []
26
+ extra_rdoc_files: []
27
+ files:
28
+ - ".gitignore"
29
+ - CHANGELOG.md
30
+ - Gemfile
31
+ - Gemfile.lock
32
+ - LICENSE.txt
33
+ - README.md
34
+ - Rakefile
35
+ - bin/justprep
36
+ - bin/setup
37
+ - justprep.gemspec
38
+ - lib/justprep.rb
39
+ - lib/justprep/version.rb
40
+ - prototype.rb
41
+ homepage: http://github.com/MadBomber/justprep/tree/main/ruby
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ allowed_push_host: https://rubygems.org
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.4.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.2.21
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A pre-processor for the 'just' command line utility
65
+ test_files: []