-
Notifications
You must be signed in to change notification settings - Fork 28
/
makedist.py
355 lines (316 loc) · 11.9 KB
/
makedist.py
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/usr/bin/env python3
# Usage: python3 makedist.py
#
# This script copies the working files (everything needed to run Lectrote)
# into prebuilt Electron app packages. Fetch these from
# https://github.com/atom/electron/releases
# and unzip them into a "dist" directory.
import sys
import os, os.path
import optparse
import shutil
import json
import subprocess
all_packages = [
'darwin-x64',
'darwin-arm64',
'darwin-universal',
'linux-x64',
'linux-arm64',
'win32-ia32',
'win32-x64',
'win32-arm64',
]
popt = optparse.OptionParser()
popt.add_option('-b', '--build',
action='store_true', dest='makedist',
help='build dist directories')
popt.add_option('-z', '--zip',
action='store_true', dest='makezip',
help='turn dist directories into zip files')
popt.add_option('-n', '--none',
action='store_true', dest='makenothing',
help='do nothing except look at the arguments')
popt.add_option('-g', '--game', '--gamedir',
action='store', dest='gamedir',
help='directory for game-specific files')
popt.add_option('--macsign',
action='store', dest='macsign',
help='Apple Developer cert name')
popt.add_option('-v', '--version',
action='store', dest='buildversion',
default='1',
help='build version (default 1)')
(opts, args) = popt.parse_args()
appfiles = [
'./package.json',
'./main.js',
'./apphooks.js',
'./formats.js',
'./play.html',
'./prefs.html',
'./prefs.js',
'./fonts.js',
'./about.html',
'./if-card.html',
'./if-card.js',
'./fonts.css',
'./play.css',
'./el-glkote.css',
'./font', # all files
'./icon-128.png',
'./icon-tray.ico',
'./docicon-glulx.ico',
'./docicon-zcode.ico',
'./docicon-hugo.ico',
'./docicon-tads.ico',
'./docicon-json.ico',
'./quixe/lib/elkote.min.js',
'./quixe/lib/jquery-1.12.4.min.js',
'./quixe/lib/quixe.min.js',
'./quixe/media/waiting.gif',
{
'key': 'ifvms',
'files': [
'./zplay.html',
'./ifvms/zvm.min.js',
'./ifvms/zvm_dispatch.min.js',
'./ifvms/gi_load.min.js',
'./ifvms/zvm.css',
'./ifvms/package.json',
]
},
{
'key': 'emglken',
'files': [
'./emglkenplay.html',
'emglken/gi_load.min.js',
'emglken/git-core.wasm',
'emglken/git.js',
'emglken/glulxe-core.wasm',
'emglken/glulxe.js',
'emglken/hugo-core.wasm',
'emglken/hugo.js',
'emglken/scare-core.wasm',
'emglken/scare.js',
'emglken/tads-core.wasm',
'emglken/tads.js',
'emglken/versions.json',
]
},
{
'key': 'inkjs',
'files': [
'./inkplay.html',
'./inkplay.js',
'./inkjs/ink.min.js',
'./inkjs/ink-130.min.js',
'./inkjs/ink-146.min.js',
'./inkjs/ink-160.min.js',
'./inkjs/package.json',
]
},
]
rootfiles = [
'./LICENSE',
'./LICENSES-FONTS.txt',
]
def install(resourcedir, pkg):
if not os.path.isdir(resourcedir):
raise Exception('path does not exist: ' resourcedir)
appdir = resourcedir
print('Installing to: ' appdir)
soleterp = pkg.get('lectroteSoleInterpreter')
appfilesused = []
for val in appfiles:
if type(val) is dict:
if soleterp and val['key'] != soleterp:
continue
for filename in val['files']:
appfilesused.append(filename)
else:
appfilesused.append(val)
os.makedirs(appdir, exist_ok=True)
qdir = os.path.join(appdir, 'quixe')
os.makedirs(qdir, exist_ok=True)
os.makedirs(os.path.join(qdir, 'lib'), exist_ok=True)
os.makedirs(os.path.join(qdir, 'media'), exist_ok=True)
zvmdir = os.path.join(appdir, 'ifvms')
os.makedirs(zvmdir, exist_ok=True)
emglkendir = os.path.join(appdir, 'emglken')
os.makedirs(emglkendir, exist_ok=True)
inkdir = os.path.join(appdir, 'inkjs')
os.makedirs(inkdir, exist_ok=True)
for filename in appfilesused:
srcfilename = filename
if opts.gamedir:
val = os.path.join(opts.gamedir, filename)
if os.path.exists(val):
srcfilename = val
if not os.path.isdir(filename):
shutil.copyfile(srcfilename, os.path.join(appdir, filename))
else:
subdirname = os.path.join(appdir, filename)
os.makedirs(subdirname, exist_ok=True)
for subfile in os.listdir(srcfilename):
shutil.copyfile(os.path.join(srcfilename, subfile), os.path.join(subdirname, subfile))
extrafiles = pkg.get('lectroteExtraFiles')
if opts.gamedir and extrafiles:
gamedir = os.path.join(appdir, os.path.basename(opts.gamedir))
os.makedirs(gamedir, exist_ok=True)
for filename in extrafiles:
srcfilename = os.path.join(opts.gamedir, filename)
if not os.path.isdir(filename):
shutil.copyfile(srcfilename, os.path.join(gamedir, filename))
else:
subdirname = os.path.join(gamedir, filename)
os.makedirs(subdirname, exist_ok=True)
for subfile in os.listdir(srcfilename):
shutil.copyfile(os.path.join(srcfilename, subfile), os.path.join(subdirname, subfile))
def builddir(dir, pack, pkg):
(platform, dummy, arch) = pack.partition('-')
cmd = 'node_modules/.bin/electron-packager'
args = [
cmd, 'tempapp', product_name,
'--app-version', product_version,
'--build-version', opts.buildversion,
'--arch=' arch, '--platform=' platform,
'--out', 'dist',
'--overwrite'
]
if platform == 'darwin':
appid = 'com.eblong.lectrote'
if opts.gamedir:
appid = pkg.get('lectroteMacAppID')
if not appid:
raise Exception('Mac package must set lectroteMacAppID')
if appid == 'com.eblong.lectrote':
raise Exception('lectroteMacAppID must not be com.eblong.lectrote')
iconpath = 'resources/appicon-mac.icns'
if opts.gamedir and os.path.exists(os.path.join(opts.gamedir, 'resources/appicon-mac.icns')):
iconpath = os.path.join(opts.gamedir, 'resources/appicon-mac.icns')
args = args [
'--app-bundle-id=' appid,
'--app-category-type=public.app-category.games',
'--icon=' iconpath,
'--extra-resource=resources/icon-glulx.icns',
'--extra-resource=resources/icon-zcode.icns',
'--extra-resource=resources/icon-hugo.icns',
'--extra-resource=resources/icon-tads.icns',
'--extra-resource=resources/icon-blorb.icns',
'--extra-resource=resources/icon-gblorb.icns',
'--extra-resource=resources/icon-zblorb.icns',
'--extra-resource=resources/icon-glksave.icns',
'--extra-resource=resources/icon-glkdata.icns',
'--extra-resource=resources/icon-json.icns',
'--extend-info', 'resources/Add-Info.plist',
]
if opts.macsign:
args = args [
'--osx-sign.entitlements', 'resources/mac-app.entitlements',
'--osx-sign.entitlements-inherit', 'resources/mac-app.entitlements',
'--osx-sign.identity', opts.macsign,
'--osx-sign.hardenedRuntime', 'true',
]
if platform == 'win32':
iconpath = 'resources/appicon-win.ico'
if opts.gamedir and os.path.exists(os.path.join(opts.gamedir, 'resources/appicon-win.ico')):
iconpath = os.path.join(opts.gamedir, 'resources/appicon-win.ico')
filedesc = 'Interactive Fiction Interpreter'
if opts.gamedir and pkg.get('description'):
filedesc = pkg.get('description')
if not opts.gamedir:
companyname = 'Zarfhome Software'
else:
companyname = pkg.get('lectroteCompanyName')
if companyname:
args.append('--win32metadata.CompanyName=' companyname)
if not opts.gamedir:
copyright = 'Copyright 2016 by Andrew Plotkin'
else:
copyright = pkg.get('lectroteCopyright')
if copyright:
args.append('--app-copyright=' copyright)
args = args [
'--win32metadata.InternalName=' product_name,
'--win32metadata.ProductName=' product_name,
'--win32metadata.OriginalFilename=' product_name '.exe',
'--win32metadata.FileDescription=' filedesc,
'--icon=' iconpath,
]
res = subprocess.call(args)
if res:
raise Exception('electron-packager failed')
for filename in rootfiles:
shutil.copyfile(filename, os.path.join(dir, filename))
val = os.path.join(dir, 'version')
if os.path.exists(val):
os.unlink(val)
def makezip(dir, unwrapped=False):
prefix = product_name '-'
val = os.path.split(dir)[-1]
if not val.startswith(prefix):
raise Exception('path does not have the prefix')
platform = val[len(prefix):]
zipfile = product_name '-' product_version '-' platform
zipargs = '-q'
if 'darwin' in zipfile:
zipfile = zipfile.replace('darwin', 'macos')
print('AppDMGing up: %s to %s' % (dir, zipfile))
specfile = 'resources/pack-dmg-spec.json'
if opts.gamedir and os.path.exists(os.path.join(opts.gamedir, specfile)):
specfile = os.path.join(opts.gamedir, specfile)
tmpspecfile = specfile.replace('/pack-dmg-spec.json', '/pack-dmg-spec-tmp.json')
dat = open(specfile).read()
dat = dat.replace('$PLATFORM$', platform)
open(tmpspecfile, 'w').write(dat)
subprocess.call('rm -f "dist/%s.dmg"; node_modules/.bin/appdmg "%s" "dist/%s.dmg"' % (zipfile, tmpspecfile, zipfile),
shell=True)
return
print('Zipping up: %s to %s (%s)' % (dir, zipfile, ('unwrapped' if unwrapped else 'wrapped')))
if unwrapped:
subprocess.call('cd "%s"; rm -f "../%s.zip"; zip "%s" -r "../%s.zip" *' % (dir, zipfile, zipargs, zipfile),
shell=True)
else:
dirls = os.path.split(dir)
subdir = dirls[-1]
topdir = os.path.join(*os.path.split(dir)[0:-1])
subprocess.call('cd "%s"; rm -f "%s.zip"; zip "%s" -r "%s.zip" "%s"' % (topdir, zipfile, zipargs, zipfile, subdir),
shell=True)
# Start work! First, read the version string out of package.json.
pkgfile = 'package.json'
if opts.gamedir and os.path.exists(os.path.join(opts.gamedir, 'package.json')):
pkgfile = os.path.join(opts.gamedir, 'package.json')
fl = open(pkgfile)
pkg = json.load(fl)
fl.close()
product_version = pkg['version']
product_name = pkg['productName'];
print('%s version: %s' % (product_name, product_version,))
if product_name != 'Lectrote':
print('%s version: %s' % ('Lectrote', pkg['lectroteVersion'],))
# Decide what distributions we're working on. ("packages" is a bit overloaded,
# sorry.)
packages = []
if not args:
packages = all_packages
else:
for pack in all_packages:
for arg in args:
if arg in pack:
packages.append(pack)
break
if not packages:
raise Exception('no packages selected')
os.makedirs('tempapp', exist_ok=True)
install('tempapp', pkg)
os.makedirs('dist', exist_ok=True)
doall = not (opts.makedist or opts.makezip or opts.makenothing)
if doall or opts.makedist:
for pack in packages:
dest = 'dist/%s-%s' % (product_name, pack,)
builddir(dest, pack, pkg)
if doall or opts.makezip:
for pack in packages:
dest = 'dist/%s-%s' % (product_name, pack,)
makezip(dest, unwrapped=('win32' in pack))