#!/usr/bin/env ruby
require "pathname"
require "rake"

include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path("../../",  __FILE__)

chdir APP_ROOT do
  # This script is a starting point to setup your application.
  # Add necessary setup steps to this file:

  if File.exist?(".env")
    $stderr.puts <<-EOT.gsub(/^ {6}/, "")
      \n\e[31m[DEPRECATION] =================================================
      The file
          #{APP_ROOT.join(".env")}
      is being deprecated. Please move this file to:
          /etc/ood/config/apps/files/env
      and delete this '.env' file.
      ===============================================================\e[0m
    EOT
  end

  puts "\n== Building Files App =="

  puts "\n== Installing dependencies =="
  rm_rf "node_modules"
  sh "npm install --production --prefix tmp yarn"
  sh "tmp/node_modules/yarn/bin/yarn --production install"

  puts "\n== Restarting application server =="
  touch "tmp/restart.txt"
  puts ""
end
