Module: Bauk::Gen
- Extended by:
- Utils::Log
- Defined in:
- lib/bauk/gen.rb,
lib/bauk/gen/init.rb,
lib/bauk/gen/module.rb,
lib/bauk/gen/version.rb,
lib/bauk/gen/generator.rb,
lib/bauk/gen/inputs/base.rb,
lib/bauk/gen/config_utils.rb,
lib/bauk/gen/configs/base.rb,
lib/bauk/gen/inputs/error.rb,
lib/bauk/gen/outputs/base.rb,
lib/bauk/gen/configs/error.rb,
lib/bauk/gen/configs/files.rb,
lib/bauk/gen/outputs/error.rb,
lib/bauk/gen/inputs/templates.rb,
lib/bauk/gen/outputs/filesystem.rb,
lib/bauk/gen/contents/erb_content.rb,
lib/bauk/gen/contents/base_content.rb,
lib/bauk/gen/contents/file_content.rb,
lib/bauk/gen/contents/string_content.rb
Defined Under Namespace
Modules: ConfigUtils, Configs, Contents, Init, Inputs, Outputs
Classes: Generator, Module
Constant Summary
collapse
- VERSION =
'0.0.2'
Class Method Summary
collapse
Class Method Details
.config(generators = []) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/bauk/gen.rb', line 35
def self.config(generators = [])
config = Bauk::Gen::Configs::Files.new.generate_config
generators = parse_generators generators, config
unless log.info?
puts YAML.dump config
return
end
config = {}
Dir.chdir(config[:base_dir] || '.') do
generators.each do |generator|
config[generator] = load_generator(generator, config.deep_merge!(config[:generators]&.[](generator) || {})).config
end
end
puts YAML.dump config
end
|
.generate(generators = []) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/bauk/gen.rb', line 23
def self.generate(generators = [])
config = Bauk::Gen::Configs::Files.new.generate_config
log.debug "Using generated config: #{config}"
generators = parse_generators generators, config
Dir.chdir(config[:base_dir] || '.') do
generators.each do |generator|
load_generator(generator, config.deep_merge!(config[:generators]&.[](generator) || {})).generate
end
end
end
|
.init(generators = []) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/bauk/gen.rb', line 53
def self.init(generators = [])
generators = parse_generators generators
if generators.empty?
log.error "Adding default generator (You can specify init with a custom generator using the -g/--generator flag)"
generators = ['bauk_gen']
end
generators.each do |generator|
load_generator(generator, {}).init
end
end
|
.load_generator(module_name, config) ⇒ Object
94
95
96
97
98
|
# File 'lib/bauk/gen.rb', line 94
def self.load_generator(module_name, config)
parts = module_name.to_s.split(%r{-|/|::|\s+|_})
require "#{parts.join('/').downcase}/generator"
Object.const_get("#{parts.map(&:capitalize).join('::')}::Generator").new config
end
|
.parse ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/bauk/gen.rb', line 64
def self.parse()
generators = []
Bauk::Utils::BaseParser.new(
opts: lambda do |opts|
opts.on('-c', '--config key[=val]', 'Override config items from the command-line') do |conf|
raise "--config argument is not yet implemented"
end
opts.on('-g', '--generator [generator-module]', 'The generators to run') do |gen|
generators << gen
end
end,
generate: {
aliases: %i[gen g],
info: 'Run the generation',
action: -> { generate generators }
},
config: {
aliases: %i[conf c],
info: 'Dump the config. Add one verbose level to dump the fully generated config',
action: -> { config generators }
},
init: {
aliases: %i[i],
info: 'Initialise the generator here with some basic examples',
action: -> { init generators }
}
).parse
end
|
.parse_generators(generators = [], config = {}) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/bauk/gen.rb', line 15
def self.parse_generators(generators = [], config = {})
if generators.empty?
generators = config[:generators]&.keys || []
end
log.error "No generators found" if generators.empty?
generators
end
|