From e28259b1edb280e4eb2a1add0b4fe8bd0884c03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=88=D0=B0?= Date: Thu, 19 Sep 2019 09:25:21 +0300 Subject: [PATCH] Added options in screenshots lane --- xcode/aux_scripts/download_screenshots.sh | 11 -- xcode/aux_scripts/screenshots.rb | 187 ++++++++++------------ xcode/commonFastfile | 20 ++- 3 files changed, 102 insertions(+), 116 deletions(-) delete mode 100755 xcode/aux_scripts/download_screenshots.sh diff --git a/xcode/aux_scripts/download_screenshots.sh b/xcode/aux_scripts/download_screenshots.sh deleted file mode 100755 index 8f4010e..0000000 --- a/xcode/aux_scripts/download_screenshots.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -export INFO_PATH="$(dirname $PWD)" - -while read -r token file; do -do_stuff_with "$token" -do_stuff_with "$file" -done < $INFO_PATH/Figma/test.txt - -SCRIPT_PATH=`dirname $0` -ruby $SCRIPT_PATH/screenshots.rb --token="$token" --file="$file" --folder=$INFO_PATH/fastlane/screenshots diff --git a/xcode/aux_scripts/screenshots.rb b/xcode/aux_scripts/screenshots.rb index 05b8bda..7a09952 100755 --- a/xcode/aux_scripts/screenshots.rb +++ b/xcode/aux_scripts/screenshots.rb @@ -5,107 +5,94 @@ require 'json' require 'fileutils' require 'docopt' -baseUrl = 'https://api.figma.com/v1/' -filesUrl = 'files/' -imageUrl = 'images/' +def screenshots(token, file, folder) + + baseUrl = 'https://api.figma.com/v1/' + filesUrl = 'files/' + imageUrl = 'images/' + figmaToken = token; + figmaFile = file; + imagesFolder = folder; + imagesFormat = "png" -# 1. Get input for Figma API -doc = < --file= --folder= -DOCOPT + #################################################### + puts '🌿 Get all nodes for file...' + #################################################### + + # 2. Get all nodes for file with screenshots + response = RestClient::Request.new( + :method => :get, + :url => baseUrl + filesUrl + figmaFile, + :headers => { + 'X-FIGMA-TOKEN': figmaToken + }, + :verify_ssl => false + ).execute + results = JSON.parse(response.to_str) + + #################################################### + puts '🌿 Get url for image...' + #################################################### + + # 3. Create dictionary with url screenshots + screenshotPage = String.new + pages = results['document']['children'] + for tempPage in pages + if tempPage['name'] == 'Screenshots' then + screenshotPage = tempPage + break + end + end + + screenshotIds = String.new + screenshotFrames = Hash.new + groups = screenshotPage['children'] + for tempGroup in groups + + if tempGroup['type'] == 'GROUP' then + groupName = tempGroup['name'] + nodes = tempGroup['children'] + + for tempNode in nodes + if tempNode['type'] == 'FRAME' then + screenshotFrames[tempNode['id']] = '/' + groupName + '/' + tempNode['name'] + screenshotIds += tempNode['id'] + ',' + end + end + end + end + + # 4. Get url for images + response = RestClient::Request.new( + :method => :get, + :url => baseUrl+imageUrl+figmaFile, + :headers => { + 'X-FIGMA-TOKEN': figmaToken, + :params => {:ids => screenshotIds[0..-2], :scale => 3, :format => imagesFormat}, + }, + :verify_ssl => false + ).execute + results = JSON.parse(response.to_str) + + #################################################### + puts '🌿 Download images...' + #################################################### + + # 5. Download images in folders + imagesUrl = results['images'] + imagesUrl.each do |key, value| + data = RestClient.get(value).body + folder = (imagesFolder + screenshotFrames[key]).chop + FileUtils.mkdir_p folder + File.write(imagesFolder + screenshotFrames[key] + '.' + imagesFormat, data, mode: 'wb') + end + + #################################################### + puts '🌿 Finish. Hooray!' + #################################################### -begin - args = Docopt::docopt(doc) - rescue Docopt::Exit => e - puts e.message - exit end - -figmaToken = args['--token']; -figmaFile = args['--file']; -imagesFolder = args['--folder']; -imagesFormat = "png" - -#################################################### -puts '🌿 Start.' -#################################################### - -#################################################### -puts '🌿 Get all nodes for file...' -#################################################### - -# 2. Get all nodes for file with screenshots -response = RestClient::Request.new( - :method => :get, - :url => baseUrl + filesUrl + figmaFile, - :headers => { - 'X-FIGMA-TOKEN': figmaToken - }, - :verify_ssl => false -).execute -results = JSON.parse(response.to_str) - -#################################################### -puts '🌿 Get url for image...' -#################################################### - -# 3. Create dictionary with url screenshots -screenshotPage = String.new -pages = results['document']['children'] -for tempPage in pages - if tempPage['name'] == 'Screenshots' then - screenshotPage = tempPage - break - end -end - -screenshotIds = String.new -screenshotFrames = Hash.new -groups = screenshotPage['children'] -for tempGroup in groups - - if tempGroup['type'] == 'GROUP' then - groupName = tempGroup['name'] - nodes = tempGroup['children'] - - for tempNode in nodes - if tempNode['type'] == 'FRAME' then - screenshotFrames[tempNode['id']] = '/' + groupName + '/' + tempNode['name'] - screenshotIds += tempNode['id'] + ',' - end - end - end -end - -# 4. Get url for images -response = RestClient::Request.new( - :method => :get, - :url => baseUrl+imageUrl+figmaFile, - :headers => { - 'X-FIGMA-TOKEN': figmaToken, - :params => {:ids => screenshotIds[0..-2], :scale => 3, :format => imagesFormat}, - }, - :verify_ssl => false -).execute -results = JSON.parse(response.to_str) - -#################################################### -puts '🌿 Download images...' -#################################################### - -# 5. Download images in folders -imagesUrl = results['images'] -imagesUrl.each do |key, value| - data = RestClient.get(value).body - folder = (imagesFolder + screenshotFrames[key]).chop - FileUtils.mkdir_p folder - File.write(imagesFolder + screenshotFrames[key] + '.' + imagesFormat, data, mode: 'wb') -end - -#################################################### -puts '🌿 Finish. Hooray!' -#################################################### - diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 163b8de..950187a 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -1,3 +1,5 @@ +import '../build-scripts/xcode/aux_scripts/screenshots.rb' + $appName = File.basename(Dir['../*.xcworkspace'].first, '.*') private_lane :installDependencies do |options| @@ -45,10 +47,12 @@ private_lane :uploadToFabric do |options| ) end -lane :screenshots do - path = File.expand_path "../build-scripts/xcode/aux_scripts/download_screenshots.sh" - sh "bash #{path}" - end +lane :exportStoreScreenshots do |options| + figmaToken = options[:figmaToken] + figmaFile = options[:figmaFile] + imagesFolder = File.expand_path "../fastlane/screenshots" + screenshots(figmaToken, figmaFile, imagesFolder) + end private_lane :uploadToAppStore do |options| upload_to_app_store( @@ -112,13 +116,14 @@ private_lane :buildConfiguration do |options| if options[:uploadToAppStore] options[:compileBitcode] = options[:compileBitcode].nil? ? true : options[:compileBitcode] options[:include_symbols] = options[:include_symbols].nil? ? true : options[:include_symbols] + options = options.merge(get_screenshots_options()) options = options.merge(make_options_for_lane_name("AppStore")) options = merge_options_with_config_file(options) syncCodeSigning(options) buildArchive(options) - screenshots() + exportStoreScreenshots(options) uploadToAppStore(options) end end @@ -219,6 +224,11 @@ def get_keychain_options(options) return {:keychain_name => keychain_name, :keychain_password => keychain_password} end +def get_screenshots_options() + figmaTokenAndFileOptions = load_options_from("screenshots.yaml") + return figmaTokenAndFileOptions +end + def configuration_type_from_lane_name(lane_name) case when lane_name.start_with?("Enterprise")