-
Notifications
You must be signed in to change notification settings - Fork 238
/
Rakefile
101 lines (83 loc) · 2.95 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/rake
DESTINATIONS = {
:ios_sim => "OS=14.5,name=iPhone 11,platform=iOS Simulator",
:tvos_sim => "OS=14.5,name=Apple TV,platform=tvOS Simulator",
}
CARTHAGE_VERSION = '0.38.0'
SWIFTLINT_VERSION = '0.44.0'
## UTILS ##
def run(command, xcpretty: true)
if xcpretty && system('xcpretty --version >/dev/null')
sh "set -o pipefail && #{command} | xcpretty -c"
else
sh command
end
end
def xcodebuild(scheme: '', sdk: '', destination: '', action: 'build')
run %Q(xcodebuild -workspace Example/ReusableDemo.xcworkspace -scheme "#{scheme}" -sdk #{sdk} -destination="#{destination}" ONLY_ACTIVE_ARCH=NO #{action})
end
def install_pkg(pkg_url)
require 'tmpdir'
Dir.mktmpdir do |dir|
tmppath = File.join(dir, File.basename(pkg_url))
sh("curl -Lo #{tmppath} #{pkg_url}")
sh("sudo installer -pkg #{tmppath} -target /")
end
end
## TASKS ##
namespace :carthage do
desc "Install Carthage from pkg"
task :install do
next if system('which carthage >/dev/null') && Gem::Version.new(`carthage version`.chomp) >= Gem::Version.new(CARTHAGE_VERSION)
install_pkg("https://github.com/Carthage/Carthage/releases/download/#{CARTHAGE_VERSION}/Carthage.pkg")
end
desc "Builds the Reusable framework using Carthage"
task :build => :install do
run "carthage build --no-skip-current --use-xcframeworks --verbose"
end
end
namespace :demo do
desc "Builds the ReusableDemo app for iOS using xcodebuild."
task :ios do |t, args|
xcodebuild(scheme: 'ReusableDemo iOS', sdk: 'iphonesimulator', destination: DESTINATIONS[:ios_sim])
end
desc "Builds the ReusableDemo app for tvOS using xcodebuild."
task :tvos do |t, args|
xcodebuild(scheme: 'ReusableDemo tvOS', sdk: 'appletvsimulator', destination: DESTINATIONS[:tvos_sim])
end
end
namespace :fmk do
desc "Builds the Reusable framework for iOS using xcodebuild."
task :ios do |t, args|
xcodebuild(scheme: 'Reusable-iOS', sdk: 'iphonesimulator', destination: DESTINATIONS[:ios_sim])
end
desc "Builds the Reusable framework for tvOS using xcodebuild."
task :tvos do |t, args|
xcodebuild(scheme: 'Reusable-tvOS', sdk: 'appletvsimulator', destination: DESTINATIONS[:tvos_sim])
end
end
namespace :pod do
desc "Lints the Reusable.podspec"
task :lint do |t|
run("pod lib lint --allow-warnings --quick", xcpretty: false)
end
end
namespace :spm do
desc 'Build using SPM'
task :build do |task|
puts '*** Compile using SPM ***'
sh 'xcrun swift build'
end
end
namespace :swiftlint do
desc "Install SwiftLint from pkg"
task :install do
next if system('which swiftlint >/dev/null') && Gem::Version.new(`swiftlint version`.chomp) >= Gem::Version.new(SWIFTLINT_VERSION)
install_pkg("https://github.com/realm/SwiftLint/releases/download/#{SWIFTLINT_VERSION}/SwiftLint.pkg")
end
desc "Run SwiftLint on the source code"
task :run => :install do
run('swiftlint lint --strict', xcpretty: false)
end
end
# TODO: "namespace :test" once we have Unit Tests