Verified Commit 3ecbd2b3 authored by Camil Staps's avatar Camil Staps 🚀

Start electron when run without arguments; add npm command line argument to run npm install, etc.

parent f15a64e0
......@@ -11,6 +11,10 @@ import qualified Data.Map
from Data.Map import :: Map, instance Functor (Map k)
import Data.Map.GenJSON
import Data.Tuple
import System.CommandLine
import System.File
import System.FilePath
import System.Process
import System._Unsafe
import qualified Text
from Text import class Text, instance Text String
......@@ -126,8 +130,49 @@ serveElectron ::
!([String] ElectronOptions EngineOptions -> (ElectronOptions, EngineOptions, [StartableTask]))
!(String ElectronProcess UniversalConnectionDetails -> Task Connection)
!*World -> *World
serveElectron modOpts startConnection w = doTasksWithOptions
(\[arg0:argv] opts
serveElectron modOpts startConnection w
# ([_:args],w) = getCommandLine w
| isEmpty args
# w = maybeInstall w
= justRunProcess electron ["."] w
# action = hd args
| action == "npm"
= justRunProcess "npm" (tl args) w
| action == "serve"
= serve modOpts startConnection w
| otherwise
= abort ("Unknown action '"+++action+++"'\n")
where
electron = concatPaths ["node_modules","electron","dist","electron"]
maybeInstall :: !*World -> *World
maybeInstall w
# (exi,w) = fileExists electron w
| exi = w
# w = maybeCreatePackage w
# (_,w) = fclose (stderr <<< "electron binary not found; running npm install...\n") w
= justRunProcess "npm" ["install"] w
maybeCreatePackage :: !*World -> *World
maybeCreatePackage w
# (exi,w) = fileExists "package.json" w
| exi = w
# (_,w) = fclose (stderr <<< "package.json not found; creating...\n") w
# (_,w) = writeFile "package.json" "{\"devDependencies\":{\"electron\":\"^8.2.3\"}}" w
= w
justRunProcess :: !FilePath ![String] !*World -> *World
justRunProcess cmd args w
# (rcode,w) = callProcess cmd args Nothing w
# rcode = if (isError rcode) 1 (fromOk rcode)
= setReturnCode rcode w
serve ::
!([String] ElectronOptions EngineOptions -> (ElectronOptions, EngineOptions, [StartableTask]))
!(String ElectronProcess UniversalConnectionDetails -> Task Connection)
!*World -> *World
serve modOpts startConnection w = doTasksWithOptions
(\[arg0,_:argv] opts
# electron_opts =
{ port = 0
, debug = False
......
......@@ -201,7 +201,7 @@ function run (_opts) {
const opts=DEFAULTS;
Object.assign (opts,_opts);
const args=['--electron-port',opts.port,'--port',opts.itasks_port];
const args=['serve','--electron-port',opts.port,'--port',opts.itasks_port];
const server=spawn ('./'+opts.app+'.exe',args,{stdio: 'inherit'});
server.on ('close',code => {
if (code!==0 && code!==null)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment