Skip to content
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

V2.0 #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions .idea/fluent-icons.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"github-actions.workflows.pinned.workflows": [
".github/workflows/update.yml"
]
}
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ source "https://rubygems.org"
gemspec

gem "rake", "~> 12.0"

gem "pry", "~> 0.14.2"
7 changes: 6 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
fluent-icons (1.1.2.207)
fluent-icons (1.1.2.220)
actionview (>= 6)
railties (>= 6)

Expand Down Expand Up @@ -29,6 +29,7 @@ GEM
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
builder (3.2.4)
coderay (1.1.3)
concurrent-ruby (1.2.2)
crass (1.0.6)
erubi (1.12.0)
Expand All @@ -49,6 +50,9 @@ GEM
progress_bar (1.3.3)
highline (>= 1.6, < 3)
options (~> 2.3.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.3)
racc (1.7.1)
rack (2.2.7)
Expand Down Expand Up @@ -83,6 +87,7 @@ DEPENDENCIES
fluent-icons!
git (~> 1.9)
progress_bar (~> 1.3)
pry (~> 0.14.2)
rake (~> 12.0)

BUNDLED WITH
Expand Down
89 changes: 56 additions & 33 deletions bin/update
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,81 @@ else
Git.clone('https://github.com/microsoft/fluentui-system-icons.git', 'fluentui-system-icons')
end

puts 'Transferring the SVG Icons'
icons = Dir['fluentui-system-icons/assets/*/SVG/*']
progress_bar = ProgressBar.new(icons.size)
@schema = {
'name' => 'Fluent UI Icons',
'icons' => {},
'dictionary' => {},

'errors' => {
'metadata' => [],
'icons' => []
}
}

icons.each do |icon|
FileUtils.copy(icon, 'lib/build/svg')
progress_bar.increment!
end
files = Dir.glob(File.join('fluentui-system-icons', 'assets', '*', '{SVG/*,metadata.json}')).group_by { |file| file.split(File::SEPARATOR)[2] }

puts 'Organising the Icons'
groups_pb = ProgressBar.new(files.map(&:first).size)
icons_pb = ProgressBar.new(files.map(&:last).flatten.size)

@generate_docs = false
@docs = false
@schema = {}
files.each do |group, files|
icon_name = group.split.join('_').downcase

Dir['lib/build/svg/*.svg'].map { |icon| icon.split('/').last.split('.').first }.group_by { |icon| icon.split('_')[2..][-0..-3].join('_') }.each do |group, icons|
@schema[group] = {
name: icons[0].split('_')[0..-3].join('_'),
weights: [],
styles: [],
icons: { }
}
metadata_file = files.find { |file| file.end_with?('metadata.json') }

unless (metadata = JSON.parse(File.read(metadata_file)) rescue nil)
@schema['errors']['metadata'] << icon_name

# TODO: Build the metadata based on the files in the folder
#
metadata = {
'name' => group,
'size' => [],
'style' => [],
'metaphor' => []
}
end

icons.group_by { |icon| icon.split('_').last }.each do |variation, icons|
@schema[group][:icons][variation] = {}
@schema[group][:styles] << variation
metadata['label'] = metadata['name']
metadata['name'] = icon_name
metadata['icons'] = {}
metadata['metaphor']&.map!(&:downcase)

icons.each do |icon|
name = icon.split('_')[2..-3].join('_')
weight = icon.split('_')[-2]
src = ['lib/build/svg', "#{ icon }.svg"].join('/')
metadata['style'].map(&:downcase).each do |style|
metadata['icons'][style] = {}

metadata['size'].each do |size|
svg_file_path = File.join('fluentui-system-icons', 'assets', group, 'SVG', "ic_fluent_#{icon_name}_#{size}_#{style}.svg")
# next unless File.exist?(svg_file_path)

begin
path = "#{ File.read(src).match(/.*<path([^\/]*)/)[0] } />"
rescue
path = "<path id='error' icon=#{ icon } />"
metadata['icons'][style][size] = File.read(svg_file_path).match(/.*<path([^\/]*)/)[0]
rescue => e
@schema['errors']['icons'] << icon_name
metadata['icons'][style][size] = "<path id='error' icon=#{ icon_name } />"
end

@schema[group][:weights] << weight
@schema[group][:icons][variation][weight] = path
icons_pb.increment!
end
end

@schema['icons'][icon_name] = metadata

metadata['metaphor']&.each { |metaphor| @schema['dictionary'][metaphor] = icon_name }

groups_pb.increment!
end

puts 'Skipping schema generation. Not yet implemented..'
if (@schema['errors']['metadata'] || @schema['errors']['icons']).any?
puts "I couldn't process #{@schema['errors']['metadata'].size} sets, and #{@schema['errors']['icons'].size} icons. This is likely due the metadata file missing, or the icon not being available."
end

File.open('lib/build/data.json', 'w+') do |f|
f.write(@schema.to_json)
end

if @generate_docs
puts 'Generating a new Preview file'

template = File.read('lib/public/fluent-ui-icons.template.html.erb')
result = ERB.new(template).result(binding)

Expand All @@ -84,5 +107,5 @@ if @generate_docs
end
end

puts 'Cleaning up'
FileUtils.rm_rf('fluentui-system-icons') if Dir.exist?('fluentui-system-icons')
# puts 'Cleaning up'
# FileUtils.rm_rf('fluentui-system-icons') if Dir.exist?('fluentui-system-icons')
2 changes: 1 addition & 1 deletion lib/build/data.json

Large diffs are not rendered by default.

Loading