justprep 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5215db017617c8b34a0e8db31b2d2f0e2db2d59c0600671347fdad324ebad83
4
- data.tar.gz: b8d16fec5e8898ed0c8154cc1856c83f2b8419d93c1f56e758f95291bff48fde
3
+ metadata.gz: fa284b4a811b6a6482c55b8fbb60e13e20833583d92d7b5d43672bf0dd9178a1
4
+ data.tar.gz: 592f588b3f165fa25e4fb0309f6763ceb625d8859cb6e1d80709a98bb3bd0eb8
5
5
  SHA512:
6
- metadata.gz: bae352f6da8c9b2b1f3a174f64f695485373225db830be20694688e02cc7368aab9e5548862c5e2e24d8ee985eef7f09b20bf674cee6ac85217418958af541e1
7
- data.tar.gz: 50d4c6fd1f70c4e042e07d948fb0561e43e0788f73d277d54476e2cbbe9c4587fe4686b69262b7a7eb3d53494146f1a1516f0b3d9925651887d67415e568e73a
6
+ metadata.gz: a5d250ba9b75361d51c0c756772a846199f8486b4ce2772b0c2d60e76550e9f3bde3b59ac2b3d77d249594bb30246a89de64d97e26e4089ba3dd711bacf2535d
7
+ data.tar.gz: 6dc5e9a051e6326a95decf12dae092fe9ca59d97f25344009818f784fdf47f12960ccbe007a921d46b12ff4264b6536b0a5257e5e92f7bda4dd708aafd9e27c7
data/README.md CHANGED
@@ -1,19 +1,28 @@
1
- # Justprep
1
+ # `justprep`
2
2
 
3
- A pre-processor to the "just" command-line utility packaged as a Ruby Gem.
3
+ Just a CLI pre-processor tool for task runners like "just" my current favorite.
4
4
 
5
- ## Installation
5
+ This directory is the codebase for the Ruby gem implementation. It also contains the common directory where \*.crb files are kept. These are the files that are shared between this Ruby gem implementation and the Crystal implementation.
6
6
 
7
- $ gem install justprep
7
+ ### Installation for the Ruby version
8
8
 
9
- ## Usage
9
+ gem install justprep
10
10
 
11
- See the top-level README.md file.
11
+ ### Installation for the Crystal version
12
12
 
