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.0.2", :revision => "8f2ace746d1b84702bb618308efa65dc0c3f8a34" head "https://github.com/elastic/kibana.git" bottle do sha256 "20ed1a8d44c2e2ba8425e33cc97389f56579286b117029844b3cdd8226ff75be" => :sierra sha256 "f627d1175936d42ef4ca2cfee8b454fa1c7513918d409b0d6cb9497a55810168" => :el_capitan sha256 "b8f75a650d97d270cebd90459a7dcd6115ba5244692ff0968453e0b455db4a67" => :yosemite end resource "node" do url "https://nodejs.org/dist/v7.2.0/node-v7.2.0.tar.xz" # N.B. includes vendored dependencies sha256 "486d4db7ef659521ad2fafefca877638da07bef61e2aee090207ff52149294fb" 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", "linux-x86", "windows-x86"]) if OS.mac? && Hardware::CPU.is_64_bit? platform = "darwin-x64" elsif OS.linux? platform = Hardware::CPU.is_64_bit? ? "linux-x64" : "linux-x86" else raise "Installing Kibana via Homebrew is only supported on Darwin x86_64, Linux i386, Linux i686, and Linux 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,webpackShims}"] inreplace "#{bin}/kibana", %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