https://github.com/johnsusek/framework-bridge
Swift JSExport extensions for macOS system frameworks
https://github.com/johnsusek/framework-bridge
appkit javascriptcore jsexport macos swift
Last synced: 3 months ago
JSON representation
Swift JSExport extensions for macOS system frameworks
- Host: GitHub
- URL: https://github.com/johnsusek/framework-bridge
- Owner: johnsusek
- License: mit
- Created: 2021-10-29T21:15:02.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-13T13:27:37.000Z (about 4 years ago)
- Last Synced: 2025-09-06T22:04:26.727Z (4 months ago)
- Topics: appkit, javascriptcore, jsexport, macos, swift
- Language: Swift
- Homepage:
- Size: 1.14 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# framework-bridge
Swift [JSExport](https://developer.apple.com/documentation/javascriptcore/jsexport) [extensions](https://docs.swift.org/swift-book/LanguageGuide/Extensions.html) for macOS system frameworks.
## Progress
[Foundation](https://github.com/johnsusek/framework-bridge/tree/master/modules/Foundation)

[AppKit](https://github.com/johnsusek/framework-bridge/tree/master/modules/AppKit)

## Usage
Swift
```swift
import JavaScriptCore
import FrameworkBridge
let context = JSContext()!
context.bridgeClass("NSSound")
```
Javascript
```javascript
NSSound({ named: "Chirp" }).play();
```
## Tests
Test compilation of JSExport classes:
`./test/compilation/compilation.sh`
Test runtime registration of classes:
`./test/registration/registration.sh`
## Dev Tools
### gen-headers
Generates swift headers for AppKit classes. This data is used by ast-builder
`node index.js ../../metadata/frameworks.json ../../tmp/headers`
### ast-builder
Parses swift headers into an ast and store in json.
`swift run ast-builder ../../metadata/frameworks.json ../../tmp/headers ../../tmp/ast`
### attribute-list-builder
Parses swift headers into a list of attributes (i.e. unavailable, renamed, etc).
This data is used by macos-metadata-builder to build the swift jsexport
classes (specifically to hide unavailable or obsoleted decls).
This also generates aliases.json and structs.json.
`node index.js ../../metadata/frameworks.json ../../tmp/ast ../../tmp/attributes`
### macos-metadata-generator
Generates swift jsexport classes; uses data generated from the above tools.
See README in [macos-metadata-generator](https://github.com/johnsusek/macos-metadata-generator) repo for more details.
# Dev
* Edit metadata/frameworks.json if you are adding a new framework
* Run gen-header, ast-builder and attribute-list-builder to populate tmp/ folders
* Run macos-metadata-generator to populate tmp/swift/
* Add classes to classesToRegister.json and registration test app