1.2.4 • Published 7 years ago

ts-ioc-compiler v1.2.4

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

ts-ioc-compiler

ts-ioc-compiler is used to compile interfaces as string in typescript compile time. Supports interface intellisense and avoids magic strings in your code.

Works together with ezinjector

https://github.com/jeppeskovsen/ezinjector

Installation

$ npm install ts-ioc-compiler --save-dev

Examples

container.register<IService>(Service);
Container.getInstance<IService>();
@Inject<IService>()
@StaticInject<IService>()

Becomes this at compile time:

container.register("IService", Service);
Container.getInstance("IService");
@Inject("IService")
@StaticInject("IService")

With Gulp

const tsIocCompiler = require("ts-ioc-compiler");

gulp.src("./scripts/*.ts")
    .pipe(tsIocCompiler.transform())
    .pipe(ts())
    .pipe(gulp.dest('./test/dist'));

Configs

Put inside tsIocCompiler..transform() or tsIocCompiler.setConfig()

{
    replacements: [{
        find: /(\.register)<(\w+?)>\s?\(/ig,
        replace: "$1(\"$2\", "
    }, {
        find: /(\@Inject|@StaticInject|Container\.getInstance)<(\w+?)>\s?\(/ig,
        replace: "$1(\"$2\""
    }]
}

Webpack loader

https://github.com/jeppeskovsen/ts-ioc-compiler-loader

$ npm install ts-ioc-compiler-loader --save-dev

Example:

module: {
    rules: [
        // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
        { 
            test: /\.tsx?$/, 
            loaders: ["awesome-typescript-loader", "ts-ioc-compiler-loader"]
        }
    ]
}
1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago