diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..f29b5f7 --- /dev/null +++ b/.env.sample @@ -0,0 +1,3 @@ +DEPLOY_HOSTNAME= +DEPLOY_USERNAME= +DEPLOY_PATH= diff --git a/.gitignore b/.gitignore index 03c9b61..484aacb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build/ tmp/ node_modules/ *.log +.env diff --git a/Gemfile b/Gemfile index 17e071f..ffbb04e 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,4 @@ gem "sass" gem "standardrb" gem "ryo.rb" gem "paint" +gem "dotenv" diff --git a/Gemfile.lock b/Gemfile.lock index 038a988..e74e06f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,6 +18,7 @@ GEM ddmetrics (1.0.1) ddplugin (1.0.3) diff-lcs (1.5.0) + dotenv (2.8.1) em-websocket (0.5.3) eventmachine (>= 0.12.9) http_parser.rb (~> 0) @@ -130,6 +131,7 @@ PLATFORMS x86_64-freebsd-13 DEPENDENCIES + dotenv nanoc (~> 4.12) nanoc-live (~> 1.0) paint diff --git a/Rakefile.rb b/Rakefile.rb index c202051..c18e986 100644 --- a/Rakefile.rb +++ b/Rakefile.rb @@ -15,6 +15,12 @@ namespace :deploy do task local: ["nanoc:compile"] do Deploy::Local.call end + + task remote: ["nanoc:compile"] do + require "dotenv" + Dotenv.load + Deploy::Remote.call + end end namespace :linter do diff --git a/lib/tasks/deploy.rb b/lib/tasks/deploy.rb index b7981cf..4d4765f 100644 --- a/lib/tasks/deploy.rb +++ b/lib/tasks/deploy.rb @@ -2,4 +2,5 @@ module Tasks::Deploy require_relative "deploy/local" + require_relative "deploy/remote" end diff --git a/lib/tasks/deploy/remote.rb b/lib/tasks/deploy/remote.rb new file mode 100644 index 0000000..ae8e1de --- /dev/null +++ b/lib/tasks/deploy/remote.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class Tasks::Deploy::Remote + attr_reader :hostname, :user, :path + + def self.call + new.call + end + + def initialize + @hostname = ENV["DEPLOY_HOSTNAME"] + @user = ENV["DEPLOY_USERNAME"] + @path = ENV["DEPLOY_PATH"] + @build_dir = File.join(Dir.getwd, "build", "al-quran", ".") + end + + def call + rsync! + end + + private + + def rsync! + print "Wait...", "\n" + system( + "rsync", + "--delete", + "-rvah", + "--chmod=Du=rwx,Fu=rw", + @build_dir, "#{@user}@#{@hostname}:#{@path}" + ) + if $?.success? + print "\n", Paint["OK", :green, :bold] + else + print Paint["ERROR", :red, :bold] + exit! + end + end +end