#!/usr/bin/env ruby require 'thor' require 'colorize' require 'awesome_print' ### if ['-v', '--version'].include?(ARGV[0]) puts 'v%s' % Pathname.new(__dir__).join('../.version').read.chomp exit end ### # Load app if possible if ARGV[0] if File.exist?('./config/application.rb') require './config/application.rb' end if !defined?(LuxAssets) && File.exist?('./config/environment.rb') require './config/environment.rb' end if !defined?(LuxAssets) require_relative '../lib/lux_assets' end end ### module ::Cli extend self def run what puts what.green system what end def die text puts text.red exit end def info text puts '* %s' % text.magenta end end ### class AssetsCli < Thor desc :install, 'Install all needed packages via yarn' def install packages = ["coffee-script", "node-sass", "typescript", "babel-cli", "autoprefixer-cli"] if `which yarn`.empty? Cli.die('yarn not found -> install with "npm install yarn -g"') end for pkg in packages Cli.run 'yarn add %s' % pkg end puts '* Installed: %s' % packages.map(&:green).join(', ') if ENV['RACK_ENV'] != 'test' unless LuxAssets::CONFIG_PATH.exist? source = Pathname.new(__FILE__).join("../../misc/assets.rb") LuxAssets::CONFIG_PATH.write source.read puts '* Added template %s' % LuxAssets::CONFIG_PATH.to_s.green end puts "* To include LuxAssets rake tasks in Rakefile, just require 'lux_assets'".green end end desc :show, 'Show all files/data in manifest' def show LuxAssets.examine end desc :compile, 'Compile assets for production' def compile LuxAssets.compile_all do |name, path| puts "Compile #{name.green} -> #{path}" end end desc :clear, 'Clear all caches' def clear Cli.run 'rm -rf ./tmp/assets' Cli.run 'rm -rf ./public/assets' Cli.run 'rm ./public/manifest.json' end desc :monitor, 'Montitor and compile changed files' def monitor LuxAssets::Cli.monitor end end ### trap("SIGINT") { Cli.die 'ctrl+c exit' } AssetsCli.start ARGV