npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-for-gir

v1.0.1

Published

Typescript .d.ts generator from GIR for gjs or node-gtk

Downloads

24

Readme

ts-for-gjs

TypeScript binding generator for GJS and node-gtk (in a very early stage). Inspired by gir2dts but re-written and re-designed to be a more thorough TypeScript description of the GObject introspection interfaces.

The definitions can be used for both TypeScript or JavaScript projects.

Install

git clone https://github.com/sammydre/ts-for-gjs
cd ts-for-gjs
npm install
npm link

Usage

After you have linked this project you can use the ts-for-gir command in you project:

$ ts-for-gir --help  
Typescript .d.ts generator from GIR for gjs or node-gtk

VERSION
  ts-for-gir/1.0.0 linux-x64 node-v12.14.1

USAGE
  $ ts-for-gir [COMMAND]

COMMANDS
  generate  Generates .d.ts files from GIR for gjs or node-gtk
  help      display help for ts-for-gir
  list      Lists all available GIR modules

Generate .d.ts files

$ ts-for-gir generate --help                                                                                                                                                       :(
Generates .d.ts files from GIR for gjs or node-gtk

USAGE
  $ ts-for-gir generate MODULES

ARGUMENTS
  MODULES  [default: *] GIR modules to load, e.g. 'Gio-2.0'. Accepts multiple modules

OPTIONS
  -b, --buildType=lib|types            [default for gjs: lib, default for node: types] Force the definitions generation type
  -e, --environments=gjs|node          [default: gjs,node] javascript environment
  -g, --girDirectories=girDirectories  [default: /usr/share/gir-1.0] GIR directory
  -h, --help                           show CLI help
  -i, --ignore=ignore                  [default: ] modules that should be ignored
  -o, --outdir=outdir                  [default: @types] directory to output to
  -p, --print                          print the output to console and create no files
  -v, --verbose                        Switch on/off the verbose mode
  --configName=configName              name of the config if you want to use a different name
  --ignoreConflicts                    Do not ask for package versions if multiple versions are found
  --pretty                             prettifies the generated .d.ts files

EXAMPLES
  # Run 'ts-for-gir generate' in your gjs or node-gtk project to generate typings for your project, pass the gir modules you need for your project
  ts-for-gir generate

  # You can also use wild cards
  ts-for-gir generate Gtk*

  # If you want to parse all of your locally installed gir modules run
  ts-for-gir generate '*'

  # Generate .d.ts. files only for gjs
  ts-for-gir generate '*' -e gjs

  # Generate .d.ts. files only for node
  ts-for-gir generate '*' -e node

  # Use a special config file
  ts-for-gir generate --configName='.ts-for-gir.gtk4.rc.js

  # Generate .d.ts. files but not for Gtk-3.0 and xrandr-1.3
  ts-for-gir generate --ignore=Gtk-3.0 xrandr-1.3

List available GIR modules

$ ts-for-gir list --help
Lists all available GIR modules

USAGE
  $ ts-for-gir list MODULES

ARGUMENTS
  MODULES  [default: *] GIR modules to load, e.g. 'Gio-2.0'. Accepts multiple modules

OPTIONS
  -g, --girDirectories=girDirectories  [default: /usr/share/gir-1.0] GIR directory
  -h, --help                           show CLI help
  -i, --ignore=ignore                  [default: true] modules that should be ignored
  -v, --verbose                        Switch on/off the verbose mode
  --configName=configName              name of the config if you want to use a different name

EXAMPLES
  # Lists all available GIR modules in ./vala-girs/gir-1.0
  ts-for-gir list -g ./vala-girs/gir-1.0

  # Lists all available GIR modules in /usr/share/gir-1.0 but not Gtk-3.0 and xrandr-1.3
  ts-for-gir list --ignore=Gtk-3.0 xrandr-1.3

Config

In addition to the option of passing options as a CLI flag, you can also write them in a config file. To do that, create a new config file called .ts-for-girrc.js in your project root directory, like this:

module.exports = {
    pretty: false,
    print: false,
    verbose: true,
    environments: ['gjs', 'node'],
    outdir: '@types',
    girDirectories: '/usr/share/gir-1.0',
    modules: ['*'],
    ignore: [],
}

Examples

Run npm run regress or ts-for-gir --configName='.ts-for-gir.regress.rc.js' in the root of this project to generate the type definitons for the examples

Now open some code with an editor that understands TypeScript and see what happens, for example Visual Studio Code.

code examples/gjs/browser

What it's like

screencast

Development

Install GObject Introspection Repository files:

# Ubuntu 18.04
sudo apt update && sudo apt install \
    libappindicator3-dev \
    libgda-5.0-dev \
    libgirepository1.0-dev \
    libgtk-3-dev \
    libgtksourceview-3.0-dev \
    libnotify-dev \
    libsoup2.4-dev \
    libwebkit2gtk-4.0-dev

Generate example type definitions:

npm run regress

CLI

Run npm link, this is similar to npm -g install ts-for-gir but links to your local development repository which allows you to test your changes directly.

Now you can execute ts-for-gir anywhere on your system:

ts-for-gir --help

Related Projects

TypeScript Type Definitions

Other

  • gjs-docs - GJS documentation server written using gjs
  • node-gtk - GIO bindings for NodeJS
  • cgjs - A NodeJS / CommonJS Runtime for GJS
  • jsgtk - Replaced by cgjs
  • vala-girs - Collection of GIRs and VAPIs for the Vala toolchain