Last active
December 18, 2015 08:29
-
-
Save ichi/5754723 to your computer and use it in GitHub Desktop.
Rakefile。 coffeeとsassのwatchするタスクと、 schemaSpyするタスク。 cakephpなんかのときに。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# path は絶対でも相対でもok | |
defaults: &defaults | |
schema_spy: | |
jar: 'vendors/java/schemaSpy/schemaSpy_5.0.0.jar' | |
driver: 'vendors/java/mysql/mysql-connector-java-5.1.24-bin.jar' | |
output: 'app/Config/Schema/Apps/Analysis' | |
coffee: | |
targets: | |
- app/webroot/js/coffee:app/webroot/js/app.js | |
- app/webroot/backend/js/coffee:app/webroot/backend/js/app.js | |
sass: | |
targets: | |
- app/webroot/css/app.scss:app/webroot/css/app.css | |
develop: | |
<<: *defaults | |
test: | |
<<: *defaults | |
production: | |
<<: *defaults | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'yaml' | |
require 'json' | |
# 設定読み込み | |
@dir = File.dirname(__FILE__) | |
@env = ENV['APPLICATION_ENV'] || 'develop' | |
@config = YAML.load_file(ENV['RAKE_CONFIG_YAML'] || 'config/rake_config.yml')[@env] || {} | |
@db_config = JSON.load `php -r "require_once('app/Config/database.php'); echo json_encode((new DATABASE_CONFIG())->#{@env});"` | |
# default | |
task :default => ['assets:watch'] | |
namespace :db do | |
namespace :schema do | |
desc "analyze schema with schemaSpy" | |
task :analyze do | |
spy_config = @config['schema_spy'] | |
cmd = <<-CMD.gsub /\s{2,}/, ' ' | |
java \ | |
-jar #{File.expand_path(spy_config['jar'], @dir)} \ | |
-dp #{File.expand_path(@spy_config['driver'], @dir)} \ | |
-t mysql \ | |
-db #{@db_config['database']} \ | |
-host #{@db_config['host']} \ | |
-port #{@db_config['port'] || 3306} \ | |
-u #{@db_config['login']} \ | |
#{"-p #{@db_config['password']}" unless @db_config['password'].empty?} \ | |
-charset UTF-8 \ | |
-o #{File.expand_path(spy_config['output'], @dir)} | |
CMD | |
puts "**command**" | |
puts cmd | |
puts "\n" | |
puts "**output**" | |
exec cmd | |
end | |
end | |
end | |
namespace 'assets' do | |
desc 'watch & compile coffee scripts & sass files' | |
task :watch do | |
commands = [] | |
sass_targets = @config['sass'] && @config['sass']['targets'] || [] | |
coffee_targets = @config['coffee'] && @config['coffee']['targets'] || [] | |
# sass | |
commands << "sass --watch #{sass_targets.join(' ')}" unless sass_targets.empty? | |
# coffee | |
commands += coffee_targets.map do |target| | |
target, output = target.split ':' | |
output_options = if output | |
"-#{File.extname(output) == '.js' && File.extname(target).empty? ? 'j' : 'o'} #{output}" | |
end | |
"coffee #{output_options} -wc #{target}" | |
end | |
pids = commands.compact.map do |cmd| | |
puts "**command** #{cmd}" | |
Process.fork{ exec cmd } | |
end | |
Signal.trap(:TERM) { Process.kill(:QUIT, *pids) } | |
Signal.trap(:INT) { Process.kill(:QUIT, *pids) } | |
Process.waitall | |
puts "" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment