JXA-userland / JXA

JavaScript for Automation(JXA) packages for TypeScript/Node.js.
MIT License
417 stars 21 forks source link

Feat/npx sdef to dfs #8

Closed havardh closed 5 years ago

havardh commented 5 years ago

It turns out that the sdef command can be used to generate .d.ts files from App bundles. I've made the input parameter to the command the path to the app bundle to allow bundles outside of the /Applications folder to be converted too.

Fixes #7

azu commented 5 years ago

Great!

I've published https://github.com/JXA-userland/JXA/releases/tag/v1.3.0

JMichaelTX commented 5 years ago

Can someone please explain how to use this, and what the benefits are? I'm trying to use this extension with Visual Studio Code, and I'm having trouble. I know very little about bash scripting, so please provide detailed instructions. Thanks.

havardh commented 5 years ago

@JMichaelTX: This tool will generate TypeScript definitions for any application bundle which sdef can derive a .sdef file for. My own intention is to use it to generate types for applications which are not found in the types package. You can follow #5 to see discussion that lead to this feature.

Building from the example in this repo, these are the instructions to use this command.

  1. move into the example folder cd example
  2. install the @jxa/types package yarn add @jxa/types
  3. Make a directory to store types mkdir types
  4. Generate types for Google Chrome (assuming it is installed at /Applications/Google Chrome.app npx @jxa/sdef-to-dts /Applications/Google\ Chrome.app --output types
  5. Add the type imports to src/example.ts import { GoogleChrome } from "../types/GoogleChrome.t.ds import { Application } from "@jxa/types";
  6. Add the following code snippet to the src/example.ts file
    run(() => {
    Application<GoogleChrome>("GoogleChrome").
    });

Visual Studio Code should provide autocomplete suggestions for the Google Chrome application after the ..

Running @jxa/sdef-to-dts requires that you have xcode or Command Line Tools set up so that sdef runs correctly.