From 9fbd031196c27d450c1a402a17e082235ef3d9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=88=D0=B0?= Date: Mon, 10 Jun 2019 10:33:55 +0300 Subject: [PATCH] Add script for download screenshots --- xcode/aux_scripts/download_screenshots.sh | 11 +++ xcode/aux_scripts/screenshots.rb | 111 ++++++++++++++++++++++ xcode/commonFastfile | 6 ++ 3 files changed, 128 insertions(+) create mode 100755 xcode/aux_scripts/download_screenshots.sh create mode 100755 xcode/aux_scripts/screenshots.rb diff --git a/xcode/aux_scripts/download_screenshots.sh b/xcode/aux_scripts/download_screenshots.sh new file mode 100755 index 0000000..8f4010e --- /dev/null +++ b/xcode/aux_scripts/download_screenshots.sh @@ -0,0 +1,11 @@ +#!/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 new file mode 100755 index 0000000..05b8bda --- /dev/null +++ b/xcode/aux_scripts/screenshots.rb @@ -0,0 +1,111 @@ + +require 'net/http' +require 'rest-client' +require 'json' +require 'fileutils' +require 'docopt' + +baseUrl = 'https://api.figma.com/v1/' +filesUrl = 'files/' +imageUrl = 'images/' + +# 1. Get input for Figma API +doc = < --file= --folder= +DOCOPT + +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 040c3ab..163b8de 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -45,6 +45,11 @@ 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 + private_lane :uploadToAppStore do |options| upload_to_app_store( username: options[:username] || options[:apple_id], @@ -113,6 +118,7 @@ private_lane :buildConfiguration do |options| syncCodeSigning(options) buildArchive(options) + screenshots() uploadToAppStore(options) end end