1.0.0 • Published 4 years ago

gulp-angularjs-ts-class-annotate v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

gulp-angularjs-ts-class-annotate

Gulp plugin which adds AngularJS dependency annotation for Typescript classes

Internally uses angularjs-ts-class-annotate library.

Important notes and limitations

  • Only typescript classes are supported.
  • Adds AngularJS $inject statement for constructors in all classes, regardless if they are registered in the AngularJS injector or not.
  • Existing $inject statements are totally ignored.

Motivation

  • Do not write code which may be automatically generated
  • Makes typescript files ready for uglification after compiling to js

Usage example

npm install --save-dev gulp-angularjs-ts-class-annotate

typescript@3 is a peer dependency, make sure to install it (if not have already):

npm install --save-dev typescript@3
const gulp = require("gulp");
const ngAnnotate = require("gulp-angularjs-ts-class-annotate");

gulp.task("annotate", function () {
	return gulp.src("./src/**/*.ts")
		.pipe(ngAnnotate())
		.pipe(gulp.dest("annotated"));
});

After running gulp task, original typescript file

class Class1 {
	constructor(private $log: ng.ILogService, private $window: ng.IWindowService) {
	}
}

will be saved as:

class Class1 {
static $inject = ["$log","$window"];
	constructor(private $log: ng.ILogService, private $window: ng.IWindowService) {
	}
}

Full usage demo can be seeing here.

Building locally

npm install
npm install typescript@3 --no-save
npm run demo