Add script for download screenshots
This commit is contained in:
parent
1da691921b
commit
9fbd031196
|
|
@ -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
|
||||
|
|
@ -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 = <<DOCOPT
|
||||
My pro
|
||||
|
||||
Usage:
|
||||
#{__FILE__} --token=<token> --file=<file> --folder=<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!'
|
||||
####################################################
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue