lolipop-mc-starter-rails 0.4.1 → 0.5.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: 43d3ac2f3a32ff600b9e05120acfb616abbd3531369053f9f186afbeca467bff
4
- data.tar.gz: bc5855689c6131cd4f2c768a226a709e1538ab9e48e84ee70d1365c2c789f62e
3
+ metadata.gz: 5c99ebc6101e516e3543ad91275a29684ed64fe9c9bcaa3b8e0dcb74e5ead9d6
4
+ data.tar.gz: c7a05b26a3591f44cfc3feab657730258c55c33f079941170887ce8a0f0ca84b
5
5
  SHA512:
6
- metadata.gz: 3393923238e1e0502380649a90df57f4e090a226d4f3bdc460ea912642b117a9db47a6153bce990b45d702daddbe4b3234643c39cd0e80a709d5d3116bfbdf57
7
- data.tar.gz: 9fc6fa9a14ff1781796c78a9f6f27bded933b66782ac7db7b1e11f2936b409fc621a6e52b4ec7e9cae4e56bf008b75a1a4532278091f7b90ba380e2911f75f86
6
+ metadata.gz: df5943d1d2088c42280ce67a36d70449829bb2d2c526a8fcc38941ec66200ceea1195508feec193579b9616b9e7562ffa551e4021b6e95272e745a4ad5f44be3
7
+ data.tar.gz: 4a1b0f5f3c8b797b66d6647b22e80f8b3af1f763ba0e09f70098db55a7b3a98d0bdca99ac0007aebaa04ed02c00bc9f95f071a38fd00ddbb11734cfef783cbde
@@ -2,8 +2,10 @@ require 'dry/inflector'
2
2
  require 'paint'
3
3
  require 'yaml'
4
4
  require 'tty-prompt'
5
+ require 'open3'
5
6
 
6
7
  require 'lolipop/mc/starter/rails/version'
8
+ require 'lolipop/mc/starter/rails/config'
7
9
  require 'lolipop/mc/starter/rails/cli'
8
10
 
9
11
  module Lolipop
@@ -4,11 +4,9 @@ module Lolipop
4
4
  module Rails
5
5
  module CheckItem
6
6
  class Base
7
- NOCHECK = '-'.freeze
8
- SKIPCHECK = 'skip'.freeze
9
-
10
7
  def initialize
11
8
  @item_name = item_name
9
+ @config = Lolipop::Mc::Starter::Rails::Config
12
10
  end
13
11
 
14
12
  def item_name
@@ -27,23 +25,6 @@ module Lolipop
27
25
  def hint
28
26
  puts "まだ #{@item_name} のヒントが書かれていません"
29
27
  end
30
-
31
- def load_config
32
- config_path = "#{Dir.pwd}/.mc-rails.yml"
33
- unless File.exist?(config_path)
34
- f = File.open(config_path, 'w')
35
- YAML.dump({'git' => NOCHECK, 'ruby' => NOCHECK, 'rails' => NOCHECK, 'ssh' => NOCHECK}, f)
36
- f.close
37
- end
38
- YAML.load_file(config_path)
39
- end
40
-
41
- def dump_config(obj)
42
- config_path = "#{Dir.pwd}/.mc-rails.yml"
43
- f = File.open(config_path, 'w')
44
- YAML.dump(obj, f)
45
- f.close
46
- end
47
28
  end
48
29
  end
49
30
  end
@@ -5,13 +5,13 @@ module Lolipop
5
5
  module CheckItem
6
6
  class EnvDatabase < Base
7
7
  def check
8
- config = load_config
8
+ config = @config.load
9
9
  ssh_command = config['ssh']
10
- if ssh_command == NOCHECK
10
+ if ssh_command == @config::NOCHECK
11
11
  raise 'SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください'
12
12
  end
13
13
  begin
14
- stdout = `#{ssh_command} env`
14
+ stdout, stderr, status = Open3.capture3("#{ssh_command} env")
15
15
  rescue => e
16
16
  raise "SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください #{e.message}"
17
17
  end
@@ -8,13 +8,13 @@ module Lolipop
8
8
  key_path = "#{Dir.pwd}/config/master.key"
9
9
  raise 'config/master.keyがありません' unless File.exist?(key_path)
10
10
 
11
- config = load_config
11
+ config = @config.load
12
12
  ssh_command = config['ssh']
