forked from hatena/hatena-bookmark-googlechrome-extension
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
77 lines (64 loc) · 2.37 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# encoding: utf-8
require 'rake/clean'
require 'json'
require 'pathname'
require 'open-uri'
project_name = 'hatena-bookmark'
root_path = Pathname.new(__FILE__).parent
src_path = root_path.join('src')
chrome_manifest_path = src_path.join('chrome/manifest.json')
output_path = root_path.join('bin')
task :release => [:clean, :package]
task :default => [:filecopy]
CLEAN.include ['**/.*.sw?', '.*.sw?']
namespace :manifest do
desc "json schema check"
task :validate_chrome do
require 'jsonschema'
data = JSON.parse chrome_manifest_path.read
schema = JSON.parse open('https://gist.github.com/os0x/179669/raw/').read # manifest.json schema by os0x
puts "JSON schema check."
begin
JSON::Schema.validate(data, schema)
puts "JSON schema valid."
rescue JSON::Schema::ValueError => e
puts "JSON schema invalid!"
puts e.to_s
end
end
end
# 指定のディレクトリ (複数) の中にあるファイル全てを
# 別のディレクトリの中にコピーするためのタスクを定義する。
def setup_filecopy_task(taskname, obj_dir_path_str, src_dir_path_strs)
obj_dir = Pathname.new(obj_dir_path_str)
obj_file_path_strs = []
src_dir_path_strs.each do |src_dir_path_str|
src_dir_pathname = Pathname.new(src_dir_path_str)
Pathname.glob(src_dir_pathname.to_s + '/**/*') do |pathname|
src_str = pathname.to_s
dist = obj_dir + pathname.relative_path_from(src_dir_pathname)
dist_str = dist.to_s
if pathname.directory?
directory dist_str
else
file dist_str => [ dist.dirname.to_s, src_str ] do |t|
cp src_str, t.name
end
end
obj_file_path_strs << dist
end
end
directory obj_dir_path_str
task taskname => [ obj_dir.to_s ] + obj_file_path_strs
end
setup_filecopy_task(:filecopy_chrome, 'obj/chrome', [ 'src/main', 'src/chrome' ])
setup_filecopy_task(:filecopy_opera, 'obj/opera', [ 'src/main', 'src/opera' ])
task :filecopy => [ :filecopy_chrome, :filecopy_opera ]
desc "Chrome 拡張リリース用の zip ファイルを生成する"
task :package_chrome => [ :filecopy_chrome ] do
# TODO src_path を使うように
# TODO output_path を使うように
# TODO project_name を使うように
sh 'find obj/chrome | grep -v \'^obj/chrome/tests\\(/\\|$\\)\' | xargs zip bookmark-googlechrome-extension.zip'
end
task :package => [ :package_chrome ]