souls 1.3.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/souls/cli/cli_exception.rb +10 -0
- data/lib/souls/cli/console/index.rb +2 -8
- data/lib/souls/cli/create/index.rb +135 -144
- data/lib/souls/cli/generate/job.rb +4 -4
- data/lib/souls/cli/generate/manager.rb +13 -7
- data/lib/souls/cli/generate/mutation.rb +5 -5
- data/lib/souls/cli/generate/mutation_rbs.rb +5 -5
- data/lib/souls/cli/generate/rspec_query.rb +12 -8
- data/lib/souls/cli/generate/rspec_resolver.rb +8 -8
- data/lib/souls/cli/release/release.rb +2 -0
- data/lib/souls/cli/update/mutation.rb +33 -48
- data/lib/souls/utils/index.rb +2 -2
- 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
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 504cd4ab4030690ba86843de1b9af5544394c39480a8394e2bc0be6e9cc09494
|
4
|
+
data.tar.gz: 1294690c238452bcd9a5d06e2f4b1f6eeec02c1da8850772bb523a88e80f41ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58ba05001034b78f384ab7fb2c6c9d36b3e15881433a810242530c60677aef2b4f69e55d67542f676bc2ccd638744bb79b5c99c97c16c42575082d5bc2e8b112
|
7
|
+
data.tar.gz: 3ac42b34963cd62fd8e53520594a5f2ece24763dcdbdd70ac4dbea94694014b724caed14c75f543f61847de7313f92b63e2518fb1213561c4da3aeeae1554693
|
@@ -3,14 +3,8 @@ module Souls
|
|
3
3
|
desc "console", "Run IRB Console"
|
4
4
|
method_option :env, aliases: "--e", default: "development", desc: "Difine APP Enviroment - development | production"
|
5
5
|
def console
|
6
|
-
|
7
|
-
|
8
|
-
system("RACK_ENV=production bundle exec irb")
|
9
|
-
else
|
10
|
-
system("bundle exec irb")
|
11
|
-
end
|
12
|
-
rescue Thor::Error => e
|
13
|
-
raise(Thor::Error, e)
|
6
|
+
return system("RACK_ENV=production bundle exec irb") if options[:env].eql? "production"
|
7
|
+
system("bundle exec irb")
|
14
8
|
end
|
15
9
|
end
|
16
10
|
end
|
@@ -12,92 +12,86 @@ module Souls
|
|
12
12
|
app = Souls.configuration.app
|
13
13
|
port = 3000 + workers.size
|
14
14
|
souls_worker_name = "souls-#{app}-#{options[:name]}"
|
15
|
-
download_worker(
|
16
|
-
souls_conf_update(
|
17
|
-
souls_conf_update(
|
18
|
-
workflow(
|
19
|
-
procfile(
|
20
|
-
mother_procfile(
|
21
|
-
souls_config_init(
|
22
|
-
steepfile(
|
23
|
-
souls_helper_rbs(
|
15
|
+
download_worker(options[:name])
|
16
|
+
souls_conf_update(souls_worker_name)
|
17
|
+
souls_conf_update(souls_worker_name, "api")
|
18
|
+
workflow(options[:name])
|
19
|
+
procfile(options[:name], port)
|
20
|
+
mother_procfile(options[:name])
|
21
|
+
souls_config_init(options[:name])
|
22
|
+
steepfile(options[:name])
|
23
|
+
souls_helper_rbs(options[:name])
|
24
24
|
system("cd apps/#{options[:name]} && bundle")
|
25
|
-
souls_worker_credit(
|
25
|
+
souls_worker_credit(options[:name])
|
26
26
|
end
|
27
27
|
true
|
28
|
-
rescue Thor::Error => e
|
29
|
-
raise(Thor::Error, e)
|
30
28
|
end
|
31
29
|
|
32
30
|
private
|
33
31
|
|
34
|
-
def steepfile(worker_name
|
32
|
+
def steepfile(worker_name)
|
35
33
|
file_path = "./Steepfile"
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
new_line.write(" check \"apps/#{worker_name}/#{path}\"\n")
|
44
|
-
end
|
45
|
-
new_line.write("end\n")
|
46
|
-
else
|
47
|
-
new_line.write(line)
|
34
|
+
|
35
|
+
write_txt = ""
|
36
|
+
File.open(file_path, "r") do |f|
|
37
|
+
f.each_line do |line|
|
38
|
+
if line.strip.to_s == "end"
|
39
|
+
["app", "db/seeds.rb", "constants", "app.rb"].each do |path|
|
40
|
+
write_txt += " check \"apps/#{worker_name}/#{path}\"\n"
|
48
41
|
end
|
42
|
+
write_txt += "end\n"
|
43
|
+
else
|
44
|
+
write_txt += line
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|
52
|
-
|
53
|
-
FileUtils.mv(new_file_path, file_path)
|
48
|
+
File.open(file_path, "w") { |f| f.write(write_txt) }
|
54
49
|
end
|
55
50
|
|
56
|
-
def procfile(worker_name
|
57
|
-
|
58
|
-
file_path = "#{file_dir}/Procfile.dev"
|
51
|
+
def procfile(worker_name, port)
|
52
|
+
file_path = "apps/#{worker_name}/Procfile.dev"
|
59
53
|
File.open(file_path, "w") do |f|
|
60
54
|
f.write("#{worker_name}: bundle exec puma -p #{port} -e development")
|
61
55
|
end
|
62
56
|
end
|
63
57
|
|
64
|
-
def mother_procfile(worker_name
|
58
|
+
def mother_procfile(worker_name)
|
65
59
|
file_path = "Procfile.dev"
|
66
60
|
File.open(file_path, "a") do |f|
|
67
61
|
f.write("\n#{worker_name}: foreman start -f ./apps/#{worker_name}/Procfile.dev")
|
68
62
|
end
|
69
63
|
end
|
70
64
|
|
71
|
-
def souls_conf_update(worker_name
|
65
|
+
def souls_conf_update(worker_name, strain)
|
72
66
|
workers = Souls.configuration.workers
|
73
67
|
port = 3000 + workers.size
|
74
68
|
file_path = strain == "mother" ? "config/souls.rb" : "apps/api/config/souls.rb"
|
75
|
-
new_file_path = "souls.rb"
|
76
|
-
worker_switch = false
|
77
|
-
File.open(new_file_path, "w") do |new_line|
|
78
|
-
File.open(file_path, "r") do |f|
|
79
|
-
f.each_line do |line|
|
80
|
-
worker_switch = true if line.include?("config.workers")
|
81
|
-
next if line.strip == "end"
|
82
69
|
|
83
|
-
|
70
|
+
write_txt = ""
|
71
|
+
File.open(file_path, "r") do |f|
|
72
|
+
f.each_line do |line|
|
73
|
+
worker_switch = line.include?("config.workers")
|
74
|
+
next if line.strip == "end"
|
84
75
|
|
85
|
-
|
76
|
+
unless worker_switch
|
77
|
+
write_txt += line
|
78
|
+
next
|
79
|
+
end
|
86
80
|
|
87
|
-
|
88
|
-
|
89
|
-
|
81
|
+
write_txt += " config.workers = [\n"
|
82
|
+
workers.each do |worker|
|
83
|
+
write_txt += <<-TEXT
|
90
84
|
{
|
91
85
|
name: "#{worker[:name]}",
|
92
86
|
endpoint: "#{worker[:endpoint]}",
|
93
87
|
port: #{worker[:port]}
|
94
88
|
},
|
95
|
-
|
96
|
-
end
|
97
|
-
break
|
89
|
+
TEXT
|
98
90
|
end
|
91
|
+
break
|
99
92
|
end
|
100
|
-
|
93
|
+
end
|
94
|
+
write_txt += <<-TEXT
|
101
95
|
{
|
102
96
|
name: "#{worker_name}",
|
103
97
|
endpoint: "",
|
@@ -105,13 +99,12 @@ module Souls
|
|
105
99
|
}
|
106
100
|
]
|
107
101
|
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
FileUtils.mv(new_file_path, file_path)
|
102
|
+
TEXT
|
103
|
+
|
104
|
+
File.open(file_path, "w") { |f| f.write(write_txt) }
|
112
105
|
end
|
113
106
|
|
114
|
-
def workflow(worker_name
|
107
|
+
def workflow(worker_name)
|
115
108
|
file_dir = ".github/workflows"
|
116
109
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
117
110
|
file_path = "#{file_dir}/#{worker_name}.yml"
|
@@ -119,101 +112,99 @@ end
|
|
119
112
|
worker_name_camelize = worker_name.camelize
|
120
113
|
File.open(file_path, "w") do |f|
|
121
114
|
f.write(<<~TEXT)
|
122
|
-
|
115
|
+
name: #{worker_name_camelize}
|
123
116
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
117
|
+
on:
|
118
|
+
push:
|
119
|
+
branches:
|
120
|
+
- main
|
121
|
+
paths:
|
122
|
+
- "apps/#{worker_name}/**"
|
123
|
+
- ".github/workflows/#{worker_name}.yml"
|
131
124
|
|
132
|
-
|
133
|
-
|
125
|
+
jobs:
|
126
|
+
build:
|
134
127
|
|
135
|
-
|
128
|
+
runs-on: ubuntu-20.04
|
136
129
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
env:
|
142
|
-
POSTGRES_PASSWORD: postgres
|
143
|
-
options: >-
|
144
|
-
--health-cmd pg_isready
|
145
|
-
--health-interval 10s
|
146
|
-
--health-timeout 5s
|
147
|
-
--health-retries 5
|
148
|
-
|
149
|
-
steps:
|
150
|
-
- uses: actions/checkout@v2
|
151
|
-
- name: Set up Ruby 3.0
|
152
|
-
uses: actions/setup-ruby@v1
|
153
|
-
with:
|
154
|
-
ruby-version: 3.0
|
155
|
-
- name: Build and test with Rake
|
130
|
+
services:
|
131
|
+
db:
|
132
|
+
image: postgres:13
|
133
|
+
ports: ["5433:5432"]
|
156
134
|
env:
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
135
|
+
POSTGRES_PASSWORD: postgres
|
136
|
+
options: >-
|
137
|
+
--health-cmd pg_isready
|
138
|
+
--health-interval 10s
|
139
|
+
--health-timeout 5s
|
140
|
+
--health-retries 5
|
141
|
+
|
142
|
+
steps:
|
143
|
+
- uses: actions/checkout@v2
|
144
|
+
- name: Set up Ruby 3.0
|
145
|
+
uses: actions/setup-ruby@v1
|
146
|
+
with:
|
147
|
+
ruby-version: 3.0
|
148
|
+
- name: Build and test with Rake
|
149
|
+
env:
|
150
|
+
PGHOST: 127.0.0.1
|
151
|
+
PGUSER: postgres
|
152
|
+
RACK_ENV: test
|
153
|
+
run: |
|
154
|
+
sudo apt-get -yqq install libpq-dev
|
155
|
+
cd apps/#{worker_name}
|
156
|
+
gem install bundler
|
157
|
+
bundle install --jobs 4 --retry 3
|
158
|
+
bundle exec rake db:create RACK_ENV=test
|
159
|
+
bundle exec rake db:migrate RACK_ENV=test
|
160
|
+
bundle exec rspec
|
168
161
|
|
169
|
-
|
170
|
-
|
162
|
+
- name: Checkout the repository
|
163
|
+
uses: actions/checkout@v2
|
171
164
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
165
|
+
- name: GCP Authenticate
|
166
|
+
uses: google-github-actions/setup-gcloud@master
|
167
|
+
with:
|
168
|
+
version: "323.0.0"
|
169
|
+
project_id: ${{ secrets.SOULS_GCP_PROJECT_ID }}
|
170
|
+
service_account_key: ${{ secrets.SOULS_GCP_SA_KEY }}
|
171
|
+
export_default_credentials: true
|
179
172
|
|
180
|
-
|
181
|
-
|
173
|
+
- name: Configure Docker
|
174
|
+
run: gcloud auth configure-docker --quiet
|
182
175
|
|
183
|
-
|
184
|
-
|
176
|
+
- name: Build Docker container
|
177
|
+
run: docker build -f ./apps/#{worker_name}/Dockerfile ./apps/#{worker_name} -t gcr.io/${{ secrets.SOULS_GCP_PROJECT_ID }}/${{secrets.SOULS_APP_NAME}}-#{worker_name}
|
185
178
|
|
186
|
-
|
187
|
-
|
179
|
+
- name: Push to Container Resistory
|
180
|
+
run: docker push gcr.io/${{ secrets.SOULS_GCP_PROJECT_ID }}/${{secrets.SOULS_APP_NAME}}-#{worker_name}
|
188
181
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
182
|
+
- name: Deploy to Cloud Run
|
183
|
+
run: |
|
184
|
+
gcloud run deploy souls-${{ secrets.SOULS_APP_NAME }}-#{worker_name} \\
|
185
|
+
--service-account=${{ secrets.SOULS_APP_NAME }}@${{ secrets.SOULS_GCP_PROJECT_ID }}.iam.gserviceaccount.com \\
|
186
|
+
--image=gcr.io/${{ secrets.SOULS_GCP_PROJECT_ID }}/${{secrets.SOULS_APP_NAME}}-#{worker_name} \\
|
187
|
+
--memory=4Gi \\
|
188
|
+
--region=${{ secrets.SOULS_GCP_REGION }} \\
|
189
|
+
--allow-unauthenticated \\
|
190
|
+
--platform=managed \\
|
191
|
+
--quiet \\
|
192
|
+
--concurrency=80 \\
|
193
|
+
--port=8080 \\
|
194
|
+
--set-cloudsql-instances=${{ secrets.SOULS_GCLOUDSQL_INSTANCE }} \\
|
195
|
+
--set-env-vars="SOULS_DB_USER=${{ secrets.SOULS_DB_USER }}" \\
|
196
|
+
--set-env-vars="SOULS_DB_PW=${{ secrets.SOULS_DB_PW }}" \\
|
197
|
+
--set-env-vars="SOULS_DB_HOST=${{ secrets.SOULS_DB_HOST }}" \\
|
198
|
+
--set-env-vars="SOULS_TZ=${{ secrets.SOULS_TZ }}" \\
|
199
|
+
--set-env-vars="SOULS_SECRET_KEY_BASE=${{ secrets.SOULS_SECRET_KEY_BASE }}" \\
|
200
|
+
--set-env-vars="SOULS_PROJECT_ID=${{ secrets.SOULS_GCP_PROJECT_ID }}"
|
208
201
|
TEXT
|
209
202
|
end
|
210
203
|
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
211
204
|
file_path
|
212
|
-
rescue StandardError => e
|
213
|
-
raise(StandardError, e)
|
214
205
|
end
|
215
206
|
|
216
|
-
def souls_config_init(worker_name
|
207
|
+
def souls_config_init(worker_name)
|
217
208
|
app_name = Souls.configuration.app
|
218
209
|
project_id = Souls.configuration.project_id
|
219
210
|
config_dir = "apps/#{worker_name}/config"
|
@@ -222,23 +213,23 @@ end
|
|
222
213
|
file_path = "#{config_dir}/souls.rb"
|
223
214
|
File.open(file_path, "w") do |f|
|
224
215
|
f.write(<<~TEXT)
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
216
|
+
Souls.configure do |config|
|
217
|
+
config.app = "#{app_name}"
|
218
|
+
config.project_id = "#{project_id}"
|
219
|
+
config.region = "asia-northeast1"
|
220
|
+
config.endpoint = "/endpoint"
|
221
|
+
config.strain = "worker"
|
222
|
+
config.fixed_gems = ["spring"]
|
223
|
+
config.workers = []
|
224
|
+
end
|
234
225
|
TEXT
|
235
226
|
end
|
236
227
|
rescue StandardError => e
|
237
228
|
puts(e)
|
238
229
|
end
|
239
230
|
|
240
|
-
def souls_helper_rbs(worker_name
|
241
|
-
file_dir = "./sig/#{worker_name}/app/utils
|
231
|
+
def souls_helper_rbs(worker_name)
|
232
|
+
file_dir = "./sig/#{worker_name}/app/utils"
|
242
233
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
243
234
|
file_path = "#{file_dir}/souls_helper.rbs"
|
244
235
|
File.open(file_path, "w") do |f|
|
@@ -278,7 +269,7 @@ end
|
|
278
269
|
end
|
279
270
|
end
|
280
271
|
|
281
|
-
def download_worker(worker_name
|
272
|
+
def download_worker(worker_name)
|
282
273
|
version = Souls.get_latest_version_txt(service_name: "worker").join(".")
|
283
274
|
file_name = "worker-v#{version}.tgz"
|
284
275
|
url = "https://storage.googleapis.com/souls-bucket/boilerplates/workers/#{file_name}"
|
@@ -289,7 +280,7 @@ end
|
|
289
280
|
FileUtils.rm(file_name)
|
290
281
|
end
|
291
282
|
|
292
|
-
def souls_worker_credit(worker_name
|
283
|
+
def souls_worker_credit(worker_name)
|
293
284
|
line = Paint["====================================", :yellow]
|
294
285
|
puts("\n")
|
295
286
|
puts(line)
|
@@ -4,9 +4,9 @@ module Souls
|
|
4
4
|
method_option :mailer, type: :boolean, aliases: "--mailer", default: false, desc: "Mailer Option"
|
5
5
|
def job(class_name)
|
6
6
|
if options[:mailer]
|
7
|
-
mailgun_mailer(class_name
|
7
|
+
mailgun_mailer(class_name)
|
8
8
|
else
|
9
|
-
create_job_mutation(class_name
|
9
|
+
create_job_mutation(class_name)
|
10
10
|
end
|
11
11
|
Souls::Generate.new.invoke(:job_rbs, [class_name], {})
|
12
12
|
Souls::Generate.new.invoke(:rspec_job, [class_name], {})
|
@@ -16,7 +16,7 @@ module Souls
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def create_job_mutation(class_name
|
19
|
+
def create_job_mutation(class_name)
|
20
20
|
file_dir = "./app/graphql/mutations/"
|
21
21
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
22
22
|
file_path = "#{file_dir}#{class_name.singularize}.rb"
|
@@ -44,7 +44,7 @@ module Souls
|
|
44
44
|
file_path
|
45
45
|
end
|
46
46
|
|
47
|
-
def mailgun_mailer(class_name
|
47
|
+
def mailgun_mailer(class_name)
|
48
48
|
file_dir = "./app/graphql/mutations/"
|
49
49
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
50
50
|
file_path = "#{file_dir}#{class_name.singularize}.rb"
|
@@ -3,18 +3,28 @@ module Souls
|
|
3
3
|
desc "manager [MANAGER_NAME]", "Generate GraphQL Mutation Template"
|
4
4
|
method_option :mutation, aliases: "--mutation", required: true, desc: "Mutation File Name"
|
5
5
|
def manager(class_name)
|
6
|
+
create_manager(class_name, options[:mutation])
|
7
|
+
Souls::Generate.new.invoke(:manager_rbs, [singularized_class_name], { mutation: options[:mutation] })
|
8
|
+
Souls::Generate.new.invoke(:rspec_manager, [singularized_class_name], { mutation: options[:mutation] })
|
9
|
+
rescue Thor::Error => e
|
10
|
+
raise(Thor::Error, e)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create_manager(class_name, mutation)
|
6
16
|
singularized_class_name = class_name.underscore.singularize
|
7
17
|
file_dir = "./app/graphql/mutations/managers/#{singularized_class_name}_manager"
|
8
18
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
9
|
-
file_path = "#{file_dir}/#{
|
19
|
+
file_path = "#{file_dir}/#{mutation}.rb"
|
10
20
|
raise(StandardError, "Already Exist!") if File.exist?(file_path)
|
11
21
|
|
12
22
|
File.open(file_path, "w") do |f|
|
13
23
|
f.write(<<~TEXT)
|
14
24
|
module Mutations
|
15
25
|
module Managers::#{singularized_class_name.camelize}Manager
|
16
|
-
class #{
|
17
|
-
description "#{
|
26
|
+
class #{mutation.underscore.camelize} < BaseMutation
|
27
|
+
description "#{mutation} description"
|
18
28
|
## Edit `argument` and `field`
|
19
29
|
argument :argument, String, required: true
|
20
30
|
|
@@ -32,11 +42,7 @@ module Souls
|
|
32
42
|
TEXT
|
33
43
|
end
|
34
44
|
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
35
|
-
Souls::Generate.new.invoke(:manager_rbs, [singularized_class_name], { mutation: options[:mutation] })
|
36
|
-
Souls::Generate.new.invoke(:rspec_manager, [singularized_class_name], { mutation: options[:mutation] })
|
37
45
|
file_path
|
38
|
-
rescue Thor::Error => e
|
39
|
-
raise(Thor::Error, e)
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|
@@ -21,7 +21,7 @@ module Souls
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
def create_mutation(class_name
|
24
|
+
def create_mutation(class_name)
|
25
25
|
singularized_class_name = class_name.singularize.underscore
|
26
26
|
file_dir = "./app/graphql/mutations/base/#{singularized_class_name}"
|
27
27
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
@@ -29,7 +29,7 @@ module Souls
|
|
29
29
|
raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
|
30
30
|
|
31
31
|
params = Souls.get_relation_params(class_name: singularized_class_name, col: "mutation")
|
32
|
-
File.open(file_path, "
|
32
|
+
File.open(file_path, "a") do |f|
|
33
33
|
f.write(<<~TEXT)
|
34
34
|
module Mutations
|
35
35
|
module Base::#{singularized_class_name.camelize}
|
@@ -91,7 +91,7 @@ module Souls
|
|
91
91
|
file_path
|
92
92
|
end
|
93
93
|
|
94
|
-
def update_mutation(class_name
|
94
|
+
def update_mutation(class_name)
|
95
95
|
singularized_class_name = class_name.singularize.underscore
|
96
96
|
file_dir = "./app/graphql/mutations/base/#{singularized_class_name}"
|
97
97
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
@@ -165,7 +165,7 @@ module Souls
|
|
165
165
|
end
|
166
166
|
|
167
167
|
# 3. Mutation - Delete
|
168
|
-
def delete_mutation(class_name
|
168
|
+
def delete_mutation(class_name)
|
169
169
|
file_path = "./app/graphql/mutations/base/#{class_name}/delete_#{class_name}.rb"
|
170
170
|
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
171
171
|
|
@@ -195,7 +195,7 @@ module Souls
|
|
195
195
|
end
|
196
196
|
|
197
197
|
# 4. Mutation - Destroy Delete
|
198
|
-
def destroy_delete_mutation(class_name
|
198
|
+
def destroy_delete_mutation(class_name)
|
199
199
|
file_path = "./app/graphql/mutations/base/#{class_name}/destroy_delete_#{class_name}.rb"
|
200
200
|
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
201
201
|
|
@@ -13,7 +13,7 @@ module Souls
|
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
def create_rbs_mutation(class_name
|
16
|
+
def create_rbs_mutation(class_name)
|
17
17
|
file_path = ""
|
18
18
|
Dir.chdir(Souls.get_mother_path.to_s) do
|
19
19
|
file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
|
@@ -96,14 +96,14 @@ module Souls
|
|
96
96
|
raise(Thor::Error, e)
|
97
97
|
end
|
98
98
|
|
99
|
-
def update_rbs_mutation(class_name
|
99
|
+
def update_rbs_mutation(class_name)
|
100
100
|
file_path = ""
|
101
101
|
Dir.chdir(Souls.get_mother_path.to_s) do
|
102
102
|
file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
|
103
103
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
104
104
|
file_path = "#{file_dir}/update_#{class_name}.rbs"
|
105
105
|
params = Souls.get_relation_params(class_name: class_name, col: "mutation")
|
106
|
-
params[:params]
|
106
|
+
params[:params] < { column_name: "id", type: "string", array: false }
|
107
107
|
File.open(file_path, "w") do |f|
|
108
108
|
f.write(<<~TEXT)
|
109
109
|
module Mutations
|
@@ -175,7 +175,7 @@ module Souls
|
|
175
175
|
file_path
|
176
176
|
end
|
177
177
|
|
178
|
-
def delete_rbs_mutation(class_name
|
178
|
+
def delete_rbs_mutation(class_name)
|
179
179
|
file_path = ""
|
180
180
|
Dir.chdir(Souls.get_mother_path.to_s) do
|
181
181
|
file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
|
@@ -206,7 +206,7 @@ module Souls
|
|
206
206
|
raise(Thor::Error, e)
|
207
207
|
end
|
208
208
|
|
209
|
-
def destroy_delete_rbs_mutation(class_name
|
209
|
+
def destroy_delete_rbs_mutation(class_name)
|
210
210
|
file_path = ""
|
211
211
|
Dir.chdir(Souls.get_mother_path.to_s) do
|
212
212
|
file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
|
@@ -6,10 +6,10 @@ module Souls
|
|
6
6
|
file_path = "./spec/queries/#{singularized_class_name}_spec.rb"
|
7
7
|
return "RspecQuery already exist! #{file_path}" if File.exist?(file_path)
|
8
8
|
|
9
|
-
rspec_query_head(
|
10
|
-
rspec_query_after_head(
|
11
|
-
rspec_query_params(
|
12
|
-
rspec_query_end(
|
9
|
+
rspec_query_head(singularized_class_name)
|
10
|
+
rspec_query_after_head(singularized_class_name)
|
11
|
+
rspec_query_params(singularized_class_name)
|
12
|
+
rspec_query_end(singularized_class_name)
|
13
13
|
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
14
14
|
file_path
|
15
15
|
rescue Thor::Error => e
|
@@ -18,7 +18,7 @@ module Souls
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def rspec_query_head(class_name
|
21
|
+
def rspec_query_head(class_name)
|
22
22
|
file_dir = "./spec/queries/"
|
23
23
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
24
24
|
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
@@ -30,8 +30,10 @@ module Souls
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def rspec_query_after_head(class_name
|
33
|
+
def rspec_query_after_head(class_name)
|
34
34
|
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
35
|
+
return unless File.exist?(file_path)
|
36
|
+
|
35
37
|
path = "./db/schema.rb"
|
36
38
|
@on = false
|
37
39
|
@user_exist = false
|
@@ -78,8 +80,10 @@ module Souls
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
|
-
def rspec_query_params(class_name
|
83
|
+
def rspec_query_params(class_name)
|
82
84
|
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
85
|
+
return unless File.exist?(file_path)
|
86
|
+
|
83
87
|
path = "./db/schema.rb"
|
84
88
|
@on = false
|
85
89
|
File.open(file_path, "a") do |new_line|
|
@@ -123,7 +127,7 @@ module Souls
|
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
126
|
-
def rspec_query_end(class_name
|
130
|
+
def rspec_query_end(class_name)
|
127
131
|
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
128
132
|
path = "./db/schema.rb"
|
129
133
|
@on = false
|
@@ -6,10 +6,10 @@ module Souls
|
|
6
6
|
file_path = "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
7
7
|
return "Resolver already exist! #{file_path}" if File.exist?(file_path)
|
8
8
|
|
9
|
-
rspec_resolver_head(
|
10
|
-
rspec_resolver_after_head(
|
11
|
-
rspec_resolver_params(
|
12
|
-
rspec_resolver_end(
|
9
|
+
rspec_resolver_head(singularized_class_name)
|
10
|
+
rspec_resolver_after_head(singularized_class_name)
|
11
|
+
rspec_resolver_params(singularized_class_name)
|
12
|
+
rspec_resolver_end(singularized_class_name)
|
13
13
|
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
14
14
|
file_path
|
15
15
|
rescue Thor::Error => e
|
@@ -18,7 +18,7 @@ module Souls
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def rspec_resolver_head(class_name
|
21
|
+
def rspec_resolver_head(class_name)
|
22
22
|
file_dir = "./spec/resolvers/"
|
23
23
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
24
24
|
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
@@ -30,7 +30,7 @@ module Souls
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def rspec_resolver_after_head(class_name
|
33
|
+
def rspec_resolver_after_head(class_name)
|
34
34
|
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
35
35
|
path = "./db/schema.rb"
|
36
36
|
@on = false
|
@@ -86,7 +86,7 @@ module Souls
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
def rspec_resolver_params(class_name
|
89
|
+
def rspec_resolver_params(class_name)
|
90
90
|
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
91
91
|
path = "./db/schema.rb"
|
92
92
|
@on = false
|
@@ -142,7 +142,7 @@ module Souls
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
def rspec_resolver_end(class_name
|
145
|
+
def rspec_resolver_end(class_name)
|
146
146
|
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
147
147
|
path = "./db/schema.rb"
|
148
148
|
@on = false
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative "../cli_exception"
|
2
|
+
|
1
3
|
module Souls
|
2
4
|
class Update < Thor
|
3
5
|
desc "create_mutation [CLASS_NAME]", "Update GraphQL Type from schema.rb"
|
@@ -5,33 +7,13 @@ module Souls
|
|
5
7
|
singularized_class_name = class_name.singularize.underscore
|
6
8
|
new_cols = Souls.get_columns_num(class_name: singularized_class_name)
|
7
9
|
dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
|
8
|
-
new_file_path = "tmp/create_mutation.rb"
|
9
10
|
file_path = "#{dir_name}/create_#{singularized_class_name}.rb"
|
10
|
-
|
11
|
-
|
12
|
-
File.open(new_file_path, "w") do |new_line|
|
13
|
-
f.each_line do |line|
|
14
|
-
new_line.write(line)
|
15
|
-
next unless line.include?("argument") && !argument
|
16
|
-
|
17
|
-
new_cols.each do |col|
|
18
|
-
type = Souls.type_check(col[:type])
|
19
|
-
type = "[#{type}]" if col[:array]
|
20
|
-
args = check_mutation_argument(class_name: class_name)
|
21
|
-
next if args.include?(col[:column_name])
|
22
|
-
next if col[:column_name] == "created_at" || col[:column_name] == "updated_at"
|
11
|
+
raise Souls::CLIException.new("File #{file_path} is missing. Please recreate it and then run this command again.") unless
|
12
|
+
File.exist? file_path
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
argument = true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
FileUtils.rm(file_path)
|
31
|
-
FileUtils.mv(new_file_path, file_path)
|
14
|
+
mutation_argument = check_mutation_argument(class_name, "create")
|
15
|
+
overwrite_class_file(mutation_argument, file_path, new_cols)
|
32
16
|
puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
33
|
-
rescue Thor::Error => e
|
34
|
-
raise(Thor::Error, e)
|
35
17
|
end
|
36
18
|
|
37
19
|
desc "update_mutation [CLASS_NAME]", "Update GraphQL Type from schema.rb"
|
@@ -39,38 +21,41 @@ module Souls
|
|
39
21
|
singularized_class_name = class_name.singularize.underscore
|
40
22
|
new_cols = Souls.get_columns_num(class_name: singularized_class_name)
|
41
23
|
dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
|
42
|
-
new_file_path = "tmp/update_mutation.rb"
|
43
24
|
file_path = "#{dir_name}/update_#{singularized_class_name}.rb"
|
44
|
-
|
45
|
-
|
46
|
-
File.open(new_file_path, "w") do |new_line|
|
47
|
-
f.each_line do |line|
|
48
|
-
new_line.write(line)
|
49
|
-
next unless line.include?("argument") && !argument
|
25
|
+
raise Souls::CLIException.new("File #{file_path} is missing. Please recreate it and then run this command again.") unless
|
26
|
+
File.exist? file_path
|
50
27
|
|
51
|
-
|
52
|
-
|
53
|
-
type = "[#{type}]" if col[:array]
|
54
|
-
args = check_mutation_argument(class_name: class_name, action: "update")
|
55
|
-
next if args.include?(col[:column_name])
|
56
|
-
next if col[:column_name] == "created_at" || col[:column_name] == "updated_at"
|
28
|
+
mutation_argument = check_mutation_argument(class_name, "update")
|
29
|
+
overwrite_class_file(mutation_argument, file_path, new_cols)
|
57
30
|
|
58
|
-
new_line.write(" argument :#{col[:column_name]}, #{type}, required: false\n")
|
59
|
-
end
|
60
|
-
argument = true
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
FileUtils.rm(file_path)
|
65
|
-
FileUtils.mv(new_file_path, file_path)
|
66
31
|
puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
67
|
-
rescue Thor::Error => e
|
68
|
-
raise(Thor::Error, e)
|
69
32
|
end
|
70
33
|
|
71
34
|
private
|
72
35
|
|
73
|
-
def
|
36
|
+
def overwrite_class_file(mutation_argument, file_path, new_cols)
|
37
|
+
write_txt = String.new
|
38
|
+
File.open(file_path, "r") do |f|
|
39
|
+
f.each_line do |line|
|
40
|
+
write_txt << line
|
41
|
+
next if new_cols.empty? || !line.strip.start_with?("argument")
|
42
|
+
|
43
|
+
until new_cols.empty?
|
44
|
+
col = new_cols.pop
|
45
|
+
type = Souls.type_check(col[:type])
|
46
|
+
type = "[#{type}]" if col[:array]
|
47
|
+
args = mutation_argument
|
48
|
+
next if args.include?(col[:column_name])
|
49
|
+
next if col[:column_name] == "created_at" || col[:column_name] == "updated_at"
|
50
|
+
|
51
|
+
write_txt << " argument :#{col[:column_name]}, #{type}, required: false\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
File.open(file_path, "w") { |f| f.write(write_txt) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_mutation_argument(class_name, action)
|
74
59
|
singularized_class_name = class_name.singularize.underscore
|
75
60
|
dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
|
76
61
|
file_path = "#{dir_name}/#{action}_#{singularized_class_name}.rb"
|
data/lib/souls/utils/index.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Souls
|
2
2
|
module Utils
|
3
3
|
def get_mother_path
|
4
|
-
|
4
|
+
Dir.pwd.split(Souls.configuration.app)[0] + Souls.configuration.app
|
5
5
|
end
|
6
6
|
|
7
7
|
def get_api_path
|
8
|
-
|
8
|
+
Dir.pwd.split(Souls.configuration.app)[0] + Souls.configuration.app + "/apps/api"
|
9
9
|
end
|
10
10
|
|
11
11
|
def type_check(type)
|
data/lib/souls/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
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: 1.
|
4
|
+
version: 1.4.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-11-
|
13
|
+
date: 2021-11-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- exe/souls
|
128
128
|
- lib/souls.rb
|
129
129
|
- lib/souls/cli.rb
|
130
|
+
- lib/souls/cli/cli_exception.rb
|
130
131
|
- lib/souls/cli/console/index.rb
|
131
132
|
- lib/souls/cli/create/index.rb
|
132
133
|
- lib/souls/cli/db/create_migration_rbs.rb
|