-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_theme.rb
executable file
·67 lines (55 loc) · 1.87 KB
/
package_theme.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'fileutils'
require 'tmpdir'
DARK_THEME = ARGV.include?('dark')
THEME_NAME = if DARK_THEME then 'podAmp-dark' else 'podAmp' end
DEST_DIR = File.join(__dir__, 'dist', THEME_NAME)
DEST_ZIP = File.join(__dir__, 'dist', "#{THEME_NAME}.zip")
if ARGV.include?("clean")
puts "===> Removing dest dir"
FileUtils.rm_f(DEST_DIR)
end
FileUtils.mkdir_p(DEST_DIR)
COPIED_FILES = Array.new
File.join(DEST_DIR, 'wps', "#{THEME_NAME}.wps").tap do |dest_file|
puts "===> Copying WPS theme"
FileUtils.mkdir_p(File.dirname(dest_file))
COPIED_FILES << dest_file
puts dest_file
FileUtils.cp(File.join(__dir__, 'wps', 'podAmp.wps'), dest_file)
end
def copy(kind, pattern, dest_dir)
source_files = Dir[*pattern]
return if source_files.empty?
puts "===> Copying #{kind}"
FileUtils.mkdir_p(dest_dir)
source_files.each do |source_file|
dest_file = File.join(dest_dir, File.basename(source_file))
COPIED_FILES << dest_file
puts dest_file
FileUtils.cp(source_file, dest_file)
end
end
copy :fonts, File.join(__dir__, 'fonts', '*.fnt'), File.join(DEST_DIR, 'fonts')
copy :images, File.join(__dir__, 'wps', THEME_NAME, '*.bmp'), File.join(DEST_DIR, 'wps', THEME_NAME)
puts "===> Creating zip archive for distribution ..."
FileUtils.rm_f DEST_ZIP
rootdir = __dir__
dirs = COPIED_FILES.map { |x| File.dirname(x.sub("#{rootdir}/dist/#{THEME_NAME}", '.rockbox')) }.uniq
Dir.mktmpdir do |tmpdir|
Dir.chdir(tmpdir) do
dirs.each do |d|
puts "mkdir\t#{d}"
FileUtils.mkdir_p(d)
end
COPIED_FILES.each do |source_file|
dest_file = source_file.sub("#{rootdir}/dist/#{THEME_NAME}", '.rockbox')
puts "cp\t#{source_file} -> #{dest_file}"
FileUtils.cp(source_file, dest_file)
end
zip_command = ["zip", DEST_ZIP, "-r", ".rockbox"]
puts zip_command.join(' ')
system *zip_command
end
end