Open scripting opened 7 years ago
I suppose something like ShellJS which exposes a synchronous JavaScript API to system commands should work fine.
Another idea is implementing Frontier verbs using the sync API: e.g. fs.readfileSync()
, fs.writefileSync()
, fs.readdirSync()
and so on.
Hi Marco! ;-)
Re ShellJS, not sure about that. Could you imagine something like the example script written in that language? Would it be so simple. Simplicity and directness are important goals.
I've done that. The file verbs weren't a problem, but there were important places where there was no way to do synchronous ops, for example, making HTTP requests. As far as I can tell there's no way to do synchronous network communication in Node.
I think it requires a different interpreter than the one we use in Node and in the browser, one that implements a function call synchronously, without exception. That's how we did it in Frontier, btw. (There were verbs for forking threads, so it handled threading, but with the opposite assumption from JS system calls.)
I have put a few months into this, here and there, and keep hitting really thick walls. To give you an idea of where I stopped, here's a fragment from one of the attempts. You can see how the verbs are implemented. I completely punted on synchronous on http function. It made the project worthless basically, because so much http communication happens in the worlds I inhabit. ;-)
But the biggest problem was the inability to make a synchronous call from the main thread in an Electron app to the browser window. This means you can't use scripts to enhance the editing environment for scripts, which is a total non-starter for a scripting environment.
Not sure if this is what you're looking for, but I came across StratifiedJS as a potential solution.
Andrew I just watched the first five minutes of their demo, and it appears to be exactly what I was looking for. Same philosophy as Frontier, but they added structures for threading that we never got to. Now I have to see what's involved in getting something working here in my Electron app. Thanks for the pointer. ;-)
I'm looking for:
A hello world app for StratifiedJS.
A list of system modules (file reading and writing, http for example).
A few slightly more complicated demo apps to show how basic features work.
I'm sure they are there somewhere! ;-)
I don't have any direct experience with it, but ShellJS sounds a lot like what you are talking about.
(oops, had a stale page and didn't see the earlier comments)
It's so funny, I just sent you an email. ShellJS is not it, but it appears that Stratified JS is.
The goal is to get something like the example script to work in JavaScript.
https://gist.github.com/scripting/f122c9356733ac7373e60ae865fef702
Dave
Has anyone done a JavaScript implementation system calls are synchronous? I'd like to use JavaScript the way other people use shell scripts.
Here's an example of the kind of code I routinely write as part of my development process. This script runs whenever I save one of my Node projects, and copies the public files to the place where my GitHub repo lives. It's not written in JavaScript, but I'd like to create a system where it could be.
I like having a full programming language, with variables, structures and arrays, persistent data, and all the flow control syntax of an Algol-like language. This is a situation where the efficiencies of async is not appropriate, makes things far too complex for system scripting applications.
I did some searching, found this page of JavaScript shells on MDN. Can't tell which of them might be an answer. I have a feeling that it's not going to be based on V8.
For people who are familiar with Frontier, a system scripting environment I developed in the 80s and 90s, I would like to do something like that, but in JavaScript, possibly running in an Electron shell. I know it would be weird to have another JavaScript interpreter running inside Electron, but I've seen weirder things.
PS: Though I'm sure no one will read this far -- the answer is not promises, or async functions in ES6. I want much much more simplicity in the scripts.