Permalink
Newer
Older
100755 163 lines (134 sloc) 5.73 KB
Oct 24, 2012
2
3
module Fusuma
4
5
require 'time'
6
require 'fileutils'
7
8
APP_NAME = 'fusuma'
Oct 24, 2012
9
VERSION = '0.1.0'
Oct 24, 2012
10
11
class Build
12
13
BUILD_TIME = Time.now.iso8601
14
15
############################################################################
16
# the project and build heirarchy
17
PROJECT_ROOT = File.dirname(__FILE__)
18
DEFAULT_CONFIGURATION = File.join(PROJECT_ROOT, 'default_configuration.json')
Oct 24, 2012
19
PROJECT_LICENSE = File.join(PROJECT_ROOT, 'LICENSE.txt')
20
BUILD_ROOT = File.join(PROJECT_ROOT, 'build')
21
BUILD_DIR = File.join(BUILD_ROOT, BUILD_TIME)
22
OSX_APP_DIR = File.join(BUILD_DIR, "#{APP_NAME}.app")
23
CONTENTS_DIR = File.join(OSX_APP_DIR, 'Contents')
24
BUILD_STAMP_FILE = File.join(CONTENTS_DIR, 'build')
25
FRAMEWORKS_DIR = File.join(CONTENTS_DIR, 'Frameworks')
26
# MACRUBY_DIR = File.join(FRAMEWORKS_DIR, 'MacRuby.framework') # TODO: embed MacRuby
27
INFO_PLIST_FILE = File.join(CONTENTS_DIR, 'Info.plist')
28
MACOS_DIR = File.join(CONTENTS_DIR, 'MacOS')
Oct 24, 2012
29
EXECUTABLE_FILE = File.join(MACOS_DIR, APP_NAME)
Oct 24, 2012
30
PROFILE_DIR = File.join(CONTENTS_DIR, 'Profile')
31
RESOURCES_DIR = File.join(CONTENTS_DIR, 'Resources')
32
LICENSE_FILE = File.join(PROJECT_ROOT, 'LICENSE.txt')
33
APP_BIN_DIR = File.join(RESOURCES_DIR, 'bin')
34
CONF_DIR = File.join(RESOURCES_DIR, 'conf')
35
CONFIGURATION = File.join(CONF_DIR, 'configuration.json')
Oct 24, 2012
36
# ICON_FILE = File.join(RESOURCES_DIR, "#{APP_NAME}.icns") # TODO: make icon
Oct 24, 2012
37
APP_LIB_DIR = File.join(RESOURCES_DIR, 'lib')
38
VERSION_FILE = File.join(APP_LIB_DIR, 'version.rb')
39
LOG_DIR = File.join(RESOURCES_DIR, 'log')
Oct 24, 2012
40
APP_VENDOR_DIR = File.join(RESOURCES_DIR, 'vendor')
41
VERSION_PLIST_FILE = File.join(CONTENTS_DIR, 'version.plist')
42
# ICON_CHECK_FILE = File.join(OSX_APP_DIR, 'Icon?')
43
PROJECT_SOURCE_DIR = File.join(PROJECT_ROOT, 'source')
44
SOURCE_BIN_DIR = File.join(PROJECT_SOURCE_DIR, 'bin')
45
SOURCE_CONF_DIR = File.join(PROJECT_SOURCE_DIR, 'conf')
46
SOURCE_LIB_DIR = File.join(PROJECT_SOURCE_DIR, 'lib')
47
SOURCE_VENDOR_DIR = File.join(PROJECT_SOURCE_DIR, 'vendor')
48
############################################################################
Oct 24, 2012
50
BUILD_STAMP_CONTENTS = BUILD_TIME
Oct 24, 2012
52
LICENSE_CONTENTS = File.open(PROJECT_LICENSE).read
Oct 24, 2012
54
INFO_PLIST_CONTENTS = <<-TEXT
55
<?xml version="1.0" encoding="UTF-8"?>
56
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
57
<plist version="1.0">
58
<dict>
59
<key>CFBundleExecutable</key>
60
<string>#{APP_NAME}</string>
61
<key>NSPrincipalClass</key>
62
<string>NSApplication</string>
63
<key>LSUIElement</key>
64
<true/>
65
</dict>
66
</plist>
67
TEXT
Oct 24, 2012
69
EXECUTABLE_CONTENTS = <<-TEXT
70
#!/bin/sh
71
cd "`dirname $0`/../Resources"
72
/usr/local/bin/macruby bin/#{APP_NAME}
73
TEXT
Oct 24, 2012
75
VERSION_PLIST_CONTENTS = <<-TEXT
76
<?xml version="1.0" encoding="UTF-8"?>
77
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
78
<plist version="1.0">
79
<dict>
80
<key>CFBundleShortVersionString</key>
81
<string>#{VERSION}</string>
82
<key>CFBundleVersion</key>
83
<string>#{VERSION}</string>
84
<key>ProjectName</key>
85
<string>#{APP_NAME}</string>
86
</dict>
87
</plist>
88
TEXT
Oct 24, 2012
90
VERSION_CONTENTS = <<-TEXT
Oct 24, 2012
91
module #{APP_NAME.capitalize}
Oct 24, 2012
92
VERSION = "#{VERSION}"
93
end
94
TEXT
95
96
def create_directories
Oct 24, 2012
97
# FileUtils.makedirs will create all parent directories needed
98
directories = [FRAMEWORKS_DIR, MACOS_DIR, PROFILE_DIR, CONF_DIR, LOG_DIR]
Oct 24, 2012
99
100
directories.each do |directory|
Oct 24, 2012
101
FileUtils.makedirs directory
102
end
103
end
104
Oct 24, 2012
105
def copy_source
106
# each source directory constant is paired with a target app directory
107
# ex. SOURCE_BIN_DIR is paired with APP_BIN_DIR
Oct 24, 2012
109
110
source.each do |directory|
111
values = %w(SOURCE APP).each
112
copy_dir { Build.const_get "#{values.next}_#{directory}_DIR" }
113
end
114
end
115
116
def copy_dir
117
FileUtils.copy_entry(yield, yield)
118
end
119
Oct 24, 2012
120
def create_files
Oct 24, 2012
121
# each file name constant is paired with a file contents constant.
122
# ex. EXECUTABLE_FILE is paired with EXECUTABLE_CONTENTS
123
files = %w(BUILD_STAMP INFO_PLIST EXECUTABLE LICENSE VERSION_PLIST VERSION)
124
125
files.each do |file|
Oct 24, 2012
126
values = %w(FILE CONTENTS).each
127
write_file { Build.const_get "#{file}_#{values.next}" }
128
end
129
Oct 24, 2012
130
File.chmod(0766, EXECUTABLE_FILE) # make app launcher executable
Oct 24, 2012
131
end
132
133
def write_file
134
File.open(yield, 'w') { |f| f.write yield }
135
end
136
137
def configure_with(configuration)
138
File.open(CONFIGURATION, 'w') do |file|
139
file.write File.open(configuration).read
140
end
141
end
142
143
def initialize(configuration)
144
create_directories
145
copy_source
146
create_files
Oct 24, 2012
147
148
configure_with(configuration)
149
Oct 24, 2012
150
puts "#{APP_NAME} has been created and saved to #{OSX_APP_DIR}."
151
rescue => error
152
puts error.message
153
puts error.backtrace.join("\n")
Oct 24, 2012
154
end
155
end
156
end
157
158
configuration = ARGV.shift
159
configuration ||= Fusuma::Build::DEFAULT_CONFIGURATION # use the default configuration if none given
160
161
Fusuma::Build.new(configuration)
Oct 24, 2012
162