texture_packer 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41c159bf066da74aab198997c1f78a2ecc6c6bf6
4
- data.tar.gz: 6d5473a3b14ccb99cdb030d638f50446d2e95c97
3
+ metadata.gz: 50175f11beb2095b7d3d52f2c27e04f39837bbb8
4
+ data.tar.gz: 8de222d7e72038388525ab7da84bd75d5302ab78
5
5
  SHA512:
6
- metadata.gz: 94f61a4db7e19bc00b685ce7c3d7c84bd7f11318e868fa172ea9804aecaa29580a99e17be97dcb8f987db69007b25f3806db2cf5967f5f5e6e3552ca14fb57be
7
- data.tar.gz: 1c36f77fa566bcf998b1b174831618d4f8cfb4aaeca13cf1b607c7b55d9577bdb2421464663558057c5befb0cd0c1b89d83b9418fe39a88e13e91e747ec55130
6
+ metadata.gz: f839205b5acfb2660a86133411449d38b7105db7537bb1ed99afe4c67c9a1e5ebe31a71055394f41b5f2ac76f223fcfc76995599afeff679a73c3bcaf68404a0
7
+ data.tar.gz: 973c930ad6e5fb3b078f548a45150a54ddfc43729d5b361d50ba7f4dc910688801a9bfde421067dee4c8780cf774d0b96c2c7be293a0c8176c978f21a3c42f86
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ## Change Log
2
+
3
+ ### [upcoming](https://github.com/khiav223577/texture_packer/compare/v1.3.0...HEAD) 2020/03/04
4
+ - [#9](https://github.com/khiav223577/texture_packer/pull/9) escape shell command argument (@Fatmylin)
5
+ - [#5](https://github.com/khiav223577/texture_packer/pull/5) 為 pack_scss 加上 -v, -h 二個參數的功能 (@khiav223577)
6
+
7
+ ### [v1.3.0](https://github.com/khiav223577/texture_packer/compare/v1.2.0...v1.3.0) 2020/02/20
8
+ - [#4](https://github.com/khiav223577/texture_packer/pull/4) 使用 html5 的 lang 自動切換不同語系的圖片 (@Fatmylin)
9
+ - [#3](https://github.com/khiav223577/texture_packer/pull/3) add test cases (@khiav223577)
10
+ - [#2](https://github.com/khiav223577/texture_packer/pull/2) setup travis CI (@khiav223577)
11
+
12
+ ### [v1.1.0](https://github.com/khiav223577/texture_packer/compare/v1.0.0...v1.1.0) 2018/02/27
13
+ - [#1](https://github.com/khiav223577/texture_packer/pull/1) 支援分別輸出電腦版與 mobile 版圖片,但 css 用同一份 (@khiav223577)
@@ -1,84 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'yaml'
3
- require 'pathname'
4
- require 'fileutils'
5
- require 'texture_packer'
6
- # ----------------------------------------------------------------
7
- # ● 載入 yaml
8
- # ----------------------------------------------------------------
9
- def load_yaml(path)
10
- begin
11
- return YAML.load_file(Pathname.new(__dir__).join(path)) || {}
12
- rescue Errno::ENOENT
13
- return {}
14
- end
15
- end
16
-
17
- SETTING = load_yaml('setting.yml')
18
-
19
- def exec_cmd(cmd)
20
- begin
21
- puts cmd
22
- puts `#{cmd}`
23
- rescue => e
24
- puts e
25
- end
26
- end
27
-
28
- def write_to_file(path, content)
29
- puts "output: #{path} #{File.write(path, content)} bytes"
30
- end
31
-
32
- exec_cmd('TexturePacker packer.tps')
33
-
34
- if File.exists?('packed_mobile.css') # 向下相容
35
- exec_cmd('mv packed_mobile.css packed_m.css')
36
- exec_cmd('mv packed_mobile.png packed_m.png')
37
- end
38
- has_mobile = true if File.exists?('packed_m.css')
39
-
40
- # ----------------------------------------------------------------
41
- # ● 由路徑計算 class 名字
42
- # ----------------------------------------------------------------
43
- dir_name = File.expand_path(Dir.pwd).gsub(/.*\/Texture-Packer\/.*?\/(.*)/, '\1')
44
-
45
- output_paths_mapping = Dir['*.css'].map do |path|
46
- name = File.basename(path, '.css')
47
- next [name[/packed_(.*)/, 1], name]
48
- end.to_h
49
-
50
- content = output_paths_mapping.map{|_, path| File.read("#{path}.css") }.join
51
- packer = TexturePacker.new(dir_name, output_paths_mapping, content, has_mobile)
52
- output0, output1, output2 = packer.parse!
53
- output = output0 + output1 + output2
54
-
55
- # ----------------------------------------------------------------
56
- # ● 壓縮圖片
57
- # ----------------------------------------------------------------
58
- output_paths_mapping.each do |_, path|
59
- exec_cmd("pngquant #{path}.png --force")
60
- end
61
-
62
- write_to_file('packed.scss', output)
63
-
64
- # ----------------------------------------------------------------
65
- # ● 自動輸出到專案
66
- # ----------------------------------------------------------------
67
- if SETTING['project_dir']
68
- css_pre_lines = ["@import './mixin.scss';"]
69
- css_pre_lines.unshift("@import 'global_mixins';") if has_mobile
70
-
71
- sub_dirs = dir_name.split(File::Separator)[0...-1]
72
- css_path = Pathname.new(SETTING['project_dir']).join('app', 'assets', 'stylesheets', 'packed_sprites', *sub_dirs, packer.dir_without_theme)
73
- img_path = Pathname.new(SETTING['project_dir']).join('app', 'assets', 'images', *sub_dirs)
74
- FileUtils.mkdir_p(css_path)
75
- FileUtils.mkdir_p(img_path)
76
- write_to_file(css_path.join('mixin.scss'), output1)
77
- write_to_file(css_path.join('ocean.scss'), "#{css_pre_lines.join("\n")}\n\n#{output2}")
78
- output_paths_mapping.each do |_, path|
79
- FileUtils.cp("#{path}-fs8.png", img_path.join("#{path.sub('packed', packer.base_dir_name)}.png"))
80
- exec_cmd("pngquant #{path}.png --force")
81
- end
82
- end
83
-
2
+ require 'texture_packer/cli'
84
3
 
4
+ TexturePacker::CLI.new(ARGV).run
@@ -1,8 +1,11 @@
1
1
  require 'texture_packer/version'
2
2
 
3
3
  class TexturePacker
4
+ attr_reader :dir_name
4
5
  attr_reader :base_dir_name
5
6
  attr_reader :dir_without_theme
7
+ attr_reader :output_paths_mapping
8
+ attr_reader :has_mobile
6
9
 
7
10
  def initialize(dir_name, output_paths_mapping, content, has_mobile)
8
11
  @output_paths_mapping = output_paths_mapping
@@ -0,0 +1,94 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require 'texture_packer'
4
+
5
+ class TexturePacker::Cli
6
+ def initialize(argv)
7
+ @options = Options.new(argv)
8
+ end
9
+
10
+ def run
11
+ return @options.hook_run.call if @options.hook_run
12
+
13
+ pack_css!
14
+
15
+ packer = create_packer
16
+ output0, output1, output2 = packer.parse!
17
+ output = output0 + output1 + output2
18
+
19
+ compress_images! # 壓縮圖片
20
+ write_to_file('packed.scss', output)
21
+
22
+ write_to_project_dir!(packer, output1, output2) if @options.project_dir
23
+ end
24
+
25
+ private
26
+
27
+ def pack_css!
28
+ exec_cmd('TexturePacker', 'packer.tps')
29
+ end
30
+
31
+ # ----------------------------------------------------------------
32
+ # ● 壓縮圖片
33
+ # ----------------------------------------------------------------
34
+ def compress_images!
35
+ output_paths_mapping.each do |_, path|
36
+ exec_cmd('pngquant', "#{path}.png", '--force')
37
+ end
38
+ end
39
+
40
+ def create_packer
41
+ has_mobile = true if File.exists?('packed_m.css')
42
+
43
+ # 由路徑計算 class 名字
44
+ dir_name = File.expand_path(Dir.pwd).gsub(/.*\/Texture-Packer\/.*?\/(.*)/, '\1')
45
+
46
+ content = output_paths_mapping.map{|_, path| File.read("#{path}.css") }.join
47
+ return TexturePacker.new(dir_name, output_paths_mapping, content, has_mobile)
48
+ end
49
+
50
+ def output_paths_mapping
51
+ @output_paths_mapping ||= begin
52
+ Dir['*.css'].map do |path|
53
+ name = File.basename(path, '.css')
54
+ next [name[/packed_(.*)/, 1], name]
55
+ end.to_h
56
+ end
57
+ end
58
+
59
+ # ----------------------------------------------------------------
60
+ # ● 自動輸出到專案
61
+ # ----------------------------------------------------------------
62
+ def write_to_project_dir!(packer, output1, output2)
63
+ css_pre_lines = ["@import './mixin.scss';"]
64
+ css_pre_lines.unshift("@import 'global_mixins';") if packer.has_mobile
65
+
66
+ sub_dirs = packer.dir_name.split(File::Separator)[0...-1]
67
+
68
+ project_assets_path = Pathname.new(@options.project_dir).join('app', 'assets')
69
+ css_path = project_assets_path.join('stylesheets', 'packed_sprites', *sub_dirs, packer.dir_without_theme)
70
+ img_path = project_assets_path.join('images', *sub_dirs)
71
+ FileUtils.mkdir_p(css_path)
72
+ FileUtils.mkdir_p(img_path)
73
+ write_to_file(css_path.join('mixin.scss'), output1)
74
+ write_to_file(css_path.join('ocean.scss'), "#{css_pre_lines.join("\n")}\n\n#{output2}")
75
+ packer.output_paths_mapping.each do |_, path|
76
+ FileUtils.cp("#{path}-fs8.png", img_path.join("#{path.sub('packed', packer.base_dir_name)}.png"))
77
+ end
78
+ end
79
+
80
+ def exec_cmd(*args)
81
+ begin
82
+ puts args.join(' ')
83
+ puts system(*args)
84
+ rescue => e
85
+ puts e
86
+ end
87
+ end
88
+
89
+ def write_to_file(path, content)
90
+ puts "output: #{path} #{File.write(path, content)} bytes"
91
+ end
92
+ end
93
+
94
+ require 'texture_packer/cli/options'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ class TexturePacker::Cli::Options
6
+ attr_reader :hook_run
7
+ attr_reader :project_dir
8
+
9
+ def initialize(argv)
10
+ OptionParser.new do |opts|
11
+ opts.on('-v', '--version', 'show the version number') do
12
+ @hook_run = ->{ puts(TexturePacker::VERSION) }
13
+ end
14
+
15
+ opts.on("-h", "--help", "Prints this help") do
16
+ @hook_run = ->{ puts(opts) }
17
+ end
18
+
19
+ opts.on("-pPATH", "--project_dir=PATH", "Copy the generated scss files / images to specified project") do |val|
20
+ @project_dir = val
21
+ end
22
+ end.parse!(argv)
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  class TexturePacker
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
31
31
  spec.add_development_dependency 'rake', '~> 12.0'
32
32
  spec.add_development_dependency 'minitest', '~> 5.0'
33
+ spec.add_development_dependency 'mocha', '~> 1.11.2'
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texture_packer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: executables
10
10
  cert_chain: []
11
- date: 2020-02-20 00:00:00.000000000 Z
11
+ date: 2020-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '5.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: mocha
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.11.2
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 1.11.2
61
75
  description: texture packer
62
76
  email:
63
77
  - mrtmrt15xn@yahoo.com.tw
@@ -68,6 +82,7 @@ extra_rdoc_files: []
68
82
  files:
69
83
  - ".gitignore"
70
84
  - ".travis.yml"
85
+ - CHANGELOG.md
71
86
  - CODE_OF_CONDUCT.md
72
87
  - LICENSE.txt
73
88
  - README.md
@@ -75,6 +90,8 @@ files:
75
90
  - executables/pack_scss
76
91
  - gemfiles/Gemfile.gemfile
77
92
  - lib/texture_packer.rb
93
+ - lib/texture_packer/cli.rb
94
+ - lib/texture_packer/cli/options.rb
78
95
  - lib/texture_packer/version.rb
79
96
  - texture_packer.gemspec
80
97
  homepage: https://github.com/khiav223577/texture_packer