convert executable to node module/object - javascript

I tried searching, but with not luck.
I want to convert/wrap an executable to use it easily and nicely in node, and not calling child_process.exec all the time.
For example, if I wanted to do it with git, instead of git help or git clone git://repo.git I'll have somethings like:
var git = new cmd('git');
git.help();
git.clone('git://repo.git');
etc..
Doe's anyone knows if something like that exist?
The closest thing I've found so far is run-cmd which can do somethings like that but not automatically. I'll need to create the object with all the parameters I want.
Thanks,
Ariel

Related

logging in a table like pm2 with nodeJS

I want to format all of my script's logs into a table for clarity purposes. Kind of what pm2 (process manager 2) does atm for example.
As of today I use console.table(logs) where logs is an object of variables I want to keep track of. It works great but I want to get rid of the trailing \n that console.table includes.
I would want to do something like: process.stdout.write(table(logs)) where I don't have to create the table function myself.
I tried to find the source code of console.table to copy it and remove the trailing newline as a utils function without success. any idea?
The npm package c-log does a wonderful job at this : npm c-log

After Effects applyPreset : bad path

So I'm totally new to ExtendScript, and already amazed. I've been trying to automatize the creation of standard videos, and to do so I want to create presets and apply them to footage. So I use the applyPreset(File) method of the layers.
The new File("path") seems to open fine, but then applyPreset is unhappy because it tells me my path is wrong. Namely, After Effects says "Unable to call applyPreset because of parameter 1 : incorrect path "/Users/Charles/Documents/Slide-In-1.ffx"". Yet my path, I can assure you, is absolutely correct. Being on Mac, I used "~/Documents/Slide-In-1.ffx", which got replaced by "/Users/Charles/Documents/Slide-In-1.ffx" according to the error output (this replacement is correct, clearly). So where's the problem ? How can I check that a file has indeed been found and opened by JavaScript ? Thanks a lot in advance.
Charles
Seems my path was in fact bad. Something fishy, but I had to change my file organisation anyway to have a clean centralized git repo, and it started working.
you can test if a file exists like this:
if( File(YOURPATH).exists )
If true, this object refers to a file or file-system alias that actually exists in the file system.
http://jongware.mit.edu/Js/pc_File.html

How do I create a folder using ExtendScript?

This seems like it would be a very easy problem to solve, but I've been banging my head against it for almost an hour. All I need is a snippet of javascript/extendscript code so that my InDesign CS6 script can create a folder. I know the existing folder in which the new one should be created, and I know the name that this new folder should be called. But how do I get javascript to do it?
By the way, all searches online for the folderObj.create() method, which is in the JavaScript Tools Guide, prove useless. I've tried several variations on that method, but nothing seems to actually create the folder. What am I missing?
var f = new Folder('/c/myfolder/');
if (!f.exists)
f.create();
Okay, found a work-around: I have to specify the folder absolutely, rather than use the ~ home shortcut. In addition, I have use /Volumes at the very beginning. Thus, the code becomes:
var f = new Folder("/Volumes/apache HD/Users/apache/Desktop/my_new_fodler");
f.create();
And that seems to work, finally. Thanks for your help, #Anna Forrest and #fabiantheblind! (You seem to be the resident ExtendScript expert around here.)
try this:
var f = new Folder("~/Desktop/my_new_fodler");
f.create();

Writing git API for javascript node module

Hi recently I have to implement a git API for a node module, so we can have version control through programmatic interface. I came upon this post to find some good modules that I can use.
However, after playing around with some of them, I realized that none of them provide the feature of querying the commit history of a single file (like calling 'git log --follow '). I would like to extend that feature into my module but since I have no experience before, does anyone know where I should start?
The libraries you mentioned should be a good starting point. Take node-git's lib/git.js file for example. There you can find the following lines:
// Call the native git binary
Git.prototype.call_git = function(prefix, command, postfix, options, args, callback) {
// ...
This is a good starting point to understand how the author maps Node functions on system calls and and allows the callback to work with the output.
I would start a fork of the project. Look for the log function in the same file, which starts like
Git.prototype.log = function(commit, path, options, callback) {
Copy the function, give it a proper name and try to adopt it to meet your needs.
If you succeed and like to help, you could start a pull request on GitHub to help the author and add the functionallity to the official project.
I would do it this way. I hope this helps.

Gnome shell extensions: stdout from GLib.IOChannel

So I'm making a Gnome Shell extension. And I want to be able to run some command. (The command is actually "synclient -m 100", but that is off topic)
So, what I have done so far is
s=GLib.spawn_async_with_pipes(null, ["synclient","-m","100"], null, GLib.SpawnFlags.SEARCH_PATH,null)
c=GLib.IOChannel.unix_new(s[3])
The first line spawns my process. It is definitely working.
s[3] is the file descriptor for the stout of the process. (It has something to do with pipes. Not really sure about the whole pipe thing.)
Anyway, my problem is that I can't seem to read anything from the output of synclient.
This is what I'm using for reference, but it seems that not all of the functions work. For example, I want to use add_watch, but that apperently doesn't work with gnome extensions.
I've tried using a bunch or read functions and specifically read_line_string, but they all have problems. For read_line_string it seems like it should all work except I can't figure out how to create a StringBuilder object to pass as an argument.
So, does anyone know how to get the output of a command?
Edit: also I'm kind of confused about which language the extensions use. I think it's javascript, but the docs I'm using seem to make me think Vala, whatever that is (I'm guessing a variation of java?).
Edit 2:
So, what I've got now is
let [res, pid, in_fd, out_fd, err_fd] =
GLib.spawn_async_with_pipes(
null, ["synclient","-m","100"], null, GLib.SpawnFlags.SEARCH_PATH, null);
out_reader = new Gio.DataInputStream({ base_stream: new Gio.UnixInputStream({fd: out_fd}) });
And to read a line:
let [out, size] = out_reader.read_line(null);
This gives me the output of the command, but it still doesn't give me any way to get some callback whenever the DataInputStream is changed. I need to be able to do something whenever there is a new line in the stream.
Gnome Shell extensions are usually written in JavaScript. They use JavaScript bindings to libraries like GLib that are written in C. There are also Vala bindings to those libraries, and that is the documentation you are looking at. Here is the documentation for the JS bindings, unofficial as yet.
StringBuilder is a Vala language feature that corresponds to GLib.String in JS.
How do you know add_watch() doesn't work? What do you expect and what does it do instead?

Categories

Resources