Added Rubocop; try to bump iOS version number correctly on build

This commit is contained in:
Ken-ichi Ueda
2023-05-03 16:02:47 -07:00
parent 27356d5b9f
commit e7edbfab07
7 changed files with 204 additions and 94 deletions

91
.rubocop.yml Normal file
View File

@@ -0,0 +1,91 @@
AllCops:
NewCops: enable
Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation
IndentationWidth: 2
Layout/CaseIndentation:
EnforcedStyle: end
Layout/EndAlignment:
EnforcedStyleAlignWith: start_of_line
Layout/DotPosition:
EnforcedStyle: trailing
Layout/LineEndStringConcatenationIndentation:
EnforcedStyle: indented
Layout/MultilineAssignmentLayout:
EnforcedStyle: same_line
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
Layout/MultilineOperationIndentation:
EnforcedStyle: indented
Layout/SpaceInsideBlockBraces:
SpaceBeforeBlockParameters: false
Layout/SpaceAroundBlockParameters:
# This is weird, but without it you get a conflict / infinite loop with
# SpaceInsideParens
EnforcedStyleInsidePipes: space
Layout/SpaceInsideParens:
EnforcedStyle: space
Lint/NoReturnInBeginEndBlocks:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Naming/AccessorMethodName:
Enabled: false
Naming/VariableNumber:
Enabled: false
Style/Documentation:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Style/PercentLiteralDelimiters:
PreferredDelimiters:
"%w": "()"
# Not sure why but this causes some weird failures
Style/RedundantSort:
Enabled: false
Style/SymbolArray:
Enabled: false
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/WordArray:
Enabled: false

10
Gemfile
View File

@@ -1,8 +1,10 @@
source 'https://rubygems.org' # frozen_string_literal: true
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby '>= 2.6.10'
gem 'cocoapods', '>= 1.11.3' source "https://rubygems.org"
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"
gem "cocoapods", ">= 1.11.3"
gem "fastlane" gem "fastlane"
gem "nokogiri" gem "nokogiri"

View File

@@ -9,7 +9,7 @@ GEM
minitest (>= 5.1) minitest (>= 5.1)
tzinfo (~> 2.0) tzinfo (~> 2.0)
zeitwerk (~> 2.3) zeitwerk (~> 2.3)
addressable (2.8.2) addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0) public_suffix (>= 2.0.2, < 6.0)
algoliasearch (1.27.5) algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3) httpclient (~> 2.8, >= 2.8.3)
@@ -17,16 +17,16 @@ GEM
artifactory (3.0.15) artifactory (3.0.15)
atomos (0.1.3) atomos (0.1.3)
aws-eventstream (1.2.0) aws-eventstream (1.2.0)
aws-partitions (1.740.0) aws-partitions (1.759.0)
aws-sdk-core (3.171.0) aws-sdk-core (3.171.0)
aws-eventstream (~> 1, >= 1.0.2) aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0) aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5) aws-sigv4 (~> 1.5)
jmespath (~> 1, >= 1.6.1) jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.63.0) aws-sdk-kms (1.64.0)
aws-sdk-core (~> 3, >= 3.165.0) aws-sdk-core (~> 3, >= 3.165.0)
aws-sigv4 (~> 1.1) aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.120.0) aws-sdk-s3 (1.121.0)
aws-sdk-core (~> 3, >= 3.165.0) aws-sdk-core (~> 3, >= 3.165.0)
aws-sdk-kms (~> 1) aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4) aws-sigv4 (~> 1.4)
@@ -116,7 +116,7 @@ GEM
faraday_middleware (1.2.0) faraday_middleware (1.2.0)
faraday (~> 1.0) faraday (~> 1.0)
fastimage (2.2.6) fastimage (2.2.6)
fastlane (2.212.1) fastlane (2.212.2)
CFPropertyList (>= 2.3, < 4.0.0) CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0) addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0) artifactory (~> 3.0)
@@ -159,7 +159,7 @@ GEM
fourflusher (2.3.1) fourflusher (2.3.1)
fuzzy_match (2.0.4) fuzzy_match (2.0.4)
gh_inspector (1.1.3) gh_inspector (1.1.3)
google-apis-androidpublisher_v3 (0.38.0) google-apis-androidpublisher_v3 (0.41.0)
google-apis-core (>= 0.11.0, < 2.a) google-apis-core (>= 0.11.0, < 2.a)
google-apis-core (0.11.0) google-apis-core (0.11.0)
addressable (~> 2.5, >= 2.5.1) addressable (~> 2.5, >= 2.5.1)
@@ -190,7 +190,7 @@ GEM
google-cloud-core (~> 1.6) google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a) googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0) mini_mime (~> 1.0)
googleauth (1.5.0) googleauth (1.5.2)
faraday (>= 0.17.3, < 3.a) faraday (>= 0.17.3, < 3.a)
jwt (>= 1.4, < 3.0) jwt (>= 1.4, < 3.0)
memoist (~> 0.16) memoist (~> 0.16)
@@ -290,4 +290,4 @@ RUBY VERSION
ruby 2.7.5p203 ruby 2.7.5p203
BUNDLED WITH BUNDLED WITH
2.2.27 2.3.9

