souls 0.26.7 → 0.27.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07a268eb135f4ca4ea45eb8249231c9fc816695012de869aeb4b1df50fa2b25f
4
- data.tar.gz: 994e784b8ecf513a97df0c2227a96b26c115d1dacc85c989d002e9f714deb204
3
+ metadata.gz: 0c9fa990d327564396a323f48715af865bfdd1e825cbf2538dbb3318675c08aa
4
+ data.tar.gz: b403de454c2c6bc8619201a36af1e7d80ece07e6561fc149e32cd4821e20b021
5
5
  SHA512:
6
- metadata.gz: 27f41b2976489276d4597fce40e333f2bb314c34a6aa89178d4a74bc3ea9a45d74d635583a82c62ab8e6b2e11a836172d71afbb7edbb3cf01ba48d50d47d05b6
7
- data.tar.gz: 2a2c09c4df16367eebd6144f2955d12782d3d6add3f7d37ebfa404ef02bd7e449775c54cc2698466ab7b1b9ff3559d9a2f8d84f08f7e7f27c4d6502f46e7ce57
6
+ metadata.gz: c395c5b01a546475640257ac32f05fe3f59f4a8a4c42a040f1ef3cf9543b082fe9b9b5e2f9ba094dd683e9f30d59c15b7e1e73ac27231c56b65f1814cf052b9a
7
+ data.tar.gz: 50edef7da97873ec4a2521051f3bcb77e8bef07bd63e25ef53052379eacc83bf8adc96eb6dcf4167ad1a243e7fb2a2f78512828d3d5620ebe22b208a39a65976
data/exe/souls CHANGED
@@ -55,8 +55,13 @@ begin
55
55
  end
56
56
  when "release"
57
57
  Souls::Release.return_method
58
- when "update"
59
- puts(Paint["Coming soon..", :cyan])
58
+ when "model:update"
59
+ status = Paint["Updating Models...", :yellow]
60
+ Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
61
+ Whirly.status = status
62
+ Souls.update_models
63
+ Whirly.status = "Done!"
64
+ end
60
65
  when "add"
61
66
  graphql_class = ARGV[1]
62
67
  case graphql_class
data/lib/souls.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "souls/init"
4
4
  require_relative "souls/generate"
5
5
  require_relative "souls/gcloud"
6
6
  require_relative "souls/release"
7
+ require "date"
7
8
  require "dotenv/load"
8
9
  require "json"
9
10
  require "fileutils"
@@ -191,6 +192,7 @@ module Souls
191
192
 
192
193
  system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{file_name}")
193
194
  system("gsutil cp #{service_name}.tgz #{bucket_url}/#{service_name.pluralize}/#{release_name}")
195
+ system("gsutil cp .rubocop.yml #{bucket_url}/.rubocop.yml")
194
196
  FileUtils.rm("#{service_name}.tgz")
195
197
  "#{service_name}-v#{new_ver} Succefully Stored to GCS! "
196
198
  end
@@ -282,6 +284,86 @@ module Souls
282
284
  puts(Paint["\nSuccessfully Updated #{service_name} Gemfile!", :green])
283
285
  end
284
286
 
287
+ def update_models
288
+ current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
289
+ permitted_dirs = %w[worker api]
290
+ unless permitted_dirs.include?(current_dir_name)
291
+ raise(StandardError, "You are at wrong directory!Go to API or Worker Directory!")
292
+ end
293
+
294
+ cp_dir = get_models_path(service_name: current_dir_name)
295
+ cp_dir.each do |path|
296
+ cp_and_dl_files(api_dir: path[:api], worker_dir: path[:worker])
297
+ end
298
+ end
299
+
300
+ def cp_and_dl_files(api_dir: "", worker_dir: "")
301
+ if Dir["#{worker_dir}/*.rb"].blank?
302
+
303
+ api_latest_date = 1
304
+ worker_latest_date = 0
305
+ else
306
+ api_file_data = file_diff(Dir["#{api_dir}/*.rb"])
307
+ worker_file_data = file_diff(Dir["#{worker_dir}/*.rb"])
308
+
309
+ api_latest_date = Date.parse(api_file_data.max)
310
+ worker_latest_date = Date.parse(worker_file_data.max)
311
+ end
312
+
313
+ if api_latest_date < worker_latest_date
314
+ FileUtils.rm_rf(api_dir) if Dir.exist?(api_dir)
315
+ FileUtils.mkdir(api_dir) unless Dir.exist?(api_dir)
316
+ system("cp -r #{worker_dir}/* #{api_dir}")
317
+ else
318
+ FileUtils.rm_rf(worker_dir) if Dir.exist?(worker_dir)
319
+ FileUtils.mkdir(worker_dir) unless Dir.exist?(worker_dir)
320
+ system("cp -r #{api_dir}/* #{worker_dir}")
321
+ end
322
+ end
323
+
324
+ def get_models_path(service_name: "api")
325
+ case service_name
326
+ when "api"
327
+ api_path = "."
328
+ worker_path = "../worker"
329
+ when "worker"
330
+ api_path = "../api"
331
+ worker_path = "."
332
+ end
333
+ [
334
+ {
335
+ api: "#{api_path}/db",
336
+ worker: "#{worker_path}/db"
337
+ },
338
+ {
339
+ api: "#{api_path}/app/models",
340
+ worker: "#{worker_path}/app/models"
341
+ },
342
+ {
343
+ api: "#{api_path}/spec/factories",
344
+ worker: "#{worker_path}/spec/factories"
345
+ }
346
+ ]
347
+ end
348
+
349
+ def file_diff(paths = [])
350
+ paths.map do |path|
351
+ stat(path)[:last_update]
352
+ end
353
+ end
354
+
355
+ def stat(path)
356
+ s = File::Stat.new(path)
357
+ last_update = s.mtime.to_s
358
+ last_status_change = s.ctime.to_s
359
+ last_access = s.atime.to_s
360
+ {
361
+ last_update: last_update,
362
+ last_status_change: last_status_change,
363
+ last_access: last_access
364
+ }
365
+ end
366
+
285
367
  def detect_change
