|
1 | | -SWIFTGEN_VERSION="6.1.0" |
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +SWIFTGEN_VERSION = '6.1.0' |
2 | 4 |
|
3 | 5 | require 'fileutils' |
4 | 6 | require 'tmpdir' |
5 | 7 | require 'rake/clean' |
6 | | -PROJECT_DIR = File.expand_path(File.dirname(__FILE__)) |
| 8 | +PROJECT_DIR = __dir__ |
7 | 9 |
|
8 | 10 | task default: %w[gen] |
9 | 11 |
|
10 | | -desc "Install required dependencies" |
11 | | -task :dependencies => %w[dependencies:check] |
| 12 | +desc 'Install required dependencies' |
| 13 | +task dependencies: %w[dependencies:check] |
12 | 14 |
|
13 | 15 | namespace :dependencies do |
14 | | - task :check => %w[gen:check] |
| 16 | + task check: %w[gen:check] |
15 | 17 |
|
16 | 18 | namespace :gen do |
17 | | - |
| 19 | + desc 'Install SwiftGen if needed' |
18 | 20 | task :check do |
19 | 21 | if swiftgen_needs_install |
20 | | - dependency_failed("SwiftGen") |
21 | | - Rake::Task["dependencies:gen:install"].invoke |
| 22 | + dependency_failed('SwiftGen') |
| 23 | + Rake::Task['dependencies:gen:install'].invoke |
22 | 24 | end |
23 | 25 | end |
24 | 26 |
|
| 27 | + desc 'Install SwiftGen' |
25 | 28 | task :install do |
26 | 29 | puts "Installing SwiftGen #{SWIFTGEN_VERSION} into #{swiftgen_path}" |
27 | 30 | Dir.mktmpdir do |tmpdir| |
28 | 31 | zipfile = "#{tmpdir}/swiftgen-#{SWIFTGEN_VERSION}.zip" |
29 | | - sh "curl --fail --location -o #{zipfile} https://github.com/SwiftGen/SwiftGen/releases/download/#{SWIFTGEN_VERSION}/swiftgen-#{SWIFTGEN_VERSION}.zip || true" |
30 | | - if File.exists?(zipfile) |
| 32 | + source = "https://github.com/SwiftGen/SwiftGen/releases/download/#{SWIFTGEN_VERSION}/swiftgen-#{SWIFTGEN_VERSION}.zip" |
| 33 | + sh "curl --fail --location -o #{zipfile} #{source} || true" |
| 34 | + if File.exist?(zipfile) |
31 | 35 | zipdir = "#{tmpdir}/swiftgen-#{SWIFTGEN_VERSION}" |
32 | 36 | sh "unzip -q #{zipfile} -d #{zipdir}" |
33 | 37 | Dir.chdir(zipdir) do |
34 | 38 | puts "Copying SwiftGen #{SWIFTGEN_VERSION} into #{swiftgen_path}" |
35 | 39 | FileUtils.remove_entry_secure(swiftgen_path) if Dir.exist?(swiftgen_path) |
36 | | - FileUtils.mkdir_p("#{swiftgen_path}") |
37 | | - FileUtils.cp_r("#{zipdir}/lib", "#{swiftgen_path}") |
38 | | - FileUtils.cp_r("#{zipdir}/bin", "#{swiftgen_path}") |
| 40 | + FileUtils.mkdir_p(swiftgen_path.to_s) |
| 41 | + FileUtils.cp_r("#{zipdir}/lib", swiftgen_path.to_s) |
| 42 | + FileUtils.cp_r("#{zipdir}/bin", swiftgen_path.to_s) |
39 | 43 | end |
40 | 44 | end |
41 | 45 | end |
42 | 46 | end |
43 | | - CLOBBER << "vendor/swiftgen" |
| 47 | + CLOBBER << 'vendor/swiftgen' |
44 | 48 | end |
45 | | - |
46 | 49 | end |
47 | 50 |
|
48 | | -CLOBBER << "vendor" |
| 51 | +CLOBBER << 'vendor' |
49 | 52 |
|
50 | | -desc "Regenerates the master Gridicon enum from PDF assets" |
51 | | -task :gen => %w[dependencies:gen:check] do |
| 53 | +desc 'Regenerates the master Gridicon enum from PDF assets' |
| 54 | +task gen: %w[dependencies:gen:check] do |
52 | 55 | swiftgen %w[xcassets -p Gridicons.stencil Gridicons/Gridicons/Gridicons.xcassets] |
53 | | - puts "Done!" |
| 56 | + puts 'Done!' |
54 | 57 | end |
55 | 58 |
|
56 | 59 | def swiftgen_path |
57 | | - "#{PROJECT_DIR}/vendor/swiftgen" |
| 60 | + "#{PROJECT_DIR}/vendor/swiftgen" |
58 | 61 | end |
59 | 62 |
|
60 | 63 | def swiftgen(args) |
61 | 64 | args = [swiftgen_bin] + args |
62 | | - sh(*args.join(" ") + " > Gridicons/Gridicons/GridiconsGenerated.swift") |
| 65 | + sh(["#{args.join(' ')} > Gridicons/Gridicons/GridiconsGenerated.swift"]) |
63 | 66 | end |
64 | 67 |
|
65 | 68 | def swiftgen_bin |
66 | | - "#{swiftgen_path}/bin/swiftgen" |
| 69 | + "#{swiftgen_path}/bin/swiftgen" |
67 | 70 | end |
68 | 71 |
|
69 | 72 | def swiftgen_needs_install |
70 | 73 | return true unless File.exist?(swiftgen_bin) |
| 74 | + |
71 | 75 | installed_version = `"#{swiftgen_bin}" --version | awk '{print $2}'`.chomp |
72 | 76 | installed_version.slice!(0) |
73 | | - return (installed_version != SWIFTGEN_VERSION) |
| 77 | + (installed_version != SWIFTGEN_VERSION) |
74 | 78 | end |
75 | 79 |
|
76 | 80 | def dependency_failed(component) |
77 | 81 | msg = "#{component} dependencies missing or outdated. " |
78 | 82 | if ENV['DRY_RUN'] |
79 | | - msg += "Run rake dependencies to install them." |
80 | | - fail msg |
| 83 | + msg += 'Run rake dependencies to install them.' |
| 84 | + raise msg |
81 | 85 | else |
82 | | - msg += "Installing..." |
| 86 | + msg += 'Installing...' |
83 | 87 | puts msg |
84 | 88 | end |
85 | 89 | end |
0 commit comments