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 => "v4.5.1", :revision => "addb28966a74b61791ceda352cd5b8b1200f2b2a" head "https://github.com/elastic/kibana.git" bottle do sha256 "3ad7c608d760e0f232b7314576fc604ab5d01359a9ecc3865626e35ba762673f" => :sierra sha256 "2a4de8b9c0223d3e7ef17e776ab79401e8c0e5ba78ba238f6d8159d8d16fb9be" => :el_capitan sha256 "ec01418d4941f836cd7afcdfb79919ba1d8eae6ddf32ec5df4b7d49d6e5781c2" => :yosemite sha256 "58dd7c70a51d0410ef7b3622e4022f2cc15a2060bc6a393bc29e1d79505084fb" => :mavericks end devel do url "https://github.com/elastic/kibana.git", :tag => "v5.0.0-alpha3", :revision => "b6190c95064a7c48c390c4566e82b5a562ca744f" version "5.0.0-alpha3" end resource "node" do url "https://nodejs.org/dist/v4.4.4/node-v4.4.4.tar.gz" sha256 "53c694c203ee18e7cd393612be08c61ed6ab8b2a165260984a99c014d1741414" end def install resource("node").stage buildpath/"node" cd buildpath/"node" do system "./configure", "--prefix=#{libexec}/node" system "make", "install" end # do not download binary installs of Node.js inreplace buildpath/"tasks/build/index.js", /('_build:downloadNodeBuilds:\w+',)/, "// \\1" # do not build packages for other platforms platforms = Set.new(["darwin-x64", "linux-x64", "linux-x86", "windows"]) 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" # do not build zip package inreplace buildpath/"tasks/build/archives.js", /(await exec\('zip'.*)/, "// \\1" # 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" mkdir "tar" do system "tar", "--strip-components", "1", "-xf", Dir[buildpath/"target/kibana-*-#{platform}.tar.gz"].first rm_f Dir["bin/*.bat"] prefix.install "bin", "config", "node_modules", "optimize", "package.json", "src", "webpackShims" end 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/"installedPlugins").mkdir end def caveats; <<-EOS.undent Config: #{etc}/kibana/ If you wish to preserve your plugins upon upgrade, make a copy of #{prefix}/installedPlugins 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