hanami-cli 2.0.0.alpha8.1 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -2
- data/Gemfile +2 -3
- data/README.md +13 -11
- data/hanami-cli.gemspec +3 -2
- data/lib/hanami/cli/bundler.rb +3 -7
- data/lib/hanami/cli/commands/app/command.rb +68 -0
- data/lib/hanami/cli/commands/{monolith → app}/console.rb +6 -6
- data/lib/hanami/cli/commands/{monolith → app}/db/create.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/create_migration.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/drop.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/migrate.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/db/reset.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/rollback.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/db/sample_data.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/db/seed.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/db/setup.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/structure/dump.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/version.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/generate/action.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/generate/slice.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/generate.rb +1 -1
- data/lib/hanami/cli/commands/{monolith → app}/install.rb +1 -1
- data/lib/hanami/cli/commands/app/routes.rb +82 -0
- data/lib/hanami/cli/commands/app/server.rb +58 -0
- data/lib/hanami/cli/commands/{monolith → app}/version.rb +1 -1
- data/lib/hanami/cli/commands/app.rb +46 -0
- data/lib/hanami/cli/commands/db/utils/database.rb +10 -10
- data/lib/hanami/cli/commands/gem/new.rb +29 -38
- data/lib/hanami/cli/commands/gem/version.rb +21 -1
- data/lib/hanami/cli/commands/gem.rb +2 -4
- data/lib/hanami/cli/commands.rb +9 -10
- data/lib/hanami/cli/generators/{monolith → app}/action/action.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/action/template.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/action/template.html.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/action/view.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/action.rb +2 -2
- data/lib/hanami/cli/generators/{monolith → app}/action_context.rb +1 -1
- data/lib/hanami/cli/generators/{monolith → app}/slice/action.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice/entities.erb +0 -0
- data/lib/hanami/cli/generators/{gem/application/monolith → app/slice}/keep.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice/repository.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice/routes.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice/view.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice.rb +2 -2
- data/lib/hanami/cli/generators/{monolith → app}/slice_context.rb +1 -1
- data/lib/hanami/cli/generators/context.rb +2 -2
- data/lib/hanami/cli/generators/gem/{application/monolith/entities.erb → app/action.erb} +3 -3
- data/lib/hanami/cli/generators/gem/{application/monolith/application.erb → app/app.erb} +1 -1
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/config_ru.erb +0 -0
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/env.erb +0 -0
- data/lib/hanami/cli/generators/gem/app/gemfile.erb +15 -0
- data/lib/hanami/cli/generators/{monolith/slice → gem/app}/keep.erb +0 -0
- data/lib/hanami/cli/generators/gem/app/operation.erb +9 -0
- data/lib/hanami/cli/generators/gem/app/rakefile.erb +3 -0
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/readme.erb +0 -0
- data/lib/hanami/cli/generators/gem/app/relation.erb +7 -0
- data/lib/hanami/cli/generators/gem/app/repository.erb +9 -0
- data/lib/hanami/cli/generators/gem/app/routes.erb +11 -0
- data/lib/hanami/cli/generators/gem/app/settings.erb +9 -0
- data/lib/hanami/cli/generators/gem/{application/monolith/functions.erb → app/transformations.erb} +1 -1
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/types.erb +0 -0
- data/lib/hanami/cli/generators/gem/app/validator.erb +12 -0
- data/lib/hanami/cli/generators/gem/app/view.erb +9 -0
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/view_context.erb +1 -6
- data/lib/hanami/cli/generators/gem/app/view_part.erb +10 -0
- data/lib/hanami/cli/generators/gem/app.rb +64 -0
- data/lib/hanami/cli/generators/version.rb +55 -0
- data/lib/hanami/cli/rake_tasks.rb +54 -0
- data/lib/hanami/cli/repl/core.rb +7 -7
- data/lib/hanami/cli/server.rb +45 -0
- data/lib/hanami/cli/version.rb +1 -1
- data/lib/hanami/console/context.rb +12 -12
- data/lib/hanami/console/plugins/slice_readers.rb +2 -2
- metadata +85 -60
- data/lib/hanami/cli/commands/application.rb +0 -67
- data/lib/hanami/cli/commands/monolith.rb +0 -55
- data/lib/hanami/cli/generators/gem/application/monolith/action.erb +0 -21
- data/lib/hanami/cli/generators/gem/application/monolith/gemfile.erb +0 -19
- data/lib/hanami/cli/generators/gem/application/monolith/operation.erb +0 -18
- data/lib/hanami/cli/generators/gem/application/monolith/rakefile.erb +0 -3
- data/lib/hanami/cli/generators/gem/application/monolith/repository.erb +0 -13
- data/lib/hanami/cli/generators/gem/application/monolith/routes.erb +0 -4
- data/lib/hanami/cli/generators/gem/application/monolith/settings.erb +0 -6
- data/lib/hanami/cli/generators/gem/application/monolith/validation_contract.erb +0 -14
- data/lib/hanami/cli/generators/gem/application/monolith.rb +0 -83
- data/lib/hanami/cli/generators/gem/application.rb +0 -21
- data/lib/hanami/rake_tasks.rb +0 -52
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "dry/files"
|
4
|
-
|
5
|
-
require_relative "db/utils/database"
|
6
|
-
|
7
|
-
module Hanami
|
8
|
-
module CLI
|
9
|
-
module Commands
|
10
|
-
class Application < Hanami::CLI::Command
|
11
|
-
module Environment
|
12
|
-
def call(**opts)
|
13
|
-
env = opts[:env]
|
14
|
-
|
15
|
-
hanami_env = env ? env.to_s : ENV["HANAMI_ENV"] || "development"
|
16
|
-
|
17
|
-
ENV["HANAMI_ENV"] = hanami_env
|
18
|
-
|
19
|
-
super(**opts)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.inherited(klass)
|
24
|
-
super
|
25
|
-
klass.option(:env, required: false, desc: "Application's environment")
|
26
|
-
klass.prepend(Environment)
|
27
|
-
end
|
28
|
-
|
29
|
-
def application
|
30
|
-
@application ||=
|
31
|
-
begin
|
32
|
-
require "hanami/prepare"
|
33
|
-
Hanami.application
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def run_command(klass, *args)
|
38
|
-
klass.new(
|
39
|
-
out: out,
|
40
|
-
inflector: application.inflector,
|
41
|
-
fs: Dry::Files
|
42
|
-
).call(*args)
|
43
|
-
end
|
44
|
-
|
45
|
-
def measure(desc)
|
46
|
-
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
47
|
-
result = yield
|
48
|
-
stop = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
49
|
-
|
50
|
-
if result
|
51
|
-
out.puts "=> #{desc} in #{(stop - start).round(4)}s"
|
52
|
-
else
|
53
|
-
out.puts "!!! => #{desc.inspect} FAILED"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def database
|
58
|
-
@database ||= Commands::DB::Utils::Database[application]
|
59
|
-
end
|
60
|
-
|
61
|
-
def database_config
|
62
|
-
database.config
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
module CLI
|
5
|
-
module Commands
|
6
|
-
module Monolith
|
7
|
-
require_relative "monolith/version"
|
8
|
-
# require_relative "monolith/install"
|
9
|
-
# require_relative "monolith/generate"
|
10
|
-
require_relative "monolith/install"
|
11
|
-
require_relative "monolith/generate"
|
12
|
-
require_relative "monolith/console"
|
13
|
-
require_relative "monolith/db/create"
|
14
|
-
require_relative "monolith/db/create_migration"
|
15
|
-
require_relative "monolith/db/drop"
|
16
|
-
require_relative "monolith/db/migrate"
|
17
|
-
require_relative "monolith/db/setup"
|
18
|
-
require_relative "monolith/db/reset"
|
19
|
-
require_relative "monolith/db/rollback"
|
20
|
-
require_relative "monolith/db/sample_data"
|
21
|
-
require_relative "monolith/db/seed"
|
22
|
-
require_relative "monolith/db/structure/dump"
|
23
|
-
require_relative "monolith/db/version"
|
24
|
-
|
25
|
-
def self.extended(base)
|
26
|
-
base.module_eval do
|
27
|
-
register "version", Version, aliases: ["v", "-v", "--version"]
|
28
|
-
# FIXME: temporary disabled for Hanami v2.0.0.alpha2
|
29
|
-
# register "install", Install
|
30
|
-
|
31
|
-
# FIXME: temporary disabled for Hanami v2.0.0.alpha2
|
32
|
-
# register "generate", aliases: ["g"] do |prefix|
|
33
|
-
# prefix.register "slice", Generate::Slice
|
34
|
-
# prefix.register "action", Generate::Action
|
35
|
-
# end
|
36
|
-
|
37
|
-
register "console", Commands::Monolith::Console
|
38
|
-
|
39
|
-
register "db create", Commands::Monolith::DB::Create
|
40
|
-
register "db create_migration", Commands::Monolith::DB::CreateMigration
|
41
|
-
register "db drop", Commands::Monolith::DB::Drop
|
42
|
-
register "db migrate", Commands::Monolith::DB::Migrate
|
43
|
-
register "db setup", Commands::Monolith::DB::Setup
|
44
|
-
register "db reset", Commands::Monolith::DB::Reset
|
45
|
-
register "db rollback", Commands::Monolith::DB::Rollback
|
46
|
-
register "db sample_data", Commands::Monolith::DB::SampleData
|
47
|
-
register "db seed", Commands::Monolith::DB::Seed
|
48
|
-
register "db structure dump", Commands::Monolith::DB::Structure::Dump
|
49
|
-
register "db version", Commands::Monolith::DB::Version
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# auto_register: false
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "json" # required for Hanami::Action::Flash to work
|
5
|
-
require "hanami/action"
|
6
|
-
require "hanami/action/cookies"
|
7
|
-
require "hanami/action/csrf_protection"
|
8
|
-
require "hanami/action/session"
|
9
|
-
|
10
|
-
module <%= classified_app_name %>
|
11
|
-
class Action < Hanami::Action
|
12
|
-
def self.inherited(klass)
|
13
|
-
super
|
14
|
-
|
15
|
-
# These will need to be sorted by the framework eventually
|
16
|
-
klass.include Hanami::Action::Cookies
|
17
|
-
klass.include Hanami::Action::Session
|
18
|
-
klass.include Hanami::Action::CSRFProtection
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "rake"
|
6
|
-
|
7
|
-
gem "hanami-router", "<%= hanami_version %>"
|
8
|
-
gem "hanami-controller", "<%= hanami_version %>"
|
9
|
-
gem "hanami-validations", "<%= hanami_version %>"
|
10
|
-
gem "hanami-view", git: "https://github.com/hanami/view.git", branch: "master"
|
11
|
-
gem "dry-cli", "~> 0.6", require: false, git: "https://github.com/dry-rb/dry-cli.git", branch: "feature/file-utils-class"
|
12
|
-
gem "hanami-cli", git: "https://github.com/hanami/cli.git", branch: "main"
|
13
|
-
gem "hanami", require: false, git: "https://github.com/hanami/hanami.git", branch: "feature/hanami-2-cli"
|
14
|
-
|
15
|
-
gem "puma"
|
16
|
-
|
17
|
-
group :cli, :development, :test do
|
18
|
-
gem "hanami-rspec", git: "https://github.com/hanami/rspec.git", branch: "main"
|
19
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# auto_register: false
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "dry/monads"
|
5
|
-
require "dry/matcher/result_matcher"
|
6
|
-
|
7
|
-
module <%= classified_app_name %>
|
8
|
-
class Operation
|
9
|
-
include Dry::Monads[:result, :try]
|
10
|
-
|
11
|
-
class << self
|
12
|
-
def inherited(klass)
|
13
|
-
klass.include Dry::Monads[:do]
|
14
|
-
klass.include Dry::Matcher::ResultMatcher.for(:call)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# auto_register: false
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "rom-repository"
|
5
|
-
require_relative "entities"
|
6
|
-
|
7
|
-
module <%= classified_app_name %>
|
8
|
-
class Repository < ROM::Repository::Root
|
9
|
-
include Deps[container: "persistence.rom"]
|
10
|
-
|
11
|
-
struct_namespace Entities
|
12
|
-
end
|
13
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# auto_register: false
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "dry/validation"
|
5
|
-
require "dry/schema/messages/i18n"
|
6
|
-
|
7
|
-
module <%= classified_app_name %>
|
8
|
-
module Validation
|
9
|
-
class Contract < Dry::Validation::Contract
|
10
|
-
config.messages.backend = :i18n
|
11
|
-
config.messages.top_namespace = "validation"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "erb"
|
4
|
-
require "shellwords"
|
5
|
-
require "hanami/cli/generators/context"
|
6
|
-
|
7
|
-
module Hanami
|
8
|
-
module CLI
|
9
|
-
module Generators
|
10
|
-
module Gem
|
11
|
-
module Application
|
12
|
-
class Monolith
|
13
|
-
def initialize(fs:, inflector:, command_line:)
|
14
|
-
super()
|
15
|
-
@fs = fs
|
16
|
-
@inflector = inflector
|
17
|
-
@command_line = command_line
|
18
|
-
end
|
19
|
-
|
20
|
-
def call(app, slice, slice_url_prefix, context: Context.new(inflector, app), &blk)
|
21
|
-
generate_app(app, context)
|
22
|
-
blk.call
|
23
|
-
generate_slice!(slice, slice_url_prefix)
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
attr_reader :fs
|
29
|
-
|
30
|
-
attr_reader :inflector
|
31
|
-
|
32
|
-
attr_reader :command_line
|
33
|
-
|
34
|
-
def generate_app(app, context) # rubocop:disable Metrics/AbcSize
|
35
|
-
fs.write(".env", t("env.erb", context))
|
36
|
-
|
37
|
-
fs.write("README.md", t("readme.erb", context))
|
38
|
-
fs.write("Gemfile", t("gemfile.erb", context))
|
39
|
-
fs.write("Rakefile", t("rakefile.erb", context))
|
40
|
-
fs.write("config.ru", t("config_ru.erb", context))
|
41
|
-
|
42
|
-
fs.write("config/application.rb", t("application.erb", context))
|
43
|
-
fs.write("config/settings.rb", t("settings.erb", context))
|
44
|
-
fs.write("config/routes.rb", t("routes.erb", context))
|
45
|
-
|
46
|
-
fs.write("lib/tasks/.keep", t("keep.erb", context))
|
47
|
-
|
48
|
-
fs.write("lib/#{app}/entities/.keep", t("keep.erb", context))
|
49
|
-
fs.write("lib/#{app}/persistence/relations/.keep", t("keep.erb", context))
|
50
|
-
fs.write("lib/#{app}/validation/contract.rb", t("validation_contract.erb", context))
|
51
|
-
fs.write("lib/#{app}/view/context.rb", t("view_context.erb", context))
|
52
|
-
fs.write("lib/#{app}/action.rb", t("action.erb", context))
|
53
|
-
fs.write("lib/#{app}/entities.rb", t("entities.erb", context))
|
54
|
-
fs.write("lib/#{app}/functions.rb", t("functions.erb", context))
|
55
|
-
fs.write("lib/#{app}/operation.rb", t("operation.erb", context))
|
56
|
-
fs.write("lib/#{app}/repository.rb", t("repository.erb", context))
|
57
|
-
fs.write("lib/#{app}/types.rb", t("types.erb", context))
|
58
|
-
end
|
59
|
-
|
60
|
-
def generate_slice!(slice_name, slice_url_prefix)
|
61
|
-
slice_name = Shellwords.shellescape(slice_name)
|
62
|
-
slice_url_prefix = Shellwords.shellescape(slice_url_prefix)
|
63
|
-
|
64
|
-
command_line.call("hanami generate slice #{slice_name} --url-prefix=#{slice_url_prefix}").tap do |result|
|
65
|
-
raise "hanami generate slice #{slice_name} failed\n\n\n#{result.err.inspect}" unless result.successful?
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def template(path, context)
|
70
|
-
require "erb"
|
71
|
-
|
72
|
-
ERB.new(
|
73
|
-
File.read(__dir__ + "/monolith/#{path}")
|
74
|
-
).result(context.ctx)
|
75
|
-
end
|
76
|
-
|
77
|
-
alias_method :t, :template
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
module CLI
|
5
|
-
module Generators
|
6
|
-
module Gem
|
7
|
-
module Application
|
8
|
-
class << self
|
9
|
-
def call(architecture, fs, inflector, command_line)
|
10
|
-
require_relative "./application/#{architecture}"
|
11
|
-
|
12
|
-
generator_name = inflector.classify(architecture).to_sym
|
13
|
-
const_get(generator_name).new(fs: fs, inflector: inflector, command_line: command_line)
|
14
|
-
end
|
15
|
-
alias_method :[], :call
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/hanami/rake_tasks.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rake"
|
4
|
-
require "hanami/cli/bundler"
|
5
|
-
|
6
|
-
module Hanami
|
7
|
-
# Install Rake tasks in an application
|
8
|
-
#
|
9
|
-
# @since 2.0.0
|
10
|
-
class RakeTasks
|
11
|
-
include Rake::DSL
|
12
|
-
|
13
|
-
# @since 2.0.0
|
14
|
-
# @api private
|
15
|
-
@tasks = []
|
16
|
-
|
17
|
-
# @since 2.0.0
|
18
|
-
# @api private
|
19
|
-
@_mutex = Mutex.new
|
20
|
-
|
21
|
-
# @since 2.0.0
|
22
|
-
# @api private
|
23
|
-
def self.register_tasks(&blk)
|
24
|
-
@_mutex.synchronize do
|
25
|
-
@tasks << blk
|
26
|
-
@tasks.uniq!
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# @since 2.0.0
|
31
|
-
# @api private
|
32
|
-
def self.tasks
|
33
|
-
@_mutex.synchronize do
|
34
|
-
@tasks
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# @since 0.6.0
|
39
|
-
# @api private
|
40
|
-
def self.install_tasks
|
41
|
-
new.call(tasks)
|
42
|
-
end
|
43
|
-
|
44
|
-
# @since 2.0.0
|
45
|
-
# @api private
|
46
|
-
def call(tasks)
|
47
|
-
tasks.each(&:call)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
Hanami::CLI::Bundler.require(:cli)
|