souls 1.3.6 → 1.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67562406559d88c75d9c4f6dd7364524b947a0b02cdefd241b03c0a606f03f32
4
- data.tar.gz: f7dc79a83361b8fc49675953760f2552cefbd46b39aa83e06c5fc3282283f91c
3
+ metadata.gz: dbb16141ab19f58659aeb2e45587f68cf946f86a0560fd16f795f7a1d9a62a6c
4
+ data.tar.gz: 381b9878c2e9aae9377f8ccf89527f205948f771c5488b0514b236090e7b685f
5
5
  SHA512:
6
- metadata.gz: 697e0be85783dc17f4e4a283ab8b3bd46b9cccc693bdb170f1e4b9d33f0f221a8ac125ff21319e895a2b7f1233848d74b124b9a361041d1b583bd2b3ee4b4556
7
- data.tar.gz: c24ba7aaba182beed99d69dd1159897a5d2164457f24f75ce0a3f0c2f9c6eab14384e181d7049054bc345b847f31615a113f45a50c3cf36ef5503192e869dc48
6
+ metadata.gz: 2db6f4571323641f101d9fbcc4c8323346bb7e585b027338a2404bd8205379bb8cb8d1723f549e6d09fdebe0d390f7d985d72a1de1649822babb61ae75fc9751
7
+ data.tar.gz: 3dbb68d38591725177e54af26172d6476bf6fe802b097df4bb840c0d4d9fac8fa1a4f939e36ad94e53f25987b63c5be0a17b335dbe87b351e69a01f6a6359d49
data/README.md CHANGED
@@ -11,12 +11,16 @@
11
11
  </a>
12
12
  <a aria-label="Downloads Number" href="https://rubygems.org/gems/souls">
13
13
  <img alt="" src="https://badgen.net/rubygems/dt/souls">
14
+ </a>
15
+ <a aria-label="Test" href="https://rubygems.org/gems/souls">
16
+ <img alt="" src="https://github.com/elsoul/souls/actions/workflows/gem-test.yml/badge.svg">
14
17
  </a>
15
18
  <a aria-label="License" href="https://github.com/elsoul/souls/blob/master/LICENSE.txt">
16
19
  <img alt="" src="https://badgen.net/badge/license/Apache/blue">
17
20
  </a>
18
21
  </p>
19
22
 
23
+
20
24
  ## SOULs Serverless Application Framework Document
21
25
 
22
26
  - [Go to SOULs Document](https://souls.elsoul.nl/)
@@ -0,0 +1,10 @@
1
+ module Souls
2
+ class CLIException < StandardError
3
+ attr_reader :message
4
+
5
+ def initialize(message)
6
+ super
7
+ @message = message
8
+ end
9
+ end
10
+ end
@@ -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
- case options[:env]
7
- when "production"
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(worker_name: options[:name])
16
- souls_conf_update(worker_name: souls_worker_name)
17
- souls_conf_update(worker_name: souls_worker_name, strain: "api")
18
- workflow(worker_name: options[:name])
19
- procfile(worker_name: options[:name], port: port)
20
- mother_procfile(worker_name: options[:name])
21
- souls_config_init(worker_name: options[:name])
22
- steepfile(worker_name: options[:name])
23
- souls_helper_rbs(worker_name: options[:name])
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(worker_name: options[:name])
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: "mailer")
32
+ def steepfile(worker_name)
35
33
  file_path = "./Steepfile"
36
- new_file_path = "config/Steepfile"
37
- File.open(new_file_path, "w") do |new_line|
38
- File.open(file_path, "r") do |f|
39
- f.each_line do |line|
40
- case line.strip.to_s
41
- when "end"
42
- ["app", "db/seeds.rb", "constants", "app.rb"].each do |path|
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
- FileUtils.rm(file_path)
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: "mailer", port: 3000)
57
- file_dir = "apps/#{worker_name}"
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: "mailer")
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: "", strain: "mother")
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
- new_line.write(line) unless worker_switch
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
- next unless worker_switch
76
+ unless worker_switch
77
+ write_txt += line
78
+ next
79
+ end
86
80
 
87
- new_line.write(" config.workers = [\n")
88
- workers.each do |worker|
89
- new_line.write(<<-TEXT)
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
- TEXT
96
- end
97
- break
89
+ TEXT
98
90
  end
91
+ break
99
92
  end
100
- new_line.write(<<-TEXT)
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
- TEXT
109
- end
110
- FileUtils.rm(file_path)
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
- name: #{worker_name_camelize}
115
+ name: #{worker_name_camelize}
123
116
 
