require "language/node" class Kibana < Formula desc "Analytics and search dashboard for Elasticsearch" homepage "https://www.elastic.co/products/kibana" url "https://github.com/elastic/kibana.git", :tag => "v6.0.0", :revision => "f8bc449f5a6b28d0597730b1cf03fefe7e33422e" head "https://github.com/elastic/kibana.git" bottle do sha256 "d36792a23c71a68e2361ad9ed22ad04c08d15c298d207d470880b6da633a5304" => :high_sierra sha256 "5296f320ffabc02cf521b243f09a811e80184cf4fbe76ae9181b89268b9825c0" => :sierra sha256 "d0ab882df05d1ec930affb76c2b995f91f10a7badfaad260d65df4670aa95524" => :el_capitan end resource "node" do url "https://github.com/nodejs/node.git", :tag => "v6.11.5", :revision => "e4f3e73b8cb58291380afbdb333c85789f2a5ce9" end def install resource("node").stage do system "./configure", "--prefix=#{libexec}/node" system "make", "test" system "make", "install" end # do not build packages for other platforms inreplace buildpath/"tasks/config/platforms.js", /('(linux-x64|windows-x64)',?(?!;))/, "// \\1" # trick the build into thinking we've already downloaded the Node.js binary mkdir_p buildpath/".node_binaries/#{resource("node").version}/darwin-x64" # set npm env and fix cache edge case (https://github.com/Homebrew/brew/pull/37#issuecomment-208840366) ENV.prepend_path "PATH", prefix/"libexec/node/bin" system "npm", "install", "-ddd", "--build-from-source", "--#{Language::Node.npm_cache_config}" system "npm", "run", "build", "--", "--release", "--skip-os-packages", "--skip-archives" prefix.install Dir["build/kibana-#{version}-darwin-x86_64/{bin,config,node_modules,optimize,package.json,src,ui_framework,webpackShims}"] inreplace "#{bin}/kibana", %r{/node/bin/node}, "/libexec/node/bin/node" inreplace "#{bin}/kibana-plugin", %r{/node/bin/node}, "/libexec/node/bin/node" cd prefix do inreplace "config/kibana.yml", "/var/run/kibana.pid", var/"run/kibana.pid" (etc/"kibana").install Dir["config/*"] rm_rf "config" end end def post_install ln_s etc/"kibana", prefix/"config" (prefix/"data").mkdir (prefix/"plugins").mkdir end def caveats; <<~EOS Config: #{etc}/kibana/ If you wish to preserve your plugins upon upgrade, make a copy of #{opt_prefix}/plugins before upgrading, and copy it into the new keg location after upgrading. EOS end plist_options :manual => "kibana" def plist; <<~EOS Label #{plist_name} Program #{opt_bin}/kibana RunAtLoad EOS end test do ENV["BABEL_CACHE_PATH"] = testpath/".babelcache.json" assert_match /#{version}/, shell_output("#{bin}/kibana -V") end end