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 => "v5.4.1", :revision => "725943bf9e3ca6f5e7d286ded25b0207fc68caaa" head "https://github.com/elastic/kibana.git" bottle do sha256 "4740e799c140ee9f49a8051bd335186906e2fa886bfdf39f5b9dd2a50132d074" => :sierra sha256 "17732a62d8727afb2c28674b839717c4a7ff9dc7eb4c4336f4e4e25f7df2f06c" => :el_capitan sha256 "2628de60f25dfba79280763b6d8539a4c67b17aa2138f601be4bb24c9fc883bb" => :yosemite end resource "node" do url "https://nodejs.org/dist/v6.10.2/node-v6.10.2.tar.xz" sha256 "80aa11333da99813973a99646e2113c6be5b63f665c0731ed14ecb94cbe846b6" 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 platforms = Set.new(["darwin-x64", "linux-x64", "windows-x64"]) if MacOS.prefer_64_bit? platform = "darwin-x64" else raise "Installing Kibana via Homebrew is only supported on macOS x86_64" end platforms.delete(platform) sub = platforms.to_a.join("|") inreplace buildpath/"tasks/config/platforms.js", /('(#{sub})',?(?!;))/, "// \\1" # trick the build into thinking we've already downloaded the Node.js binary mkdir_p buildpath/".node_binaries/#{resource("node").version}/#{platform}" # 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" Pathname.new("#{ENV["HOME"]}/.npmrc").write Language::Node.npm_cache_config system "npm", "install", "--verbose" system "npm", "run", "build", "--", "--release", "--skip-os-packages", "--skip-archives" prefix.install Dir["build/kibana-#{version}-#{platform.sub("x64", "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.undent 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.undent 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