124
- on:
125
- push:
126
- branches:
127
- - main
128
- paths:
129
- - "apps/#{worker_name}/**"
130
- - ".github/workflows/#{worker_name}.yml"
117
+ on:
118
+ push:
119
+ branches:
120
+ - main
121
+ paths:
122
+ - "apps/#{worker_name}/**"
123
+ - ".github/workflows/#{worker_name}.yml"
131
124
 
132
- jobs:
133
- build:
125
+ jobs:
126
+ build:
134
127
 
135
- runs-on: ubuntu-20.04
128
+ runs-on: ubuntu-20.04
136
129
 
137
- services:
138
- db:
139
- image: postgres:13
140
- ports: ["5433:5432"]
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
- PGHOST: 127.0.0.1
158
- PGUSER: postgres
159
- RACK_ENV: test
160
- run: |
161
- sudo apt-get -yqq install libpq-dev
162
- cd apps/#{worker_name}
163
- gem install bundler
164
- bundle install --jobs 4 --retry 3
165
- bundle exec rake db:create RACK_ENV=test
166
- bundle exec rake db:migrate RACK_ENV=test
167
- bundle exec rspec
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
- - name: Checkout the repository
170
- uses: actions/checkout@v2
162
+ - name: Checkout the repository
163
+ uses: actions/checkout@v2
171
164
 
172
- - name: GCP Authenticate
173
- uses: google-github-actions/setup-gcloud@master
174
- with:
175
- version: "323.0.0"
176
- project_id: ${{ secrets.SOULS_GCP_PROJECT_ID }}
177
- service_account_key: ${{ secrets.SOULS_GCP_SA_KEY }}
178
- export_default_credentials: true
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
- - name: Configure Docker
181
- run: gcloud auth configure-docker --quiet
173
+ - name: Configure Docker
174
+ run: gcloud auth configure-docker --quiet
182
175
 
183
- - name: Build Docker container
184
- 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}
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
- - name: Push to Container Resistory
187
- run: docker push gcr.io/${{ secrets.SOULS_GCP_PROJECT_ID }}/${{secrets.SOULS_APP_NAME}}-#{worker_name}
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
- - name: Deploy to Cloud Run
190
- run: |
191
- gcloud run deploy souls-${{ secrets.SOULS_APP_NAME }}-#{worker_name} \\
192
- --service-account=${{ secrets.SOULS_APP_NAME }}@${{ secrets.SOULS_GCP_PROJECT_ID }}.iam.gserviceaccount.com \\
193
- --image=gcr.io/${{ secrets.SOULS_GCP_PROJECT_ID }}/${{secrets.SOULS_APP_NAME}}-#{worker_name} \\
194
- --memory=4Gi \\
195
- --region=${{ secrets.SOULS_GCP_REGION }} \\
196
- --allow-unauthenticated \\
197
- --platform=managed \\
198
- --quiet \\
199
- --concurrency=80 \\
200
- --port=8080 \\
201
- --set-cloudsql-instances=${{ secrets.SOULS_GCLOUDSQL_INSTANCE }} \\
202
- --set-env-vars="SOULS_DB_USER=${{ secrets.SOULS_DB_USER }}" \\
203
- --set-env-vars="SOULS_DB_PW=${{ secrets.SOULS_DB_PW }}" \\
204
- --set-env-vars="SOULS_DB_HOST=${{ secrets.SOULS_DB_HOST }}" \\
205
- --set-env-vars="SOULS_TZ=${{ secrets.SOULS_TZ }}" \\
206
- --set-env-vars="SOULS_SECRET_KEY_BASE=${{ secrets.SOULS_SECRET_KEY_BASE }}" \\
207
- --set-env-vars="SOULS_PROJECT_ID=${{ secrets.SOULS_GCP_PROJECT_ID }}"
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: "mailer")
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
- Souls.configure do |config|
226
- config.app = "#{app_name}"
227
- config.project_id = "#{project_id}"
228
- config.region = "asia-northeast1"
229
- config.endpoint = "/endpoint"
230
- config.strain = "worker"
231
- config.fixed_gems = ["spring"]
232
- config.workers = []
233
- end
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: "mailer")
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: "mailer")
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: "mailer")
283
+ def souls_worker_credit(worker_name)
293
284
  line = Paint["====================================", :yellow]
294
285
  puts("\n")
295
286
  puts(line)
@@ -24,8 +24,9 @@ module Souls
24
24
  SOULS_DB_HOST=#{get_sql_ip.strip}
25
25
  SOULS_DB_PW=#{options[:root_password]}
26
26
  SOULS_DB_USER=postgres
27
- SOULS_TZ="#{region_to_timezone(region: region)}"
27
+ SOULS_GCP_PROJECT_ID=#{project_id}
28
28
  SOULS_SECRET_KEY_BASE="#{SecureRandom.base64(64)}"