13
- if ssh_command == NOCHECK
13
+ if ssh_command == @config::NOCHECK
14
14
  raise 'SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください'
15
15
  end
16
16
  begin
17
- stdout = `#{ssh_command} env`
17
+ stdout, stderr, status = Open3.capture3("#{ssh_command} env")
18
18
  rescue => e
19
19
  raise "SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください #{e.message}"
20
20
  end
@@ -5,13 +5,13 @@ module Lolipop
5
5
  module CheckItem
6
6
  class EnvRailsStatic < Base
7
7
  def check
8
- config = load_config
8
+ config = @config.load
9
9
  ssh_command = config['ssh']
10
- if ssh_command == NOCHECK
10
+ if ssh_command == @config::NOCHECK
11
11
  raise 'SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください'
12
12
  end
13
13
  begin
14
- stdout = `#{ssh_command} env`
14
+ stdout, stderr, status = Open3.capture3("#{ssh_command} env")
15
15
  rescue => e
16
16
  raise "SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください #{e.message}"
17
17
  end
@@ -5,13 +5,13 @@ module Lolipop
5
5
  module CheckItem
6
6
  class EnvRuby < Base
7
7
  def check
8
- config = load_config
8
+ config = @config.load
9
9
  ssh_command = config['ssh']
10
- if ssh_command == NOCHECK
10
+ if ssh_command == @config::NOCHECK
11
11
  raise 'SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください'
12
12
  end
13
13
  begin
14
- stdout = `#{ssh_command} env`
14
+ stdout, stderr, status = Open3.capture3("#{ssh_command} env")
15
15
  rescue => e
16
16
  raise "SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください #{e.message}"
17
17
  end
@@ -6,14 +6,14 @@ module Lolipop
6
6
  class Git < Base
7
7
  def check
8
8
  begin
9
- stdout = `git version`
9
+ stdout, stderr, status = Open3.capture3("git version")
10
10
  rescue => e
11
11
  raise "Gitコマンドがみつかりません #{e.message}"
12
12
  end
13
13
  raise "Gitコマンドが古いです #{stdout.strip}" unless stdout.match(/git version 2/)
14
- config = load_config
14
+ config = @config.load
15
15
  config['git'] = stdout.strip
16
- dump_config(config)
16
+ @config.dump(config)
17
17
  "Gitコマンドがインストールされています [#{stdout.strip}]"
18
18
  end
19
19
 
@@ -6,7 +6,7 @@ module Lolipop
6
6
  class GitLog < Base
7
7
  def check
8
8
  begin
9
- stdout = `git log`
9
+ stdout, stderr, status = Open3.capture3("git log")
10
10
  rescue => e
11
11
  raise "まだローカルのGitリポジトリにコミットがないようです #{e.message}"
12
12
  end
@@ -6,7 +6,7 @@ module Lolipop
6
6
  class GitRemote < Base
7
7
  def check
8
8
  begin
9
- stdout = `git remote`
9
+ stdout, stderr, status = Open3.capture3("git remote")
10
10
  rescue => e
11
11
  raise "Gitコマンドがみつかりません #{e.message}"
12
12
  end
@@ -6,15 +6,15 @@ module Lolipop
6
6
  class Rails < Base
7
7
  def check
8
8
  begin
9
- stdout = `#{Dir.pwd}/bin/rails -v`
9
+ stdout, stderr, status = Open3.capture3("#{Dir.pwd}/bin/rails -v")
10
10
  rescue => e
11
11
  raise "Railsコマンドがインストールされていません #{e.message}"
12
12
  end
13
13
  raise 'Railsコマンドでエラーが発生しています' unless stdout.match(/^Rails/)
14
14
  raise 'Railsのバージョンが5.2.xではありません' unless stdout.match(/5\.2/)
15
- config = load_config
15
+ config = @config.load
16
16
  config['rails'] = stdout.strip
17
- dump_config(config)
17
+ @config.dump(config)
18
18
  "Rails5.2がインストールされています [#{stdout.strip}]"
19
19
  end
20
20
 
@@ -5,11 +5,11 @@ module Lolipop
5
5
  module CheckItem
6
6
  class Ruby < Base
7
7
  def check
8
- stdout = `ruby -v`
8
+ stdout, stderr, status = Open3.capture3("ruby -v")
9
9
  raise "マネージドクラウドがサポートしているバージョンのRubyがみつかりません [#{stdout.strip}]" unless stdout.match(/ruby 2\.[56]\.\d/)
