11 from os
.path
import join
, basename
13 def xp_filename(basename
):
14 return re
.sub('["<>*?|\\\\]', "_",
15 basename
.replace("/", "-").replace(":", "."))
17 def versionify(version
):
18 return ".".join(filter(lambda x
: x
.isdigit(),
19 re
.split("[-+.]", version
))[:3])
21 def main(nwdir
, nwpackage
):
22 if not os
.path
.isdir(nwdir
):
23 raise StandardError("input (%r) is not a directory" % nwdir
)
24 nwzip
= zipfile
.ZipFile(nwpackage
)
25 icnss
= filter(lambda f
: f
.lower().endswith(".icns"),
27 package
= json
.load(nwzip
.open("package.json"))
28 app
= join(nwdir
, "node-webkit.app")
29 title
= package
["window"]["title"]
30 exe
= package
["name"].split(".")[-1]
32 CFBundleDisplayName
=title
,
33 CFBundleExecutable
=exe
,
34 CFBundleIdentifier
=package
["name"],
35 CFBundleInfoDictionaryVersion
="6.0",
37 CFBundlePackageType
="APPL",
38 CFBundleShortVersionString
=package
["version"],
39 CFBundleIconFile
="nw.icns",
40 CFBundleVersion
=versionify(package
["version"]),
41 LSMinimumSystemVersion
="10.6.0",
42 NSPrincipalClass
="NSApplication",
43 NSSupportsAutomaticGraphicsSwitching
=True,
47 os
.remove(join(app
, "Contents", "Resources", "nw.icns"))
48 nwzip
.extract(icnss
[0], join(app
, "Contents", "Resources"))
49 plist
["CFBundleIconFile"] = icnss
[0]
50 plistlib
.writePlist(plist
, join(app
, "Contents/Info.plist"))
51 exedir
= join(app
, "Contents", "MacOS")
52 shutil
.move(join(exedir
, "node-webkit"), join(exedir
, exe
))
53 shutil
.copy(nwpackage
, join(app
, "Contents", "Resources", "app.nw"))
54 shutil
.move(app
, join(app
, "..", xp_filename(title
) + ".app"))
56 if __name__
== "__main__":