29
+ TZ="#{region_to_timezone(region: region)}"
29
30
  TEXT
30
31
  end
31
32
  end
@@ -40,11 +41,12 @@ module Souls
40
41
  SOULS_GCP_PROJECT_ID=#{project_id}
41
42
  SOULS_GCP_REGION=#{region}
42
43
  SOULS_GCLOUDSQL_INSTANCE="#{project_id}:#{region}:#{instance_name}"
43
- SOULS_TZ="#{region_to_timezone(region: region)}"
44
44
  SOULS_SECRET_KEY_BASE="#{SecureRandom.base64(64)}"
45
+ TZ="#{region_to_timezone(region: region)}"
45
46
  TEXT
46
47
  end
47
48
  end
49
+ Souls::Github.new
48
50
  rescue Thor::Error => e
49
51
  raise(Thor::Error, e)
50
52
  end
@@ -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: class_name)
7
+ mailgun_mailer(class_name)
8
8
  else
9
- create_job_mutation(class_name: 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: "send-mailer")
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: "mailer")
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}/#{options[:mutation]}.rb"
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 #{options[:mutation].underscore.camelize} < BaseMutation
17
- description "#{options[:mutation]} 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: "user")
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, "w") do |f|
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: "user")
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: "user")
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: "user")
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: "user")
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: "user")
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] << { column_name: "id", type: "string", array: false }
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: "user")
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: "user")
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(class_name: singularized_class_name)
10
- rspec_query_after_head(class_name: singularized_class_name)
11
- rspec_query_params(class_name: singularized_class_name)
12
- rspec_query_end(class_name: singularized_class_name)
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: "user")
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: "user")
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: "user")
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: "user")
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(class_name: singularized_class_name)
10
- rspec_resolver_after_head(class_name: singularized_class_name)
11
- rspec_resolver_params(class_name: singularized_class_name)
12
- rspec_resolver_end(class_name: singularized_class_name)
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: "user")
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: "user")
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: "user")
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: "user")
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
@@ -21,7 +21,7 @@ module Souls
21
21
  git submodule add -f https://github.com/ruby/gem_rbs_collection.git vendor/rbs/gem_rbs_collection
22
22
  "
23
23
  )
24
- souls_api_credit(app_name: app_name, service_name: service_name)
24
+ souls_api_credit(app_name)
25
25
  end
26
26
 
27
27
  private
@@ -159,14 +159,13 @@ module Souls
159
159
  system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/Procfile")
160
160
  system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/Steepfile")
161
161
  system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/gitignore")
162
- system("cd #{app_name} && curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/.env.production.sample")
163
162
  system("cd #{app_name} && mv gitignore .gitignore")
164
163
  system("cd #{app_name} && bundle")
165
164
  system("cd #{app_name}/apps/api && bundle")
166
165
  FileUtils.rm(sig_name)
167
166
  end
168
167
 
169
- def souls_api_credit(app_name: "souls", service_name: "api")
168
+ def souls_api_credit(app_name)
170
169
  line = Paint["====================================", :yellow]
171
170
  puts("\n")
172
171
  puts(line)
@@ -2,6 +2,8 @@ module Souls
2
2
  class CLI < Thor
3
3
  desc "release", "Release Gem"
4
4
  def release
5
+ raise(StandardError, "hey! It's Broken!") unless system("rspec")
6
+
5
7
  system("gem install souls")
6
8
  sleep(3)
7
9
  current_souls_ver = Souls::VERSION.strip.split(".").map(&:to_i)
@@ -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
- argument = false
11
- File.open(file_path) do |f|
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
- new_line.write(" argument :#{col[:column_name]}, #{type}, required: false\n")
25
- end
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
- argument = false
45
- File.open(file_path) do |f|
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
- new_cols.each do |col|
52
- type = Souls.type_check(col[:type])
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 check_mutation_argument(class_name: "user", action: "create")
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"
@@ -1,11 +1,11 @@
1
1
  module Souls
2
2
  module Utils
3
3
  def get_mother_path
4
- FileUtils.pwd.split(Souls.configuration.app)[0] + Souls.configuration.app
4
+ Dir.pwd.split(Souls.configuration.app)[0] + Souls.configuration.app
5
5
  end
6
6
 
7
7
  def get_api_path
8
- FileUtils.pwd.split(Souls.configuration.app)[0] + Souls.configuration.app + "/apps/api"
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,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "1.3.6".freeze
2
+ VERSION = "1.4.1".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 1.3.6
1
+ 1.4.1
@@ -1 +1 @@
1
- 1.3.6
1
+ 1.4.1
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.3.6
4
+ version: 1.4.1
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-01 00:00:00.000000000 Z
13
+ date: 2021-11-05 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