10
- config = load_config
10
+ config = @config.load
11
11
  config['ruby'] = stdout.strip
12
- dump_config(config)
12
+ @config.dump(config)
13
13
  "マネージドクラウドがサポートしているバージョンのRubyがインストールされています [#{stdout.strip}]"
14
14
  end
15
15
 
@@ -5,19 +5,19 @@ module Lolipop
5
5
  module CheckItem
6
6
  class SSH < Base
7
7
  def check
8
- config = load_config
8
+ config = @config.load
9
9
  ssh_command = config['ssh']
10
10
 
11
- if ssh_command != NOCHECK
11
+ if ssh_command != @config::NOCHECK
12
12
  begin
13
- stdout = `#{ssh_command} hostname`
13
+ stdout, stderr, status = Open3.capture3("#{ssh_command} hostname")
14
14
  rescue => e
15
15
  puts "SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください #{e.message}"
16
16
  ssh_command = ''
17
17
  end
18
18
  end
19
19
 
20
- if [NOCHECK, ''].include?(ssh_command)
20
+ if [@config::NOCHECK, ''].include?(ssh_command)
21
21
  prompt = TTY::Prompt.new(active_color: :cyan)
22
22
  ssh_command = prompt.ask('SSHコマンドを入力してください(マネージドクラウドのプロジェクト詳細に記載があります):')
23
23
  begin
@@ -28,7 +28,7 @@ module Lolipop
28
28
  end
29
29
  raise 'SSHコマンドの実行に失敗しました。入力したコマンドを確認してください' unless stdout.match(/^gitpush-ruby.+lolipop\.io/)
30
30
  config['ssh'] = ssh_command
31
- dump_config(config)
31
+ @config.dump(config)
32
32
  "SSHコマンドの設定が完了しています [#{ssh_command}]"
33
33
  end
34
34
 
@@ -1,6 +1,7 @@
1
1
  require 'thor'
2
2
  require 'lolipop/mc/starter/rails/check_list'
3
3
  require 'lolipop/mc/starter/rails/generators'
4
+ require 'lolipop/mc/starter/rails/nodebrew'
4
5
 
5
6
  module Lolipop
6
7
  module Mc
@@ -17,6 +18,11 @@ module Lolipop
17
18
  Lolipop::Mc::Starter::Rails::Generators::DatabaseURL.run
18
19
  end
19
20
 
21
+ desc 'nodebrew', 'マネージドクラウドのRailsプロジェクトにnodebrewをインストールしてNode.jsの最新のstable versionをインストールします'
22
+ def nodebrew
23
+ Lolipop::Mc::Starter::Rails::Nodebrew.run
24
+ end
25
+
20
26
  option :version, type: :boolean, aliases: :v
21
27
  def help(version = nil)
22
28
  if version
