foobara-files-generator 0.2.3 → 0.2.5
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/CHANGELOG.md +13 -0
- data/src/interpolating_generator.rb +57 -0
- data/src/write_generated_files_to_disk.rb +42 -6
- data/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e7ae36a50e618ac6d4b8a9c61f4b413f9d0364f2c7fa00454c79cdd557316110
|
|
4
|
+
data.tar.gz: c92f9131dfdc00f1c5cab24e2f8c564985308d25ce89a6d3673aaa82783d7062
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c466555bac70807a8939e7fed1d991df446e1085cea8958d99a5b06520fde3359c0ead59cef47b96bd4ae764e12ee2527b49b90a86f36b17c32d52dc2f303009
|
|
7
|
+
data.tar.gz: c62bc0c1d3218cfbc6b32a27df9bf88ade22bc5e5140639f8d8331009f9c5e5e65220b3cb4c817b02737c0bd0b8750e219808a35637c9ae011c72d2e304736b9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## [0.2.5] - 2026-10-21
|
|
2
|
+
|
|
3
|
+
- Come up with a tighter generated json files format
|
|
4
|
+
- Pretty generate the generated files json so that it isn't one long line
|
|
5
|
+
|
|
6
|
+
## [0.2.4] - 2026-10-06
|
|
7
|
+
|
|
8
|
+
- Rotate generated files json with a deprecated name
|
|
9
|
+
to non-deprecated name if it has a deprecated name
|
|
10
|
+
- If file contents are empty after deleting interpolated content
|
|
11
|
+
then delete the file instead of writing it
|
|
12
|
+
- Add an InterpolatingGenerator mixin
|
|
13
|
+
|
|
1
14
|
## [0.2.3] - 2026-10-05
|
|
2
15
|
|
|
3
16
|
- Make sure version.rb is loaded where it might be used
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module InterpolatingGenerator
|
|
3
|
+
def generate(_elements_to_generate)
|
|
4
|
+
start_marker = self.start_marker
|
|
5
|
+
end_marker = self.end_marker
|
|
6
|
+
|
|
7
|
+
content = "#{start_marker}#{new_content}#{end_marker}"
|
|
8
|
+
|
|
9
|
+
if File.exist?(template_path)
|
|
10
|
+
match = insert_at&.match(target_contents)
|
|
11
|
+
|
|
12
|
+
content = if match
|
|
13
|
+
if match.captures.empty?
|
|
14
|
+
pre = match[0]
|
|
15
|
+
post = ""
|
|
16
|
+
else
|
|
17
|
+
pre, *post = match.captures
|
|
18
|
+
post = post.join
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
"#{match.pre_match}#{pre}#{content}#{post}#{match.post_match}"
|
|
22
|
+
else
|
|
23
|
+
"#{target_contents}#{content}"
|
|
24
|
+
end
|
|
25
|
+
else
|
|
26
|
+
match = /\A\n+/.match(content)
|
|
27
|
+
|
|
28
|
+
# simplecov:disable
|
|
29
|
+
if match
|
|
30
|
+
# simplecov:enable
|
|
31
|
+
newline_count = match[0].size
|
|
32
|
+
start_marker = start_marker[newline_count..]
|
|
33
|
+
content = match.post_match
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
match = /\n+\z/.match(content)
|
|
37
|
+
|
|
38
|
+
# simplecov:disable
|
|
39
|
+
if match
|
|
40
|
+
# simplecov:enable
|
|
41
|
+
newline_count = match[0].size
|
|
42
|
+
end_marker = end_marker[...-newline_count]
|
|
43
|
+
content = match.pre_match
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
content = "#{content}\n"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
{ content:, start_marker:, end_marker: }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def new_content = raise NotImplementedError
|
|
53
|
+
def insert_at = nil
|
|
54
|
+
def start_marker = raise NotImplementedError
|
|
55
|
+
def end_marker = raise NotImplementedError
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -44,10 +44,14 @@ module Foobara
|
|
|
44
44
|
end_marker = generated_file.end_marker
|
|
45
45
|
file_info[:end_marker] = end_marker if end_marker
|
|
46
46
|
|
|
47
|
+
if file_info.keys.size == 1
|
|
48
|
+
file_info = file_path
|
|
49
|
+
end
|
|
50
|
+
|
|
47
51
|
files << file_info
|
|
48
52
|
end
|
|
49
53
|
|
|
50
|
-
content = JSON.
|
|
54
|
+
content = JSON.pretty_generate(generated_files_hash)
|
|
51
55
|
|
|
52
56
|
paths_to_source_code[generated_files_json_filename] = FilesGenerator::Types::GeneratedFile.new(content:)
|
|
53
57
|
end
|
|
@@ -72,6 +76,10 @@ module Foobara
|
|
|
72
76
|
contents = Util.deep_symbolize_keys(contents)
|
|
73
77
|
|
|
74
78
|
contents[:files].map! do |generated_file_data|
|
|
79
|
+
if generated_file_data.is_a?(::String)
|
|
80
|
+
generated_file_data = { file_path: generated_file_data }
|
|
81
|
+
end
|
|
82
|
+
|
|
75
83
|
FilesGenerator::Types::GeneratedFileRecord.new(**generated_file_data)
|
|
76
84
|
end
|
|
77
85
|
end
|
|
@@ -79,7 +87,13 @@ module Foobara
|
|
|
79
87
|
contents
|
|
80
88
|
end
|
|
81
89
|
|
|
90
|
+
def old_generated_files_path(key = self.class.generator_key)
|
|
91
|
+
"#{output_directory}/#{generated_files_json_filename(key)}"
|
|
92
|
+
end
|
|
93
|
+
|
|
82
94
|
def delete_old_files_if_needed
|
|
95
|
+
rotate_old_generated_files_json_if_needed
|
|
96
|
+
|
|
83
97
|
generated_files_info = old_generated_files_json_contents
|
|
84
98
|
|
|
85
99
|
return unless generated_files_info
|
|
@@ -97,6 +111,26 @@ module Foobara
|
|
|
97
111
|
end.each(&:join)
|
|
98
112
|
end
|
|
99
113
|
|
|
114
|
+
def rotate_old_generated_files_json_if_needed
|
|
115
|
+
keys = self.class.generator_key
|
|
116
|
+
|
|
117
|
+
return unless keys.is_a?(::Array)
|
|
118
|
+
|
|
119
|
+
key, *deprecated_keys = keys
|
|
120
|
+
|
|
121
|
+
non_deprecated_path = old_generated_files_path(key)
|
|
122
|
+
return if File.exist?(non_deprecated_path)
|
|
123
|
+
|
|
124
|
+
deprecated_keys.each do |key|
|
|
125
|
+
path = old_generated_files_path(key)
|
|
126
|
+
|
|
127
|
+
if File.exist?(path)
|
|
128
|
+
FileUtils.mv(path, non_deprecated_path)
|
|
129
|
+
break
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
100
134
|
def write_all_files_to_disk
|
|
101
135
|
paths_to_source_code.map do |path, generated_file|
|
|
102
136
|
Thread.new do
|
|
@@ -128,9 +162,7 @@ module Foobara
|
|
|
128
162
|
end
|
|
129
163
|
end
|
|
130
164
|
|
|
131
|
-
def generated_files_json_filename
|
|
132
|
-
key = self.class.generator_key
|
|
133
|
-
|
|
165
|
+
def generated_files_json_filename(key = self.class.generator_key)
|
|
134
166
|
if key
|
|
135
167
|
key = key.first if key.is_a?(::Array)
|
|
136
168
|
|
|
@@ -225,7 +257,7 @@ module Foobara
|
|
|
225
257
|
return unless end_index
|
|
226
258
|
# simplecov:enable
|
|
227
259
|
|
|
228
|
-
end_index += start_index + start_marker.size
|
|
260
|
+
end_index += start_index + start_marker.size
|
|
229
261
|
end_index += end_marker.size
|
|
230
262
|
|
|
231
263
|
keep_first = contents[0...start_index]
|
|
@@ -233,7 +265,11 @@ module Foobara
|
|
|
233
265
|
|
|
234
266
|
contents = keep_first + keep_last
|
|
235
267
|
|
|
236
|
-
|
|
268
|
+
if contents.strip.empty?
|
|
269
|
+
FileUtils.rm_f(file_path)
|
|
270
|
+
else
|
|
271
|
+
File.write(file_path, contents)
|
|
272
|
+
end
|
|
237
273
|
end
|
|
238
274
|
end
|
|
239
275
|
end
|
data/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foobara-files-generator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miles Georgi
|
|
@@ -45,6 +45,7 @@ files:
|
|
|
45
45
|
- src/files_generator.rb
|
|
46
46
|
- src/files_generator/bundler_actions.rb
|
|
47
47
|
- src/generate.rb
|
|
48
|
+
- src/interpolating_generator.rb
|
|
48
49
|
- src/symlink.rb
|
|
49
50
|
- src/types/generate_result.rb
|
|
50
51
|
- src/types/generated_file.rb
|