Quellcode durchsuchen

feat: add upgrade for macos, linux, windows

Mark24 vor 2 Jahren
Ursprung
Commit
15394d3f80
6 geänderte Dateien mit 87 neuen und 82 gelöschten Zeilen
  1. 1 0
      installer.rb
  2. 12 0
      lib/core.rb
  3. 11 25
      os/LinuxDistro.rb
  4. 9 47
      os/MacOS.rb
  5. 10 10
      os/Windows.rb
  6. 44 0
      share/upgrade.rb

+ 1 - 0
installer.rb

@@ -2,6 +2,7 @@
 
 require "./lib/core"
 require "./lib/config"
+require "./share/upgrade"
 
 module OSPatch
   def check_os

+ 12 - 0
lib/core.rb

@@ -63,6 +63,18 @@ module RimeDeploy
     end
   end
 
+  class Store
+    @config_path = nil
+
+    def self.config_path=(value)
+      @config_path = value
+    end
+
+    def self.config_path
+      @config_path
+    end
+  end
+
   class Job
     attr_accessor :status, :intro
     def initialize

+ 11 - 25
os/LinuxDistro.rb

@@ -4,15 +4,6 @@ module RimeDeploy
     ConfigPathFcitx = "~/.config/fcitx/rime"
     ConfigPathFcitx5 = "~/.local/share/fcitx5/rime"
 
-    @config_path = nil
-    def self.config_path=(value)
-      @config_path = value
-    end
-
-    def self.config_path
-      @config_path
-    end
-
     class CheckInstallRimeJob < Job
       def call
         puts "==== Rime auto deploy ====".green