@@ -0,0 +1,24 @@
1
+ module Lolipop::Mc::Starter::Rails
2
+ module Config
3
+ NOCHECK = '-'.freeze
4
+ SKIPCHECK = 'skip'.freeze
5
+
6
+ def self.load
7
+ config_path = "#{Dir.pwd}/.mc-rails.yml"
8
+ unless File.exist?(config_path)
9
+ f = File.open(config_path, 'w')
10
+ YAML.dump({'git' => NOCHECK, 'ruby' => NOCHECK, 'rails' => NOCHECK, 'ssh' => NOCHECK, 'nodejs' => NOCHECK}, f)
11
+ f.close
12
+ end
13
+ YAML.load_file(config_path)
14
+ end
15
+
16
+ def self.dump(obj)
17
+ config_path = "#{Dir.pwd}/.mc-rails.yml"
18
+ f = File.open(config_path, 'w')
19
+ YAML.dump(obj, f)
20
+ f.close
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,79 @@
1
+ module Lolipop::Mc::Starter::Rails
2
+ module Nodebrew
3
+ def self.run
4
+ begin
5
+ @config = Lolipop::Mc::Starter::Rails::Config
6
+ config = @config.load
7
+ @ssh_command = config['ssh']
8
+ if @ssh_command == @config::NOCHECK
9
+ raise 'SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください'
10
+ end
11
+ install_nodebrew
12
+ check_env_path
13
+ install_node_stable
14
+ use_node_stable
15
+ cleanup
16
+ rescue => e
17
+ puts '❌ ' + Paint[e.message, :red]
18
+ end
19
+ end
20
+
21
+ def self.install_nodebrew
22
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} ls /var/app/.nodebrew")
23
+ if status == 0
24
+ puts '✅ ' + Paint['nodebrewはインストールされています', :green].to_s
25
+ return
26
+ end
27
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} wget git.io/nodebrew")
28
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} perl nodebrew setup")
29
+ puts '✅ ' + Paint['nodebrewをインストールしました', :green].to_s
30
+ end
31
+
32
+ def self.check_env_path
33
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} env")
34
+ md = stdout.match(/PATH=([^\s]+)/)
35
+ raise '環境変数 `PATH` ありません。マネージドクラウドのプロジェクトではない可能性があります' unless md
36
+ path = md[1]
37
+ raise "環境変数 `PATH` にnodebrewのPATH設定がないようです。マネージドクラウドのプロジェクト詳細の `環境変数の設定と管理` で環境変数 `PATH` に `/var/app/.nodebrew/current/bin:#{path}` を設定して追加してください" unless path.match(/nodebrew/)
38
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} which nodebrew")
39
+ if status == 0
40
+ puts '✅ ' + Paint['環境変数 `PATH` の設定を確認しました', :green].to_s
41
+ return
42
+ end
43
+ raise '環境変数 `PATH` の設定が間違っている可能性があります。マネージドクラウドのプロジェクト詳細の `環境変数の設定と管理` を確認してください'
44
+ end
45
+
46
+ def self.install_node_stable
47
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} nodebrew install stable")
48
+ raise "Node.jsのインストールに失敗しました: #{stdout}" unless (status == 0 || stdout.match('already installed'))
49
+ puts stdout
50
+ puts '✅ ' + Paint["Node.jsをインストールしました", :green].to_s
51
+ end
52
+
53
+ def self.use_node_stable
54
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} nodebrew use stable")
55
+ raise "nodebrew use stableに失敗しました: #{stderr}" unless status == 0
56
+ puts stdout
57
+
58
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} which nodejs")
59
+ raise "nodejsコマンドの差し替えに失敗しました: #{stderr}" unless status == 0
60
+ unless stdout.match('/var/app/.nodebrew/current/bin/node')
61
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} ln -s /var/app/.nodebrew/current/bin/node /var/app/.nodebrew/current/bin/nodejs")
62
+ raise "nodejsコマンドの差し替えに失敗しました: #{stderr}" unless status == 0
63
+ end
64
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} nodejs -v")
65
+ raise "nodejsコマンドの差し替えに失敗しました: #{stderr}" if stdout.match(/^v4/)
66
+ puts stdout
67
+
68
+ config = @config.load
69
+ config['nodejs'] = stdout.strip
70
+ @config.dump(config)
71
+ puts '✅ ' + Paint["nodebrew use stableを実行しました。そしてstableバージョンをnodejsコマンドで実行できるようにしました", :green].to_s
72
+ end
73
+
74
+ def self.cleanup
75
+ stdout, stderr, status = Open3.capture3("#{@ssh_command} rf -f /var/app/nodebrew")
76
+ puts '✅ ' + Paint["cleanupを実行しました", :green].to_s
77
+ end
78
+ end
79
+ end
@@ -2,7 +2,7 @@ module Lolipop
2
2
  module Mc
3
3
  module Starter
4
4
  module Rails
5
- VERSION = '0.4.1'.freeze
5
+ VERSION = '0.5.0'.freeze
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolipop-mc-starter-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1low
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-23 00:00:00.000000000 Z
11
+ date: 2019-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -158,8 +158,10 @@ files:
158
158
  - lib/lolipop/mc/starter/rails/check_item/ssh.rb
159
159
  - lib/lolipop/mc/starter/rails/check_list.rb
160
160
  - lib/lolipop/mc/starter/rails/cli.rb
161
+ - lib/lolipop/mc/starter/rails/config.rb
161
162
  - lib/lolipop/mc/starter/rails/generators.rb
162
163
  - lib/lolipop/mc/starter/rails/generators/database_url.rb
164
+ - lib/lolipop/mc/starter/rails/nodebrew.rb
163
165
  - lib/lolipop/mc/starter/rails/version.rb
164
166
  - lolipop-mc-starter-rails.gemspec
165
167
  homepage: https://github.com/k1LoW/lolipop-mc-starter-rails