foobara-files-generator 0.1.2 → 0.1.4
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 +8 -0
- data/README.md +1 -10
- data/src/files_generator.rb +12 -12
- data/src/generate.rb +4 -2
- data/src/symlink.rb +43 -0
- data/src/write_generated_files_to_disk.rb +24 -10
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cf98ecb24a6c06ed9168b0dbf7c14a4d6aa19b7a0365684634a295de86fed57
|
|
4
|
+
data.tar.gz: 2626b68d7005938cc276c044523857154aee0fbde4a4ce1717df847b7dc35cbe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 65e71db48ca1463143cfbab679dba25423992018fddc5fe19858d2d7ccd8f5bd355600e4bb47727ac45e23c08a5b759b3e92908521422a6e07ac7c8b43356a52
|
|
7
|
+
data.tar.gz: a51167675d456aa2686f283f1679c929471d28f233f8599e7fc6d0909f0a7a392d224166ebc094fe25ffc00f7cf75359ed7129979717e44ff7396b7795de89f5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
# Foobara::FilesGenerator
|
|
2
2
|
|
|
3
|
-
Contains common-code useful in different
|
|
4
|
-
|
|
5
|
-
## Development
|
|
6
|
-
|
|
7
|
-
For local development, for now, run the following:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
bundle config set local.foobara ../foobara
|
|
11
|
-
bundle config set disable_local_branch_check true
|
|
12
|
-
```
|
|
3
|
+
Contains common-code useful in different Foobara generators
|
|
13
4
|
|
|
14
5
|
## Contributing
|
|
15
6
|
|
data/src/files_generator.rb
CHANGED
|
@@ -6,9 +6,9 @@ module Foobara
|
|
|
6
6
|
|
|
7
7
|
class << self
|
|
8
8
|
def manifest_to_generator_classes(_manifest)
|
|
9
|
-
# :
|
|
9
|
+
# simplecov:disable
|
|
10
10
|
raise "subclass responsibility"
|
|
11
|
-
# :
|
|
11
|
+
# simplecov:enable
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def generators_for(manifest)
|
|
@@ -40,9 +40,9 @@ module Foobara
|
|
|
40
40
|
if file.end_with?(".erb")
|
|
41
41
|
[*path, file[0..-5]]
|
|
42
42
|
else
|
|
43
|
-
# :
|
|
43
|
+
# simplecov:disable
|
|
44
44
|
raise "expected a .erb extension. Maybe override #target_path"
|
|
45
|
-
# :
|
|
45
|
+
# simplecov:enable
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -55,9 +55,9 @@ module Foobara
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def generators_for(...)
|
|
58
|
-
# :
|
|
58
|
+
# simplecov:disable
|
|
59
59
|
self.class.generators_for(...)
|
|
60
|
-
# :
|
|
60
|
+
# simplecov:enable
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def generator_for(...)
|
|
@@ -86,9 +86,9 @@ module Foobara
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def template_path
|
|
89
|
-
# :
|
|
89
|
+
# simplecov:disable
|
|
90
90
|
raise "Subclass responsibility"
|
|
91
|
-
# :
|
|
91
|
+
# simplecov:enable
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
def absolute_template_path
|
|
@@ -102,9 +102,9 @@ module Foobara
|
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
def templates_dir
|
|
105
|
-
# :
|
|
105
|
+
# simplecov:disable
|
|
106
106
|
"#{Dir.pwd}/templates"
|
|
107
|
-
# :
|
|
107
|
+
# simplecov:enable
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
def template_string
|
|
@@ -128,9 +128,9 @@ module Foobara
|
|
|
128
128
|
if relevant_manifest.respond_to?(method_name)
|
|
129
129
|
relevant_manifest.send(method_name, *, &)
|
|
130
130
|
else
|
|
131
|
-
# :
|
|
131
|
+
# simplecov:disable
|
|
132
132
|
super
|
|
133
|
-
# :
|
|
133
|
+
# simplecov:enable
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
136
|
|
data/src/generate.rb
CHANGED
|
@@ -9,9 +9,9 @@ module Foobara
|
|
|
9
9
|
attr_accessor :element_to_generate
|
|
10
10
|
|
|
11
11
|
def base_generator
|
|
12
|
-
# :
|
|
12
|
+
# simplecov:disable
|
|
13
13
|
raise "subclass responsibility"
|
|
14
|
-
# :
|
|
14
|
+
# simplecov:enable
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def elements_to_generate
|
|
@@ -60,7 +60,9 @@ module Foobara
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
def generate_element
|
|
63
|
+
# simplecov:disable
|
|
63
64
|
return unless element_to_generate.applicable?
|
|
65
|
+
# simplecov:enable
|
|
64
66
|
|
|
65
67
|
paths_to_source_code[Util.array(element_to_generate.target_path).join("/")] =
|
|
66
68
|
element_to_generate.generate(elements_to_generate)
|
data/src/symlink.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
class FilesGenerator
|
|
3
|
+
class Symlink < String
|
|
4
|
+
@mutex = Mutex.new
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def supported?
|
|
8
|
+
return @supported if defined?(@supported)
|
|
9
|
+
# simplecov:disable-next
|
|
10
|
+
return @supported if @mutex.nil?
|
|
11
|
+
|
|
12
|
+
@mutex.synchronize do
|
|
13
|
+
target_path = ".foobara-symlink-test-target"
|
|
14
|
+
symlink_path = ".foobara-symlink-test-link"
|
|
15
|
+
|
|
16
|
+
@supported = begin
|
|
17
|
+
FileUtils.rm_f(target_path)
|
|
18
|
+
FileUtils.rm_f(symlink_path)
|
|
19
|
+
|
|
20
|
+
File.write(target_path, "hi!")
|
|
21
|
+
File.symlink(target_path, symlink_path)
|
|
22
|
+
|
|
23
|
+
File.symlink?(symlink_path)
|
|
24
|
+
# TODO: figure out which of these actually happen in Windows
|
|
25
|
+
# rubocop:disable-next Lint/ShadowedException
|
|
26
|
+
rescue Errno::EACCES, NotImplementedError, SystemCallError
|
|
27
|
+
# TODO: come up with a way to test this
|
|
28
|
+
# simplecov:disable
|
|
29
|
+
false
|
|
30
|
+
# simplecov:enable
|
|
31
|
+
ensure
|
|
32
|
+
FileUtils.rm_f(target_path)
|
|
33
|
+
FileUtils.rm_f(symlink_path)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
@mutex = nil
|
|
37
|
+
@supported
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -30,18 +30,20 @@ module Foobara
|
|
|
30
30
|
file_list_file = "#{output_directory}/#{generated_files_json_filename}"
|
|
31
31
|
|
|
32
32
|
if File.exist?(file_list_file)
|
|
33
|
-
# :
|
|
33
|
+
# simplecov:disable
|
|
34
34
|
file_list = JSON.parse(File.read(file_list_file))
|
|
35
35
|
|
|
36
36
|
file_list.map do |file|
|
|
37
37
|
Thread.new { FileUtils.rm_f("#{output_directory}/#{file}") }
|
|
38
38
|
end.each(&:join)
|
|
39
|
-
# :
|
|
39
|
+
# simplecov:enable
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def write_all_files_to_disk
|
|
44
|
+
# simplecov:disable
|
|
44
45
|
if paths_to_source_code.key?(generated_files_json_filename)
|
|
46
|
+
# simplecov:enable
|
|
45
47
|
write_file_to_disk(generated_files_json_filename, paths_to_source_code[generated_files_json_filename])
|
|
46
48
|
end
|
|
47
49
|
|
|
@@ -53,7 +55,19 @@ module Foobara
|
|
|
53
55
|
def write_file_to_disk(path, contents)
|
|
54
56
|
path = "#{output_directory}/#{path}"
|
|
55
57
|
FileUtils.mkdir_p(File.dirname(path))
|
|
56
|
-
|
|
58
|
+
|
|
59
|
+
if contents.is_a?(FilesGenerator::Symlink)
|
|
60
|
+
if FilesGenerator::Symlink.supported?
|
|
61
|
+
File.symlink(contents, path)
|
|
62
|
+
# simplecov:disable
|
|
63
|
+
else
|
|
64
|
+
# TODO: come up with a way to test this path
|
|
65
|
+
FileUtils.cp_r(contents, path)
|
|
66
|
+
# simplecov:enable
|
|
67
|
+
end
|
|
68
|
+
else
|
|
69
|
+
File.write(path, contents)
|
|
70
|
+
end
|
|
57
71
|
end
|
|
58
72
|
|
|
59
73
|
def generated_files_json_filename
|
|
@@ -61,9 +75,9 @@ module Foobara
|
|
|
61
75
|
|
|
62
76
|
if key
|
|
63
77
|
# TODO: test this path
|
|
64
|
-
# :
|
|
78
|
+
# simplecov:disable
|
|
65
79
|
"#{key}-generator.json"
|
|
66
|
-
# :
|
|
80
|
+
# simplecov:enable
|
|
67
81
|
else
|
|
68
82
|
"foobara-generated.json"
|
|
69
83
|
end
|
|
@@ -82,14 +96,14 @@ module Foobara
|
|
|
82
96
|
exit_status = wait_thr.value
|
|
83
97
|
|
|
84
98
|
unless exit_status.success?
|
|
85
|
-
# :
|
|
99
|
+
# simplecov:disable
|
|
86
100
|
message = "Could not #{cmd}\n#{stderr.read}"
|
|
87
101
|
if raise_if_fails
|
|
88
102
|
raise CouldNotExecuteError, message
|
|
89
103
|
else
|
|
90
104
|
warn "WARNING: #{message}"
|
|
91
105
|
end
|
|
92
|
-
# :
|
|
106
|
+
# simplecov:enable
|
|
93
107
|
end
|
|
94
108
|
|
|
95
109
|
exit_status
|
|
@@ -107,7 +121,7 @@ module Foobara
|
|
|
107
121
|
end
|
|
108
122
|
|
|
109
123
|
def run_cmd_and_return_output(cmd)
|
|
110
|
-
retval = ""
|
|
124
|
+
retval = +""
|
|
111
125
|
|
|
112
126
|
Open3.popen3(cmd) do |_stdin, stdout, stderr, wait_thr|
|
|
113
127
|
loop do
|
|
@@ -119,10 +133,10 @@ module Foobara
|
|
|
119
133
|
|
|
120
134
|
exit_status = wait_thr.value
|
|
121
135
|
unless exit_status.success?
|
|
122
|
-
# :
|
|
136
|
+
# simplecov:disable
|
|
123
137
|
raise CouldNotExecuteError, "could not #{cmd}\n#{stderr.read}"
|
|
124
138
|
end
|
|
125
|
-
# :
|
|
139
|
+
# simplecov:enable
|
|
126
140
|
end
|
|
127
141
|
rescue Errno::ENOENT
|
|
128
142
|
raise CouldNotExecuteError, "Could not run: #{cmd}\nMaybe it is not installed?"
|
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.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miles Georgi
|
|
@@ -44,6 +44,7 @@ files:
|
|
|
44
44
|
- lib/foobara/files_generator/bundler_actions.rb
|
|
45
45
|
- src/files_generator.rb
|
|
46
46
|
- src/generate.rb
|
|
47
|
+
- src/symlink.rb
|
|
47
48
|
- src/write_generated_files_to_disk.rb
|
|
48
49
|
homepage: https://github.com/foobara/files-generator
|
|
49
50
|
licenses:
|
|
@@ -62,13 +63,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
62
63
|
- - ">="
|
|
63
64
|
- !ruby/object:Gem::Version
|
|
64
65
|
version: 3.4.0
|
|
66
|
+
- - "<"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '4.1'
|
|
65
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
70
|
requirements:
|
|
67
71
|
- - ">="
|
|
68
72
|
- !ruby/object:Gem::Version
|
|
69
73
|
version: '0'
|
|
70
74
|
requirements: []
|
|
71
|
-
rubygems_version:
|
|
75
|
+
rubygems_version: 4.0.20
|
|
72
76
|
specification_version: 4
|
|
73
77
|
summary: Common code reused across code generator projects
|
|
74
78
|
test_files: []
|