-
Notifications
You must be signed in to change notification settings - Fork 1
/
wrapper.coffee
30 lines (25 loc) · 884 Bytes
/
wrapper.coffee
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
fs = require "fs"
{spawn} = require "child_process"
nexeres = require "nexeres"
path = require "path-extra"
datadir = path.datadir "hacky-game"
zip_file = path.join datadir, "game.zip"
nwjs_dl_folder = path.join datadir, "nw.js"
nwjs_exe = path.join nwjs_dl_folder, "nw.exe"
nwjs_url = "http://dl.nwjs.io/v0.21.3/nwjs-v0.21.3-win-x64.zip"
try fs.mkdirSync datadir
try fs.mkdirSync nwjs_dl_folder
zip = nexeres.get "game.zip"
run = ->
proc = spawn nwjs_exe, [zip_file, process.execPath], detached: yes, stdio: ['ignore', 'ignore', 'ignore']
proc.unref()
fs.writeFile zip_file, zip, (err)->
throw err if err
if fs.existsSync nwjs_exe
run()
else
downloader = require "nw-builder/lib/downloader.js"
downloader.downloadAndUnpack nwjs_dl_folder, nwjs_url
.then run
.catch (err)->
console.error "Failed to download and unpack #{nwjs_url} to #{nwjs_dl_folder}: #{err}"