View File

@@ -1,6 +1,8 @@
# frozen_string_literal: true
require "fileutils" require "fileutils"
appfile_path = File.join( File.expand_path( File.dirname( __FILE__ ) ), "Appfile" ) appfile_path = File.join( __dir__, "Appfile" )
unless File.exist?( appfile_path ) unless File.exist?( appfile_path )
UI.abort_with_message! <<~NO_APPFILE_ERROR.gsub( /\s+/, " " ).strip UI.abort_with_message! <<~NO_APPFILE_ERROR.gsub( /\s+/, " " ).strip
Could not find #{appfile_path}. Copy the example file in that directory to Could not find #{appfile_path}. Copy the example file in that directory to
@@ -8,12 +10,12 @@ unless File.exist?( appfile_path )
NO_APPFILE_ERROR NO_APPFILE_ERROR
end end
VERSION = File.open( "../package.json" ) { | f | JSON.parse( f.read )["version"] } VERSION = File.open( "../package.json" ) {| f | JSON.parse( f.read )["version"] }
editor_cmd = [ editor_cmd = [
ENV["EDITOR"], ENV["EDITOR"],
`git config core.editor`, `git config core.editor`,
`which vi` `which vi`
].map{| e | e.to_s.strip }.detect {| e | !e.empty? } ].map {| e | e.to_s.strip }.detect {| e | !e.empty? }
if editor_cmd.nil? if editor_cmd.nil?
UI.abort_with_message! <<~NO_EDITOR_ERROR UI.abort_with_message! <<~NO_EDITOR_ERROR
Could not find an editor, not even vi. Set the EDITOR environmental Could not find an editor, not even vi. Set the EDITOR environmental
@@ -31,13 +33,13 @@ PACKAGE_ID = CredentialsManager::AppfileConfig.try_fetch_value( :package_name )
def set_android_version_code( new_version_code ) def set_android_version_code( new_version_code )
build_gradle_path = "../android/app/build.gradle" build_gradle_path = "../android/app/build.gradle"
new_gradle = File.read( build_gradle_path ).sub( /versionCode\s+\d+/, "versionCode #{new_version_code}" ) new_gradle = File.read( build_gradle_path ).sub( /versionCode\s+\d+/, "versionCode #{new_version_code}" )
File.open( build_gradle_path, "w" ) { | f | f.write( new_gradle ) } File.open( build_gradle_path, "w" ) {| f | f.write( new_gradle ) }
end end
def set_android_version_name( new_version_name ) def set_android_version_name( _new_version_name )
build_gradle_path = "../android/app/build.gradle" build_gradle_path = "../android/app/build.gradle"
new_gradle = File.read( build_gradle_path ).sub( /versionName\s+".+"/, "versionName \"#{VERSION}\"" ) new_gradle = File.read( build_gradle_path ).sub( /versionName\s+".+"/, "versionName \"#{VERSION}\"" )
File.open( build_gradle_path, "w" ) { | f | f.write( new_gradle ) } File.open( build_gradle_path, "w" ) {| f | f.write( new_gradle ) }
end end
def get_changelog_path( build_number = nil ) def get_changelog_path( build_number = nil )
@@ -49,8 +51,8 @@ end
def get_aab_path( build_number = nil ) def get_aab_path( build_number = nil )
build_number ||= get_build_number( xcodeproj: XCODEPROJ ) build_number ||= get_build_number( xcodeproj: XCODEPROJ )
aab_path = File.join( File.join(
File.expand_path( File.dirname( __FILE__ ) ), __dir__,
"..", "..",
"android", "android",
"app", "app",
@@ -64,8 +66,8 @@ end
def get_apk_path( build_number = nil ) def get_apk_path( build_number = nil )
build_number ||= get_build_number( xcodeproj: XCODEPROJ ) build_number ||= get_build_number( xcodeproj: XCODEPROJ )
aab_path = File.join( File.join(
File.expand_path( File.dirname( __FILE__ ) ), __dir__,
"..", "..",
"android", "android",
"app", "app",
@@ -79,8 +81,8 @@ end
def get_ipa_path( build_number = nil ) def get_ipa_path( build_number = nil )
build_number ||= get_build_number( xcodeproj: XCODEPROJ ) build_number ||= get_build_number( xcodeproj: XCODEPROJ )
aab_path = File.join( File.join(
File.expand_path( File.dirname( __FILE__ ) ), __dir__,
"..", "..",
"ios", "ios",
"build", "build",
@@ -94,6 +96,7 @@ lane :tag do
last_tag = last_git_tag last_tag = last_git_tag
# Increment the iOS build number # Increment the iOS build number
increment_build_number( xcodeproj: XCODEPROJ ) increment_build_number( xcodeproj: XCODEPROJ )
increment_version_number( version_number: VERSION )
build_number = get_build_number( xcodeproj: XCODEPROJ ) build_number = get_build_number( xcodeproj: XCODEPROJ )
# set android/app/build.gradle versionCode to this build_number # set android/app/build.gradle versionCode to this build_number
set_android_version_code( build_number ) set_android_version_code( build_number )
@@ -105,7 +108,7 @@ lane :tag do
if last_tag && changes.empty? if last_tag && changes.empty?
UI.abort_with_message! "Nothing has changed since the last tag (#{last_tag})" UI.abort_with_message! "Nothing has changed since the last tag (#{last_tag})"
end end
# Get release notes # Get release notes
# Bit silly but takes advantage of existing syntax highlighting # Bit silly but takes advantage of existing syntax highlighting
fname = "COMMIT_EDITMSG" fname = "COMMIT_EDITMSG"
@@ -127,7 +130,7 @@ lane :tag do
end end
release_notes.strip! release_notes.strip!
FileUtils.rm( fname ) FileUtils.rm( fname )
if release_notes.strip.size == 0 if release_notes.strip.size.zero?
reset_git_repo skip_clean: true reset_git_repo skip_clean: true
UI.abort_with_message! "You gotta enter release notes!" UI.abort_with_message! "You gotta enter release notes!"
end end
@@ -145,10 +148,14 @@ lane :tag do
git_add( path: changelog_git_path ) git_add( path: changelog_git_path )
# commit # commit
commit_version_bump( message: tag, xcodeproj: XCODEPROJ, include: [ commit_version_bump(
"android/app/build.gradle", message: tag,
changelog_git_path xcodeproj: XCODEPROJ,
] ) include: [
"android/app/build.gradle",
changelog_git_path
]
)
push_to_git_remote push_to_git_remote
# Create a tag for this release # Create a tag for this release
@@ -160,7 +167,7 @@ platform :android do
lane :build do lane :build do
desc "Build release files for Android" desc "Build release files for Android"
keystore_properties_path = File.join( keystore_properties_path = File.join(
File.expand_path( File.dirname( __FILE__ ) ), __dir__,
"..", "..",
"android", "android",
"keystore.properties" "keystore.properties"
@@ -291,14 +298,18 @@ lane :release do
) )
if github_release if github_release
UI.important "Release already exists at #{github_release["url"]}. You need to manually upload any missing assets." UI.important "Release already exists at #{github_release['url']}. You need to manually upload any missing assets."
else else
set_github_release( set_github_release(
repository_name: "inaturalist/iNaturalistReactNative", repository_name: "inaturalist/iNaturalistReactNative",
api_token: ENV["GITHUB_TOKEN"], api_token: ENV["GITHUB_TOKEN"],
name: last_tag, name: last_tag,
tag_name: last_tag, tag_name: last_tag,
description: ( File.read( changelog_path ) rescue nil ), description: begin
File.read( changelog_path )
rescue StandardError
nil
end,
# This is really just a fallback in case last_tag isn't really a tag # This is really just a fallback in case last_tag isn't really a tag
commitish: "main", commitish: "main",
upload_assets: [apk_path] upload_assets: [apk_path]
@@ -312,7 +323,9 @@ lane :internal do
# Ensure build files exist for the latest tag # Ensure build files exist for the latest tag
aab_path = get_aab_path aab_path = get_aab_path
unless File.exist?( aab_path ) unless File.exist?( aab_path )
UI.abort_with_message! "AAB does not exist at #{aab_path}. You may need to run the release lane before making a beta" UI.abort_with_message! <<~MSG
AAB does not exist at #{aab_path}. You may need to run the release lane before making a beta
MSG
end end
last_tag = last_git_tag last_tag = last_git_tag
if last_tag.nil? || last_tag.empty? if last_tag.nil? || last_tag.empty?
@@ -370,4 +383,3 @@ lane :prod do
# been able to test that yet # been able to test that yet
upload_to_play_store( version_code: build_number, track: "beta", track_promote_to: "production" ) upload_to_play_store( version_code: build_number, track: "beta", track_promote_to: "production" )
end end

View File

@@ -1,5 +1,7 @@
require_relative '../node_modules/react-native/scripts/react_native_pods' # frozen_string_literal: true
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative "../node_modules/react-native/scripts/react_native_pods"
require_relative "../node_modules/@react-native-community/cli-platform-ios/native_modules"
platform :ios, min_ios_version_supported platform :ios, min_ios_version_supported
prepare_react_native_project! prepare_react_native_project!
@@ -13,102 +15,103 @@ prepare_react_native_project!
# dependencies: { # dependencies: {
# ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}), # ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ``` # ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled # flipper_config = ENV["NO_FLIPPER"] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled
linkage = ENV['USE_FRAMEWORKS'] linkage = ENV["USE_FRAMEWORKS"]
if linkage != nil unless linkage.nil?
Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
use_frameworks! :linkage => linkage.to_sym use_frameworks! linkage: linkage.to_sym
end end
target 'iNaturalistReactNative' do target "iNaturalistReactNative" do
config = use_native_modules! config = use_native_modules!
# Flags change depending on the env values. # Flags change depending on the env values.
flags = get_default_flags() flags = get_default_flags
permissions_path = '../node_modules/react-native-permissions/ios' permissions_path = "../node_modules/react-native-permissions/ios"
use_react_native!( use_react_native!(
:path => config[:reactNativePath], path: config[:reactNativePath],
# Hermes is now enabled by default. Disable by setting this flag to false. # Hermes is now enabled by default. Disable by setting this flag to false.
# Upcoming versions of React Native may rely on get_default_flags(), but # Upcoming versions of React Native may rely on get_default_flags(), but
# we make it explicit here to aid in the React Native upgrade process. # we make it explicit here to aid in the React Native upgrade process.
:hermes_enabled => flags[:hermes_enabled], hermes_enabled: flags[:hermes_enabled],
:fabric_enabled => flags[:fabric_enabled], fabric_enabled: flags[:fabric_enabled],
# Enables Flipper. # Enables Flipper.
# #
# Note that if you have use_frameworks! enabled, Flipper will not work and # Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line. # you should disable the next line.
# :flipper_configuration => flipper_config, # :flipper_configuration => flipper_config,
# An absolute path to your application root. # An absolute path to your application root.
:app_path => "#{Pod::Config.instance.installation_root}/.." app_path: "#{Pod::Config.instance.installation_root}/.."
) )
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi', :modular_headers => true pod "React-jsi", path: "../node_modules/react-native/ReactCommon/jsi", modular_headers: true
pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse" pod "Permission-LocationWhenInUse", path: "#{permissions_path}/LocationWhenInUse"
pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary" pod "Permission-PhotoLibrary", path: "#{permissions_path}/PhotoLibrary"
pod 'react-native-config', :path => '../node_modules/react-native-config' pod "react-native-config", path: "../node_modules/react-native-config"
pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons' pod "RNVectorIcons", path: "../node_modules/react-native-vector-icons"
ENVFILES = { envfiles = {
'Debug' => '$(PODS_ROOT)/../../.env.staging', "Debug" => "$(PODS_ROOT)/../../.env.staging",
'Release' => '$(PODS_ROOT)/../../.env', "Release" => "$(PODS_ROOT)/../../.env"
} }.freeze
post_install do |installer| post_install do | installer |
# use different .env files for staging and production # use different .env files for staging and production
# https://github.com/luggit/react-native-config#ios-1 # https://github.com/luggit/react-native-config#ios-1
installer.pods_project.targets.each do |target| installer.pods_project.targets.each do | target |
target.build_configurations.each do |config| target.build_configurations.each do | build_config |
# the following two lines allow the app to build with XCode 14.3 RC # the following two lines allow the app to build with XCode 14.3 RC
# https://stackoverflow.com/questions/72729591/fbreactnativespec-h-error-after-upgrading-from-0-68-x-to-0-69-0/74487309#74487309 # https://stackoverflow.com/questions/72729591/fbreactnativespec-h-error-after-upgrading-from-0-68-x-to-0-69-0/74487309#74487309
config.build_settings['SWIFT_VERSION'] = '5.0' build_config.build_settings["SWIFT_VERSION"] = "5.0"
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.4' build_config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = "12.4"
if target.name == 'react-native-config' if target.name == "react-native-config"
config.build_settings['ENVFILE'] = ENVFILES[config.name] build_config.build_settings["ENVFILE"] = envfiles[build_config.name]
end end
end end
end end
# code below appears to be necessary for building pods with XCode 14: https://github.com/facebook/react-native/issues/34673#issuecomment-1252114414 # code below appears to be necessary for building pods with XCode 14: https://github.com/facebook/react-native/issues/34673#issuecomment-1252114414
react_native_post_install( react_native_post_install(
installer, installer,
# Set `mac_catalyst_enabled` to `true` in order to apply patches # Set `mac_catalyst_enabled` to `true` in order to apply patches
# necessary for Mac Catalyst builds # necessary for Mac Catalyst builds
:mac_catalyst_enabled => false mac_catalyst_enabled: false
) )
__apply_Xcode_12_5_M1_post_install_workaround(installer) __apply_Xcode_12_5_M1_post_install_workaround( installer )
# Add these lines for Xcode 14 builds # Add these lines for Xcode 14 builds
installer.generated_projects.each do |project| installer.generated_projects.each do | project |
project.targets.each do |target| project.targets.each do | target |
target.build_configurations.each do |config| target.build_configurations.each do | build_config |
config.build_settings["DEVELOPMENT_TEAM"] = "iNaturalist, LLC" build_config.build_settings["DEVELOPMENT_TEAM"] = "iNaturalist, LLC"
end end
end end
end end
# End of added lines # End of added lines
# https://github.com/Agontuk/react-native-geolocation-service/issues/287#issuecomment-980772489 # https://github.com/Agontuk/react-native-geolocation-service/issues/287#issuecomment-980772489
installer.pods_project.targets.each do |target| installer.pods_project.targets.each do | target |
target.build_configurations.each do |config| target.build_configurations.each do | build_config |
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" build_config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
# code below appears to be necessary for building pods with XCode 14: # code below appears to be necessary for building pods with XCode 14:
# https://github.com/facebook/react-native/issues/34673#issuecomment-1252114414 # https://github.com/facebook/react-native/issues/34673#issuecomment-1252114414
config.build_settings["DEVELOPMENT_TEAM"] = "iNaturalist, LLC" build_config.build_settings["DEVELOPMENT_TEAM"] = "iNaturalist, LLC"
end end
end end
installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result| installer.target_installation_results.pod_target_installation_results.each do | _pod_name, inst_result |
target_installation_result.native_target.build_configurations.each do |config| inst_result.native_target.build_configurations.each do | build_config |
# For third party modules who have React-bridging dependency to search correct headers # For third party modules who have React-bridging dependency to search correct headers
config.build_settings['HEADER_SEARCH_PATHS'] ||= '$(inherited) ' build_config.build_settings["HEADER_SEARCH_PATHS"] ||= "$(inherited) "
config.build_settings['HEADER_SEARCH_PATHS'] << '"$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" ' build_config.build_settings["HEADER_SEARCH_PATHS"] <<
config.build_settings['HEADER_SEARCH_PATHS'] << '"$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers" ' '"$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" '
build_config.build_settings["HEADER_SEARCH_PATHS"] <<
'"$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers" '
end end
end end
#react_native_post_install(installer) # react_native_post_install(installer)
`sed -i -e $'s/__IPHONE_10_0/__IPHONE_12_0/' Pods/RCT-Folly/folly/portability/Time.h` `sed -i -e $'s/__IPHONE_10_0/__IPHONE_12_0/' Pods/RCT-Folly/folly/portability/Time.h`
end end
end end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require "nokogiri" require "nokogiri"
num_cleaned = 0 num_cleaned = 0
@@ -5,11 +7,13 @@ num_cleaned = 0
unless path.end_with?( ".svg" ) unless path.end_with?( ".svg" )
raise "#{path} is not a .svg file" raise "#{path} is not a .svg file"
end end
svg = File.read( path ) svg = File.read( path )
doc = Nokogiri::XML( svg, &:noblanks ) doc = Nokogiri::XML( svg, &:noblanks )
if doc.at( "svg" )["width"].to_i != 24 || doc.at( "svg" )["height"].to_i != 24 if doc.at( "svg" )["width"].to_i != 24 || doc.at( "svg" )["height"].to_i != 24
raise "#{path} is not a 24x24 square" raise "#{path} is not a 24x24 square"
end end
doc.search( "//path" ).each do | path_node | doc.search( "//path" ).each do | path_node |
if path_node["fill-rule"] == "evenodd" || path_node["style"] =~ /fill-rule:\s+?evenodd/ if path_node["fill-rule"] == "evenodd" || path_node["style"] =~ /fill-rule:\s+?evenodd/
raise "#{path} has a path with evenodd. They should all have nonzero fill." raise "#{path} has a path with evenodd. They should all have nonzero fill."
@@ -17,20 +21,18 @@ num_cleaned = 0
end end
doc.at( "defs" )&.remove doc.at( "defs" )&.remove
if doc.namespaces.include?( "xmlns:sodipodi" ) if doc.namespaces.include?( "xmlns:sodipodi" )
doc.search( "//sodipodi:namedview" ).each do | node | doc.search( "//sodipodi:namedview" ).each( &:remove )
node.remove
end
end end
doc.traverse do | node | doc.traverse do | node |
next unless node.respond_to? :attributes next unless node.respond_to? :attributes
node.attributes.each do |key, val|
if ( node.attributes.each do | key, val |
next unless
val&.namespace&.prefix == "sodipodi" || val&.namespace&.prefix == "sodipodi" ||
val&.namespace&.prefix == "inkscape" || val&.namespace&.prefix == "inkscape" ||
%w(id style fill).include?( key ) %w(id style fill).include?( key )
)
val.remove val.remove
end
end end
end end
# doc.at("svg").remove_attribute "xmlns:inkscape" # doc.at("svg").remove_attribute "xmlns:inkscape"

View File

@@ -12,7 +12,7 @@ if ! type react-native-asset > /dev/null; then
exit exit
fi fi
bundle exec ruby scripts/clean-icon-svgs.rb src/images/icons/*.svg bundle exec ruby scripts/clean_icon_svgs.rb src/images/icons/*.svg
# Generate the font file and the glyphmap # Generate the font file and the glyphmap
fantasticon src/images/icons/ \ fantasticon src/images/icons/ \