-
Notifications
You must be signed in to change notification settings - Fork 6
/
build_app
executable file
·162 lines (134 loc) · 5.73 KB
/
build_app
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/ruby
module Fusuma
require 'time'
require 'fileutils'
APP_NAME = 'fusuma'
VERSION = '0.1.0'
class Build
BUILD_TIME = Time.now.iso8601
############################################################################
# the project and build heirarchy
PROJECT_ROOT = File.dirname(__FILE__)
DEFAULT_CONFIGURATION = File.join(PROJECT_ROOT, 'default_configuration.json')
PROJECT_LICENSE = File.join(PROJECT_ROOT, 'LICENSE.txt')
BUILD_ROOT = File.join(PROJECT_ROOT, 'build')
BUILD_DIR = File.join(BUILD_ROOT, BUILD_TIME)
OSX_APP_DIR = File.join(BUILD_DIR, "#{APP_NAME}.app")
CONTENTS_DIR = File.join(OSX_APP_DIR, 'Contents')
BUILD_STAMP_FILE = File.join(CONTENTS_DIR, 'build')
FRAMEWORKS_DIR = File.join(CONTENTS_DIR, 'Frameworks')
# MACRUBY_DIR = File.join(FRAMEWORKS_DIR, 'MacRuby.framework') # TODO: embed MacRuby
INFO_PLIST_FILE = File.join(CONTENTS_DIR, 'Info.plist')
MACOS_DIR = File.join(CONTENTS_DIR, 'MacOS')
EXECUTABLE_FILE = File.join(MACOS_DIR, APP_NAME)
PROFILE_DIR = File.join(CONTENTS_DIR, 'Profile')
RESOURCES_DIR = File.join(CONTENTS_DIR, 'Resources')
LICENSE_FILE = File.join(PROJECT_ROOT, 'LICENSE.txt')
APP_BIN_DIR = File.join(RESOURCES_DIR, 'bin')
CONF_DIR = File.join(RESOURCES_DIR, 'conf')
CONFIGURATION = File.join(CONF_DIR, 'configuration.json')
# ICON_FILE = File.join(RESOURCES_DIR, "#{APP_NAME}.icns") # TODO: make icon
APP_LIB_DIR = File.join(RESOURCES_DIR, 'lib')
VERSION_FILE = File.join(APP_LIB_DIR, 'version.rb')
LOG_DIR = File.join(RESOURCES_DIR, 'log')
APP_VENDOR_DIR = File.join(RESOURCES_DIR, 'vendor')
VERSION_PLIST_FILE = File.join(CONTENTS_DIR, 'version.plist')
# ICON_CHECK_FILE = File.join(OSX_APP_DIR, 'Icon?')
PROJECT_SOURCE_DIR = File.join(PROJECT_ROOT, 'source')
SOURCE_BIN_DIR = File.join(PROJECT_SOURCE_DIR, 'bin')
SOURCE_CONF_DIR = File.join(PROJECT_SOURCE_DIR, 'conf')
SOURCE_LIB_DIR = File.join(PROJECT_SOURCE_DIR, 'lib')
SOURCE_VENDOR_DIR = File.join(PROJECT_SOURCE_DIR, 'vendor')
############################################################################
BUILD_STAMP_CONTENTS = BUILD_TIME
LICENSE_CONTENTS = File.open(PROJECT_LICENSE).read
INFO_PLIST_CONTENTS = <<-TEXT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>#{APP_NAME}</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSUIElement</key>
<true/>
</dict>
</plist>
TEXT
EXECUTABLE_CONTENTS = <<-TEXT
#!/bin/sh
cd "`dirname $0`/../Resources"
/usr/local/bin/macruby bin/#{APP_NAME}
TEXT
VERSION_PLIST_CONTENTS = <<-TEXT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleShortVersionString</key>
<string>#{VERSION}</string>
<key>CFBundleVersion</key>
<string>#{VERSION}</string>
<key>ProjectName</key>
<string>#{APP_NAME}</string>
</dict>
</plist>
TEXT
VERSION_CONTENTS = <<-TEXT
module #{APP_NAME.capitalize}
VERSION = "#{VERSION}"
end
TEXT
def create_directories
# FileUtils.makedirs will create all parent directories needed
directories = [FRAMEWORKS_DIR, MACOS_DIR, PROFILE_DIR, CONF_DIR, LOG_DIR]
directories.each do |directory|
FileUtils.makedirs directory
end
end
def copy_source
# each source directory constant is paired with a target app directory
# ex. SOURCE_BIN_DIR is paired with APP_BIN_DIR
source = %w(BIN LIB VENDOR)
source.each do |directory|
values = %w(SOURCE APP).each
copy_dir { Build.const_get "#{values.next}_#{directory}_DIR" }
end
end
def copy_dir
FileUtils.copy_entry(yield, yield)
end
def create_files
# each file name constant is paired with a file contents constant.
# ex. EXECUTABLE_FILE is paired with EXECUTABLE_CONTENTS
files = %w(BUILD_STAMP INFO_PLIST EXECUTABLE LICENSE VERSION_PLIST VERSION)
files.each do |file|
values = %w(FILE CONTENTS).each
write_file { Build.const_get "#{file}_#{values.next}" }
end
File.chmod(0766, EXECUTABLE_FILE) # make app launcher executable
end
def write_file
File.open(yield, 'w') { |f| f.write yield }
end
def configure_with(configuration)
File.open(CONFIGURATION, 'w') do |file|
file.write File.open(configuration).read
end
end
def initialize(configuration)
create_directories
copy_source
create_files
configure_with(configuration)
puts "#{APP_NAME} has been created and saved to #{OSX_APP_DIR}."
rescue => error
puts error.message
puts error.backtrace.join("\n")
end
end
end
configuration = ARGV.shift
configuration ||= Fusuma::Build::DEFAULT_CONFIGURATION # use the default configuration if none given
Fusuma::Build.new(configuration)