dts2externs v0.1.1
dts2externs
Parse typescript d.ts files and output google closure compiler externs file
Note: this is a very crude piece of software :grin: The output is messy and the only thing it does is prevent the google closure compiler from renaming external references in your code.
Installation
Local
$ npm install dts2externs --save-dev
$ node node_modules/dts2externs/dist/bin.js -h
Global
$ npm install -g dts2externs
$ dts2externs -h
Usage
In npm build scripts
For projects using typings
plugin. Add new script in your package.json
:
{
"scripts": {
"externs": "dts2externs typings/index.d.ts -o externs.js",
}
}
In gulp build scripts
For projects using typings
plugin. Include dts2externs
gulp
plugin:
var dts2externs = require('dts2externs').gulp();
Create a new gulp
task:
gulp.task('externs', function() {
return gulp.src(['typings/index.d.ts'])
.pipe(dts2externs({keepComments:true, listParsedFiles:true}))
.pipe(gulp.dest('dist'));
});
Note: added two options ( keepComments
and listParsedFiles
) as an example
In javascript code
var dts2externs = require("dts2externs");
dts2externs.generate(['typings/index.d.ts'], {listParsedFiles:true});
Ugly online example @ Tonic :grin:
In console using docopt style commandline options
using stdin / stdout
Example with the node
declaration file installed via typings
.
Note: Using stdin will create a tempfile to parse. This means relative paths in the input will not work and you'll have to concatenate stuff yourself.
$ cat typings/global/node/index.d.ts |dts2externs > externs.js
commandline help
$ dts2externs --help
Usage:
dts2externs [--help] [options] [-chkl] [-s <style>] [ (-a [-p]) ] ([-] | <file> [<file>...]) [-o <outputfile>]
dts2externs (-h | --help)
dts2externs --style=(obj|proto)
dts2externs --allow-ts [--parse-all] <file>
dts2externs --add-console --list --keep-comments --debug <file> --output=<outputfile>
Options:
-h, --help Show this.
-o, --output=FILE Output file [default: stdout]
-s, --style=STYLE Output style: obj or proto [default: obj]
-c, --add-console Add console.log, console.error, etc.. to the output
-k, --keep-comments Preserve and output comments
-l, --list List parsed files on stdout
-a, --allow-ts Allow parsing of .ts files
-p, --parse-all Parse all (including non-exported) stuffs in .ts files
--debug Print some debug info to console
License
This project is licensed under the MIT license