aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/gen_plist.lua
blob: 63f967d12fa4a160380e6d5c6cf99298d05550e5 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/lua
-- Copyright 2007-2020 Mitchell mitchell.att.foicica.com. See LICENSE.

-- This script generates the "Info.plist" file for the Mac OSX App bundle.

local lang, exts
local languages, extensions = {}, {}

-- Read languages and extensions.
local f = io.open('../modules/textadept/file_types.lua')
local types = f:read('*a'):match('M.extensions = (%b{})'):sub(2)
f:close()
for type in types:gmatch('(.-)[%],}]+') do
  if type:find('^%-%-') then
    lang, exts = type:match('([^%[]+)$'), {}
    if lang then languages[#languages + 1], extensions[lang] = lang, exts end
  else
    exts[#exts + 1] = type:match('^%[?\'?([^\'=]+)')
  end
end

-- Generate and write the XML.
local xml = {[[
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>
	<key>CFBundleDocumentTypes</key>]]}
xml[#xml + 1] = [[
	<array>
		<dict>
			<key>CFBundleTypeName</key>
			<string>Textadept document</string>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>LSItemContentTypes</key>
			<array>
				<string>com.apple.property-list</string>
				<string>com.apple.applescript.text</string>
				<string>com.apple.xcode.commands</string>
				<string>com.apple.xcode.csh-script</string>
				<string>com.apple.xcode.ksh-script</string>
				<string>com.apple.xcode.lex-source</string>
				<string>com.apple.xcode.make-script</string>
				<string>com.apple.xcode.mig-source</string>
				<string>com.apple.xcode.tcsh-script</string>
				<string>com.apple.xcode.yacc-source</string>
				<string>com.apple.xcode.zsh-script</string>
				<string>com.apple.xml-property-list</string>
				<string>com.netscape.javascript-source</string>
				<string>com.sun.java-source</string>]]
for i = 1, #languages do
  lang, exts = languages[i], extensions[languages[i]]
  if #exts > 0 then
    xml[#xml + 1] = "\t\t\t\t<string>com.textadept."..lang:gsub(' ', '-')..
                    "-source</string>"
  end
end
xml[#xml + 1] = [[
				<string>net.daringfireball.markdown</string>
				<string>public.c-header</string>
				<string>public.c-plus-plus-header </string>
				<string>public.c-plus-plus-source</string>
				<string>public.c-source</string>
				<string>public.csh-script</string>
				<string>public.css</string>
				<string>public.html</string>
				<string>public.lex-source</string>
				<string>public.mig-source</string>
				<string>public.objective-c-plus-plus-source</string>
				<string>public.objective-c-source</string>
				<string>public.perl-script</string>
				<string>public.php-script</string>
				<string>public.plain-text</string>
				<string>public.python-script</string>
				<string>public.rtf</string>
				<string>public.ruby-script</string>
				<string>public.script</string>
				<string>public.shell-script</string>
				<string>public.source-code</string>
				<string>public.text</string>
				<string>public.utf16-external-plain-text</string>
				<string>public.utf16-plain-text</string>
				<string>public.utf8-plain-text</string>
				<string>public.xml</string>
			</array>
		</dict>
		<dict>
			<key>CFBundleTypeName</key>
			<string>Anything</string>
			<key>CFBundleTypeRole</key>
			<string>Viewer</string>
			<key>LSItemContentTypes</key>
			<array>
				<string>public.data</string>
				<string>public.text</string>
			</array>
		</dict>
	</array>
	<key>UTImportedTypeDeclarations</key>
	<array>]]
for i = 1, #languages do
  lang, exts = languages[i], extensions[languages[i]]
  if #exts > 0 then
    xml[#xml + 1] = "\t\t<dict>"
    xml[#xml + 1] = "\t\t\t<key>UTTypeTagSpecification</key>"
    xml[#xml + 1] = "\t\t\t<dict>"
    xml[#xml + 1] = "\t\t\t\t<key>public.filename-extension</key>"
    xml[#xml + 1] = "\t\t\t\t<array>"
    for j = 1, #exts do
      xml[#xml + 1] = "\t\t\t\t\t<string>"..exts[j].."</string>"
    end
    xml[#xml + 1] = "\t\t\t\t</array>"
    xml[#xml + 1] = "\t\t\t</dict>"
    xml[#xml + 1] = "\t\t\t<key>UTTypeDescription</key>"
    xml[#xml + 1] = "\t\t\t<string>"..lang.." source</string>"
    xml[#xml + 1] = "\t\t\t<key>UTTypeIdentifier</key>"
    xml[#xml + 1] = "\t\t\t<string>com.textadept."..lang:gsub(' ', '-')..
                    "-source</string>"
    xml[#xml + 1] = "\t\t\t<key>UTTypeConformsTo</key>"
    xml[#xml + 1] = "\t\t\t<array>"
    xml[#xml + 1] = "\t\t\t\t<string>public.source-code</string>"
    xml[#xml + 1] = "\t\t\t</array>"
    xml[#xml + 1] = "\t\t</dict>"
  end
end
xml[#xml + 1] = [[
	</array>
	<key>CFBundleExecutable</key>
	<string>textadept_osx</string>
	<key>CFBundleIconFile</key>
	<string>textadept.icns</string>
	<key>CFBundleIdentifier</key>
	<string>com.textadept</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>Textadept</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>9.5beta</string>
	<key>CFBundleShortVersionString</key>
	<string>9.5 beta</string>
	<key>NSHighResolutionCapable</key>
	<true/>
</dict>
</plist>
]]
f = io.open('../src/Info.plist', 'w')
f:write(table.concat(xml, '\n'))
f:close()