From 7e3ca1b9292ff976563d970898b5d73076f04e36 Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Thu, 17 Apr 2014 16:39:31 +0800 Subject: [PATCH 1/2] [builder] Compile `.strings` resource files as binary plists. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eloy DurĂ¡n --- lib/motion/project/builder.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/motion/project/builder.rb b/lib/motion/project/builder.rb index 1fe52587..97cbcdea 100644 --- a/lib/motion/project/builder.rb +++ b/lib/motion/project/builder.rb @@ -454,7 +454,11 @@ EOS if reserved_app_bundle_files.include?(res) App.fail "Cannot use `#{res_path}' as a resource file because it's a reserved application bundle file" end - copy_resource(res_path, File.join(app_resources_dir, res)) + dest_path = File.join(app_resources_dir, res) + modified = copy_resource(res_path, dest_path) + if modified && should_compile_to_binary_plist?(res_path) + compile_resource_to_binary_plist(dest_path) + end end # Optional support for #eval (OSX-only). @@ -511,11 +515,23 @@ EOS end end + def should_compile_to_binary_plist?(res_path) + File.extname(res_path) == '.strings' + end + + def compile_resource_to_binary_plist(path) + App.info 'Compile', path + sh "/usr/bin/plutil -convert binary1 \"#{path}\"" + end + def copy_resource(res_path, dest_path) if !File.exist?(dest_path) or File.mtime(res_path) > File.mtime(dest_path) FileUtils.mkdir_p(File.dirname(dest_path)) App.info 'Copy', res_path FileUtils.cp_r(res_path, dest_path) + true + else + false end end From 07c4f8936b7d8b1ebc199e405033258311dac662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Thu, 17 Apr 2014 16:09:55 +0200 Subject: [PATCH 2/2] [builder] Also compile `.strings` files inside other bundles. --- lib/motion/project/builder.rb | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/motion/project/builder.rb b/lib/motion/project/builder.rb index 97cbcdea..21685d68 100644 --- a/lib/motion/project/builder.rb +++ b/lib/motion/project/builder.rb @@ -455,10 +455,12 @@ EOS App.fail "Cannot use `#{res_path}' as a resource file because it's a reserved application bundle file" end dest_path = File.join(app_resources_dir, res) - modified = copy_resource(res_path, dest_path) - if modified && should_compile_to_binary_plist?(res_path) - compile_resource_to_binary_plist(dest_path) - end + copy_resource(res_path, dest_path) + end + + # Compile all .strings files + Dir.glob(File.join(app_resources_dir, '{,**/}*.strings')).each do |strings_file| + compile_resource_to_binary_plist(strings_file) end # Optional support for #eval (OSX-only). @@ -515,10 +517,6 @@ EOS end end - def should_compile_to_binary_plist?(res_path) - File.extname(res_path) == '.strings' - end - def compile_resource_to_binary_plist(path) App.info 'Compile', path sh "/usr/bin/plutil -convert binary1 \"#{path}\"" @@ -529,9 +527,6 @@ EOS FileUtils.mkdir_p(File.dirname(dest_path)) App.info 'Copy', res_path FileUtils.cp_r(res_path, dest_path) - true - else - false end end