286
368
  git_status = `git status`
287
369
  result =
@@ -300,14 +382,13 @@ module Souls
300
382
  end
301
383
 
302
384
  class Configuration
303
- attr_accessor :app, :strain, :project_id, :worker_repo, :api_repo, :worker_endpoint, :fixed_gems
385
+ attr_accessor :app, :strain, :project_id, :github_repo, :worker_endpoint, :fixed_gems
304
386
 
305
387
  def initialize
306
388
  @app = nil
307
389
  @project_id = nil
308
390
  @strain = nil
309
- @worker_repo = nil
310
- @api_repo = nil
391
+ @github_repo = nil
311
392
  @worker_endpoint = nil
312
393
  @fixed_gems = nil
313
394
  end
@@ -16,6 +16,41 @@ module Souls
16
16
  )
17
17
  end
18
18
 
19
+ def export_key_to_console
20
+ github_repo = Souls.configuration.github_repo || "elsoul/souls"
21
+ file_path = "config/keyfile.json"
22
+ puts(Paint["======= below(ここから)=======", :cyan])
23
+ text = []
24
+ File.open(file_path, "r") do |line|
25
+ line.each_line do |l|
26
+ text << l
27
+ end
28
+ end
29
+ key = text.join(",").gsub(/^,/, "").chomp!
30
+ puts(Paint[key, :white])
31
+ puts(Paint["======= above(ここまで)=======", :cyan])
32
+ github_secret_url = "https://github.com/#{github_repo}/#{app_name}/settings/secrets/actions"
33
+ souls_doc_url = "https://souls.elsoul.nl/docs/chapter2/#43-github-シークレットキーの登録"
34
+ txt1 = <<~TEXT
35
+
36
+ ⬆⬆⬆ Copy the service account key above ⬆⬆⬆⬆
37
+
38
+ And
39
+
40
+ Go to %{yellow_text}
41
+
42
+ Reference: %{yellow_text2}
43
+ TEXT
44
+ puts(
45
+ Paint % [
46
+ txt1,
47
+ :white,
48
+ { yellow_text: [github_secret_url, :yellow], yellow_text2: [souls_doc_url, :yellow] }
49
+ ]
50
+ )
51
+ fileutils.rm(file_path)
52
+ end
53
+
19
54
  def add_service_account_role(service_account: "souls-app", project_id: "souls-app", role: "roles/firebase.admin")
20
55
  system(
21
56
  "gcloud projects add-iam-policy-binding #{project_id} \
@@ -4,6 +4,13 @@ module Souls
4
4
  def return_method(args)
5
5
  method = args[1]
6
6
  case method
7
+ when "get_iam_key"
8
+ app_name = Souls.configuration.app
9
+ project_id = Souls.configuration.project_id
10
+ Souls::Gcloud.create_service_account(service_account: app_name)
11
+ Souls::Gcloud.create_service_account_key(service_account: app_name, project_id: project_id)
12
+ Souls::Gcloud.export_key_to_console
13
+ Souls::Gcloud.enable_permissions
7
14
  when "auth_login"
8
15
  project_id = Souls.configuration.project_id
9
16
  Souls::Gcloud.auth_login(project_id: project_id)
data/lib/souls/init.rb CHANGED
@@ -93,6 +93,7 @@ module Souls
93
93
  system("curl -OL #{url}")
94
94
  system("mkdir -p #{app_name}/apps/#{service_name}")
95
95
  system("tar -zxvf ./#{file_name} -C #{app_name}/apps/")
96
+ system("curl -OL https://storage.googleapis.com/souls-bucket/boilerplates/.rubocop.yml #{app_name}")
96
97
  FileUtils.rm(file_name)
97
98
  end
98
99
 
@@ -135,6 +136,9 @@ module Souls
135
136
 
136
137
  def self.download_worker
137
138
  current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
139
+ wrong_dir = %w[apps api worker]
140
+ raise(StandardError, "You are at wrong directory!Go to Mother Directory!") if wrong_dir.include?(current_dir_name)
141
+
138
142
  version = Souls.get_latest_version_txt(service_name: "worker").join(".")
139
143
  file_name = "worker-v#{version}.tgz"
140
144
  url = "https://storage.googleapis.com/souls-bucket/boilerplates/workers/#{file_name}"
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "0.26.7".freeze
2
+ VERSION = "0.27.0".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.5.7
1
+ 0.6.0
@@ -1 +1 @@
1
- 0.5.7
1
+ 0.6.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: 0.26.7
4
+ version: 0.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI