al-quran.reflectslight.io/Rakefile.rb

102 lines
2.4 KiB
Ruby
Raw Normal View History

2022-11-02 04:49:43 +01:00
# frozen_string_literal: true
2022-10-31 19:34:23 +01:00
require "bundler/setup"
2022-11-08 11:45:40 +01:00
require "ryo"
require "listen"
2022-10-31 19:34:23 +01:00
require_relative "lib/tasks"
include Tasks
namespace :nanoc do
desc "Compile the website"
2022-10-31 19:34:23 +01:00
task :compile do
2022-11-27 19:48:41 +01:00
sh "ruby -S bundle exec nanoc co"
2022-10-31 19:34:23 +01:00
end
2022-11-08 11:45:40 +01:00
desc "Delete the build directory"
2022-11-08 11:45:40 +01:00
task :clean do
build_dir = Ryo.from(YAML.load_file("./nanoc.yaml")).output_dir
sh "rm -rf #{build_dir}"
end
2022-10-31 19:34:23 +01:00
end
2022-11-02 11:33:58 +01:00
task build: "nanoc:compile"
2022-10-31 19:34:23 +01:00
desc "Start a Ruby web server on localhost"
2022-11-03 23:09:51 +01:00
task server: ["nanoc:compile"] do
Dir.chdir(File.join(Dir.getwd, "build", "al-quran")) do
sh "ruby -S bundle exec adsf"
end
end
namespace :watch do
desc "Watch for changes (server task)"
task :server do
Bundler.with_unbundled_env { Process.wait spawn("rake build") }
Listen.to(File.join(Dir.getwd, "src")) do
Bundler.with_unbundled_env { sh "rake build" }
end.start
Rake::Task["server"].invoke
end
namespace :deploy do
desc "Watch for changes (deploy:local task)"
task :local do
Bundler.with_unbundled_env { Process.wait spawn("rake deploy:local") }
Listen.to(File.join(Dir.getwd, "src")) do
Bundler.with_unbundled_env { sh "rake deploy:local" }
end.start
sleep
end
end
end
2022-10-31 19:34:23 +01:00
namespace :deploy do
desc "Deploy to a local web server (eg nginx)"
task local: ["env:set-development-vars", "nanoc:compile"] do
2022-10-31 19:34:23 +01:00
Deploy::Local.call
end
desc "Deploy to production"
task remote: ["env:verify-production-branch",
"env:set-production-vars",
"nanoc:clean",
"nanoc:compile"] do
2022-11-10 22:53:17 +01:00
Deploy::Remote.call
end
end
namespace :env do
desc "Verify the production branch is being used"
task :'verify-production-branch' do
git_branch = `git branch --show-current`.chomp
if git_branch != "production"
warn "This task can only be run on the 'production' branch."
exit(1)
end
end
desc "Set environment variables for the production environment"
task :'set-production-vars' do
require "dotenv"
Dotenv.load
2022-11-10 22:53:17 +01:00
end
desc "Set environment variables for the development environment"
task :'set-development-vars' do
2022-11-10 22:53:17 +01:00
ENV["NODE_ENV"] ||= "development"
end
2022-10-31 19:34:23 +01:00
end
2022-11-02 04:38:46 +01:00
namespace :linter do
desc "Run the Ruby linter"
2022-11-02 04:38:46 +01:00
task :ruby do
sh "bundle exec rubocop lib/ src/"
end
desc "Run the TypeScript linter"
2022-11-02 04:38:46 +01:00
task :typescript do
sh "npm run eslint"
end
end
task lint: ["linter:ruby", "linter:typescript"]
2022-10-31 19:34:23 +01:00
task default: "deploy:local"