-
Notifications
You must be signed in to change notification settings - Fork 44
/
sc-build
executable file
·161 lines (122 loc) · 5.04 KB
/
sc-build
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
#!/usr/bin/env ruby
# BUILD SPROUTCORE APPLICATIONS
# This script will build SproutCore applications for you. Usage:
#
# sc-build build all clients
# sc-build bundle-name build just the named bundle
# sc-build -l library_root path to the library you want to load bundles from
# sc-build -t build_root set optional build root
# sc-build -e development|production defaults to production
# sc-build bundle-name -r builds bundle and dependent bundles but none others
APP_ROOT = File.expand_path(Dir.pwd)
SC_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
$:.unshift File.join(SC_ROOT,'lib') ;
# Set String encoding to Unicode
$KCODE = 'u'
# Require SproutCore
require 'rubygems'
require 'rubigen'
require 'sproutcore'
require 'optparse'
############################################################
## Define Helper Methods
##
def not_found(bundle_name)
SC.logger.fatal("Could not find a bundle named: #{bundle_name}")
exit(1)
end
############################################################
## Process Options
##
# Setup defaults
build_mode = :production
build_root = File.join(APP_ROOT,'tmp','build')
bundle_name = ARGV.shift if (ARGV.size > 0 && ARGV[0][0..0] != '-')
library_root = APP_ROOT
include_dependencies = false
verbose = false # show debug level
languages = nil
clean = false
docs = false
opts = OptionParser.new do |opts|
opts.version = SproutCore::VERSION::STRING
opts.banner = "Usage: sc-build {bundle-name} {options}"
opts.define_head "Build Tool for SproutCore applications"
opts.separator '*'*80
opts.separator 'If no flags are given, sc-build will try to build all of the bundles in the current directory'
opts.separator '*'*80
opts.on("-e", "--environment=MODE", "Set the build mode for the system. Normally you want to build in production mode (which is the default if you do not include this option), but you can use this switch to build in development mode for testing.") do |opt_build_mode|
build_mode = opt_build_mode.to_s.downcase.to_sym
end
opts.on("-t", "--target=PATH", "Set the target path for your build. Normally this will be set to tmp/build in the working directory") do |opt_target|
build_root = File.expand_path(opt_target)
end
opts.on("-l", "--library=PATH", "The library root you want to use. Normally sc-build will use the working directory. If you want to point to another project on disk to build from, use this option.") do |opt_library|
library_root = File.expand_path(opt_library)
end
opts.on("-r", "--[no-]include-required", "If passed when building a single client, then the build tool will also find any required bundles and build them as well.") do |opt_req|
include_dependencies = !!opt_req
end
opts.on("-v", "--[no-]verbose", "If set, extra debug output will be displayed during the build") do |opt_verbose|
verbose = !!opt_verbose
end
opts.on("-L", "--languages=LANGUAGE", "Pass a comma separated list of the specific languages you want to build. If you do not pass this option, the build tool will build all languages required by the bundles to function") do |opt_lang|
languages = opt_lang.split(',').map { |x| x.to_sym }
end
opts.on("-c", "--[no-]clean", "If set, then the build tool will delete a bundle's output before it builds it, so you get a clean build") do |opt_clean|
clean = !!opt_clean
end
opts.on('-d', '--[no-]docs', "Include documentation") do |opt_docs|
docs = !!opt_docs
end
end
opts.parse!
############################################################
## SETUP ENVIRONMENT
##
# Configure logger
SC.logger.level = (verbose) ? Logger::DEBUG : Logger::INFO
SC.logger.progname = $0
# Load Library
library = SC.library_for(library_root, :public_root => build_root, :build_mode => build_mode)
############################################################
## FIND BUNDLES TO BUILD
##
puts "build_root = #{build_root}"
# Find the bundles to build.
if bundle_name
# Get bundle
bundle = library.bundle_for(bundle_name.to_sym)
not_found(bundle) if bundle.nil?
# If dependencies are required, get those bundles as well
if include_dependencies
bundles = bundle.all_required_bundles
else
bundles = [bundle]
end
SC.logger.info("Building: #{bundles.map { |x| x.bundle_name } * ', ' }...")
# No bundle provided, get all bundles for library
else
bundles = library.bundles
SC.logger.info("Building ALL bundles:\n #{bundles.map { |x| x.bundle_name } * ', '}...")
end
############################################################
## BUILD EACH BUNDLE
##
# Detect required languages to build
languages = bundles.map { |b| b.installed_languages }.flatten.uniq if languages.nil?
SC.logger.info("Selected Languages: #{languages.join(', ')}")
SC.logger.info('')
bundles.each do |bundle|
SC.logger.info("Building #{bundle.bundle_name} > #{bundle.build_root}...")
if clean
SC.logger.debug("~ Cleaning #{bundle.build_root}")
FileUtils.rm_rf(bundle.build_root)
end
bundle.build(*languages)
if docs
SC.logger.debug('~ Building docs')
SC::JSDoc.generate(:bundle => bundle)
end
end
SC.logger.debug("")