Skip to content

Commit

Permalink
Create a repl that exposes Application() globally
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfaremyinitials committed May 29, 2016
1 parent d08820f commit e7a03e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
14 changes: 10 additions & 4 deletions index.js
Expand Up @@ -17,14 +17,20 @@ function dereference(path, args) {
var cmd = "osascript -l JavaScript -e 'JSON.stringify(" + path + "());'"
var res = exec(cmd, { stdio: '' }).toString().trim();
return JSON.parse(res);
} catch(e) {
return null;
}
} catch(e) {}
};

function createInspector(path) {
return () => `[object JXAReference => ${dereference(path+'.toString')}]`;
}

var createReference = function(path) {
return new Proxy((recv, _, args) => dereference(path, args), {
get: (_, prop) => createReference(`${path}.${prop}`)
get: (_, prop) => {
if(prop == 'inspect')
return createInspector(path);
return createReference(`${path}.${prop}`)
}
});
};

Expand Down
4 changes: 4 additions & 0 deletions jxa-node.js
@@ -0,0 +1,4 @@
#!/usr/bin/env node
var repl = require('repl');
var ctx = repl.start('> ').context;
ctx.Application = require('./').Application;
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -6,6 +6,9 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"jxa-node": "jxa-node.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/wtfaremyinitials/jxa.git"
Expand Down

0 comments on commit e7a03e7

Please sign in to comment.