0.0.6 • Published 7 years ago

gulp-thrift-tsd v0.0.6

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

gulp-thrift-tsd

本工具是一个Gulp插件。 Thrift编译命令-gen js,ts生成的tsd只能用于浏览器环境,使用本工具可以批量转换成Nodejs端使用的tsd。

安装

$ npm install gulp-thrift-tsd

示例

var
    gulp = require('gulp'),
    tsd = require('gulp-thrift-tsd'),
    concat = require('gulp-concat'),
    through = require('through2')
    ;

function addModule() {
    return through.obj(function (file, enc, cb) {
        if (file.isNull()) {
            cb();
            return;
        }
        var before = new Buffer('declare module "local-thriftdef" {\r\n');
        var after = new Buffer('\r\n}');
        file.contents = Buffer.concat([before, file.contents, after]);
        this.push(file);
        cb();
    });
}


gulp.task('tsd', function () {
    return gulp.src(['./node_modules/local-thriftdef/lib/*.d.ts'
        , '!./node_modules/local-thriftdef/lib/exception_types.d.ts'])
        .pipe(tsd())
        .pipe(concat('local-thriftdef.d.ts')) //合并成一个文件
        .pipe(addModule()) //添加顶级模块声明
        .pipe(gulp.dest('./'))
        ;
});

License

MIT