gwt-api-exporter

2.0.0 • Public • Published

gwt-api-exporter

NPM version build status npm download

Export a javascript API from GWT

Installation

npm i gwt-api-exporter

If you want to use the CLI, install globally:

npm i -g gwt-api-exporter

⚠️ This project uses Promise, which is only available since Node.js 0.12

What can be converted

The exporter is designed to work with files generated by the xsiframe linker, which is the default in GWT 2.7. It can handle both obfuscated and pretty files.
You will need to provide as input the file named XYZ.cache.js (name starting with MD5 hash).

To export the JS bindings, you need to use the JSInterop features available from GWT version 2.7.
Export all your names in the same object of $wnd and use the exports option to specify the name you chose.
Example: for the @JsNamespace("$wnd.example") annotation, exports would be example.
An simple example project made with Eclipse is available here: https://github.com/targos/gwt-js-example

Usage as a module

Only one method is exported and returns a Promise. If no output option is provided, the promise will resolve with the generated code. Otherwise it will write the output file and resolve with true.

var exporter = require('gwt-api-exporter');
exporter({
  input: 'xxx.cache.js',
  output: 'lib.js',
  exports: 'my.namespace',
  package: {
    name: 'my-lib',
    description: 'my awesome library',
    version: '1.0.0'
  },
  extendApi: 'function(exports) { export.extended = true }'
}).catch(function(e) {
  console.error(e);
});

package option can be the path to a package.json file or directly an object with the package data.

Usage as a CLI

gwt-api-exporter -i xxx.cache.js -e my.namespace

Options

  • -i, --input: Path to the file generated by GWT (supports only xsiframe linker)
  • -o, --output: Path for the output file (default: lib.js)
  • -e, --exports: Exported namespace of the API (without $wnd)
  • -p, --package: Path to a package.json file (default: null). If a valid file is provided, the generated lib will contain a header with some metadata like the name, description, version number...
  • -f, --no-fake: Do not use fakeWindow in browser. This is particularly useful if methods from the main window need to be called (for example $wnd.addEventListener). Care must be taken not to pollute the global object when this option is on.

License

MIT

Package Sidebar

Install

npm i gwt-api-exporter

Weekly Downloads

9

Version

2.0.0

License

MIT

Unpacked Size

14.2 kB

Total Files

7

Last publish

Collaborators

  • targos