Skip to content
This repository was archived by the owner on Jul 25, 2019. It is now read-only.

Use WIDL NAN as Node.js Module

Kenny Yuan edited this page Sep 11, 2016 · 1 revision

If you're writing Node.js scripts to build your project, use WIDL-NAN as a Node.js module would be more convenient.

const g = require('widl-nan').generator;

Promise.all([
  g.addFile('../idl/common/w3c-geometry.widl'),
  g.addFile('../idl/object-recognition/object-recognition.widl')
  ]).then(function () {
    g.compile();
    g.writeToDir('gen');
  }).catch(e => {
    console.log(e);
  });

There are 3 main APIs you should know: addFile(pathFileName), compile() and writeToDir(dirName), as the names suggest, you can add multiple Web IDL files to the generator by using addFile() (order doesn't matter), and then invoke compile() to compile them, and invoke writeToDir() at last to write all generated files to that directory.

Clone this wiki locally