require "language/node" class Lanraragi < Formula desc "Web application for archival and reading of manga/doujinshi" homepage "https://github.com/Difegue/LANraragi" url "https://github.com/Difegue/LANraragi/archive/v.0.8.1.tar.gz" sha256 "b87ca0f3b08147308d2ceee344c77e9f7068742f9b4705ed0ac298f08b4a5bad" license "MIT" head "https://github.com/Difegue/LANraragi.git", branch: "dev" bottle do sha256 cellar: :any, arm64_big_sur: "9ee88f05aaa4fe5775a41068b26450ac766ebc8520ab596107a64f1cf7a61dc8" sha256 cellar: :any, big_sur: "b6f9247a0587e23fac302d70ca69f1d07cd73f3194ea1da37e0a5f3b4bb2fb86" sha256 cellar: :any, catalina: "a3608bc9c711fc8f8cc5c051b14ef89b882bfc3a4420e2cfbf63eb6ebaee617e" sha256 cellar: :any, mojave: "fb8c7b0db15297e6174933b439a816ff4bd9eacee21779d322973a619a249d22" end depends_on "pkg-config" => :build depends_on "cpanminus" depends_on "ghostscript" depends_on "giflib" depends_on "imagemagick" depends_on "jpeg" depends_on "libpng" depends_on "node" depends_on "openssl@1.1" depends_on "perl" depends_on "redis" depends_on "zstd" uses_from_macos "libarchive" resource "Image::Magick" do url "https://cpan.metacpan.org/authors/id/J/JC/JCRISTY/Image-Magick-7.0.11-3.tar.gz" sha256 "232f2312c09a9d9ebc9de6c9c6380b893511ef7c6fc358d457a4afcec26916aa" end resource "libarchive-headers" do url "https://opensource.apple.com/tarballs/libarchive/libarchive-83.100.2.tar.gz" sha256 "e54049be1b1d4f674f33488fdbcf5bb9f9390db5cc17a5b34cbeeb5f752b207a" end resource "Archive::Peek::Libarchive" do url "https://cpan.metacpan.org/authors/id/R/RE/REHSACK/Archive-Peek-Libarchive-0.38.tar.gz" sha256 "332159603c5cd560da27fd80759da84dad7d8c5b3d96fbf7586de2b264f11b70" end def install ENV.prepend_create_path "PERL5LIB", "#{libexec}/lib/perl5" ENV.prepend_path "PERL5LIB", "#{libexec}/lib" ENV["CFLAGS"] = "-I#{libexec}/include" ENV["OPENSSL_PREFIX"] = Formula["openssl@1.1"].opt_prefix imagemagick = Formula["imagemagick"] resource("Image::Magick").stage do inreplace "Makefile.PL" do |s| s.gsub! "/usr/local/include/ImageMagick-#{imagemagick.version.major}", "#{imagemagick.opt_include}/ImageMagick-#{imagemagick.version.major}" end system "perl", "Makefile.PL", "INSTALL_BASE=#{libexec}" system "make" system "make", "install" end resource("libarchive-headers").stage do cd "libarchive/libarchive" do (libexec/"include").install "archive.h", "archive_entry.h" end end resource("Archive::Peek::Libarchive").stage do inreplace "Makefile.PL" do |s| s.gsub! "$autoconf->_get_extra_compiler_flags", "$autoconf->_get_extra_compiler_flags .$ENV{CFLAGS}" end system "cpanm", "Config::AutoConf", "--notest", "-l", libexec system "perl", "Makefile.PL", "INSTALL_BASE=#{libexec}" system "make" system "make", "install" end system "npm", "install", *Language::Node.local_npm_install_args system "perl", "./tools/install.pl", "install-full" prefix.install "README.md" (libexec/"lib").install Dir["lib/*"] libexec.install "script", "package.json", "public", "templates", "tests", "lrr.conf" cd "tools/build/homebrew" do bin.install "lanraragi" libexec.install "redis.conf" end end def caveats <<~EOS Automatic thumbnail generation will not work properly on macOS < 10.15 due to the bundled Libarchive being too old. Opening archives for reading will generate thumbnails normally. EOS end test do # Make sure lanraragi writes files to a path allowed by the sandbox ENV["LRR_LOG_DIRECTORY"] = ENV["LRR_TEMP_DIRECTORY"] = testpath %w[server.pid shinobu.pid minion.pid].each { |file| touch file } # Set PERL5LIB as we're not calling the launcher script ENV["PERL5LIB"] = libexec/"lib/perl5" # This can't have its _user-facing_ functionality tested in the `brew test` # environment because it needs Redis. It fails spectacularly tho with some # table flip emoji. So let's use those to confirm _some_ functionality. output = <<~EOS キタ━━━━━━(゚∀゚)━━━━━━!!!!! (╯・_>・)╯︵ ┻━┻ It appears your Redis database is currently not running. The program will cease functioning now. EOS # Execute through npm to avoid starting a redis-server assert_match output, shell_output("npm start --prefix #{libexec}", 61) end end