/
find.cr
51 lines (48 loc) · 1.59 KB
/
find.cr
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
require "../lock.cr"
require "file_utils"
require "mime"
# This is an exceptionally simple script that exists only to provide an easy way to
# generate a list of file names and mime types if one is compiling a full directory tree
# of files into the executable.
{
"bz2" => "application/bzip2",
"cr" => "text/crystal",
"css" => "text/css; charset=utf-8",
"eot" => "application/vnd.ms-fontobject",
"gif" => "image/gif",
"gz" => "application/gzip",
"htm" => "text/html; charset=utf-8",
"html" => "text/html; charset=utf-8",
"ico" => "image/x-icon",
"jpg" => "image/jpeg",
"jpeg" => "image/jpeg",
"js" => "text/javascript; charset=utf-8",
"json" => "application/json",
"map" => "application/json",
"otf" => "application/font-sfnt",
"pdf" => "application/pdf",
"png" => "image/png",
"svg" => "image/svg+xml",
"tar" => "application/tar",
"ttf" => "application/font-sfnt",
"txt" => "text/plain; charset=utf-8",
"xml" => "text/xml; charset=utf-8",
"wasm" => "application/wasm",
"webp" => "image/webp",
"woff" => "application/font-woff",
"woff2" => "application/font-woff2",
"yml" => "text/yaml",
"yaml" => "text/yaml",
"zip" => "application/zip",
}.each do |ext, mime|
MIME.register ".#{ext}", mime
end
FileUtils.touch("../lock.cr")
path = ARGV[0]
globs = ARGV[1..-1]?
globs = ["**/*"] if globs.nil? || (globs && globs.empty?)
globs = globs.map { |glob| File.join(path, glob) }
Dir.glob(globs).each do |file|
next if File.directory?(file)
puts "#{file}\t#{MIME.from_filename(file, "application/octet-stream")}"
end