justprep 1.0.0 → 1.2.3
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 +4 -4
- data/Gemfile.lock +2 -2
- data/bin/justprep +2 -2
- data/justfile +9 -24
- data/justprep.gemspec +2 -2
- data/lib/justprep/common/constants.crb +7 -0
- data/lib/justprep/common/error_messages.crb +53 -0
- data/lib/justprep/common/expand_file_path.crb +15 -0
- data/lib/justprep/common/generate_module_recipes.crb +27 -0
- data/lib/justprep/common/handle_command_line_parameters.crb +24 -0
- data/lib/justprep/common/include_content_from.crb +24 -0
- data/lib/justprep/common/just_find_it.crb +14 -0
- data/lib/justprep/common/replacement_for_module_line.crb +50 -0
- data/lib/justprep/common/usage.crb +46 -0
- data/lib/justprep/crystal_methods.rb +26 -0
- data/lib/justprep/version.rb +1 -1
- data/lib/justprep.rb +85 -136
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5215db017617c8b34a0e8db31b2d2f0e2db2d59c0600671347fdad324ebad83
|
4
|
+
data.tar.gz: b8d16fec5e8898ed0c8154cc1856c83f2b8419d93c1f56e758f95291bff48fde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bae352f6da8c9b2b1f3a174f64f695485373225db830be20694688e02cc7368aab9e5548862c5e2e24d8ee985eef7f09b20bf674cee6ac85217418958af541e1
|
7
|
+
data.tar.gz: 50d4c6fd1f70c4e042e07d948fb0561e43e0788f73d277d54476e2cbbe9c4587fe4686b69262b7a7eb3d53494146f1a1516f0b3d9925651887d67415e568e73a
|
data/Gemfile.lock
CHANGED
data/bin/justprep
CHANGED
data/justfile
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# github.com/MadBomber/justprep/**/ruby/justfile
|
2
2
|
#
|
3
|
-
# gem install bump
|
4
3
|
|
5
4
|
set positional-arguments := true
|
6
5
|
|
7
6
|
# List available recipes
|
8
|
-
@
|
7
|
+
@help:
|
9
8
|
echo
|
10
9
|
echo "Available Recipes at"
|
11
10
|
echo `pwd`
|
@@ -14,31 +13,17 @@ set positional-arguments := true
|
|
14
13
|
just -l --list-prefix 'just ' --list-heading ''
|
15
14
|
echo
|
16
15
|
|
16
|
+
# Run the minitest examples on the Ruby code
|
17
|
+
test: build
|
18
|
+
rake test
|
19
|
+
|
17
20
|
|
18
21
|
# Build the current gem
|
19
|
-
build:
|
22
|
+
@build:
|
20
23
|
rake clean clobber build
|
21
24
|
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# Set the version: major . minor . patch
|
28
|
-
@set version:
|
29
|
-
bump set {{version}} --no-commit --replace-in ../crystal/version.cr
|
30
|
-
|
31
|
-
|
32
|
-
# Show current version
|
33
|
-
@show:
|
34
|
-
bump current
|
35
|
-
|
26
|
+
# Install the gem locally
|
27
|
+
@install:
|
28
|
+
rake install:local
|
36
29
|
|
37
|
-
# Bump the level: major . minor . patch
|
38
|
-
bump level='patch':
|
39
|
-
#!/bin/bash
|
40
|
-
if [[ "{{level}}" =~ ^(major|minor|patch)$ ]]; then
|
41
|
-
bump {{level}} --no-commit --replace-in ../crystal/version.cr
|
42
|
-
else
|
43
|
-
echo "ERROR: level must be one of: major, minor, patch"
|
44
|
-
fi
|
data/justprep.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
load "lib/justprep/common/constants.crb"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "justprep"
|
7
|
-
spec.version =
|
7
|
+
spec.version = VERSION
|
8
8
|
spec.authors = ["Dewayne VanHoozer"]
|
9
9
|
spec.email = ["dvanhoozer@gmail.com"]
|
10
10
|
|
@@ -0,0 +1,7 @@
|
|
1
|
+
VERSION = "1.2.3"
|
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
|
6
|
+
|
7
|
+
JUSTPREP_MODULE_KEYWORD = ENV.fetch("JUSTPREP_MODULE_KEYWORD", "module")
|
@@ -0,0 +1,53 @@
|
|
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
|
+
|
22
|
+
if a_line.starts_with?(JUSTPREP_MODULE_KEYWORD)
|
23
|
+
x = a_line.index(" ", x.nil? ? 0 : x + 1) # because Crystal thinks x could be nil
|
24
|
+
end
|
25
|
+
|
26
|
+
begin_filename = x.nil? ? a_line.size + 2 : x + 2
|
27
|
+
end_filename = a_line.size
|
28
|
+
len_filename = end_filename - begin_filename + 1
|
29
|
+
|
30
|
+
len_filename = 13 if len_filename < 0
|
31
|
+
|
32
|
+
STDERR.puts (" "*begin_filename) + ("^"*len_filename)
|
33
|
+
STDERR.puts
|
34
|
+
|
35
|
+
return nil
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def error_syntax(line_number, a_line)
|
40
|
+
STDERR.puts
|
41
|
+
STDERR.puts "ERROR: Syntax Problem"
|
42
|
+
|
43
|
+
# Crystal types thinks line_number can be nil or Int32
|
44
|
+
line_out = sprintf("% d ", line_number.nil? ? 0 : line_number)
|
45
|
+
STDERR.puts (" "*line_out.size)+"|"
|
46
|
+
STDERR.puts "#{line_out}| #{a_line}"
|
47
|
+
STDERR.print (" "*line_out.size)+"| "
|
48
|
+
STDERR.puts "^"*(a_line.size)
|
49
|
+
STDERR.puts
|
50
|
+
|
51
|
+
return nil
|
52
|
+
end
|
53
|
+
|
@@ -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,27 @@
|
|
1
|
+
# .../ruby/lib/justprep/common/generate_module_recipes.crb
|
2
|
+
|
3
|
+
# Given an Array of Strings representing the fake
|
4
|
+
# module names it returns a String to be appended
|
5
|
+
# to the generated justfile.
|
6
|
+
#
|
7
|
+
# Input:
|
8
|
+
# module_names .... Array(String) fake module names
|
9
|
+
#
|
10
|
+
# Output:
|
11
|
+
# recipes ... String
|
12
|
+
#
|
13
|
+
def generate_module_recipes(module_names)
|
14
|
+
recipes = ""
|
15
|
+
|
16
|
+
module_names.each do |mod_name|
|
17
|
+
recipes += "
|
18
|
+
|
19
|
+
# Module #{mod_name}
|
20
|
+
@#{mod_name} what='' args='':
|
21
|
+
just -f {{module_#{mod_name}}} {{what}} {{args}}
|
22
|
+
|
23
|
+
"
|
24
|
+
end
|
25
|
+
|
26
|
+
return recipes
|
27
|
+
end
|
@@ -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,24 @@
|
|
1
|
+
# .../ruby/lib/justprep/common/def include_content_from.crb
|
2
|
+
|
3
|
+
|
4
|
+
# single-level inclusion
|
5
|
+
#
|
6
|
+
# Input:
|
7
|
+
# out_file .......... A File pointer for String output
|
8
|
+
# module_filename ... String The name of the file to be included
|
9
|
+
#
|
10
|
+
# Output:
|
11
|
+
# nil .... This is a function without specific return value
|
12
|
+
#
|
13
|
+
def include_content_from(out_file, module_filename)
|
14
|
+
out_file.puts "\n# >>> #{module_filename}"
|
15
|
+
|
16
|
+
File.read_lines(module_filename).each do |m_line|
|
17
|
+
out_file.puts m_line
|
18
|
+
end
|
19
|
+
|
20
|
+
out_file.puts "# <<< #{module_filename}\n"
|
21
|
+
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
|
@@ -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,50 @@
|
|
1
|
+
# .../ruby/lig/justprep/common/replacement_for_module_line.crb
|
2
|
+
|
3
|
+
# Inserts the module_name into the Array of module_names
|
4
|
+
# Returns a string that defines the variable for the path to the module
|
5
|
+
#
|
6
|
+
# This method replaces a source line that looks like this:
|
7
|
+
#
|
8
|
+
# module aaa path/to/modules/justfile
|
9
|
+
#
|
10
|
+
# with a line that looks like this:
|
11
|
+
#
|
12
|
+
# module_aaa := "path/to/modules/justfile"
|
13
|
+
#
|
14
|
+
# where "aaa" is the module name.
|
15
|
+
#
|
16
|
+
# Limitations:
|
17
|
+
#
|
18
|
+
# module_name can not have a space. Only :alphanumberic: characters
|
19
|
+
# and the underscore character are valid.
|
20
|
+
#
|
21
|
+
# The "path/to/modules/justfile" must exist. Otherwise an error
|
22
|
+
# message is generated.
|
23
|
+
#
|
24
|
+
# Input:
|
25
|
+
# line_numer .... Integer the line number in the source file
|
26
|
+
# a_string ...... String the line from the source file
|
27
|
+
#
|
28
|
+
# Output:
|
29
|
+
# an Array(String) of size 2 where
|
30
|
+
# .first is the fake module_name
|
31
|
+
# .last is the replacement string that defines the module variable
|
32
|
+
#
|
33
|
+
def replacement_for_module_line(line_number, a_string)
|
34
|
+
parts = a_string.split(" ")
|
35
|
+
|
36
|
+
if parts.size < 3
|
37
|
+
error_syntax(line_number, a_string)
|
38
|
+
exit(1)
|
39
|
+
end
|
40
|
+
|
41
|
+
module_name = parts[1]
|
42
|
+
path_to_module = parts[2..].join(" ")
|
43
|
+
|
44
|
+
unless File.exists?(path_to_module)
|
45
|
+
error_file_does_not_exist(line_number, a_string)
|
46
|
+
exit(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
return [module_name, "module_#{module_name} := \"#{path_to_module}\""]
|
50
|
+
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,26 @@
|
|
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
|
+
alias_method :ends_with?, :end_with?
|
19
|
+
alias_method :includes?, :include?
|
20
|
+
end
|
21
|
+
|
22
|
+
class File
|
23
|
+
class << self
|
24
|
+
alias_method :read_lines, :readlines
|
25
|
+
end
|
26
|
+
end
|
data/lib/justprep/version.rb
CHANGED
data/lib/justprep.rb
CHANGED
@@ -13,165 +13,114 @@
|
|
13
13
|
# JUSTPREP_FILENAME_IN ... main.just
|
14
14
|
# JUSTPREP_FILENAME_OUT ... justfile
|
15
15
|
# JUSTPREP_KEYWORDS ... 'import include require with'
|
16
|
+
# JUSTPREP_MODULE_KEYWORD . 'module'
|
17
|
+
#
|
18
|
+
# NOTE:
|
19
|
+
# JUSTPREP_KEYWORDS ** CANNOT ** include the value for
|
20
|
+
# JUSTPREP_MODULE_KEYWORD
|
16
21
|
#
|
17
22
|
|
18
|
-
|
19
|
-
require_relative "justprep/version"
|
20
|
-
|
21
|
-
module Justprep
|
22
|
-
class << self
|
23
|
-
JUSTPREP_FILENAME_IN = ENV.fetch('JUSTPREP_FILENAME_IN', 'main.just')
|
24
|
-
JUSTPREP_FILENAME_OUT = ENV.fetch('JUSTPREP_FILENAME_OUT', 'justfile')
|
25
|
-
JUSTPREP_KEYWORDS = ENV.fetch('JUSTPREP_KEYWORDS', 'import include require with').split
|
23
|
+
IMPLEMENTATION = "Ruby"
|
26
24
|
|
25
|
+
require "fileutils"
|
26
|
+
require "pathname"
|
27
|
+
require_relative "justprep/crystal_methods"
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
# The common directory contains files which are usable in
|
30
|
+
# both the Ruby gem and compiled Crystal implementations
|
31
|
+
# The files have the extension ".crb"
|
32
|
+
#
|
33
|
+
COMMON_DIR = Pathname.new(__FILE__) + '../justprep/common'
|
34
|
+
|
35
|
+
# Loading these common methods as global kernel-level
|
36
|
+
load COMMON_DIR + "constants.crb"
|
37
|
+
load COMMON_DIR + "error_messages.crb"
|
38
|
+
load COMMON_DIR + "expand_file_path.crb"
|
39
|
+
load COMMON_DIR + "handle_command_line_parameters.crb"
|
40
|
+
load COMMON_DIR + "just_find_it.crb"
|
41
|
+
load COMMON_DIR + "usage.crb"
|
42
|
+
load COMMON_DIR + "generate_module_recipes.crb"
|
43
|
+
load COMMON_DIR + "replacement_for_module_line.crb"
|
44
|
+
load COMMON_DIR + "include_content_from.crb"
|
45
|
+
|
46
|
+
class Justprep
|
47
|
+
attr_accessor :module_names
|
48
|
+
|
49
|
+
def initialize
|
50
|
+
handle_command_line_parameters # may terminate the process
|
51
|
+
@module_names = []
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# Main function called from executable
|
56
|
+
def execute
|
57
|
+
if JUSTPREP_KEYWORDS.includes?(JUSTPREP_MODULE_KEYWORD)
|
58
|
+
STDERR.puts
|
59
|
+
STDERR.puts "ERROR: Environment Variable Configuration Problem"
|
60
|
+
STDERR.puts " JUSTPREP_KEYWORDS cannot include the same value"
|
61
|
+
STDERR.puts " as the JUSTPREP_MODULE_KEYWORD"
|
62
|
+
STDERR.puts
|
63
|
+
exit(1)
|
64
|
+
end
|
31
65
|
|
32
|
-
|
33
|
-
modules << text.select{|x| x.start_with? "#{keyword} "}
|
34
|
-
end
|
66
|
+
in_filename = just_find_it
|
35
67
|
|
36
|
-
|
68
|
+
if in_filename.nil?
|
69
|
+
STDERR.puts "WARNING: JUSTPREP_FILENAME_IN Not Found: #{JUSTPREP_FILENAME_IN}"
|
70
|
+
exit(0)
|
37
71
|
end
|
38
72
|
|
73
|
+
out_filename = File.dirname(in_filename) + "/" + JUSTPREP_FILENAME_OUT
|
39
74
|
|
40
|
-
|
41
|
-
|
42
|
-
content = []
|
43
|
-
content << "\n# >>> #{file_path}"
|
44
|
-
content << file_path.readlines.map{|x| x.chomp} # TODO: support recursion??
|
45
|
-
content << "# <<< #{file_path}\n"
|
75
|
+
in_file = File.open(in_filename, "r")
|
76
|
+
out_file = File.open(out_filename, "w")
|
46
77
|
|
47
|
-
|
48
|
-
end
|
78
|
+
line_number = 0
|
49
79
|
|
80
|
+
in_file.readlines.map{|x| x.chomp}.each do |a_line|
|
81
|
+
line_number += 1
|
50
82
|
|
51
|
-
|
52
|
-
def just_find_it(here=Pathname.pwd)
|
53
|
-
mainfile = here + JUSTPREP_FILENAME_IN
|
54
|
-
return mainfile if mainfile.exist?
|
55
|
-
return nil if here == here.parent
|
56
|
-
return just_find_it(here.parent)
|
57
|
-
end
|
83
|
+
parts = a_line.to_s.split(" ")
|
58
84
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
if a_path_string.start_with? '~'
|
63
|
-
a_path_string = "${HOME}" + a_path_string[1, a_path_string.size-1]
|
85
|
+
if 0 == parts.size
|
86
|
+
out_file.puts
|
87
|
+
next
|
64
88
|
end
|
65
89
|
|
66
|
-
|
90
|
+
# NOTE: Leading spaces are not allowed. The keywords
|
91
|
+
# MUST be complete left-justified.
|
92
|
+
#
|
93
|
+
if JUSTPREP_KEYWORDS.include?(parts.first.downcase)
|
94
|
+
out_file.puts "# #{a_line}"
|
67
95
|
|
68
|
-
|
69
|
-
end
|
96
|
+
glob_filename = expand_file_path(parts[1..parts.size].join(" "))
|
70
97
|
|
71
|
-
|
72
|
-
def usage
|
73
|
-
puts <<~EOS
|
74
|
-
justprep v#{VERSION} (ruby)
|
75
|
-
A pre-processor to the just command line utility
|
76
|
-
By Dewayne VanHoozer <dvanhoozer@gmail.com>
|
77
|
-
|
78
|
-
USAGE:
|
79
|
-
justprep [flags] && just
|
80
|
-
|
81
|
-
FLAGS:
|
82
|
-
--version Shows the current version
|
83
|
-
-h, --help Displays this usage message
|
84
|
-
|
85
|
-
DESCRIPTION:
|
86
|
-
Looks for a file named #{JUSTPREP_FILENAME_IN} in the current
|
87
|
-
directory hierarchy. If found it replaces all lines that
|
88
|
-
have the keywords (#{JUSTPREP_KEYWORDS.join(", ")}) followed
|
89
|
-
by file path with the contents of the specified file.
|
90
|
-
|
91
|
-
SYSTEM ENVIRONMENT VARIABLES:
|
92
|
-
Default Value
|
93
|
-
JUSTPREP_FILENAME_IN .... main.just
|
94
|
-
JUSTPREP_FILENAME_OUT ... justfile
|
95
|
-
JUSTPREP_KEYWORDS ....... 'import include require with'
|
96
|
-
|
97
|
-
SUGGESTION:
|
98
|
-
Create an alias for your command shell. For example
|
99
|
-
alias jj='justprop && just'
|
100
|
-
|
101
|
-
THANKS TO:
|
102
|
-
Casey Rodarmor <casey@rodarmor.com>
|
103
|
-
Just because just is just a handy utility with just an odd name. :)
|
104
|
-
|
105
|
-
EOS
|
106
|
-
end
|
98
|
+
module_filenames = Dir.glob(glob_filename)
|
107
99
|
|
100
|
+
if 0 == module_filenames.size
|
101
|
+
error_file_does_not_exist(line_number, a_line)
|
102
|
+
exit(1)
|
103
|
+
end
|
108
104
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
ARGV.each do |param|
|
113
|
-
if "--version" == param
|
114
|
-
puts "jusrprep v#{VERSION} (ruby)"
|
115
|
-
elsif ["-h", "--help"].include?(param)
|
116
|
-
usage
|
105
|
+
module_filenames.each do |module_filename|
|
106
|
+
if File.exist?(module_filename)
|
107
|
+
include_content_from(out_file, module_filename)
|
117
108
|
else
|
118
|
-
|
109
|
+
error_file_does_not_exist(line_number, a_line)
|
119
110
|
exit(1)
|
120
111
|
end
|
121
112
|
end
|
113
|
+
elsif JUSTPREP_MODULE_KEYWORD == parts.first.downcase
|
114
|
+
result_array = replacement_for_module_line(line_number, a_line)
|
115
|
+
@module_names << result_array.first
|
116
|
+
out_file.puts result_array.last
|
117
|
+
else
|
118
|
+
out_file.puts a_line
|
122
119
|
end
|
123
|
-
end
|
124
|
-
|
125
|
-
|
126
|
-
# Main function called from executable
|
127
|
-
def execute
|
128
|
-
handle_command_line_parameters
|
129
|
-
|
130
|
-
mainfile = just_find_it
|
120
|
+
end # in_file.readlines ...
|
131
121
|
|
132
|
-
|
133
|
-
|
134
|
-
basefile = mainfile.parent + JUSTPREP_FILENAME_OUT
|
135
|
-
|
136
|
-
text = mainfile.readlines.map{|x| x.chomp} # drop the line ending from each line
|
137
|
-
|
138
|
-
modules = find_modules text
|
139
|
-
|
140
|
-
if modules.empty?
|
141
|
-
basefile.write text
|
142
|
-
exit(0)
|
143
|
-
end
|
144
|
-
|
145
|
-
modules.each do |a_line|
|
146
|
-
an_index = text.index a_line
|
147
|
-
begin_filename = a_line.index(' ')
|
148
|
-
module_filename = a_line[begin_filename, a_line.size - begin_filename].strip
|
149
|
-
|
150
|
-
if module_filename.empty?
|
151
|
-
STDERR.puts "#{an_index}: #{a_line}"
|
152
|
-
STDERR.puts "ERROR: No path/to/file was provided"
|
153
|
-
next
|
154
|
-
end
|
155
|
-
|
156
|
-
if module_filename.include?('~') || module_filename.include?('$')
|
157
|
-
module_filename = expand_file_path(module_filename)
|
158
|
-
end
|
159
|
-
|
160
|
-
module_path = Pathname.new(module_filename)
|
161
|
-
|
162
|
-
if module_path.relative?
|
163
|
-
module_path = mainfile.parent + module_path
|
164
|
-
end
|
165
|
-
|
166
|
-
if module_path.exist?
|
167
|
-
text[an_index] = include_content_from(module_path)
|
168
|
-
else
|
169
|
-
STDERR.puts "#{an_index}: #{a_line}"
|
170
|
-
STDERR.puts "| ERROR: File Does Not Exist - #{module_path}"
|
171
|
-
end
|
172
|
-
end
|
122
|
+
out_file.puts generate_module_recipes(@module_names)
|
173
123
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
end # module Justprep
|
124
|
+
out_file.close
|
125
|
+
end # def
|
126
|
+
end # class Justprep
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: justprep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dewayne VanHoozer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|
@@ -50,6 +50,16 @@ files:
|
|
50
50
|
- justfile
|
51
51
|
- justprep.gemspec
|
52
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/generate_module_recipes.crb
|
57
|
+
- lib/justprep/common/handle_command_line_parameters.crb
|
58
|
+
- lib/justprep/common/include_content_from.crb
|
59
|
+
- lib/justprep/common/just_find_it.crb
|
60
|
+
- lib/justprep/common/replacement_for_module_line.crb
|
61
|
+
- lib/justprep/common/usage.crb
|
62
|
+
- lib/justprep/crystal_methods.rb
|
53
63
|
- lib/justprep/version.rb
|
54
64
|
- prototype.rb
|
55
65
|
homepage: http://github.com/MadBomber/justprep/tree/main/ruby
|
@@ -72,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
82
|
- !ruby/object:Gem::Version
|
73
83
|
version: '0'
|
74
84
|
requirements: []
|
75
|
-
rubygems_version: 3.
|
85
|
+
rubygems_version: 3.3.16
|
76
86
|
signing_key:
|
77
87
|
specification_version: 4
|
78
88
|
summary: A pre-processor for the 'just' command line utility
|