sumcli 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sumcli/cli.rb +2 -3
- data/lib/sumcli/commands/add.rb +15 -3
- data/lib/sumcli/commands/{g → add}/endpoint.rb +24 -4
- data/lib/sumcli/commands/add/service.rb +73 -6
- data/lib/sumcli/commands/add/service/postgres.rb +48 -0
- data/lib/sumcli/commands/new.rb +2 -1
- data/lib/sumcli/templates/{g → add}/endpoint/.gitkeep +0 -0
- data/lib/sumcli/templates/{g → add}/endpoint/entity.rb.erb +0 -0
- data/lib/sumcli/templates/add/endpoint/model.rb.erb +4 -0
- data/lib/sumcli/templates/{g → add}/endpoint/new.rb.erb +0 -0
- data/lib/sumcli/templates/{g → add}/endpoint/test.rb.erb +0 -0
- data/lib/sumcli/templates/add/service/database.rb +2 -0
- data/lib/sumcli/templates/add/service/database.rb.erb +2 -0
- data/lib/sumcli/templates/add/service/database.yml +20 -0
- data/lib/sumcli/templates/add/service/database.yml.ctmpl +11 -0
- data/lib/sumcli/templates/add/service/database.yml.erb +19 -0
- data/lib/sumcli/templates/new/app/Gemfile +3 -0
- data/lib/sumcli/templates/new/app/Rakefile +2 -8
- data/lib/sumcli/templates/new/app/api/endpoints/base.rb +2 -0
- data/lib/sumcli/version.rb +1 -1
- data/sumcli.gemspec +2 -2
- metadata +18 -8
- data/lib/sumcli/commands/g.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fb17357faf9b0a79218491f726464b6ed260d22f959873cefaed9a99e981174
|
4
|
+
data.tar.gz: 70c9974d8181fe817cf2a5dfc139d8454b66678e10870a75de6478bf986f4a8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21e9b27cf7ade308bd38a1939695dfb3dd026d7b5c50ca20ff3333ce1b531adbf5f9252544996d4b97c05e1918ab8bfae6c79c896e3700b1e55fba22b48f9c55
|
7
|
+
data.tar.gz: 7f2ff870eb6d5248879ff34636eae35bf48ca797669c89eb7ec2f96f529abc191215a6832bd61e4d9e50a5ab1640a3ed2fb823a1ce8415fa82a5062a5f411701
|
data/Gemfile.lock
CHANGED
data/lib/sumcli/cli.rb
CHANGED
@@ -18,11 +18,10 @@ module Sumcli
|
|
18
18
|
end
|
19
19
|
map %w(--version -v) => :version
|
20
20
|
|
21
|
-
require_relative 'commands/g'
|
22
21
|
require_relative 'commands/new'
|
23
22
|
require_relative 'commands/add'
|
24
|
-
register Sumcli::Commands::
|
25
|
-
|
23
|
+
register Sumcli::Commands::Add, 'add', 'add [SUBCOMMAND]', 'Adds services to your project'
|
24
|
+
|
26
25
|
desc 'new NAME', 'Creates a new application'
|
27
26
|
method_option :help, aliases: '-h', type: :boolean,
|
28
27
|
desc: 'Display usage information'
|
data/lib/sumcli/commands/add.rb
CHANGED
@@ -8,15 +8,27 @@ module Sumcli
|
|
8
8
|
|
9
9
|
namespace :add
|
10
10
|
|
11
|
-
desc 'service NAME', '
|
11
|
+
desc 'service NAME', 'Installs infrastructure components and their initializers'
|
12
12
|
method_option :help, aliases: '-h', type: :boolean,
|
13
13
|
desc: 'Display usage information'
|
14
|
-
def service(name)
|
14
|
+
def service(name, version = nil)
|
15
15
|
if options[:help]
|
16
16
|
invoke :help, ['service']
|
17
17
|
else
|
18
18
|
require_relative 'add/service'
|
19
|
-
Sumcli::Commands::Add::Service.new(name, options).execute
|
19
|
+
Sumcli::Commands::Add::Service.new(name, version, options).execute
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'endpoint NAME [METHOD] [ROUTE]', 'Generate a new endpoint using METHOD verb and matching url ROUTE'
|
24
|
+
method_option :help, aliases: '-h', type: :boolean,
|
25
|
+
desc: 'Display usage information'
|
26
|
+
def endpoint(name, method = nil, route = nil)
|
27
|
+
if options[:help]
|
28
|
+
invoke :help, ['endpoint']
|
29
|
+
else
|
30
|
+
require_relative 'add/endpoint'
|
31
|
+
Sumcli::Commands::Add::Endpoint.new(name, method, route, options).execute
|
20
32
|
end
|
21
33
|
end
|
22
34
|
end
|
@@ -5,12 +5,15 @@ require_relative '../../command'
|
|
5
5
|
|
6
6
|
module Sumcli
|
7
7
|
module Commands
|
8
|
-
class
|
8
|
+
class Add
|
9
9
|
class Endpoint < Sumcli::Command
|
10
10
|
ENDPOINT_PATH = 'api/endpoints'
|
11
|
+
MODELS_PATH = 'app/models'
|
11
12
|
ENTITIES_PATH = 'api/entities'
|
12
13
|
TESTS_PATH = 'spec/api'
|
13
14
|
|
15
|
+
TEMPLATES_PATH = File.expand_path('../../templates/add/endpoint', __dir__)
|
16
|
+
|
14
17
|
def initialize(name, method, route, options)
|
15
18
|
@name = name
|
16
19
|
@method = method
|
@@ -26,6 +29,13 @@ module Sumcli
|
|
26
29
|
inject_route unless @method.nil?
|
27
30
|
end
|
28
31
|
|
32
|
+
def inject_mount
|
33
|
+
generator.inject_into_file("#{ENDPOINT_PATH}/base.rb", after: "# APIs\n") do <<-RB
|
34
|
+
mount API::#{@name.capitalize}
|
35
|
+
RB
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
29
39
|
def inject_route
|
30
40
|
generator.inject_into_file("#{ENDPOINT_PATH}/#{@name.underscore}.rb", after: "# ENDPOINTS\n") do <<-RB
|
31
41
|
|
@@ -42,7 +52,7 @@ module Sumcli
|
|
42
52
|
|
43
53
|
def create_test
|
44
54
|
generator.copy_file(
|
45
|
-
|
55
|
+
"#{TEMPLATES_PATH}/test.rb.erb",
|
46
56
|
"#{TESTS_PATH}/#{@name.underscore}_spec.rb",
|
47
57
|
context: @variables
|
48
58
|
)
|
@@ -50,7 +60,7 @@ module Sumcli
|
|
50
60
|
|
51
61
|
def create_entity
|
52
62
|
generator.copy_file(
|
53
|
-
|
63
|
+
"#{TEMPLATES_PATH}/entity.rb.erb",
|
54
64
|
"#{ENTITIES_PATH}/#{@name.underscore}.rb",
|
55
65
|
context: @variables
|
56
66
|
)
|
@@ -58,10 +68,20 @@ module Sumcli
|
|
58
68
|
|
59
69
|
def create_endpoint
|
60
70
|
generator.copy_file(
|
61
|
-
|
71
|
+
"#{TEMPLATES_PATH}/new.rb.erb",
|
62
72
|
"#{ENDPOINT_PATH}/#{@name.underscore}.rb",
|
63
73
|
context: @variables
|
64
74
|
)
|
75
|
+
|
76
|
+
inject_mount
|
77
|
+
end
|
78
|
+
|
79
|
+
def create_model
|
80
|
+
generator.copy_file(
|
81
|
+
"#{TEMPLATES_PATH}/model.rb.erb",
|
82
|
+
"#{MODELS_PATH}/#{@name.underscore}.rb",
|
83
|
+
context: @variables
|
84
|
+
)
|
65
85
|
end
|
66
86
|
end
|
67
87
|
end
|
@@ -8,21 +8,88 @@ module Sumcli
|
|
8
8
|
class Service < Sumcli::Command
|
9
9
|
|
10
10
|
DOCKER_FILE = 'docker-compose.yml'
|
11
|
+
TEMPLATES_PATH = File.expand_path('../../templates/add/service', __dir__)
|
12
|
+
CONFIGS_PATH = 'config'
|
11
13
|
|
12
|
-
def initialize(name, options)
|
14
|
+
def initialize(name, version, options)
|
13
15
|
@name = name
|
16
|
+
@version = version
|
14
17
|
@options = options
|
15
18
|
end
|
16
19
|
|
17
20
|
def execute(input: $stdin, output: $stdout)
|
18
|
-
|
21
|
+
if !service_exists?
|
22
|
+
self.send("add_#{@name}")
|
23
|
+
output.puts "\n #{@name} added to docker-compose"
|
24
|
+
else
|
25
|
+
output.puts "\n #{@name} already added to docker-compose"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def copy_database_files
|
30
|
+
generator.inject_into_file('Gemfile', after: "# GEMS\n\n") do <<~RUBY
|
31
|
+
gem 'pg', '~> 1.1'
|
32
|
+
gem "otr-activerecord", '~> 1.3.0'
|
33
|
+
RUBY
|
34
|
+
end
|
35
|
+
generator.copy_file("#{TEMPLATES_PATH}/database.yml", "#{CONFIGS_PATH}/database.yml")
|
36
|
+
generator.copy_file("#{TEMPLATES_PATH}/database.yml.ctmpl", "#{CONFIGS_PATH}/database.yml.ctmpl")
|
37
|
+
generator.copy_file("#{TEMPLATES_PATH}/database.rb", "#{CONFIGS_PATH}/initializers/database.rb")
|
38
|
+
generator.inject_into_file("#{CONFIGS_PATH}/application.rb", after: "require_rel '../api'\n") do
|
39
|
+
'require_rel \'initializers\''
|
40
|
+
end
|
41
|
+
generator.inject_into_file('Rakefile', after: "# TASKS\n") do <<~RUBY.strip
|
42
|
+
load "tasks/otr-activerecord.rake"
|
43
|
+
|
44
|
+
namespace :db do
|
45
|
+
task :environment do
|
46
|
+
require_relative 'config/environment'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def require_exists?
|
54
|
+
File.readlines(APPLICATION_FILE).grep(/#{INITIALIZERS_REQUIRE}/).any?
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_postgres
|
58
|
+
ver = '10'
|
59
|
+
response = ask_to_set(ver) if ver != @version && !@version.nil?
|
60
|
+
ver = @version if response
|
61
|
+
|
62
|
+
content =
|
63
|
+
<<-TEXT
|
64
|
+
db:
|
65
|
+
image: 'postgres:#{ver}'
|
66
|
+
ports:
|
67
|
+
- '5432'
|
68
|
+
TEXT
|
69
|
+
|
70
|
+
generator.safe_inject_into_file DOCKER_FILE, content, after: "services:\n"
|
71
|
+
copy_database_files
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_redis
|
75
|
+
content =
|
76
|
+
<<-TEXT
|
77
|
+
redis:
|
78
|
+
image: 'redis:#{@version}'
|
79
|
+
ports:
|
80
|
+
- '6379'
|
81
|
+
TEXT
|
82
|
+
|
83
|
+
generator.safe_inject_into_file DOCKER_FILE, content, after: "services:\n"
|
84
|
+
end
|
19
85
|
|
20
|
-
|
86
|
+
def service_exists?
|
87
|
+
File.readlines(DOCKER_FILE).grep(/#{@name}/).any?
|
21
88
|
end
|
22
89
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
90
|
+
def ask_to_set(ver)
|
91
|
+
prompt.yes?("The default version of #{@name} is #{ver}." +
|
92
|
+
"\n\nDo you want to add version #{@version}?")
|
26
93
|
end
|
27
94
|
end
|
28
95
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../command'
|
4
|
+
|
5
|
+
module Sumcli
|
6
|
+
module Commands
|
7
|
+
class Add
|
8
|
+
class Service
|
9
|
+
class Postgres < Sumcli::Command
|
10
|
+
|
11
|
+
DOCKER_FILE = 'docker-compose.yml'
|
12
|
+
|
13
|
+
def initialize(name, version, options)
|
14
|
+
@name = name
|
15
|
+
@version = version
|
16
|
+
@options = options
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute(input: $stdin, output: $stdout)
|
20
|
+
generator.copy_file 'lib/sumcli/templates/add/service/database.yml.erb',
|
21
|
+
'config/database.yml'
|
22
|
+
generator.copy_file 'lib/sumcli/templates/add/service/database.yml.ctmpl.erb',
|
23
|
+
'config/database.yml.ctmpl'
|
24
|
+
|
25
|
+
output.puts "\n #{@name} added to docker-compose" if self.send("add_#{@name}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_postgres
|
29
|
+
content =
|
30
|
+
<<-TEXT
|
31
|
+
db:
|
32
|
+
image: 'postgres:#{@version}'
|
33
|
+
ports:
|
34
|
+
- '5432'
|
35
|
+
TEXT
|
36
|
+
|
37
|
+
generator.safe_inject_into_file DOCKER_FILE, content, after: "services:\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
def ask_to_set(ver)
|
41
|
+
prompt.yes?("The default version of #{@name} is #{ver}." +
|
42
|
+
"\n\nDo you want to add with version #{@version}?")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/sumcli/commands/new.rb
CHANGED
@@ -15,7 +15,8 @@ module Sumcli
|
|
15
15
|
|
16
16
|
unless @name.nil? or File.directory?(@name)
|
17
17
|
directory = File.expand_path('../../templates/new/app', __FILE__)
|
18
|
-
|
18
|
+
generator.copy_directory(directory, @name)
|
19
|
+
return File.chmod(0744, "#{@name}/bin/console")
|
19
20
|
end
|
20
21
|
|
21
22
|
output.puts "Directory #{@name} already exists."
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
development:
|
2
|
+
adapter: postgresql
|
3
|
+
encoding: utf8
|
4
|
+
pool: 5
|
5
|
+
host: localhost
|
6
|
+
port: 5432
|
7
|
+
username: postgres
|
8
|
+
password: ''
|
9
|
+
database: app
|
10
|
+
|
11
|
+
test:
|
12
|
+
adapter: postgresql
|
13
|
+
encoding: utf8
|
14
|
+
pool: 5
|
15
|
+
host: localhost
|
16
|
+
port: 5432
|
17
|
+
username: postgres
|
18
|
+
password: ''
|
19
|
+
database: app
|
20
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
production:
|
2
|
+
encoding: unicode
|
3
|
+
adapter: postgresql
|
4
|
+
database: {{ with secret "secret/partners/database/name" }}{{ .Data.value }}{{ end }}
|
5
|
+
username: {{ with secret "secret/partners/database/username" }}{{ .Data.value }}{{ end }}
|
6
|
+
password: {{ with secret "secret/partners/database/password" }}{{ .Data.value }}{{ end }}
|
7
|
+
schema_search_path: {{ with secret "secret/partners/database/schema" }}{{ .Data.value }}{{ end }}
|
8
|
+
port: {{ keyOrDefault "service/partners/database/port" "5432" }}
|
9
|
+
host: {{ key "service/partners/database/host" }}
|
10
|
+
pool: {{ keyOrDefault "service/global/database/pool" "5" }}
|
11
|
+
timeout: {{ keyOrDefault "service/global/database/timeout" "5000" }}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
development:
|
2
|
+
adapter: postgresql
|
3
|
+
encoding: utf8
|
4
|
+
pool: 5
|
5
|
+
host: localhost
|
6
|
+
port: 5432
|
7
|
+
username: postgres
|
8
|
+
password: ''
|
9
|
+
database: sidekiq
|
10
|
+
|
11
|
+
test:
|
12
|
+
adapter: postgresql
|
13
|
+
encoding: utf8
|
14
|
+
pool: 5
|
15
|
+
host: localhost
|
16
|
+
port: 5432
|
17
|
+
username: postgres
|
18
|
+
password: ''
|
19
|
+
database: sidekiq
|
@@ -24,14 +24,8 @@
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
#
|
28
|
-
|
29
|
-
namespace :db do
|
30
|
-
task :environment do
|
31
|
-
require_relative 'config/environment'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
27
|
+
# AUTO-GENERATED (DO NOT ERASE)
|
28
|
+
# TASKS
|
35
29
|
|
36
30
|
#Load tasks
|
37
31
|
Dir.glob('lib/tasks/*.rake').each { |task| load task }
|
data/lib/sumcli/version.rb
CHANGED
data/sumcli.gemspec
CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "sumcli"
|
8
8
|
spec.license = "MIT"
|
9
9
|
spec.version = Sumcli::VERSION
|
10
|
-
spec.authors = ["Rodrigo Alves"]
|
11
|
-
spec.email = ["rodrigo.souza@sumup.com"]
|
10
|
+
spec.authors = ["Rodrigo Alves", "Danilo Lima", "Lucas Mari"]
|
11
|
+
spec.email = ["rodrigo.souza@sumup.com", "danilo.lima@sumup.com", "lucas.mari@sumup.com"]
|
12
12
|
|
13
13
|
spec.summary = %q{Scaffolds SumUp microservices code.}
|
14
14
|
spec.description = %q{Scaffolds SumUp microservices code.}
|
metadata
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sumcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Alves
|
8
|
+
- Danilo Lima
|
9
|
+
- Lucas Mari
|
8
10
|
autorequire:
|
9
11
|
bindir: exe
|
10
12
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
13
|
+
date: 2019-06-05 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: tty-box
|
@@ -363,6 +365,8 @@ dependencies:
|
|
363
365
|
description: Scaffolds SumUp microservices code.
|
364
366
|
email:
|
365
367
|
- rodrigo.souza@sumup.com
|
368
|
+
- danilo.lima@sumup.com
|
369
|
+
- lucas.mari@sumup.com
|
366
370
|
executables:
|
367
371
|
- sumcli
|
368
372
|
extensions: []
|
@@ -386,16 +390,22 @@ files:
|
|
386
390
|
- lib/sumcli/command.rb
|
387
391
|
- lib/sumcli/commands/.gitkeep
|
388
392
|
- lib/sumcli/commands/add.rb
|
393
|
+
- lib/sumcli/commands/add/endpoint.rb
|
389
394
|
- lib/sumcli/commands/add/service.rb
|
390
|
-
- lib/sumcli/commands/
|
391
|
-
- lib/sumcli/commands/g/endpoint.rb
|
395
|
+
- lib/sumcli/commands/add/service/postgres.rb
|
392
396
|
- lib/sumcli/commands/new.rb
|
393
397
|
- lib/sumcli/templates/.gitkeep
|
398
|
+
- lib/sumcli/templates/add/endpoint/.gitkeep
|
399
|
+
- lib/sumcli/templates/add/endpoint/entity.rb.erb
|
400
|
+
- lib/sumcli/templates/add/endpoint/model.rb.erb
|
401
|
+
- lib/sumcli/templates/add/endpoint/new.rb.erb
|
402
|
+
- lib/sumcli/templates/add/endpoint/test.rb.erb
|
394
403
|
- lib/sumcli/templates/add/service/.gitkeep
|
395
|
-
- lib/sumcli/templates/
|
396
|
-
- lib/sumcli/templates/
|
397
|
-
- lib/sumcli/templates/
|
398
|
-
- lib/sumcli/templates/
|
404
|
+
- lib/sumcli/templates/add/service/database.rb
|
405
|
+
- lib/sumcli/templates/add/service/database.rb.erb
|
406
|
+
- lib/sumcli/templates/add/service/database.yml
|
407
|
+
- lib/sumcli/templates/add/service/database.yml.ctmpl
|
408
|
+
- lib/sumcli/templates/add/service/database.yml.erb
|
399
409
|
- lib/sumcli/templates/new/.gitkeep
|
400
410
|
- lib/sumcli/templates/new/app/.editorconfig
|
401
411
|
- lib/sumcli/templates/new/app/.gitignore
|
data/lib/sumcli/commands/g.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'thor'
|
4
|
-
|
5
|
-
module Sumcli
|
6
|
-
module Commands
|
7
|
-
class G < Thor
|
8
|
-
|
9
|
-
namespace :g
|
10
|
-
|
11
|
-
desc 'endpoint NAME METHOD ROUTE', 'Generate a new endpoint using METHOD verb and matching url ROUTE'
|
12
|
-
method_option :help, aliases: '-h', type: :boolean,
|
13
|
-
desc: 'Display usage information'
|
14
|
-
def endpoint(name, method = nil, route = nil)
|
15
|
-
if options[:help]
|
16
|
-
invoke :help, ['endpoint']
|
17
|
-
else
|
18
|
-
require_relative 'g/endpoint'
|
19
|
-
Sumcli::Commands::G::Endpoint.new(name, method, route, options).execute
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|