-
Notifications
You must be signed in to change notification settings - Fork 1
Screenshots with parameters #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DashaGitHub
wants to merge
2
commits into
master
Choose a base branch
from
screenshots_with_parameters
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
|
||
require 'net/http' | ||
require 'rest-client' | ||
require 'json' | ||
require 'fileutils' | ||
require 'docopt' | ||
|
||
def screenshots(token, file, folder) | ||
|
||
baseUrl = 'https://api.figma.com/v1/' | ||
filesUrl = 'files/' | ||
imageUrl = 'images/' | ||
figmaToken = token; | ||
figmaFile = file; | ||
imagesFolder = 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!' | ||
#################################################### | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import '../build-scripts/xcode/aux_scripts/screenshots.rb' | ||
|
||
$appName = File.basename(Dir['../*.xcworkspace'].first, '.*') | ||
|
||
private_lane :installDependencies do |options| | ||
|
@@ -45,6 +47,13 @@ private_lane :uploadToFabric do |options| | |
) | ||
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( | ||
username: options[:username] || options[:apple_id], | ||
|
@@ -107,12 +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) | ||
exportStoreScreenshots(options) | ||
uploadToAppStore(options) | ||
end | ||
end | ||
|
@@ -213,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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can I see example of this file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. figmaToken: "21309-287b148b-987a-47b4-b82b-3abdb109260b" |
||
return figmaTokenAndFileOptions | ||
end | ||
|
||
def configuration_type_from_lane_name(lane_name) | ||
case | ||
when lane_name.start_with?("Enterprise") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move these steps into functions to improve readability