k_builder-dotnet 0.0.7

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.
data/bin/setup ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # frozen_string_literal: true
4
+
5
+ set -euo pipefail
6
+ IFS=$'\n\t'
7
+ set -vx
8
+
9
+ bundle install
10
+
11
+ # Do any other automated setup that you need to do here
Binary file
Binary file
Binary file
Binary file
data/hooks/pre-commit ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'English'
5
+
6
+ # NOTE: you may need change file permissions
7
+ # chmod +x hooks/pre-commit
8
+
9
+ exit 0 if ARGV.include?('--no-verify')
10
+
11
+ warning_keywords = %w[console.log]
12
+ keywords = %w[binding.pry console.dir byebug debugger]
13
+ files_changed = `git diff-index --name-only HEAD --`.split
14
+
15
+ # puts '----------------------------------------------------------------------'
16
+ # puts remove files changed from the pre-commit checking if they are one of the following files
17
+ # puts '----------------------------------------------------------------------'
18
+ # files_changed = files_changed - ['hooks/pre-commit']
19
+ # files_changed = files_changed - ['hooks/update-version']
20
+
21
+ # byebug may need to be in these files
22
+ files_changed -= ['Gemfile']
23
+ files_changed -= ['Gemfile.lock']
24
+ files_changed -= ['.gitignore']
25
+ files_changed -= ['README.md']
26
+
27
+ files_changed = files_changed.reject { |f| f.downcase.end_with?('.json') }
28
+ files_changed = files_changed.reject { |f| f.downcase.end_with?('.yml') }
29
+
30
+ # ignore files from specific folders
31
+
32
+ file_groups = files_changed.select do |item|
33
+ item.start_with?('hooks') # ||
34
+ # item.start_with?('lib/generators')
35
+ end
36
+
37
+ files_changed -= file_groups
38
+
39
+ # remove files that are changed because they are deleted
40
+ files_changed = files_changed.select { |filename| File.file?(filename) }
41
+
42
+ # puts '----------------------------------------------------------------------'
43
+ # puts 'Files Changed'
44
+ # puts '----------------------------------------------------------------------'
45
+ # puts files_changed
46
+ # puts '----------------------------------------------------------------------'
47
+
48
+ unless files_changed.length.zero?
49
+ # puts "#{keywords.join('|')}"
50
+ # puts "#{files_changed.join(' ')}"
51
+
52
+ `git grep -q -E "#{warning_keywords.join('|')}" #{files_changed.join(' ')}`
53
+
54
+ if $CHILD_STATUS.exitstatus.zero?
55
+ puts '' # Check following lines:''
56
+ puts $CHILD_STATUS.exitstatus
57
+ files_changed.each do |file|
58
+ warning_keywords.each do |keyword|
59
+ # puts "#{keyword} ::: #{file}"
60
+ `git grep -q -E #{keyword} #{file}`
61
+ if $CHILD_STATUS.exitstatus.zero?
62
+ line = `git grep -n #{keyword} #{file} | awk -F ":" '{print $2}'`.split.join(', ')
63
+ puts "WARNING:\t\033[31m#{file}\033[0m contains #{keyword} at line \033[33m#{line}\033[0m."
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ `git grep -q -E "#{keywords.join('|')}" #{files_changed.join(' ')}`
70
+
71
+ if $CHILD_STATUS.exitstatus.zero?
72
+ puts '' # Check following lines:''
73
+ puts $CHILD_STATUS.exitstatus
74
+ files_changed.each do |file|
75
+ keywords.each do |keyword|
76
+ # puts "#{keyword} ::: #{file}"
77
+ `git grep -q -E #{keyword} #{file}`
78
+ if $CHILD_STATUS.exitstatus.zero?
79
+ line = `git grep -n #{keyword} #{file} | awk -F ":" '{print $2}'`.split.join(', ')
80
+ puts "ERROR :\t\033[31m#{file}\033[0m contains #{keyword} at line \033[33m#{line}\033[0m."
81
+ end
82
+ end
83
+ end
84
+ puts '# Force commit with --no-verify'
85
+ exit 1
86
+ end
87
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # NOTE: you may need change file permissions
5
+ # chmod +x hooks/update-version
6
+
7
+ exit 1 if ARGV.empty?
8
+
9
+ version = ARGV[0]
10
+ version = version[1..-1] # revoke 'v' character, e.g. v0.1.1 becomes 0.1.1
11
+
12
+ namespaces = %w[KBuilder Dotnet]
13
+
14
+ indent = 0
15
+ output = ['# frozen_string_literal: true', '']
16
+
17
+ namespaces.each do |namespace|
18
+ output.push "#{' ' * indent}module #{namespace}"
19
+ indent += 1
20
+ end
21
+
22
+ output.push "#{' ' * indent}VERSION = \'#{version}'"
23
+ indent -= 1
24
+
25
+ namespaces.each do
26
+ output.push "#{' ' * indent}end"
27
+ indent -= 1
28
+ end
29
+
30
+ output.push('')
31
+
32
+ printf "%-25<label>s : %<version>s\n", label: 'GEM VERSION', version: version
33
+ File.open('lib/k_builder/dotnet/version.rb', 'w+') { |f| f.write(output.join("\n")) }
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/k_builder/dotnet/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.required_ruby_version = '>= 2.5'
7
+ spec.name = 'k_builder-dotnet'
8
+ spec.version = KBuilder::Dotnet::VERSION
9
+ spec.authors = ['David Cruwys']
10
+ spec.email = ['david@ideasmen.com.au']
11
+
12
+ spec.summary = 'K Builder Dotnet provides various fluent builders for building dotnet assets, specifically for c#'
13
+ spec.description = <<-TEXT
14
+ K Builder Dotnet provides various fluent builders for building dotnet assets, specifically for c#
15
+ TEXT
16
+ spec.homepage = 'http://appydave.com/gems/k-builder-dotnet'
17
+ spec.license = 'MIT'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
22
+
23
+ # spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
24
+
25
+ spec.metadata['homepage_uri'] = spec.homepage
26
+ spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/k_builder-dotnet'
27
+ spec.metadata['changelog_uri'] = 'https://github.com/klueless-io/k_builder-dotnet/commits/master'
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the RubyGem files that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject do |f|
33
+ f.match(%r{^(test|spec|features)/})
34
+ end
35
+ end
36
+ spec.bindir = 'exe'
37
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
+ spec.require_paths = ['lib']
39
+ # spec.extensions = ['ext/k_builder_dotnet/extconf.rb']
40
+
41
+ # spec.add_dependency 'tty-box', '~> 0.5.0'
42
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'k_builder/dotnet/version'
4
+ require 'k_builder/dotnet/code_block'
5
+ require 'k_builder/dotnet/code_snippets'
6
+ require 'k_builder/dotnet/dependency'
7
+ require 'k_builder/dotnet/namespace'
8
+
9
+ module KBuilder
10
+ module Dotnet
11
+ # raise KBuilder::Dotnet::Error, 'Sample message'
12
+ class Error < StandardError; end
13
+ end
14
+ end
15
+
16
+ puts "KBuilder::Dotnet::Version: #{KBuilder::Dotnet::VERSION}" if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ # Data structures for dotnet builder
5
+ module Dotnet
6
+ # Represents some code that you wish to inject into a template.
7
+ class CodeBlock
8
+ attr_accessor :code
9
+ attr_accessor :namespaces
10
+
11
+ def initialize(code, namespaces = [])
12
+ @code = code
13
+ @namespaces = namespaces
14
+
15
+ raise KBuilder::Dotnet::Error, 'Code cannot be nil' if code.nil?
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ module Dotnet
5
+ # Denormalized view of dot net code including use namespaces and
6
+ # nuget/project dependencies that would be needed for a single line of code.
7
+ class Snippets
8
+ attr_accessor :code_blocks
9
+ attr_accessor :use_namespaces
10
+
11
+ def initialize(code_blocks)
12
+ @code_blocks = code_blocks
13
+ @use_namespaces = code_blocks.namespaces.map(&:namespace).uniq
14
+
15
+ # dependencies = code_blocks.map(&:namespaces).flat_map(&:dependencies)
16
+
17
+ # @packages = dependencies.select { |d| d.type == :nuget }.uniq
18
+ # @references = dependencies.select { |d| d.type == :reference }.uniq
19
+ end
20
+
21
+ # attr_accessor :packages
22
+ # attr_accessor :references
23
+
24
+ # def get_dependencies; end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ # Data structures for dotnet builder
5
+ module Dotnet
6
+ # Represents any NuGet package or project reference dependencies
7
+ #
8
+ # How this information is used:
9
+ #
10
+ # Add a nuget package to the project in current folder
11
+ # - dotnet add package <PACKAGE_NAME>
12
+ #
13
+ # Add project to a solution
14
+ # - dotnet sln <SOLUTION_NAME>.sln add <PROJECT_NAME>.csproj
15
+ #
16
+ # Add project reference to a project in the current folder
17
+ # - dotnet <PROJECT_NAME>.csproj
18
+ #
19
+ class Dependency
20
+ VALID_TYPES = %i[nuget reference].freeze
21
+
22
+ # Name of dependency
23
+ attr_accessor :name
24
+
25
+ # Type of dependency
26
+ # - :nuget NuGet package
27
+ # - :reference Project reference
28
+ attr_accessor :type
29
+
30
+ def initialize(name, type)
31
+ @name = name
32
+ @type = type
33
+
34
+ raise KBuilder::Dotnet::Error, 'Name is required' if name.nil? || name.to_s == ''
35
+ raise KBuilder::Dotnet::Error, 'Unknown dependency type. Valid types: [:nuget, :reference]' unless VALID_TYPES.include?(type)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ # Data structures for dotnet builder
5
+ module Dotnet
6
+ # Represents the namespaces that code relies on
7
+ # and the dependency that this namespace may belong to
8
+ class Namespace
9
+ attr_accessor :namespace
10
+ attr_accessor :dependency
11
+
12
+ def initialize(namespace, dependency)
13
+ @namespace = namespace
14
+ @dependency = dependency
15
+
16
+ raise KBuilder::Dotnet::Error, 'Namespace is required' if namespace.nil? || namespace.to_s == ''
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,108 @@
1
+ # DotNet code, namespaces and dependencies
2
+
3
+ The following C# code is made up of code blocks, namespaces and dependencies to local projects and nuget packages.
4
+
5
+ ```csharp
6
+ namespace CustomerManagement.Api
7
+ {
8
+ using System;
9
+ using System.Collections.Generic;
10
+ using Microsoft.AspNetCore.Mvc;
11
+
12
+ public class Startup
13
+ {
14
+ public Startup(IConfiguration configuration)
15
+ {
16
+ Configuration = configuration;
17
+ }
18
+
19
+ public IConfiguration Configuration { get; }
20
+
21
+ // This method gets called by the runtime. Use this method to add services to the container.
22
+ public void ConfigureServices(IServiceCollection services)
23
+ {
24
+ services.AddHealthChecks();
25
+ }
26
+
27
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
28
+ public void Configure(
29
+ IApplicationBuilder app,
30
+ IWebHostEnvironment env)
31
+ {
32
+ app.UseHttpsRedirection();
33
+ app.UseRouting();
34
+ app.UseAuthorization();
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+ ## Dependency
41
+
42
+ Dependency represents any NuGet package or project reference dependencies
43
+
44
+ Dependency can be used in the following ways:
45
+
46
+ Add a nuget package to the project in current folder
47
+
48
+ `dotnet add package {dependency.name}`
49
+
50
+ Add project to a solution
51
+
52
+ `dotnet sln MySolution.sln add {dependency.name}.csproj`
53
+
54
+ Add project reference to a project in the current folder
55
+
56
+ `dotnet {dependency.name}.csproj`
57
+
58
+ ```ruby
59
+ # Ruby configuration for dependency
60
+ package_dependency = Dependency.new('Microsoft.EntityFrameworkCore.Design', :nuget)
61
+ project_dependency = Dependency.new('CustomerManagement.Api', :project)
62
+ ```
63
+
64
+ ## Namespace
65
+
66
+ Represents the namespaces that code relies on and the dependency that the namespace belongs to.
67
+
68
+ ```ruby
69
+ # Ruby configuration for Namespace
70
+ # May need to support version at some stage
71
+ namespace = Namespace.new('Microsoft.AspNetCore.Mvc', 'Microsoft.AspNetCore.Mvc.Core')
72
+ ```
73
+
74
+ ```bash
75
+ # NuGet package
76
+ dotnet add package Microsoft.AspNetCore.Mvc.Core -Version 2.2.5
77
+ ```
78
+
79
+ ```csharp
80
+ // Namespace
81
+ using Microsoft.AspNetCore.Mvc;
82
+ ```
83
+ ## CodeBlock
84
+
85
+ Represents a block of c# code and any namespaces required by code within the block of code
86
+
87
+ ```ruby
88
+ # Ruby configuration for CodeBlock
89
+ code = <<~CSHARP
90
+
91
+ app.UseHttpsRedirection();
92
+ app.UseRouting();
93
+ app.UseAuthorization();
94
+
95
+ CSHARP
96
+
97
+ code_block = CodeBlock(code, namespaces: ['Microsoft.AspNetCore.Mvc'])
98
+ ```
99
+
100
+ ```csharp
101
+ // Required namespace
102
+ using Microsoft.AspNetCore.Mvc;
103
+
104
+ // Block of code
105
+ app.UseHttpsRedirection();
106
+ app.UseRouting();
107
+ app.UseAuthorization();
108
+ ```
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ module Dotnet
5
+ VERSION = '0.0.7'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: k_builder-dotnet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - David Cruwys
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: " K Builder Dotnet provides various fluent builders for building dotnet
14
+ assets, specifically for c#\n"
15
+ email:
16
+ - david@ideasmen.com.au
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".github/workflows/main.yml"
22
+ - ".gitignore"
23
+ - ".rspec"
24
+ - ".rubocop.yml"
25
+ - CODE_OF_CONDUCT.md
26
+ - Gemfile
27
+ - Guardfile
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - STORIES.md
32
+ - USAGE.md
33
+ - bin/console
34
+ - bin/k
35
+ - bin/kgitsync
36
+ - bin/khotfix
37
+ - bin/setup
38
+ - docs/builder-two-projects.png
39
+ - docs/new-project1.png
40
+ - docs/new-project2.png
41
+ - docs/new-solution.png
42
+ - hooks/pre-commit
43
+ - hooks/update-version
44
+ - k_builder-dotnet.gemspec
45
+ - lib/k_builder/dotnet.rb
46
+ - lib/k_builder/dotnet/code_block.rb
47
+ - lib/k_builder/dotnet/code_snippets.rb
48
+ - lib/k_builder/dotnet/dependency.rb
49
+ - lib/k_builder/dotnet/namespace.rb
50
+ - lib/k_builder/dotnet/readme.md
51
+ - lib/k_builder/dotnet/version.rb
52
+ homepage: http://appydave.com/gems/k-builder-dotnet
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ homepage_uri: http://appydave.com/gems/k-builder-dotnet
57
+ source_code_uri: https://github.com/klueless-io/k_builder-dotnet
58
+ changelog_uri: https://github.com/klueless-io/k_builder-dotnet/commits/master
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '2.5'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.2.7
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: K Builder Dotnet provides various fluent builders for building dotnet assets,
78
+ specifically for c#
79
+ test_files: []