@@ -34,24 +25,15 @@ https://wiki.archlinux.org/title/Rime
           [
             [
               "ibus-rime",
-              -> do
-                LinuxDistroJobGroup.config_path =
-                  LinuxDistroJobGroup::ConfigPathIbus
-              end
+              -> { Store.config_path = LinuxDistroJobGroup::ConfigPathIbus }
             ],
             [
               "fcitx-rime",
-              -> do
-                LinuxDistroJobGroup.config_path =
-                  LinuxDistroJobGroup::ConfigPathFcitx
-              end
+              -> { Store.config_path = LinuxDistroJobGroup::ConfigPathFcitx }
             ],
             [
               "fcitx5-rime",
-              -> do
-                LinuxDistroJobGroup.config_path =
-                  LinuxDistroJobGroup::ConfigPathFcitx5
-              end
+              -> { Store.config_path = LinuxDistroJobGroup::ConfigPathFcitx5 }
             ],
             [
               "I'll quit first.After installed Rime by myself then run this program again.",
@@ -68,7 +50,7 @@ https://wiki.archlinux.org/title/Rime
       def call
         puts intro
         system(
-          "mv #{LinuxDistroJobGroup.config_path} #{LinuxDistroJobGroup.config_path}.#{Time.now.to_i}.old"
+          "mv #{Store.config_path} #{Store.config_path}.#{Time.now.to_i}.old"
         )
         sleep 1
         return :next
@@ -79,7 +61,7 @@ https://wiki.archlinux.org/title/Rime
       def call
         puts intro
         system(
-          "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{LinuxDistroJobGroup.config_path}"
+          "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{Store.config_path}"
         )
         sleep 1
         return :next
@@ -89,7 +71,7 @@ https://wiki.archlinux.org/title/Rime
     class CopyCustomConfigJob < Job
       def call
         puts intro
-        system("cp ./custom/*.yaml #{LinuxDistroJobGroup.config_path}/")
+        system("cp ./custom/*.yaml #{Store.config_path}/")
         sleep 1
         return :next
       end
@@ -104,12 +86,16 @@ https://wiki.archlinux.org/title/Rime
                "DEPLOY".yellow + " button."
         puts "Enjoy~ 🍻"
         puts "more info:".yellow
-        puts "Config path: #{LinuxDistroJobGroup.config_path}/"
+        puts "Config path: #{Store.config_path}/"
         return :next
       end
     end
     self.before_jobs = [CheckInstallRimeJob]
     self.jobs = [BackupRimeConfigJob, CloneConfigJob, CopyCustomConfigJob]
     self.after_jobs = [FinishedJob]
+    self.upgrade_jobs = [
+      Upgrade::UpgradeRimeAutoDeployJob,
+      Upgrade::UpgradeRimeConfigJob
+    ]
   end
 end

+ 9 - 47
os/MacOS.rb

@@ -1,7 +1,7 @@
 module RimeDeploy
   class MacOSJobGroup < JobGroup
     InstallCmd = "brew install --cask squirrel"
-    ConfigPath = "~/Library/Rime"
+    Store.config_path = "~/Library/Rime"
 
     class InstallRimeJob < Job
       def call
@@ -16,7 +16,7 @@ module RimeDeploy
       def call
         puts intro
         system(
-          "mv #{MacOSJobGroup::ConfigPath} #{MacOSJobGroup::ConfigPath}.#{Time.now.to_i}.old"
+          "mv #{Store.config_path} #{Store.config_path}.#{Time.now.to_i}.old"
         )
         sleep 1
         return :next
@@ -27,7 +27,7 @@ module RimeDeploy
       def call
         puts intro
         system(
-          "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{MacOSJobGroup::ConfigPath}"
+          "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{Store.config_path}"
         )
         sleep 1
         return :next
@@ -37,7 +37,7 @@ module RimeDeploy
     class CopyCustomConfigJob < Job
       def call
         puts intro
-        system("cp ./custom/*.yaml #{MacOSJobGroup::ConfigPath}/")
+        system("cp ./custom/*.yaml #{Store.config_path}/")
         sleep 1
         return :next
       end
@@ -52,48 +52,7 @@ module RimeDeploy
                "DEPLOY".yellow + " button."
         puts "Enjoy~ 🍻"
         puts "more info:".yellow
-        puts "Config path: #{MacOSJobGroup::ConfigPath}/"
-        return :next
-      end
-    end
-
-    class UpgradeRimeAutoDeployJob < Job
-      def call
-        puts "Upgrade `Rime Auto Deploy` script ..."
-        project_path = File.expand_path(Dir.pwd)
-        if File.directory?(File.join(project_path, ".git"))
-          puts "Git repository found."
-          system("cd #{project_path} && git remote get-url origin")
-          puts "Try upgrading..."
-          system("cd #{project_path} && git pull")
-        else
-          puts "You can download the latest version from here."
-          puts "https://github.com/Mark24Code/rime-auto-deploy"
-        end
-        return :next
-      end
-    end
-
-    class UpgradeRimeConfigJob < Job
-      def call
-        puts "Upgrade Rime Config"
-        config_path = File.expand_path(ConfigPath)
-        if File.directory?(File.join(config_path, ".git"))
-          puts "Git repository found."
-          system("cd #{config_path} && git remote get-url origin")
-          puts "Try upgrading..."
-          system("cd #{config_path} && git pull")
-        else
-          puts "Error:".yellow
-          puts "Rime Config seems broken. You may delete the directory.".red
-          puts "You can:"
-          puts "Rerun the deploy script from start choose [Auto Mode] to reinstall."
-          puts ""
-          puts "After 5 seconds, will go to [Upgrade Mode].".yellow
-          sleep 5
-          throw :halt, :run_jobs_upgrade
-        end
-
+        puts "Config path: #{Store.config_path}/"
         return :next
       end
     end
@@ -104,7 +63,10 @@ module RimeDeploy
       CloneConfigJob,
       CopyCustomConfigJob
     ]
-    self.upgrade_jobs = [UpgradeRimeAutoDeployJob, UpgradeRimeConfigJob]
     self.after_jobs = [FinishedJob]
+    self.upgrade_jobs = [
+      Upgrade::UpgradeRimeAutoDeployJob,
+      Upgrade::UpgradeRimeConfigJob
+    ]
   end
 end

+ 10 - 10
os/Windows.rb

@@ -1,7 +1,6 @@
 module RimeDeploy
   class WindowsJobGroup < JobGroup
-    ConfigPath = ENV['APPDATA'] + '\\Rime'
-
+    Store.config_path = ENV["APPDATA"] + '\\Rime'
 
     def clear_screen
       system("cls")
@@ -21,10 +20,7 @@ You can download Rime from: https://rime.im/download/
         puts ""
         ChooseSession.new(
           [
-            [
-              "I have installed Rime. Let's go next.",
-              -> {}
-            ],
+            ["I have installed Rime. Let's go next.", -> {}],
             [
               "I'll quit first.After installed Rime by myself then run this program again.",
               -> { exit 0 }
@@ -40,7 +36,7 @@ You can download Rime from: https://rime.im/download/
       def call
         puts intro
         system(
-          "move #{WindowsJobGroup::ConfigPath} #{WindowsJobGroup::ConfigPath}.#{Time.now.to_i}.old"
+          "move #{Store.config_path} #{Store.config_path}.#{Time.now.to_i}.old"
         )
         sleep 1
         return :next
@@ -51,7 +47,7 @@ You can download Rime from: https://rime.im/download/
       def call
         puts intro
         system(
-          "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{WindowsJobGroup::ConfigPath}"
+          "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{Store.config_path}"
         )
         sleep 1
         return :next
@@ -61,7 +57,7 @@ You can download Rime from: https://rime.im/download/
     class CopyCustomConfigJob < Job
       def call
         puts intro
-        system("copy .\\custom\\*.yaml #{WindowsJobGroup::ConfigPath}")
+        system("copy .\\custom\\*.yaml #{Store.config_path}")
         sleep 1
         return :next
       end
@@ -76,12 +72,16 @@ You can download Rime from: https://rime.im/download/
                "DEPLOY".yellow + " button."
         puts "Enjoy~"
         puts "more info:".yellow
-        puts "Config path: #{WindowsJobGroup::ConfigPath}"
+        puts "Config path: #{Store.config_path}"
         return :next
       end
     end
     self.before_jobs = [CheckInstallRimeJob]
     self.jobs = [BackupRimeConfigJob, CloneConfigJob, CopyCustomConfigJob]
     self.after_jobs = [FinishedJob]
+    self.upgrade_jobs = [
+      Upgrade::UpgradeRimeAutoDeployJob,
+      Upgrade::UpgradeRimeConfigJob
+    ]
   end
 end

+ 44 - 0
share/upgrade.rb

@@ -0,0 +1,44 @@
+module RimeDeploy
+  module Upgrade
+    class UpgradeRimeAutoDeployJob < Job
+      def call
+        puts "Upgrade `Rime Auto Deploy` script ..."
+        project_path = File.expand_path(Dir.pwd)
+        if File.directory?(File.join(project_path, ".git"))
+          puts "Git repository found."
+          system("cd #{project_path} && git remote get-url origin")
+          puts "Try upgrading..."
+          system("cd #{project_path} && git pull")
+        else
+          puts "You can download the latest version from here."
+          puts "https://github.com/Mark24Code/rime-auto-deploy"
+        end
+        return :next
+      end
+    end
+
+    class UpgradeRimeConfigJob < Job
+      def call
+        puts "Upgrade Rime Config"
+        config_abs_path = File.expand_path(Store.config_path)
+        if File.directory?(File.join(config_abs_path, ".git"))
+          puts "Git repository found."
+          system("cd #{config_abs_path} && git remote get-url origin")
+          puts "Try upgrading..."
+          system("cd #{config_abs_path} && git pull")
+        else
+          puts "Error:".yellow
+          puts "Rime Config seems broken. You may delete the directory.".red
+          puts "You can:"
+          puts "Rerun the deploy script from start choose [Auto Mode] to reinstall."
+          puts ""
+          puts "After 5 seconds, will go to [Upgrade Mode].".yellow
+          sleep 5
+          throw :halt, :run_jobs_upgrade
+        end
+
+        return :next
+      end
+    end
+  end
+end