13
- ## Contributing
13
+ brew install --build-from-source MadBomber/tap/justprep
14
+
15
+ ### Documentation
16
+
17
+ Since this capability is implemented in both Ruby and Crystal there is only one set of documentation. Both implementations act the same way. See the [repository's Wiki](https://github.com/MadBomber/justprep/wiki) for details.
18
+
19
+
20
+ ### Contributing
14
21
 
15
22
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/justprep.
16
23
 
24
+ If you have a different CLI task runner than what justprep currently supports, let me know so we can add it to the support list.
25
+
17
26
  ## License
18
27
 
19
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
28
+ justprep is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/justprep.gemspec CHANGED
@@ -8,18 +8,16 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Dewayne VanHoozer"]
9
9
  spec.email = ["dvanhoozer@gmail.com"]
10
10
 
11
- spec.summary = "A pre-processor for the 'just' command line utility"
11
+ spec.summary = "Just a pre-processor for CLI task runners like 'just'"
12
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.
13
+ justprep is a CLI tool implemented as a Ruby gem AND a
14
+ compiled Crystal binary. It allows a task file to be
15
+ auto-generated from seperate source files that contain
16
+ inclusionary keywords such as include, import, require
17
+ and with.
20
18
  EOS
21
19
 
22
- spec.homepage = "http://github.com/MadBomber/justprep/tree/main/ruby"
20
+ spec.homepage = "http://github.com/MadBomber/justprep"
23
21
  spec.license = "MIT"
24
22
  spec.required_ruby_version = ">= 2.4.0"
25
23
 
@@ -1,7 +1,53 @@
1
- VERSION = "1.2.3"
1
+ VERSION = "1.2.4"
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
3
+ class Justprep
6
4
 
7
- JUSTPREP_MODULE_KEYWORD = ENV.fetch("JUSTPREP_MODULE_KEYWORD", "module")
5
+ # define class variables used for configuration
6
+ # This helps Crystal know what the type of the varibles are.
7
+
8
+ @@justprep_for = "String"
9
+ @@justprep_module_keyword = "String"
10
+ @@justprep_keywords = ["String", "String"]
11
+ @@justprep_filename_in = "String"
12
+ @@justprep_filename_out = "String"
13
+ @@filename_option = "String"
14
+
15
+
16
+ # defining all these instance methods for Ruby's unit tests
17
+
18
+ def justprep_for ; @@justprep_for end
19
+ def justprep_module_keyword; @@justprep_module_keyword end
20
+ def justprep_keywords ; @@justprep_keywords end
21
+ def justprep_filename_in ; @@justprep_filename_in end
22
+ def justprep_filename_out ; @@justprep_filename_out end
23
+ def filename_option ; @@filename_option end
24
+
25
+
26
+ def using_just?
27
+ "just" == @@justprep_for
28
+ end
29
+
30
+
31
+ # Sets the configuration class variables from their cooresponding
32
+ # system environment variables. Any configuration coming from the
33
+ # command-line parameters are set in the handle_command_line_parameters()
34
+ # method.
35
+ #
36
+ def set_configuration
37
+ @@justprep_for = ENV.fetch("JUSTPREP_FOR", "just")
38
+ @@justprep_module_keyword = ENV.fetch("JUSTPREP_MODULE_KEYWORD", "module")
39
+ @@justprep_keywords = ENV.fetch("justprep_keywords", "import include require with").split
40
+
41
+ if using_just?
42
+ @@justprep_filename_in = ENV.fetch("JUSTPREP_FILENAME_IN", "main.just")
43
+ @@justprep_filename_out = ENV.fetch("JUSTPREP_FILENAME_OUT", "justfile")
44
+ @@filename_option = "-f"
45
+
46
+ else
47
+ @@justprep_filename_in = ENV.fetch("JUSTPREP_FILENAME_IN")
48
+ @@justprep_filename_out = ENV.fetch("JUSTPREP_FILENAME_OUT")
49
+ @@filename_option = ""
50
+ end
51
+ end
52
+
53
+ end # class Justprep
@@ -1,5 +1,7 @@
1
1
  # common/error_messages.crb
2
2
 
3
+ class Justprep
4
+
3
5
  # Parameters:
4
6
  # line_number .. Integer (zero-based index)
5
7
  # a_line ....... String
@@ -19,7 +21,7 @@ def error_file_does_not_exist(line_number, a_line)
19
21
 
20
22
  x = a_line.index(" ")
21
23
 
22
- if a_line.starts_with?(JUSTPREP_MODULE_KEYWORD)
24
+ if a_line.starts_with?(@@justprep_module_keyword.to_s)
23
25
  x = a_line.index(" ", x.nil? ? 0 : x + 1) # because Crystal thinks x could be nil
24
26
  end
25
27
 
@@ -51,3 +53,19 @@ def error_syntax(line_number, a_line)
51
53
  return nil
52
54
  end
53
55
 
56
+
57
+ def error_keyword_conflict
58
+ comma_space = ", "
59
+ STDERR.puts "
60
+
61
+ ERROR: There is a conflict between the environment variables
62
+ $JUSTPREP_MODULE_KEYWORD _cannot_ be in $JUSTPREP_KEYWORDS
63
+
64
+ $JUSTPREP_KEYWORDS => #{@@justprep_keywords.join(comma_space)}
65
+ $JUSTPREP_MODULE_KEYWORD => #{@@justprep_module_keyword}
66
+
67
+ "
68
+ return nil
69
+ end
70
+
71
+ end # class Justprep
@@ -1,5 +1,7 @@
1
1
  # common/expand_file_path.crb
2
2
 
3
+ class Justprep
4
+
3
5
  # use an external shell to expand system environment variables
4
6
  def expand_file_path(a_path_string)
5
7
  a_path_string = a_path_string.strip
@@ -13,3 +15,4 @@ def expand_file_path(a_path_string)
13
15
  return a_path_string
14
16
  end
15
17
 
18
+ end # class Justprep
@@ -0,0 +1,61 @@
1
+ # .../ruby/lib/justprep/common/generate_module_tasks.crb
2
+
3
+ class Justprep
4
+
5
+ # Given an Array of Strings representing the fake
6
+ # module names it returns a String to be appended
7
+ # to the generated justfile.
8
+ #
9
+ # Input:
10
+ # module_names .... Array(String) fake module names
11
+ #
12
+ # Output:
13
+ # tasks ... String
14
+ #
15
+ def generate_module_tasks(module_names)
16
+ if self.using_just?
17
+ tasks = create_just_tasks(module_names)
18
+ else
19
+ tasks = "# Do not know how to make modules for #{@@justprep_for}"
20
+ end
21
+
22
+ return tasks
23
+ end
24
+
25
+
26
+ def create_just_tasks(module_names)
27
+ tasks = ""
28
+
29
+ module_names.each do |mod_name|
30
+ tasks += "
31
+
32
+ # Module #{mod_name}
33
+ @#{mod_name} what='' args='':
34
+ #{@@justprep_for} #{@@filename_option} {{module_#{mod_name}}} {{what}} {{args}}
35
+
36
+ "
37
+ end
38
+
39
+ return tasks
40
+ end
41
+
42
+
43
+ def create_run_tasks(module_names)
44
+ tasks = ""
45
+
46
+ module_names.each do |mod_name|
47
+ tasks += "
48
+
49
+ ##
50
+ # Module #{mod_name}
51
+ # Encapsulates additional tasks
52
+ #{mod_name}:
53
+ #{JUSTPREP_FOR} #{FILENAME_OPTION} ${module_#{mod_name}} ${@}
54
+
55
+ "
56
+ end
57
+
58
+ return tasks
59
+ end
60
+
61
+ end # class Justprep
@@ -1,5 +1,6 @@
1
1
  # common/handle_command_line_parameters.crb
2
2
 
3
+ class Justprep
3
4
 
4
5
  # take care of ARGV
5
6
  #
@@ -8,17 +9,30 @@
8
9
  # otherwise it terminates the process
9
10
  #
10
11
  def handle_command_line_parameters
12
+ # When true, header/footer wrappers around include content are excluded
13
+ @@no_brag = false
14
+
11
15
  if ARGV.size > 0
12
16
  ARGV.each do |param|
13
17
  if "--version" == param
14
18
  puts "jusrprep v#{VERSION} (#{IMPLEMENTATION})"
19
+ exit(1)
15
20
  elsif ["-h", "--help"].includes?(param)
16
21
  usage
22
+ exit(1)
23
+ elsif "--no-brag" == param
24
+ @@no_brag = true
17
25
  else
18
26
  STDERR.puts "justprep does not support: #{param}"
27
+ exit(1)
19
28
  end
20
29
  end
21
-
22
- exit(1)
23
30
  end
24
31
  end
32
+
33
+
34
+ def no_brag?
35
+ @@no_brag
36
+ end
37
+
38
+ end # class Justprep
@@ -1,5 +1,6 @@
1
1
  # .../ruby/lib/justprep/common/def include_content_from.crb
2
2
 
3
+ class Justprep
3
4
 
4
5
  # single-level inclusion
5
6
  #
@@ -11,14 +12,15 @@
11
12
  # nil .... This is a function without specific return value
12
13
  #
13
14
  def include_content_from(out_file, module_filename)
14
- out_file.puts "\n# >>> #{module_filename}"
15
+ out_file.puts "\n# >>> #{module_filename}" unless no_brag?
15
16
 
16
17
  File.read_lines(module_filename).each do |m_line|
17
18
  out_file.puts m_line
18
19
  end
19
20
 
20
- out_file.puts "# <<< #{module_filename}\n"
21
+ out_file.puts "# <<< #{module_filename}\n" unless no_brag?
21
22
 
22
23
  return nil
23
24
  end
24
25
 
26
+ end # class Justprep
@@ -1,9 +1,11 @@
1
1
  # common/just_find_it.crb
2
2
 
3
+ class Justprep
4
+
3
5
  # look for first occurace of mainfile
4
6
  # returns nil when none are found.
5
7
  def just_find_it(here = FileUtils.pwd)
6
- mainfile_path = here + "/" + JUSTPREP_FILENAME_IN
8
+ mainfile_path = here + "/" + @@justprep_filename_in.to_s
7
9
  return mainfile_path if File.exists?(mainfile_path)
8
10
 
9
11
  parts = here.to_s.split("/")
@@ -12,3 +14,5 @@ def just_find_it(here = FileUtils.pwd)
12
14
  return nil if parts.empty?
13
15
  return just_find_it(parts.join('/'))
14
16
  end
17
+
18
+ end # class Justprep
@@ -1,5 +1,7 @@
1
1
  # .../ruby/lig/justprep/common/replacement_for_module_line.crb
2
2
 
3
+ class Justprep
4
+
3
5
  # Inserts the module_name into the Array of module_names
4
6
  # Returns a string that defines the variable for the path to the module
5
7
  #
@@ -48,3 +50,5 @@ def replacement_for_module_line(line_number, a_string)
48
50
 
49
51
  return [module_name, "module_#{module_name} := \"#{path_to_module}\""]
50
52
  end
53
+
54
+ end # class Justprep
@@ -1,30 +1,53 @@
1
1
  # common/usage.crb
2
2
 
3
+ class Justprep
4
+
3
5
  def usage
4
6
  usage_text = "
5
7
  justprep v#{VERSION} (#{IMPLEMENTATION})
6
8
 
7
- A pre-processor to the just command line utility
9
+ Just a pre-processor to CLI task runners such as 'just'
8
10
  By Dewayne VanHoozer <dvanhoozer@gmail.com>
9
11
 
10
12
  USAGE:
11
- justprep [flags] && just
13
+ justprep [flags]
14
+ justprep && #{@@justprep_for}
12
15
 
13
16
  FLAGS:
14
17
  --version Shows the current version
15
18
  -h, --help Displays this usage message
19
+ --no-brag Do not add header/footer around included content
16
20
 
17
21
  DESCRIPTION:
18
- Looks for a file named #{JUSTPREP_FILENAME_IN} in the current
22
+ Looks for a file named #{@@justprep_filename_in} in the current
19
23
  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.
24
+ have the keywords (#{@@justprep_keywords.join(", ")}) followed
25
+ by a file path with the contents of the specified file.
26
+
27
+ if it finds a line that begins with the module keyword
28
+ (#{@@justprep_module_keyword}) in sets up a fake module
29
+ system consistent with the target CLI task runner #{@@justprep_for}.
22
30
 
23
31
  SYSTEM ENVIRONMENT VARIABLES:
24
- Default Value
25
- JUSTPREP_FILENAME_IN .... main.just
26
- JUSTPREP_FILENAME_OUT ... justfile
32
+ Default / Current Value
33
+ JUSTPREP_FOR ............ 'just'
34
+ '#{@@justprep_for}'
35
+
36
+ JUSTPREP_FILENAME_IN .... 'main.just'
37
+ '#{@@justprep_filename_in}'
38
+
39
+ JUSTPREP_FILENAME_OUT ... 'justfile'
40
+ '#{@@justprep_filename_out}'
41
+
27
42
  JUSTPREP_KEYWORDS ....... 'import include require with'
43
+ '#{@@justprep_keywords.join(' ')}'
44
+
45
+ JUSTPREP_MODULE_KEYWORD . 'module'
46
+ '#{@@justprep_module_keyword}'
47
+
48
+ DOCUMENTATION:
49
+ A full set of documentation can be found in the project's
50
+ wiki: https://github.com/MadBomber/justprep/wiki
28
51
 
29
52
  SUGGESTION:
30
53
  Create an alias for your command shell. For example
@@ -44,3 +67,5 @@ THANKS TO:
44
67
 
45
68
  return usage_text
46
69
  end
70
+
71
+ end # class Justprep
@@ -5,7 +5,7 @@
5
5
 
6
6
  # TODO: find other classes in which Ruby/Crystal differ
7
7
 
8
- class Array
8
+ module Enumerable
9
9
  alias_method :includes?, :include?
10
10
  end
11
11
 
data/lib/justprep.rb CHANGED
@@ -10,8 +10,9 @@
10
10
  #
11
11
  # variable name default value
12
12
  # --------------------- -------------
13
- # JUSTPREP_FILENAME_IN ... main.just
14
- # JUSTPREP_FILENAME_OUT ... justfile
13
+ # JUSTPREP_FOR ............ 'just'
14
+ # JUSTPREP_FILENAME_IN ... 'main.just'
15
+ # JUSTPREP_FILENAME_OUT ... 'justfile'
15
16
  # JUSTPREP_KEYWORDS ... 'import include require with'
16
17
  # JUSTPREP_MODULE_KEYWORD . 'module'
17
18
  #
@@ -39,7 +40,7 @@ load COMMON_DIR + "expand_file_path.crb"
39
40
  load COMMON_DIR + "handle_command_line_parameters.crb"
40
41
  load COMMON_DIR + "just_find_it.crb"
41
42
  load COMMON_DIR + "usage.crb"
42
- load COMMON_DIR + "generate_module_recipes.crb"
43
+ load COMMON_DIR + "generate_module_tasks.crb"
43
44
  load COMMON_DIR + "replacement_for_module_line.crb"
44
45
  load COMMON_DIR + "include_content_from.crb"
45
46
 
@@ -47,6 +48,7 @@ class Justprep
47
48
  attr_accessor :module_names
48
49
 
49
50
  def initialize
51
+ set_configuration # sets class vars from envars
50
52
  handle_command_line_parameters # may terminate the process
51
53
  @module_names = []
52
54
  end
@@ -54,23 +56,22 @@ class Justprep
54
56
 
55
57
  # Main function called from executable
56
58
  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
59
+ # SMELL: for some reason the crystal_methods alias_method of
60
+ # includes? for include? is not working.
61
+
62
+ if @@justprep_keywords.include?(@@justprep_module_keyword)
63
+ error_keyword_conflict
63
64
  exit(1)
64
65
  end
65
66
 
66
67
  in_filename = just_find_it
67
68
 
68
69
  if in_filename.nil?
69
- STDERR.puts "WARNING: JUSTPREP_FILENAME_IN Not Found: #{JUSTPREP_FILENAME_IN}"
70
+ STDERR.puts "WARNING: $JUSTPREP_FILENAME_IN Not Found: #{@@justprep_filename_in}"
70
71
  exit(0)
71
72
  end
72
73
 
73
- out_filename = File.dirname(in_filename) + "/" + JUSTPREP_FILENAME_OUT
74
+ out_filename = File.dirname(in_filename) + "/" + @@justprep_filename_out
74
75
 
75
76
  in_file = File.open(in_filename, "r")
76
77
  out_file = File.open(out_filename, "w")
@@ -90,8 +91,8 @@ class Justprep
90
91
  # NOTE: Leading spaces are not allowed. The keywords
91
92
  # MUST be complete left-justified.
92
93
  #
93
- if JUSTPREP_KEYWORDS.include?(parts.first.downcase)
94
- out_file.puts "# #{a_line}"
94
+ if @@justprep_keywords.include?(parts.first.downcase)
95
+ out_file.puts "# #{a_line}" unless no_brag?
95
96
 
96
97
  glob_filename = expand_file_path(parts[1..parts.size].join(" "))
97
98
 
@@ -110,7 +111,7 @@ class Justprep
110
111
  exit(1)
111
112
  end
112
113
  end
113
- elsif JUSTPREP_MODULE_KEYWORD == parts.first.downcase
114
+ elsif @@justprep_module_keyword == parts.first.downcase
114
115
  result_array = replacement_for_module_line(line_number, a_line)
115
116
  @module_names << result_array.first
116
117
  out_file.puts result_array.last
@@ -119,7 +120,7 @@ class Justprep
119
120
  end
120
121
  end # in_file.readlines ...
121
122
 
122
- out_file.puts generate_module_recipes(@module_names)
123
+ out_file.puts generate_module_tasks(@module_names)
123
124
 
124
125
  out_file.close
125
126
  end # def
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.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-19 00:00:00.000000000 Z
11
+ date: 2022-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -24,14 +24,9 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: |
28
- allows a "justfile" to be auto-generated from a seperate source file
29
- that contains inclusionary keywords such as include, import, require
30
- and with. These keywords are followed by a path to a file. If the
31
- file exists, the contents of the file are inserted into the file
32
- at the position of the keyword command. After all keywords have
33
- been process a new "justfile" is created which can then be used by
34
- the 'just' tool.
27
+ description: "justprep is a CLI tool implemented as a Ruby gem AND a \ncompiled Crystal
28
+ binary. It allows a task file to be \nauto-generated from seperate source files
29
+ that contain \ninclusionary keywords such as include, import, require \nand with.\n"
35
30
  email:
36
31
  - dvanhoozer@gmail.com
37
32
  executables:
@@ -53,7 +48,7 @@ files:
53
48
  - lib/justprep/common/constants.crb
54
49
  - lib/justprep/common/error_messages.crb
55
50
  - lib/justprep/common/expand_file_path.crb
56
- - lib/justprep/common/generate_module_recipes.crb
51
+ - lib/justprep/common/generate_module_tasks.crb
57
52
  - lib/justprep/common/handle_command_line_parameters.crb
58
53
  - lib/justprep/common/include_content_from.crb
59
54
  - lib/justprep/common/just_find_it.crb
@@ -61,8 +56,7 @@ files:
61
56
  - lib/justprep/common/usage.crb
62
57
  - lib/justprep/crystal_methods.rb
63
58
  - lib/justprep/version.rb
64
- - prototype.rb
65
- homepage: http://github.com/MadBomber/justprep/tree/main/ruby
59
+ homepage: http://github.com/MadBomber/justprep
66
60
  licenses:
67
61
  - MIT
68
62
  metadata:
@@ -82,8 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
76
  - !ruby/object:Gem::Version
83
77
  version: '0'
84
78
  requirements: []
85
- rubygems_version: 3.3.16
79
+ rubygems_version: 3.3.18
86
80
  signing_key:
87
81
  specification_version: 4
88
- summary: A pre-processor for the 'just' command line utility
82
+ summary: Just a pre-processor for CLI task runners like 'just'
89
83
  test_files: []
@@ -1,27 +0,0 @@
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
data/prototype.rb DELETED
@@ -1,125 +0,0 @@
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"