souls 0.46.0 → 0.48.0
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.
- checksums.yaml +4 -4
- data/lib/souls/api/generate/index.rb +10 -0
- data/lib/souls/cli/console/index.rb +4 -0
- data/lib/souls/cli/db/index.rb +4 -0
- data/lib/souls/cli/gcloud/pubsub/subscriptions.rb +4 -0
- data/lib/souls/cli/gcloud/pubsub/topics.rb +4 -0
- data/lib/souls/cli/gcloud/run/index.rb +1 -1
- data/lib/souls/cli/gcloud/sql/index.rb +34 -1
- data/lib/souls/cli/index.rb +11 -22
- data/lib/souls/cli/init/index.rb +155 -0
- data/lib/souls/cli/release/release.rb +91 -3
- data/lib/souls/cli/server/index.rb +4 -0
- data/lib/souls/index.rb +0 -1
- data/lib/souls/utils/index.rb +114 -0
- data/lib/souls/version.rb +1 -1
- data/lib/souls/versions/.souls_api_version +1 -1
- data/lib/souls/versions/.souls_worker_version +1 -1
- data/lib/souls.rb +2 -212
- metadata +6 -3
- data/lib/souls/init.rb +0 -153
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 581824196708bbb86562b72b1afb79b7149d3b3d98068906383d67f6469873ec
|
|
4
|
+
data.tar.gz: 82194e0ae014bd374ca0f4ed2903351dd11dc132556f2a4b75a650891573f8e0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6aacc5383ccc63578b2687bf2fda4f3db8ff7a6a3982de9014da924fc4aa338dd37535f1e02ba03fb65f0311aeb1ea494554b37d268ae0b00527e8f2bbac146
|
|
7
|
+
data.tar.gz: 41825b30bb8bde62cb1fe0d5fa3ba558e8c571bc80843af4d7cd1542e94620b97ddd0c44773892bda682575b1087c961e7bb789cfa10ecef2655794b20c8e2a9
|
|
@@ -15,3 +15,13 @@ require_relative "./connection"
|
|
|
15
15
|
require_relative "./application"
|
|
16
16
|
require_relative "./migration"
|
|
17
17
|
require_relative "./manager"
|
|
18
|
+
|
|
19
|
+
# require_paths = []
|
|
20
|
+
# Dir["lib/souls/api/generate/*"].map do |n|
|
|
21
|
+
# next if n.include?("index.rb")
|
|
22
|
+
|
|
23
|
+
# require_paths << n.split("/").last.gsub(".rb", "")
|
|
24
|
+
# end
|
|
25
|
+
# require_paths.each do |path|
|
|
26
|
+
# require_relative "./#{path}"
|
|
27
|
+
# end
|
|
@@ -12,7 +12,7 @@ module Souls
|
|
|
12
12
|
|
|
13
13
|
def list(project_id: "")
|
|
14
14
|
project_id = Souls.configuration.project_id if project_id.blank?
|
|
15
|
-
system("gcloud run services list --project #{project_id}")
|
|
15
|
+
system("gcloud run services list --project #{project_id} --platform managed")
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def get_endpoint(worker_name: "")
|
|
@@ -11,13 +11,46 @@ module Souls
|
|
|
11
11
|
)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def
|
|
14
|
+
def list
|
|
15
|
+
system("gcloud sql instances list")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def setup_private_ip(instance_name: "")
|
|
15
19
|
app_name = Souls.configuration.app
|
|
16
20
|
instance_name = "#{Souls.configuration.app}-db" if instance_name.blank?
|
|
17
21
|
project_id = Souls.configuration.project_id
|
|
22
|
+
create_ip_range
|
|
23
|
+
create_vpc_connector
|
|
18
24
|
system("gcloud beta sql instances patch #{instance_name} --project=#{project_id} --network=#{app_name}")
|
|
19
25
|
end
|
|
20
26
|
|
|
27
|
+
def create_ip_range
|
|
28
|
+
app_name = Souls.configuration.app
|
|
29
|
+
system(
|
|
30
|
+
"
|
|
31
|
+
gcloud compute addresses create #{app_name}-ip-range \
|
|
32
|
+
--global \
|
|
33
|
+
--purpose=VPC_PEERING \
|
|
34
|
+
--prefix-length=16 \
|
|
35
|
+
--description='peering range for SOULs' \
|
|
36
|
+
--network=#{app_name} \
|
|
37
|
+
--project=#{app_name}"
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def create_vpc_connector
|
|
42
|
+
app_name = Souls.configuration.app
|
|
43
|
+
system(
|
|
44
|
+
"
|
|
45
|
+
gcloud services vpc-peerings connect \
|
|
46
|
+
--service=servicenetworking.googleapis.com \
|
|
47
|
+
--ranges=#{app_name}-ip-range \
|
|
48
|
+
--network=#{app_name} \
|
|
49
|
+
--project=#{app_name}
|
|
50
|
+
"
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
|
|
21
54
|
def assign_ip(instance_name: "", ip: "")
|
|
22
55
|
ip = `curl inet-ip.info` if ip.blank?
|
|
23
56
|
project_id = Souls.configuration.project_id
|
data/lib/souls/cli/index.rb
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
require_relative "./docker/index"
|
|
3
|
-
require_relative "./gcloud/index"
|
|
4
|
-
require_relative "./release/index"
|
|
5
|
-
require_relative "./sync/index"
|
|
6
|
-
require_relative "./upgrade/index"
|
|
1
|
+
require "active_support/core_ext/string/inflections"
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
module Docker
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
module Gcloud
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
module Release
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
module Sync
|
|
22
|
-
end
|
|
3
|
+
require_paths = []
|
|
4
|
+
modules =
|
|
5
|
+
Dir["lib/souls/cli/*"].map do |n|
|
|
6
|
+
next if n.include?("index.rb")
|
|
23
7
|
|
|
24
|
-
|
|
8
|
+
require_paths << n.split("/").last
|
|
9
|
+
n.split("/").last.camelize
|
|
25
10
|
end
|
|
11
|
+
modules.compact!
|
|
12
|
+
require_paths.each_with_index do |path, i|
|
|
13
|
+
require_relative "./#{path}/index"
|
|
14
|
+
Object.const_get("Souls::#{modules[i]}")
|
|
26
15
|
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
module Souls
|
|
2
|
+
module Init
|
|
3
|
+
class << self
|
|
4
|
+
def get_version(repository_name: "souls_api")
|
|
5
|
+
data = JSON.parse(
|
|
6
|
+
`curl \
|
|
7
|
+
-H "Accept: application/vnd.github.v3+json" \
|
|
8
|
+
-s https://api.github.com/repos/elsoul/#{repository_name}/releases`
|
|
9
|
+
)
|
|
10
|
+
data[0]["tag_name"]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def generate_cd
|
|
14
|
+
shell = `echo $SHELL`.strip
|
|
15
|
+
rc =
|
|
16
|
+
if shell.include?("zsh")
|
|
17
|
+
"zshrc"
|
|
18
|
+
else
|
|
19
|
+
"bash"
|
|
20
|
+
end
|
|
21
|
+
system("echo '\nalias api=\'cd apps/api\'' >> ~/.#{rc}")
|
|
22
|
+
system("echo 'alias mother=\'...\'' >> ~/.#{rc}")
|
|
23
|
+
system("echo 'alias worker=\'cd apps/worker\'' >> ~/.#{rc}")
|
|
24
|
+
puts(Paint["run `source ~/.#{rc}` to reflect your .#{rc}", :yellow])
|
|
25
|
+
puts(Paint["You can move to mother/api/worker just type", :green])
|
|
26
|
+
puts(Paint["\nmother\n", :white])
|
|
27
|
+
puts(
|
|
28
|
+
Paint["to go back to mother dir from api/worker\n\nYou can also go to api/worker from mother dir by typing",
|
|
29
|
+
:green]
|
|
30
|
+
)
|
|
31
|
+
puts(Paint["\napi\n", :white])
|
|
32
|
+
puts(Paint["or\n", :green])
|
|
33
|
+
puts(Paint["worker", :white])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def initial_config_init(app_name: "souls", service_name: "api")
|
|
37
|
+
config_dir = "./#{app_name}/apps/#{service_name}/config"
|
|
38
|
+
FileUtils.mkdir_p(config_dir) unless Dir.exist?(config_dir)
|
|
39
|
+
FileUtils.touch("#{config_dir}/souls.rb")
|
|
40
|
+
file_path = "#{config_dir}/souls.rb"
|
|
41
|
+
File.open(file_path, "w") do |f|
|
|
42
|
+
f.write(<<~TEXT)
|
|
43
|
+
Souls.configure do |config|
|
|
44
|
+
config.app = "#{app_name}"
|
|
45
|
+
config.project_id = "#{app_name}-project"
|
|
46
|
+
config.endpoint = "/endpoint"
|
|
47
|
+
config.strain = "api"
|
|
48
|
+
config.fixed_gems = ["excluded_gem"]
|
|
49
|
+
config.workers = []
|
|
50
|
+
end
|
|
51
|
+
TEXT
|
|
52
|
+
end
|
|
53
|
+
rescue StandardError => e
|
|
54
|
+
puts(e)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def download_github_actions(app_name: "souls-app")
|
|
58
|
+
file_name = "github.tgz"
|
|
59
|
+
url = "https://storage.googleapis.com/souls-bucket/github_actions/github.tgz"
|
|
60
|
+
system("curl -OL #{url}")
|
|
61
|
+
FileUtils.mkdir_p("#{app_name}/github")
|
|
62
|
+
system("tar -zxvf ./#{file_name} -C #{app_name}/")
|
|
63
|
+
FileUtils.rm(file_name)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def mother_config_init(app_name: "souls-app")
|
|
67
|
+
config_dir = "./#{app_name}/config"
|
|
68
|
+
FileUtils.mkdir_p(config_dir) unless Dir.exist?(config_dir)
|
|
69
|
+
FileUtils.touch("#{config_dir}/souls.rb")
|
|
70
|
+
file_path = "#{config_dir}/souls.rb"
|
|
71
|
+
File.open(file_path, "w") do |f|
|
|
72
|
+
f.write(<<~TEXT)
|
|
73
|
+
Souls.configure do |config|
|
|
74
|
+
config.app = "#{app_name}"
|
|
75
|
+
config.project_id = "#{app_name}-project"
|
|
76
|
+
config.endpoint = "/endpoint"
|
|
77
|
+
config.strain = "mother"
|
|
78
|
+
config.fixed_gems = ["excluded_gem"]
|
|
79
|
+
config.workers = []
|
|
80
|
+
end
|
|
81
|
+
TEXT
|
|
82
|
+
end
|
|
83
|
+
rescue StandardError => e
|
|
84
|
+
puts(e)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def start(args)
|
|
88
|
+
app_name = args[1]
|
|
89
|
+
if app_name.nil?
|
|
90
|
+
puts(Paint["you need to specify your app name", :red])
|
|
91
|
+
puts(Paint["`souls new souls-app`", :yellow])
|
|
92
|
+
exit
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
service_name = "api"
|
|
96
|
+
Souls::Init.download_souls(app_name: app_name, service_name: service_name)
|
|
97
|
+
Souls::Init.mother_config_init(app_name: app_name)
|
|
98
|
+
Souls::Init.download_github_actions(app_name: app_name)
|
|
99
|
+
Souls::Init.initial_config_init(app_name: app_name, service_name: service_name)
|
|
100
|
+
Souls::Init.souls_api_credit(app_name: app_name, service_name: service_name)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def download_souls(app_name: "souls", service_name: "api")
|
|
104
|
+
version = Souls.get_latest_version_txt(service_name: service_name).join(".")
|
|
105
|
+
file_name = "#{service_name}-v#{version}.tgz"
|
|
106
|
+
url = "https://storage.googleapis.com/souls-bucket/boilerplates/#{service_name.pluralize}/#{file_name}"
|
|
107
|
+
system("curl -OL #{url}")
|
|
108
|
+
system("mkdir -p #{app_name}/apps/#{service_name}")
|
|
109
|
+
system("tar -zxvf ./#{file_name} -C #{app_name}/apps/")
|
|
110
|
+
system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/.rubocop.yml")
|
|
111
|
+
system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/Gemfile")
|
|
112
|
+
system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/Procfile.dev")
|
|
113
|
+
system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/Procfile")
|
|
114
|
+
FileUtils.rm(file_name)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def souls_api_credit(app_name: "souls", service_name: "api")
|
|
118
|
+
line = Paint["====================================", :yellow]
|
|
119
|
+
puts("\n")
|
|
120
|
+
puts(line)
|
|
121
|
+
txt2 = <<~TEXT
|
|
122
|
+
_____ ____ __ ____#{' '}
|
|
123
|
+
/ ___// __ \\/ / / / / %{red1}
|
|
124
|
+
\\__ \\/ / / / / / / / %{red2}
|
|
125
|
+
___/ / /_/ / /_/ / /___%{red3}#{' '}
|
|
126
|
+
/____/\\____/\\____/_____%{red4}#{' '}
|
|
127
|
+
TEXT
|
|
128
|
+
red1 = ["_____", :red]
|
|
129
|
+
red2 = ["/ ___/", :red]
|
|
130
|
+
red3 = ["(__ )", :red]
|
|
131
|
+
red4 = ["/____/", :red]
|
|
132
|
+
ms = Paint % [txt2, :cyan, { red1: red1, red2: red2, red3: red3, red4: red4 }]
|
|
133
|
+
puts(ms)
|
|
134
|
+
puts(line)
|
|
135
|
+
welcome = Paint["Welcome to SOULs!", :white]
|
|
136
|
+
puts(welcome)
|
|
137
|
+
souls_ver = Paint["SOULs Version: #{Souls::VERSION}", :white]
|
|
138
|
+
puts(souls_ver)
|
|
139
|
+
puts(line)
|
|
140
|
+
endroll = <<~TEXT
|
|
141
|
+
Easy to Run
|
|
142
|
+
$ cd #{app_name}/apps/#{service_name}
|
|
143
|
+
$ bundle
|
|
144
|
+
$ souls s
|
|
145
|
+
Go To : http://localhost:4000
|
|
146
|
+
|
|
147
|
+
Doc: https://souls.elsoul.nl
|
|
148
|
+
TEXT
|
|
149
|
+
cd = Paint[endroll, :white]
|
|
150
|
+
puts(cd)
|
|
151
|
+
puts(line)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
@@ -19,11 +19,11 @@ module Souls
|
|
|
19
19
|
Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
|
|
20
20
|
Whirly.status = status
|
|
21
21
|
%w[api worker].each do |s_name|
|
|
22
|
-
|
|
23
|
-
result = Paint[
|
|
22
|
+
update_service_gemfile(service_name: s_name, version: souls_new_ver)
|
|
23
|
+
result = Paint[update_repo(service_name: s_name, update_kind: update_kind), :green]
|
|
24
24
|
Whirly.status = result
|
|
25
25
|
end
|
|
26
|
-
|
|
26
|
+
overwrite_version(new_version: souls_new_ver)
|
|
27
27
|
puts("before add")
|
|
28
28
|
system("git add .")
|
|
29
29
|
puts("before commit")
|
|
@@ -34,6 +34,94 @@ module Souls
|
|
|
34
34
|
Whirly.status = Paint["soul-v#{souls_new_ver} successfully updated!"]
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
|
+
|
|
38
|
+
def update_repo(service_name: "api", update_kind: "patch")
|
|
39
|
+
current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
|
|
40
|
+
current_ver = Souls.get_latest_version_txt(service_name: service_name)
|
|
41
|
+
new_ver = Souls.version_detector(current_ver: current_ver, update_kind: update_kind)
|
|
42
|
+
bucket_url = "gs://souls-bucket/boilerplates"
|
|
43
|
+
file_name = "#{service_name}-v#{new_ver}.tgz"
|
|
44
|
+
release_name = "#{service_name}-latest.tgz"
|
|
45
|
+
|
|
46
|
+
case current_dir_name
|
|
47
|
+
when "souls"
|
|
48
|
+
system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
|
|
49
|
+
system("echo '#{new_ver}' > apps/#{service_name}/.souls_#{service_name}_version")
|
|
50
|
+
system("cd apps/ && tar -czf ../#{service_name}.tgz #{service_name}/ && cd ..")
|
|
51
|
+
when "api", "worker", "console", "admin", "media"
|
|
52
|
+
system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
|
|
53
|
+
system("echo '#{new_ver}' > .souls_#{service_name}_version")
|
|
54
|
+
system("cd .. && tar -czf ../#{service_name}.tgz #{service_name}/ && cd #{service_name}")
|
|
55
|
+
else
|
|
56
|
+
raise(StandardError, "You are at wrong directory!")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{file_name}")
|
|
60
|
+
system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{release_name}")
|
|
61
|
+
system("gsutil cp .rubocop.yml #{bucket_url}/.rubocop.yml")
|
|
62
|
+
FileUtils.rm("#{service_name}.tgz")
|
|
63
|
+
"#{service_name}-v#{new_ver} Succefully Stored to GCS! "
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def update_service_gemfile(service_name: "api", version: "0.0.1")
|
|
67
|
+
file_dir = "./apps/#{service_name}"
|
|
68
|
+
file_path = "#{file_dir}/Gemfile"
|
|
69
|
+
gemfile_lock = "#{file_dir}/Gemfile.lock"
|
|
70
|
+
tmp_file = "#{file_dir}/tmp/Gemfile"
|
|
71
|
+
File.open(file_path, "r") do |f|
|
|
72
|
+
File.open(tmp_file, "w") do |new_line|
|
|
73
|
+
f.each_line do |line|
|
|
74
|
+
gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
|
|
75
|
+
if gem[0] == "souls"
|
|
76
|
+
old_ver = gem[1].split(".")
|
|
77
|
+
old_ver[2] = (old_ver[2].to_i + 1).to_s
|
|
78
|
+
new_line.write(" gem \"souls\", \"#{version}\"\n")
|
|
79
|
+
else
|
|
80
|
+
new_line.write(line)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
FileUtils.rm(file_path)
|
|
86
|
+
FileUtils.rm(gemfile_lock) if File.exist?(gemfile_lock)
|
|
87
|
+
FileUtils.mv(tmp_file, file_path)
|
|
88
|
+
puts(Paint["\nSuccessfully Updated #{service_name} Gemfile!", :green])
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def overwrite_version(new_version: "0.1.1")
|
|
92
|
+
FileUtils.rm("./lib/souls/version.rb")
|
|
93
|
+
file_path = "./lib/souls/version.rb"
|
|
94
|
+
File.open(file_path, "w") do |f|
|
|
95
|
+
f.write(<<~TEXT)
|
|
96
|
+
module Souls
|
|
97
|
+
VERSION = "#{new_version}".freeze
|
|
98
|
+
public_constant :VERSION
|
|
99
|
+
end
|
|
100
|
+
TEXT
|
|
101
|
+
end
|
|
102
|
+
overwrite_gemfile_lock(new_version: new_version)
|
|
103
|
+
true
|
|
104
|
+
rescue StandardError, e
|
|
105
|
+
raise(StandardError, e)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def overwrite_gemfile_lock(new_version: "0.1.1")
|
|
109
|
+
file_path = "Gemfile.lock"
|
|
110
|
+
new_file_path = "Gemfile.lock.tmp"
|
|
111
|
+
File.open(file_path, "r") do |f|
|
|
112
|
+
File.open(new_file_path, "w") do |new_line|
|
|
113
|
+
f.each_line.with_index do |line, i|
|
|
114
|
+
if i == 3
|
|
115
|
+
new_line.write(" souls (#{new_version})\n")
|
|
116
|
+
else
|
|
117
|
+
new_line.write(line)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
FileUtils.rm(file_path)
|
|
123
|
+
FileUtils.mv(new_file_path, file_path)
|
|
124
|
+
end
|
|
37
125
|
end
|
|
38
126
|
end
|
|
39
127
|
end
|
data/lib/souls/index.rb
CHANGED
data/lib/souls/utils/index.rb
CHANGED
|
@@ -7,5 +7,119 @@ module Souls
|
|
|
7
7
|
def get_api_path
|
|
8
8
|
FileUtils.pwd.split(Souls.configuration.app)[0] + Souls.configuration.app + "/apps/api"
|
|
9
9
|
end
|
|
10
|
+
|
|
11
|
+
def version_detector(current_ver: [0, 0, 1], update_kind: "patch")
|
|
12
|
+
case update_kind
|
|
13
|
+
when "patch"
|
|
14
|
+
"#{current_ver[0]}.#{current_ver[1]}.#{current_ver[2] + 1}"
|
|
15
|
+
when "minor"
|
|
16
|
+
"#{current_ver[0]}.#{current_ver[1] + 1}.0"
|
|
17
|
+
when "major"
|
|
18
|
+
"#{current_ver[0] + 1}.0.0"
|
|
19
|
+
else
|
|
20
|
+
raise(StandardError, "Wrong version!")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def get_latest_version_txt(service_name: "api")
|
|
25
|
+
case service_name
|
|
26
|
+
when "gem"
|
|
27
|
+
return Souls::VERSION.split(".").map(&:to_i)
|
|
28
|
+
when "api", "worker", "console", "admin", "media"
|
|
29
|
+
file_path = "#{Gem.dir}/gems/souls-#{Souls::VERSION}/lib/souls/versions/.souls_#{service_name}_version"
|
|
30
|
+
else
|
|
31
|
+
raise(StandardError, "You are at wrong directory!")
|
|
32
|
+
end
|
|
33
|
+
File.open(file_path, "r") do |f|
|
|
34
|
+
f.readlines[0].strip.split(".").map(&:to_i)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_columns_num(class_name: "user")
|
|
39
|
+
file_path = "./db/schema.rb"
|
|
40
|
+
class_check_flag = false
|
|
41
|
+
cols = []
|
|
42
|
+
File.open(file_path, "r") do |f|
|
|
43
|
+
f.each_line.with_index do |line, _i|
|
|
44
|
+
class_check_flag = true if line.include?("create_table") && line.include?(class_name)
|
|
45
|
+
if class_check_flag == true && !line.include?("create_table")
|
|
46
|
+
return cols if line.include?("t.index") || line.strip == "end"
|
|
47
|
+
|
|
48
|
+
types = Souls::Api::Generate.get_type_and_name(line)
|
|
49
|
+
array = line.include?("array: true")
|
|
50
|
+
cols << { column_name: types[1], type: types[0], array: array }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
cols
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def get_create_migration_type(class_name: "user")
|
|
58
|
+
pluralized_class_name = class_name.pluralize
|
|
59
|
+
file_path = Dir["db/migrate/*_create_#{pluralized_class_name}.rb"][0]
|
|
60
|
+
|
|
61
|
+
class_check_flag = false
|
|
62
|
+
response = [
|
|
63
|
+
{ column_name: "created_at", type: "datetime", array: false },
|
|
64
|
+
{ column_name: "updated_at", type: "datetime", array: false }
|
|
65
|
+
]
|
|
66
|
+
File.open(file_path) do |f|
|
|
67
|
+
f.each_line do |line|
|
|
68
|
+
class_check_flag = true if line.include?("create_table")
|
|
69
|
+
next unless class_check_flag == true && !line.include?("create_table")
|
|
70
|
+
return response if line.include?("t.timestamps") || line.strip == "end"
|
|
71
|
+
|
|
72
|
+
types = Souls::Api::Generate.get_type_and_name(line)
|
|
73
|
+
types.map { |n| n.gsub!(":", "") }
|
|
74
|
+
array = line.include?("array: true")
|
|
75
|
+
response << { column_name: types[1], type: types[0], array: array }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def get_migration_type(class_name: "user", action: "add")
|
|
81
|
+
pluralized_class_name = class_name.pluralize
|
|
82
|
+
file_paths = Dir["db/migrate/*_#{action}_column_to_#{pluralized_class_name}.rb"]
|
|
83
|
+
|
|
84
|
+
new_columns =
|
|
85
|
+
file_paths.map do |file_path|
|
|
86
|
+
get_col_name_and_type(class_name: class_name, file_path: file_path, action: action)
|
|
87
|
+
end
|
|
88
|
+
new_columns.flatten
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def get_col_name_and_type(
|
|
92
|
+
class_name: "user", file_path: "db/migrate/20210816094410_add_column_to_users.rb", action: "add"
|
|
93
|
+
)
|
|
94
|
+
pluralized_class_name = class_name.pluralize
|
|
95
|
+
response = []
|
|
96
|
+
File.open(file_path) do |line|
|
|
97
|
+
line.each_line do |file_line|
|
|
98
|
+
next unless file_line.include?("#{action}_column")
|
|
99
|
+
|
|
100
|
+
array = file_line.include?("array: true")
|
|
101
|
+
types = file_line.split(",").map(&:strip)
|
|
102
|
+
types.map { |n| n.gsub!(":", "") }
|
|
103
|
+
types[0].gsub!("#{action}_column ", "")
|
|
104
|
+
unless types[0].to_s == pluralized_class_name
|
|
105
|
+
raise(StandardError, "Wrong class_name!Please Check your migration file!")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
response << { column_name: types[1], type: types[2], array: array }
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
response
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def check_schema(class_name: "user")
|
|
115
|
+
schema_data = get_columns_num(class_name: class_name)
|
|
116
|
+
create_migration_data = get_create_migration_type(class_name: class_name)
|
|
117
|
+
add_migration_data = get_migration_type(class_name: class_name, action: "add")
|
|
118
|
+
remove_migration_data = get_migration_type(class_name: class_name, action: "remove")
|
|
119
|
+
migration_data = create_migration_data + add_migration_data - remove_migration_data
|
|
120
|
+
return "Already Up to date!" if schema_data.size == migration_data.size
|
|
121
|
+
|
|
122
|
+
schema_data - migration_data
|
|
123
|
+
end
|
|
10
124
|
end
|
|
11
125
|
end
|
data/lib/souls/version.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.27.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.27.0
|
data/lib/souls.rb
CHANGED
|
@@ -29,217 +29,6 @@ module Souls
|
|
|
29
29
|
class << self
|
|
30
30
|
attr_accessor :configuration
|
|
31
31
|
|
|
32
|
-
def update_repo(service_name: "api", update_kind: "patch")
|
|
33
|
-
current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
|
|
34
|
-
current_ver = get_latest_version_txt(service_name: service_name)
|
|
35
|
-
new_ver = version_detector(current_ver: current_ver, update_kind: update_kind)
|
|
36
|
-
bucket_url = "gs://souls-bucket/boilerplates"
|
|
37
|
-
file_name = "#{service_name}-v#{new_ver}.tgz"
|
|
38
|
-
release_name = "#{service_name}-latest.tgz"
|
|
39
|
-
|
|
40
|
-
case current_dir_name
|
|
41
|
-
when "souls"
|
|
42
|
-
system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
|
|
43
|
-
system("echo '#{new_ver}' > apps/#{service_name}/.souls_#{service_name}_version")
|
|
44
|
-
system("cd apps/ && tar -czf ../#{service_name}.tgz #{service_name}/ && cd ..")
|
|
45
|
-
when "api", "worker", "console", "admin", "media"
|
|
46
|
-
system("echo '#{new_ver}' > lib/souls/versions/.souls_#{service_name}_version")
|
|
47
|
-
system("echo '#{new_ver}' > .souls_#{service_name}_version")
|
|
48
|
-
system("cd .. && tar -czf ../#{service_name}.tgz #{service_name}/ && cd #{service_name}")
|
|
49
|
-
else
|
|
50
|
-
raise(StandardError, "You are at wrong directory!")
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{file_name}")
|
|
54
|
-
system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{release_name}")
|
|
55
|
-
system("gsutil cp .rubocop.yml #{bucket_url}/.rubocop.yml")
|
|
56
|
-
FileUtils.rm("#{service_name}.tgz")
|
|
57
|
-
"#{service_name}-v#{new_ver} Succefully Stored to GCS! "
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def version_detector(current_ver: [0, 0, 1], update_kind: "patch")
|
|
61
|
-
case update_kind
|
|
62
|
-
when "patch"
|
|
63
|
-
"#{current_ver[0]}.#{current_ver[1]}.#{current_ver[2] + 1}"
|
|
64
|
-
when "minor"
|
|
65
|
-
"#{current_ver[0]}.#{current_ver[1] + 1}.0"
|
|
66
|
-
when "major"
|
|
67
|
-
"#{current_ver[0] + 1}.0.0"
|
|
68
|
-
else
|
|
69
|
-
raise(StandardError, "Wrong version!")
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def overwrite_version(new_version: "0.1.1")
|
|
74
|
-
FileUtils.rm("./lib/souls/version.rb")
|
|
75
|
-
file_path = "./lib/souls/version.rb"
|
|
76
|
-
File.open(file_path, "w") do |f|
|
|
77
|
-
f.write(<<~TEXT)
|
|
78
|
-
module Souls
|
|
79
|
-
VERSION = "#{new_version}".freeze
|
|
80
|
-
public_constant :VERSION
|
|
81
|
-
end
|
|
82
|
-
TEXT
|
|
83
|
-
end
|
|
84
|
-
overwrite_gemfile_lock(new_version: new_version)
|
|
85
|
-
true
|
|
86
|
-
rescue StandardError, e
|
|
87
|
-
raise(StandardError, e)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def overwrite_gemfile_lock(new_version: "0.1.1")
|
|
91
|
-
file_path = "Gemfile.lock"
|
|
92
|
-
new_file_path = "Gemfile.lock.tmp"
|
|
93
|
-
File.open(file_path, "r") do |f|
|
|
94
|
-
File.open(new_file_path, "w") do |new_line|
|
|
95
|
-
f.each_line.with_index do |line, i|
|
|
96
|
-
if i == 3
|
|
97
|
-
new_line.write(" souls (#{new_version})\n")
|
|
98
|
-
else
|
|
99
|
-
new_line.write(line)
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
FileUtils.rm(file_path)
|
|
105
|
-
FileUtils.mv(new_file_path, file_path)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def get_latest_version_txt(service_name: "api")
|
|
109
|
-
case service_name
|
|
110
|
-
when "gem"
|
|
111
|
-
return Souls::VERSION.split(".").map(&:to_i)
|
|
112
|
-
when "api", "worker", "console", "admin", "media"
|
|
113
|
-
file_path = "#{Gem.dir}/gems/souls-#{Souls::VERSION}/lib/souls/versions/.souls_#{service_name}_version"
|
|
114
|
-
else
|
|
115
|
-
raise(StandardError, "You are at wrong directory!")
|
|
116
|
-
end
|
|
117
|
-
File.open(file_path, "r") do |f|
|
|
118
|
-
f.readlines[0].strip.split(".").map(&:to_i)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def update_service_gemfile(service_name: "api", version: "0.0.1")
|
|
123
|
-
file_dir = "./apps/#{service_name}"
|
|
124
|
-
file_path = "#{file_dir}/Gemfile"
|
|
125
|
-
gemfile_lock = "#{file_dir}/Gemfile.lock"
|
|
126
|
-
tmp_file = "#{file_dir}/tmp/Gemfile"
|
|
127
|
-
File.open(file_path, "r") do |f|
|
|
128
|
-
File.open(tmp_file, "w") do |new_line|
|
|
129
|
-
f.each_line do |line|
|
|
130
|
-
gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
|
|
131
|
-
if gem[0] == "souls"
|
|
132
|
-
old_ver = gem[1].split(".")
|
|
133
|
-
old_ver[2] = (old_ver[2].to_i + 1).to_s
|
|
134
|
-
new_line.write(" gem \"souls\", \"#{version}\"\n")
|
|
135
|
-
else
|
|
136
|
-
new_line.write(line)
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
FileUtils.rm(file_path)
|
|
142
|
-
FileUtils.rm(gemfile_lock) if File.exist?(gemfile_lock)
|
|
143
|
-
FileUtils.mv(tmp_file, file_path)
|
|
144
|
-
puts(Paint["\nSuccessfully Updated #{service_name} Gemfile!", :green])
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def check_schema(class_name: "user")
|
|
148
|
-
schema_data = get_columns_num(class_name: class_name)
|
|
149
|
-
create_migration_data = get_create_migration_type(class_name: class_name)
|
|
150
|
-
add_migration_data = get_migration_type(class_name: class_name, action: "add")
|
|
151
|
-
remove_migration_data = get_migration_type(class_name: class_name, action: "remove")
|
|
152
|
-
migration_data = create_migration_data + add_migration_data - remove_migration_data
|
|
153
|
-
return "Already Up to date!" if schema_data.size == migration_data.size
|
|
154
|
-
|
|
155
|
-
schema_data - migration_data
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def get_columns_num(class_name: "user")
|
|
159
|
-
file_path = "./db/schema.rb"
|
|
160
|
-
class_check_flag = false
|
|
161
|
-
cols = []
|
|
162
|
-
File.open(file_path, "r") do |f|
|
|
163
|
-
f.each_line.with_index do |line, _i|
|
|
164
|
-
class_check_flag = true if line.include?("create_table") && line.include?(class_name)
|
|
165
|
-
if class_check_flag == true && !line.include?("create_table")
|
|
166
|
-
return cols if line.include?("t.index") || line.strip == "end"
|
|
167
|
-
|
|
168
|
-
types = Souls::Api::Generate.get_type_and_name(line)
|
|
169
|
-
array = line.include?("array: true")
|
|
170
|
-
cols << { column_name: types[1], type: types[0], array: array }
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
cols
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
def get_create_migration_type(class_name: "user")
|
|
178
|
-
pluralized_class_name = class_name.pluralize
|
|
179
|
-
file_path = Dir["db/migrate/*_create_#{pluralized_class_name}.rb"][0]
|
|
180
|
-
|
|
181
|
-
class_check_flag = false
|
|
182
|
-
response = [
|
|
183
|
-
{ column_name: "created_at", type: "datetime", array: false },
|
|
184
|
-
{ column_name: "updated_at", type: "datetime", array: false }
|
|
185
|
-
]
|
|
186
|
-
File.open(file_path) do |f|
|
|
187
|
-
f.each_line do |line|
|
|
188
|
-
class_check_flag = true if line.include?("create_table")
|
|
189
|
-
next unless class_check_flag == true && !line.include?("create_table")
|
|
190
|
-
return response if line.include?("t.timestamps") || line.strip == "end"
|
|
191
|
-
|
|
192
|
-
types = Souls::Api::Generate.get_type_and_name(line)
|
|
193
|
-
types.map { |n| n.gsub!(":", "") }
|
|
194
|
-
array = line.include?("array: true")
|
|
195
|
-
response << { column_name: types[1], type: types[0], array: array }
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def get_migration_type(class_name: "user", action: "add")
|
|
201
|
-
pluralized_class_name = class_name.pluralize
|
|
202
|
-
file_paths = Dir["db/migrate/*_#{action}_column_to_#{pluralized_class_name}.rb"]
|
|
203
|
-
|
|
204
|
-
new_columns =
|
|
205
|
-
file_paths.map do |file_path|
|
|
206
|
-
get_col_name_and_type(class_name: class_name, file_path: file_path, action: action)
|
|
207
|
-
end
|
|
208
|
-
new_columns.flatten
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def get_last_migration_type(class_name: "user", action: "add")
|
|
212
|
-
pluralized_class_name = class_name.pluralize
|
|
213
|
-
file_paths = Dir["db/migrate/*_#{action}_column_to_#{pluralized_class_name}.rb"]
|
|
214
|
-
|
|
215
|
-
file_paths.max
|
|
216
|
-
resoponse = get_col_name_and_type(class_name: class_name, file_path: file_paths.max, action: action)
|
|
217
|
-
resoponse.flatten
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def get_col_name_and_type(
|
|
221
|
-
class_name: "user", file_path: "db/migrate/20210816094410_add_column_to_users.rb", action: "add"
|
|
222
|
-
)
|
|
223
|
-
pluralized_class_name = class_name.pluralize
|
|
224
|
-
response = []
|
|
225
|
-
File.open(file_path) do |line|
|
|
226
|
-
line.each_line do |file_line|
|
|
227
|
-
next unless file_line.include?("#{action}_column")
|
|
228
|
-
|
|
229
|
-
array = file_line.include?("array: true")
|
|
230
|
-
types = file_line.split(",").map(&:strip)
|
|
231
|
-
types.map { |n| n.gsub!(":", "") }
|
|
232
|
-
types[0].gsub!("#{action}_column ", "")
|
|
233
|
-
unless types[0].to_s == pluralized_class_name
|
|
234
|
-
raise(StandardError, "Wrong class_name!Please Check your migration file!")
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
response << { column_name: types[1], type: types[2], array: array }
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
response
|
|
241
|
-
end
|
|
242
|
-
|
|
243
32
|
def configure
|
|
244
33
|
self.configuration ||= Configuration.new
|
|
245
34
|
yield(configuration)
|
|
@@ -247,11 +36,12 @@ module Souls
|
|
|
247
36
|
end
|
|
248
37
|
|
|
249
38
|
class Configuration
|
|
250
|
-
attr_accessor :app, :strain, :project_id, :endpoint, :fixed_gems, :workers
|
|
39
|
+
attr_accessor :app, :strain, :project_id, :region, :endpoint, :fixed_gems, :workers
|
|
251
40
|
|
|
252
41
|
def initialize
|
|
253
42
|
@app = nil
|
|
254
43
|
@project_id = nil
|
|
44
|
+
@region = nil
|
|
255
45
|
@endpoint = nil
|
|
256
46
|
@strain = nil
|
|
257
47
|
@fixed_gems = nil
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: souls
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.48.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- POPPIN-FUMI
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: exe
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2021-09-
|
|
13
|
+
date: 2021-09-09 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activesupport
|
|
@@ -139,7 +139,9 @@ files:
|
|
|
139
139
|
- lib/souls/api/update/rspec_mutation.rb
|
|
140
140
|
- lib/souls/api/update/rspec_resolver.rb
|
|
141
141
|
- lib/souls/api/update/type.rb
|
|
142
|
+
- lib/souls/cli/console/index.rb
|
|
142
143
|
- lib/souls/cli/create/index.rb
|
|
144
|
+
- lib/souls/cli/db/index.rb
|
|
143
145
|
- lib/souls/cli/docker/index.rb
|
|
144
146
|
- lib/souls/cli/gcloud/compute/index.rb
|
|
145
147
|
- lib/souls/cli/gcloud/iam/index.rb
|
|
@@ -150,8 +152,10 @@ files:
|
|
|
150
152
|
- lib/souls/cli/gcloud/run/index.rb
|
|
151
153
|
- lib/souls/cli/gcloud/sql/index.rb
|
|
152
154
|
- lib/souls/cli/index.rb
|
|
155
|
+
- lib/souls/cli/init/index.rb
|
|
153
156
|
- lib/souls/cli/release/index.rb
|
|
154
157
|
- lib/souls/cli/release/release.rb
|
|
158
|
+
- lib/souls/cli/server/index.rb
|
|
155
159
|
- lib/souls/cli/sync/conf.rb
|
|
156
160
|
- lib/souls/cli/sync/index.rb
|
|
157
161
|
- lib/souls/cli/sync/model.rb
|
|
@@ -159,7 +163,6 @@ files:
|
|
|
159
163
|
- lib/souls/cli/upgrade/gem_update.rb
|
|
160
164
|
- lib/souls/cli/upgrade/index.rb
|
|
161
165
|
- lib/souls/index.rb
|
|
162
|
-
- lib/souls/init.rb
|
|
163
166
|
- lib/souls/utils/index.rb
|
|
164
167
|
- lib/souls/version.rb
|
|
165
168
|
- lib/souls/versions/.souls_api_version
|
data/lib/souls/init.rb
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
module Souls
|
|
2
|
-
module Init
|
|
3
|
-
def self.get_version(repository_name: "souls_api")
|
|
4
|
-
data = JSON.parse(
|
|
5
|
-
`curl \
|
|
6
|
-
-H "Accept: application/vnd.github.v3+json" \
|
|
7
|
-
-s https://api.github.com/repos/elsoul/#{repository_name}/releases`
|
|
8
|
-
)
|
|
9
|
-
data[0]["tag_name"]
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.generate_cd
|
|
13
|
-
shell = `echo $SHELL`.strip
|
|
14
|
-
rc =
|
|
15
|
-
if shell.include?("zsh")
|
|
16
|
-
"zshrc"
|
|
17
|
-
else
|
|
18
|
-
"bash"
|
|
19
|
-
end
|
|
20
|
-
system("echo '\nalias api=\'cd apps/api\'' >> ~/.#{rc}")
|
|
21
|
-
system("echo 'alias mother=\'...\'' >> ~/.#{rc}")
|
|
22
|
-
system("echo 'alias worker=\'cd apps/worker\'' >> ~/.#{rc}")
|
|
23
|
-
puts(Paint["run `source ~/.#{rc}` to reflect your .#{rc}", :yellow])
|
|
24
|
-
puts(Paint["You can move to mother/api/worker just type", :green])
|
|
25
|
-
puts(Paint["\nmother\n", :white])
|
|
26
|
-
puts(
|
|
27
|
-
Paint["to go back to mother dir from api/worker\n\nYou can also go to api/worker from mother dir by typing",
|
|
28
|
-
:green]
|
|
29
|
-
)
|
|
30
|
-
puts(Paint["\napi\n", :white])
|
|
31
|
-
puts(Paint["or\n", :green])
|
|
32
|
-
puts(Paint["worker", :white])
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def self.initial_config_init(app_name: "souls", service_name: "api")
|
|
36
|
-
config_dir = "./#{app_name}/apps/#{service_name}/config"
|
|
37
|
-
FileUtils.mkdir_p(config_dir) unless Dir.exist?(config_dir)
|
|
38
|
-
FileUtils.touch("#{config_dir}/souls.rb")
|
|
39
|
-
file_path = "#{config_dir}/souls.rb"
|
|
40
|
-
File.open(file_path, "w") do |f|
|
|
41
|
-
f.write(<<~TEXT)
|
|
42
|
-
Souls.configure do |config|
|
|
43
|
-
config.app = "#{app_name}"
|
|
44
|
-
config.project_id = "#{app_name}-project"
|
|
45
|
-
config.endpoint = "/endpoint"
|
|
46
|
-
config.strain = "api"
|
|
47
|
-
config.fixed_gems = ["excluded_gem"]
|
|
48
|
-
config.workers = []
|
|
49
|
-
end
|
|
50
|
-
TEXT
|
|
51
|
-
end
|
|
52
|
-
rescue StandardError => e
|
|
53
|
-
puts(e)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def self.download_github_actions(app_name: "souls-app")
|
|
57
|
-
file_name = "github.tgz"
|
|
58
|
-
url = "https://storage.googleapis.com/souls-bucket/github_actions/github.tgz"
|
|
59
|
-
system("curl -OL #{url}")
|
|
60
|
-
FileUtils.mkdir_p("#{app_name}/github")
|
|
61
|
-
system("tar -zxvf ./#{file_name} -C #{app_name}/")
|
|
62
|
-
FileUtils.rm(file_name)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def self.mother_config_init(app_name: "souls-app")
|
|
66
|
-
config_dir = "./#{app_name}/config"
|
|
67
|
-
FileUtils.mkdir_p(config_dir) unless Dir.exist?(config_dir)
|
|
68
|
-
FileUtils.touch("#{config_dir}/souls.rb")
|
|
69
|
-
file_path = "#{config_dir}/souls.rb"
|
|
70
|
-
File.open(file_path, "w") do |f|
|
|
71
|
-
f.write(<<~TEXT)
|
|
72
|
-
Souls.configure do |config|
|
|
73
|
-
config.app = "#{app_name}"
|
|
74
|
-
config.project_id = "#{app_name}-project"
|
|
75
|
-
config.endpoint = "/endpoint"
|
|
76
|
-
config.strain = "mother"
|
|
77
|
-
config.fixed_gems = ["excluded_gem"]
|
|
78
|
-
config.workers = []
|
|
79
|
-
end
|
|
80
|
-
TEXT
|
|
81
|
-
end
|
|
82
|
-
rescue StandardError => e
|
|
83
|
-
puts(e)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def self.start(args)
|
|
87
|
-
app_name = args[1]
|
|
88
|
-
if app_name.nil?
|
|
89
|
-
puts(Paint["you need to specify your app name", :red])
|
|
90
|
-
puts(Paint["`souls new souls-app`", :yellow])
|
|
91
|
-
exit
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
service_name = "api"
|
|
95
|
-
Souls::Init.download_souls(app_name: app_name, service_name: service_name)
|
|
96
|
-
Souls::Init.mother_config_init(app_name: app_name)
|
|
97
|
-
Souls::Init.download_github_actions(app_name: app_name)
|
|
98
|
-
Souls::Init.initial_config_init(app_name: app_name, service_name: service_name)
|
|
99
|
-
Souls::Init.souls_api_credit(app_name: app_name, service_name: service_name)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def self.download_souls(app_name: "souls", service_name: "api")
|
|
103
|
-
version = Souls.get_latest_version_txt(service_name: service_name).join(".")
|
|
104
|
-
file_name = "#{service_name}-v#{version}.tgz"
|
|
105
|
-
url = "https://storage.googleapis.com/souls-bucket/boilerplates/#{service_name.pluralize}/#{file_name}"
|
|
106
|
-
system("curl -OL #{url}")
|
|
107
|
-
system("mkdir -p #{app_name}/apps/#{service_name}")
|
|
108
|
-
system("tar -zxvf ./#{file_name} -C #{app_name}/apps/")
|
|
109
|
-
system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/.rubocop.yml")
|
|
110
|
-
system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/Gemfile")
|
|
111
|
-
system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/Procfile.dev")
|
|
112
|
-
system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/Procfile")
|
|
113
|
-
FileUtils.rm(file_name)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def self.souls_api_credit(app_name: "souls", service_name: "api")
|
|
117
|
-
line = Paint["====================================", :yellow]
|
|
118
|
-
puts("\n")
|
|
119
|
-
puts(line)
|
|
120
|
-
txt2 = <<~TEXT
|
|
121
|
-
_____ ____ __ ____#{' '}
|
|
122
|
-
/ ___// __ \\/ / / / / %{red1}
|
|
123
|
-
\\__ \\/ / / / / / / / %{red2}
|
|
124
|
-
___/ / /_/ / /_/ / /___%{red3}#{' '}
|
|
125
|
-
/____/\\____/\\____/_____%{red4}#{' '}
|
|
126
|
-
TEXT
|
|
127
|
-
red1 = ["_____", :red]
|
|
128
|
-
red2 = ["/ ___/", :red]
|
|
129
|
-
red3 = ["(__ )", :red]
|
|
130
|
-
red4 = ["/____/", :red]
|
|
131
|
-
ms = Paint % [txt2, :cyan, { red1: red1, red2: red2, red3: red3, red4: red4 }]
|
|
132
|
-
puts(ms)
|
|
133
|
-
puts(line)
|
|
134
|
-
welcome = Paint["Welcome to SOULs!", :white]
|
|
135
|
-
puts(welcome)
|
|
136
|
-
souls_ver = Paint["SOULs Version: #{Souls::VERSION}", :white]
|
|
137
|
-
puts(souls_ver)
|
|
138
|
-
puts(line)
|
|
139
|
-
endroll = <<~TEXT
|
|
140
|
-
Easy to Run
|
|
141
|
-
$ cd #{app_name}/apps/#{service_name}
|
|
142
|
-
$ bundle
|
|
143
|
-
$ souls s
|
|
144
|
-
Go To : http://localhost:4000
|
|
145
|
-
|
|
146
|
-
Doc: https://souls.elsoul.nl
|
|
147
|
-
TEXT
|
|
148
|
-
cd = Paint[endroll, :white]
|
|
149
|
-
puts(cd)
|
|
150
|
-
puts(line)
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
end
|