Change default JavaScript build behavior


#1

Since JavaScript support is part of Core (I think), I figured I’d try posting this question here. If I need to go elsewhere, just let me know.

I’m working on a Mac. The only JavaScript I work with, aside from in web pages, is JavaScript for Automation (JXA). I use language-javascript-jxa, and everything works fine - no issues.

However…

I’d like to change the “Build” behavior of JavaScript files to compile as JXA instead of whatever the default is. I know the command-line necessary to do the build. I just don’t know where to change it.

On the off chance that you want to know why I can’t just stick with the standard JXA build via language-javascript-jxa, here’s why: There are multiple packages that work with JS-grammar files, and although they would work just fine with JXA-grammar files, they don’t know it. Beautifier, for example.

So I’d like to change the grammar for my JXA files to “JavaScript”, and if I can change the default JavaScript build/run process, everything should work great.

Where do I look to make the build change for JavaScript files?


#2

Have a look at the build-osa provider


#3

Thanks for the reply, but I don’t think that answers my question.

I already know how to do OSA builds. What I want is for JavaScript-grammar files to be built this way.


#4

Can you specify what you mean by building, how do you currently do that? What do you expect instead?


#5

Packages->Script->Run Script (which does a build also).

When I do this for a JavaScript grammar file, this is what I see:

[Command: node ‘/Users/Dan/Documents/Development/bla bla bla’]

This is what I want to see:

[Command: osascript -l JavaScript ‘/Users/Dan/Documents/bla bla bla’]

Does that make sense?


#6

The script package uses the detected syntax of the current file to determine how to build the file, so for JavaScript files it uses Node to build. If you want to build JavaScript files with osacompile, you will have to switch the syntax to JXA (or use a different build package.)


#7

I already know that. And I know how to change the syntax.

What I want to know is, can I change the script package so that for JavaScript, it does not use Node, but instead uses osacompile?


#8

Of course you can edit any package (see the relevant lines), but IMO it kind of defeats the point of using a package since you would have to re-apply your changes with every new version (unless you create your own private fork).

The previously mentioned build package works differently, it doesn’t care what syntax you have specified. It either let’s you use an existing build provider for your preferred compiler or you create your own build configuration, which is a simple JSON, CSON, or YML file!


#9

You can tell script to use a specific command instead of the one it detects automatically, and you can save these settings as profiles (and then later run a script as a specific profile).


#10

Thanks. How?


#11

By selecting Run Options instead of Run.