/
init.rb
101 lines (87 loc) · 2.45 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
93
94
95
96
97
98
99
100
101
# typed: strict
# frozen_string_literal: true
module Tapioca
module Commands
class Init < Command
sig do
params(
sorbet_config: String,
tapioca_config: String,
default_postrequire: String
).void
end
def initialize(
sorbet_config:,
tapioca_config:,
default_postrequire:
)
@sorbet_config = sorbet_config
@tapioca_config = tapioca_config
@default_postrequire = default_postrequire
super()
@installer = T.let(nil, T.nilable(Bundler::Installer))
@spec = T.let(nil, T.nilable(Bundler::StubSpecification))
end
sig { override.void }
def execute
create_sorbet_config
create_tapioca_config
create_post_require
create_binstub
end
private
sig { void }
def create_sorbet_config
create_file(@sorbet_config, <<~CONTENT, skip: true, force: false)
--dir
.
--ignore=vendor/
CONTENT
end
sig { void }
def create_tapioca_config
create_file(@tapioca_config, <<~YAML, skip: true, force: false)
gem:
# Add your `gem` command parameters here:
#
# exclude:
# - gem_name
# doc: true
# workers: 5
dsl:
# Add your `dsl` command parameters here:
#
# exclude:
# - SomeGeneratorName
# workers: 5
YAML
end
sig { void }
def create_post_require
create_file(@default_postrequire, <<~CONTENT, skip: true, force: false)
# typed: true
# frozen_string_literal: true
# Add your extra requires here (`#{default_command(:require)}` can be used to boostrap this list)
CONTENT
end
sig { void }
def create_binstub
force = File.exist?(Tapioca::BINARY_FILE)
installer.generate_bundler_executable_stubs(spec, { force: force })
say_status(
force ? :force : :create,
Tapioca::BINARY_FILE,
force ? :yellow : :green
)
end
sig { returns(Bundler::Installer) }
def installer
@installer ||= Bundler::Installer.new(Bundler.root, Bundler.definition)
end
sig { returns(Bundler::StubSpecification) }
def spec
@spec ||= Bundler.definition.specs.find { |s| s.name == "tapioca" }
end
end
end
end