bauk-gen 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de5868b1779c5cd722f72f92b60b978fab6587e85647f2c769b1073b83a96e09
4
+ data.tar.gz: 2d95ff83a373a966122849806b627883ac1e6d5622da0c3c74fa23ad5bef5e93
5
+ SHA512:
6
+ metadata.gz: e51ac968d79487618b98e02b6836ab476bc527f388b15a85f840bb1151d0831ea0cf8bfe0e4312fc9bd117f8381c8ccfcc959bf0a0b7e5f201d99bfba098cf12
7
+ data.tar.gz: 11aaedc3de69f7dc0011985499640deadfb65f9f6a93d5a1ccfb00fe6a0d84c93b7e07713bcd1aebe5d453b7c6b7f41bac622a5148c623a4edc9635c814b4358
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ /.bauk/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kubajasko@hotmail.co.uk. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in bauk-gen.gemspec
6
+ gemspec
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bauk-gen (0.0.2)
5
+ bauk-core (~> 0.0)
6
+ deep_merge (~> 1.2)
7
+ log4r (~> 1.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.0)
13
+ bauk-core (0.0.4)
14
+ deep_merge (1.2.1)
15
+ diff-lcs (1.3)
16
+ jaro_winkler (1.5.3)
17
+ log4r (1.1.10)
18
+ parallel (1.17.0)
19
+ parser (2.6.4.0)
20
+ ast (~> 2.4.0)
21
+ rainbow (3.0.0)
22
+ rake (10.5.0)
23
+ rspec (3.8.0)
24
+ rspec-core (~> 3.8.0)
25
+ rspec-expectations (~> 3.8.0)
26
+ rspec-mocks (~> 3.8.0)
27
+ rspec-core (3.8.2)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-expectations (3.8.4)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-mocks (3.8.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-support (3.8.2)
36
+ rubocop (0.74.0)
37
+ jaro_winkler (~> 1.5.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 2.6)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 1.4.0, < 1.7)
43
+ ruby-progressbar (1.10.1)
44
+ unicode-display_width (1.6.0)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bauk-gen!
51
+ bundler (~> 2.0)
52
+ rake (~> 10.0)
53
+ rspec (~> 3.0)
54
+ rubocop (~> 0.74)
55
+
56
+ BUNDLED WITH
57
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Kuba Jasko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Bauk::Gen
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bauk/gen`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bauk-gen'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bauk-gen
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ Filesystem layout:
28
+ <gem templates>
29
+ ~/.bauk/generator/
30
+ config.yaml
31
+ templates/
32
+ common/
33
+ <gen-nam>/
34
+ components/
35
+ common/
36
+ <gen-name>/
37
+ ./.bauk/generator/ (as above)
38
+
39
+ Example config:
40
+ ```yaml
41
+ config:
42
+ name: ProjectA
43
+ description: Project for A
44
+ generators:
45
+ default:
46
+ inputs:
47
+ templates:
48
+ dirs:
49
+ - /path/a
50
+ - /path/b
51
+ outputs:
52
+ base_dir: sub/folder
53
+ config:
54
+ name: ProjectA-gen1
55
+ modules:
56
+ gradle:
57
+ config:
58
+ name: project-a
59
+
60
+ ```
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bauk-gen. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
75
+
76
+ ## Code of Conduct
77
+
78
+ Everyone interacting in the Bauk::Gen project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bauk-gen/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
9
+
10
+ task :version, [:type] do |_t, args|
11
+ # Params
12
+ version_file = 'lib/bauk/gen/version.rb'
13
+ type = (args.type || :patch).to_sym
14
+ # Get version
15
+ version_file_contents = File.read(version_file)
16
+ version = version_file_contents.scan(/VERSION\s*=\s*["'](.*)["']/).flatten[0]
17
+ (major, minor, patch) = version.split('.').map(&:to_i)
18
+
19
+ if type == :major then major += 1; minor = 0; patch = 0
20
+ elsif type == :minor then minor += 1; patch = 0
21
+ elsif type == :patch then patch += 1
22
+ else raise 'Invalid type given. Valid types are: major, minor, patch'
23
+ end
24
+
25
+ puts "Incrementing #{type}: #{version} -> #{[major, minor, patch].join('.')}"
26
+ version = [major, minor, patch].join('.')
27
+ version_file_contents.sub!(/VERSION\s*=\s*["'].*["']/, "VERSION = '#{version}'")
28
+ File.write(version_file, version_file_contents)
29
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'bauk/gen/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'bauk-gen'
9
+ spec.version = Bauk::Gen::VERSION
10
+ spec.authors = ['Kuba Jasko']
11
+ spec.email = ['kubajasko@hotmail.co.uk']
12
+
13
+ spec.summary = 'Generator framework wrapping erb.'
14
+ spec.description = 'It is config driven and extensible, while also allows different inputs and outputs.' \
15
+ 'You can create gems that this will pull in, enabling adding in custom templates and options'
16
+ spec.homepage = 'https://gitlab.com/BAUK/bauk-gen'
17
+ spec.license = 'MIT'
18
+
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://gitlab.com/BAUK/bauk-gen'
23
+ spec.metadata['changelog_uri'] = 'https://gitlab.com/BAUK/bauk-gen/commits/master'
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject do |f|
29
+ f.match(%r{^(test|spec|features)/})
30
+ end
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_development_dependency 'bundler', '~> 2.0'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_development_dependency 'rubocop', '~> 0.74'
40
+
41
+ spec.add_runtime_dependency 'bauk-core', '~> 0.0'
42
+ spec.add_runtime_dependency 'deep_merge', '~> 1.2'
43
+ spec.add_runtime_dependency 'log4r', '~> 1.1'
44
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'bauk/gen'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bauk/gen'
5
+ require 'bauk/gen/generator'
6
+
7
+ Bauk::Gen.parse
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bauk/gen/version'
4
+ require 'bauk/utils/log'
5
+ require 'bauk/utils/base_parser'
6
+ require 'bauk/gen/configs/files'
7
+ require 'bauk/gen/init'
8
+ require 'fileutils'
9
+ require 'deep_merge'
10
+
11
+
12
+ module Bauk
13
+ module Gen
14
+ extend Bauk::Utils::Log
15
+ def self.parse_generators(generators = [], config = {})
16
+ if generators.empty?
17
+ generators = config[:generators]&.keys || []
18
+ end
19
+ log.error "No generators found" if generators.empty?
20
+ generators
21
+ end
22
+
23
+ def self.generate(generators = [])
24
+ config = Bauk::Gen::Configs::Files.new.generate_config
25
+ log.debug "Using generated config: #{config}"
26
+ generators = parse_generators generators, config
27
+
28
+ Dir.chdir(config[:base_dir] || '.') do
29
+ generators.each do |generator|
30
+ load_generator(generator, config.deep_merge!(config[:generators]&.[](generator) || {})).generate
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.config(generators = [])
36
+ config = Bauk::Gen::Configs::Files.new.generate_config
37
+ generators = parse_generators generators, config
38
+
39
+ unless log.info?
40
+ puts YAML.dump config
41
+ return
42
+ end
43
+
44
+ config = {}
45
+ Dir.chdir(config[:base_dir] || '.') do
46
+ generators.each do |generator|
47
+ config[generator] = load_generator(generator, config.deep_merge!(config[:generators]&.[](generator) || {})).config
48
+ end
49
+ end
50
+ puts YAML.dump config
51
+ end
52
+
53
+ def self.init(generators = [])
54
+ generators = parse_generators generators
55
+ if generators.empty?
56
+ log.error "Adding default generator (You can specify init with a custom generator using the -g/--generator flag)"
57
+ generators = ['bauk_gen']
58
+ end
59
+ generators.each do |generator|
60
+ load_generator(generator, {}).init
61
+ end
62
+ end
63
+
64
+ def self.parse()
65
+ generators = []
66
+ Bauk::Utils::BaseParser.new(
67
+ opts: lambda do |opts|
68
+ opts.on('-c', '--config key[=val]', 'Override config items from the command-line') do |conf|
69
+ # TODO
70
+ raise "--config argument is not yet implemented"
71
+ end
72
+ opts.on('-g', '--generator [generator-module]', 'The generators to run') do |gen|
73
+ generators << gen
74
+ end
75
+ end,
76
+ generate: {
77
+ aliases: %i[gen g],
78
+ info: 'Run the generation',
79
+ action: -> { generate generators }
80
+ },
81
+ config: {
82
+ aliases: %i[conf c],
83
+ info: 'Dump the config. Add one verbose level to dump the fully generated config',
84
+ action: -> { config generators }
85
+ },
86
+ init: {
87
+ aliases: %i[i],
88
+ info: 'Initialise the generator here with some basic examples',
89
+ action: -> { init generators }
90
+ }
91
+ ).parse
92
+ end
93
+
94
+ def self.load_generator(module_name, config)
95
+ parts = module_name.to_s.split(%r{-|/|::|\s+|_})
96
+ require "#{parts.join('/').downcase}/generator"
97
+ Object.const_get("#{parts.map(&:capitalize).join('::')}::Generator").new config
98
+ end
99
+ end
100
+ end