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
|
# File 'lib/souls/cli/create/functions.rb', line 10
def functions(function_name)
supported_languages = {
ruby: %w[2.6 2.7],
nodejs: %w[16 14 12 10],
python: %w[3.9 3.8 3.7],
go: ["1.16", "1.13"]
}
prompt = TTY::Prompt.new
runtime = prompt.select("Select Runtime?", supported_languages.keys.map(&:to_s).map(&:camelize))
runtime_downcased = runtime.downcase
version = prompt.select("Select Version?", supported_languages[runtime.downcase.to_sym].sort.reverse)
version_string = "#{runtime_downcased}#{version.gsub('.', '')}"
runtime_methods = get_runtime_create_method(runtime: runtime_downcased)
file_dir = "./apps/cf-#{version_string}-#{function_name}"
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
runtime_methods.each do |method|
file_extension =
case runtime_downcased
when "nodejs"
method == "package" ? "json" : "js"
when "python"
method == "requirements" ? "txt" : "py"
when "go"
method == "go" ? "mod" : "go"
else
"rb"
end
file_path =
if method == "gemfile"
"#{file_dir}/Gemfile"
else
"#{file_dir}/#{method}.#{file_extension}"
end
file_name = file_dir.gsub("./apps/", "")
File.write(file_path, Object.const_get("Template::#{runtime}").__send__(method, file_name))
SOULs::Painter.create_file(file_path)
end
create_env_yaml(file_dir:)
endroll = <<~TEXT
♤ Deploy Cloud Functions ♤
$ cd apps/cf-#{version_string}-#{function_name}
$ souls functions deploy
$ souls functions help
Doc: https://souls.elsoul.nl
TEXT
puts(Paint[endroll, :white])
end
|