Skip to content

Commit

Permalink
Merge pull request #89 from inversify/2.0.0-alpha.0
Browse files Browse the repository at this point in the history
added 2.0.0-alpha.0
  • Loading branch information
remojansen committed Mar 1, 2016
2 parents a52c29e + 9ab5fb8 commit 4c129e3
Show file tree
Hide file tree
Showing 84 changed files with 3,109 additions and 863 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ typings

dist

source/*.js
test/*.js
src/**/*.js
test/**/*.js
type_definitions/*.js
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ CONTRIBUTING.md
tsd.json
.travis.yml
.gitignore
.tsdrc
.vscode
3 changes: 0 additions & 3 deletions .tsdrc

This file was deleted.

10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"src/**/*.js": true,
"test/**/*.js": true,
"type_definitions/**/*.js": true
}
}
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $ npm install
```
3 - Install TSD typings:
```
$ typings install
$ tsd install
```

4 - Run tests:
Expand All @@ -24,6 +24,8 @@ $ gulp test

Please try to [combine multiple commits before pushing](http://stackoverflow.com/questions/6934752/combining-multiple-commits-before-pushing-in-git)

Please use `TDD` when fixing bugs. This means that you should write a unit test that fails because it reproduces the issue, then fix the issue finaly run the test to ensure that the issue has been resolved. This helps us to prevent fixed bugs from happening again in the future.
Please use `TDD` when fixing bugs. This means that you should write a unit test that fails because
it reproduces the issue, then fix the issue finaly run the test to ensure that the issue has been
resolved. This helps us to prevent fixed bugs from happening again in the future.

Please try keep the test coverage at 100%. Write additional unit test if necesary
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Wolk Software Ltd.
Copyright (c) 2015 Remo H. Jansen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A lightweight IoC container written in TypeScript.
Visit http://inversify.io/ for more information.

### About
InversifyJS is a lightweight pico inversion of control (IoC) container for TypeScript and JavaScript apps. A pico IoC container uses a class constructor to identify and inject its dependencies.
InversifyJS is a lightweight (4KB) pico inversion of control (IoC) container for TypeScript and JavaScript apps. A pico IoC container uses a class constructor to identify and inject its dependencies.

InversifyJS is easy to integrate with the majority of existing JavaScript frameworks and encourage the usage of the best OOP and IoC practices.

Expand Down Expand Up @@ -104,23 +104,23 @@ class FooBar implements FooBarInterface {
Before we can start resolving and injecting dependencies we need to create an instance of the InversifyJS Kernel class. The Kernel will automatically detect is a class has some dependencies by examining its constructor. The Kernel will automatically detect if a class has some dependencies by examining the metadata provided by the Inject decorator.

```
import { TypeBinding, Kernel } from "inversify";
import { Binding, BindingScope, Kernel } from "inversify";
var kernel = new Kernel();
```

In order to resolve a dependency, the kernel needs to be told which implementation type (classes) to associate with each service type (interfaces). We will use type bindings for this purpose. A type binding (or just a binding) is a mapping between a service type (an interface), and an implementation type (class).

```
kernel.bind(new TypeBinding<FooInterface>("FooInterface", Foo, TypeBindingScopeEnum.Transient));
kernel.bind(new TypeBinding<BarInterface>("BarInterface", Bar, TypeBindingScopeEnum.Singleton));
kernel.bind(new TypeBinding<FooBarInterface>("FooBarInterface", FooBar));
kernel.bind(new Binding<FooInterface>("FooInterface", Foo, BindingScope.Transient));
kernel.bind(new Binding<BarInterface>("BarInterface", Bar, BindingScope.Singleton));
kernel.bind(new Binding<FooBarInterface>("FooBarInterface", FooBar));
```

When we declare a type binding, the TypeScript compiler will check that the implementation type (class) is actually and implementation of the service type (interface) and throw a compilation error if that is not the case.

```
// Compilation error: Bar does not implement FooInterface
kernel.bind(new TypeBinding<FooInterface>("FooInterface", Bar));
kernel.bind(new Binding<FooInterface>("FooInterface", Bar));
```

We should keep the InversifyJS Kernel instantiation and type bindings centralized in one unique IoC configuration file. This will help us to abstract our application from the IoC configuration.
Expand Down
119 changes: 80 additions & 39 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ var gulp = require("gulp"),
tsc = require("gulp-typescript"),
coveralls = require('gulp-coveralls'),
uglify = require("gulp-uglify"),
docco = require("gulp-docco"),
typedoc = require("gulp-typedoc"),
rename = require("gulp-rename"),
runSequence = require("run-sequence"),
header = require("gulp-header"),
pkg = require(__dirname + "/package.json"),
mocha = require("gulp-mocha"),
istanbul = require("gulp-istanbul");

//******************************************************************************
//* LINT
//******************************************************************************
gulp.task("lint", function() {
return gulp.src([
__dirname + "/source/**/**.ts",
__dirname + "/test/**/**.test.ts"
])
.pipe(tslint())
.pipe(tslint.report("verbose"));

var config = { emitError: (process.env.CI) ? true : false };

return gulp.src([
"src/**/**.ts",
"test/**/**.test.ts",
"type_definitions/**/**.ts"
])
.pipe(tslint())
.pipe(tslint.report("verbose", config));
});

//******************************************************************************
Expand All @@ -37,68 +40,106 @@ gulp.task("lint", function() {
var tsProject = tsc.createProject("tsconfig.json");

gulp.task("build-source", function() {
return gulp.src(__dirname + "/source/**/**.ts")
.pipe(tsc(tsProject))
.js.pipe(gulp.dest(__dirname + "/build/source/"));
return gulp.src([
"src/**/**.ts",
"typings/browser.d.ts",
"node_modules/reflect-metadata/reflect-metadata.d.ts"
])
.pipe(tsc(tsProject))
.on('error', function (err) {
process.exit(1);
})
.js.pipe(gulp.dest("src/"));
});

var tsTestProject = tsc.createProject("tsconfig.json");

gulp.task("build-test", function() {
return gulp.src(__dirname + "/test/**/*.ts")
.pipe(tsc(tsTestProject))
.js.pipe(gulp.dest(__dirname + "/build/test/"));
return gulp.src([
"test/**/*.ts",
"typings/browser.d.ts",
"node_modules/reflect-metadata/reflect-metadata.d.ts"
])
.pipe(tsc(tsTestProject))
.on('error', function (err) {
process.exit(1);
})
.js.pipe(gulp.dest("test/"));
});

var tsTypeDefinitionsProject = tsc.createProject("tsconfig.json");

gulp.task("build-type-definitions", function() {
return gulp.src(__dirname + "/type_definitions/**/*.ts")
return gulp.src("type_definitions/**/*.ts")
.pipe(tsc(tsTypeDefinitionsProject))
.js.pipe(gulp.dest(__dirname + "/build/type_definitions/"));
.on('error', function (err) {
process.exit(1);
})
.js.pipe(gulp.dest("type_definitions/"));
});

gulp.task("build", function(cb) {
runSequence("build-source", "build-test", "build-type-definitions", cb);
runSequence("lint", "build-source", "build-test", "build-type-definitions", cb);
});

//******************************************************************************
//* DOCUMENT
//******************************************************************************
gulp.task("document", function () {
return gulp.src(__dirname + "/build/source/*.js")
.pipe(docco())
.pipe(gulp.dest(__dirname + "/documentation"));
return gulp
.src(["src/*.ts"])
.pipe(typedoc({
// TypeScript options (see typescript docs)
target: "es5",
module: "commonjs",
moduleResolution: "node",
isolatedModules: false,
jsx: "react",
experimentalDecorators: true,
emitDecoratorMetadata: true,
noImplicitAny: false,
noLib: false,
preserveConstEnums: true,
suppressImplicitAnyIndexErrors: true,
// Output options (see typedoc docs)
out: "./documentation",
name: "InversifyJS",
version: true
}));
});

//******************************************************************************
//* BUNDLE
//******************************************************************************
gulp.task("bundle", function () {

var b = browserify({
standalone : 'inversify',
entries: __dirname + "/build/source/inversify.js",
entries: "src/inversify.js",
debug: true
});

return b.bundle()
.pipe(source("inversify.js"))
.pipe(buffer())
.pipe(gulp.dest(__dirname + "/bundled/source/"));
.pipe(gulp.dest("bundled/src/"));

});

//******************************************************************************
//* TEST
//******************************************************************************

gulp.task("mocha", function() {
return gulp.src('build/test/**/*.test.js')
return gulp.src([
'node_modules/reflect-metadata/Reflect.js',
'test/**/*.test.js'
])
.pipe(mocha({ui: 'bdd'}))
.pipe(istanbul.writeReports());
});

gulp.task("istanbul:hook", function() {
return gulp.src(['build/source/**/*.js'])
return gulp.src(['src/**/*.js'])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
Expand All @@ -111,25 +152,25 @@ gulp.task("cover", function() {
.pipe(coveralls());
});

gulp.task("build-and-test", function(cb) {
runSequence("build", "istanbul:hook", "mocha", "cover", cb);
gulp.task("test", function(cb) {
runSequence("istanbul:hook", "mocha", "cover", cb);
});

//******************************************************************************
//* BAKE
//******************************************************************************
gulp.task("copy", function() {
return gulp.src(__dirname + "/bundled/source/inversify.js")
.pipe(gulp.dest(__dirname + "/dist/"));
return gulp.src("bundled/src/inversify.js")
.pipe(gulp.dest("dist/"));
});

gulp.task("compress", function() {
return gulp.src(__dirname + "/bundled/source/inversify.js")
return gulp.src("bundled/src/inversify.js")
.pipe(uglify({ preserveComments : false }))
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest(__dirname + "/dist/"))
.pipe(gulp.dest("dist/"))
});

gulp.task("header", function() {
Expand All @@ -144,26 +185,26 @@ gulp.task("header", function() {
" */",
""].join("\n");

gulp.src(__dirname + "/dist/inversify.js")
gulp.src("dist/inversify.js")
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest(__dirname + "/dist/"));
.pipe(gulp.dest("dist/"));

return gulp.src(__dirname + "/dist/inversify.min.js")
return gulp.src("dist/inversify.min.js")
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest(__dirname + "/dist/"));
.pipe(gulp.dest("dist/"));
});

gulp.task("dist", function(cb) {
runSequence("bundle", "copy", "compress", "header", "document", cb);
runSequence("bundle", "copy", "compress", "header", cb);
});

//******************************************************************************
//* DEFAULT
//******************************************************************************
gulp.task("default", function (cb) {
runSequence(
"lint",
"build-and-test",
"build",
"test",
"dist",
cb);
});
});
30 changes: 17 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inversify",
"version": "1.3.1",
"version": "2.0.0-alpha.0",
"description": "A lightweight IoC container written in TypeScript.",
"main": "dist/inversify.js",
"typings": "type_definitions/inversify-npm.d.ts",
Expand All @@ -9,21 +9,21 @@
},
"scripts": {
"test": "gulp",
"prepublish": "gulp build-and-test && gulp dist"
"prepublish": "gulp build && gulp test && gulp dist"
},
"repository": {
"type": "git",
"url": "https://github.com/inversify/InversifyJS.git"
},
"keywords": [
"IoC",
"container",
"JavaScript",
"TypeScript",
"dependency",
"inversion",
"inversion",
"control"
"ioc",
"di",
"javascript",
"typescript",
"node",
"dependency injection",
"dependency inversion",
"inversion of control container"
],
"author": "Remo H. Jansen",
"license": "MIT",
Expand All @@ -32,26 +32,30 @@
},
"homepage": "http://inversify.io",
"engines": {},
"dependencies": {},
"dependencies": {
"reflect-metadata": "^0.1.3"
},
"devDependencies": {
"browserify": "^13.0.0",
"chai": "^3.4.1",
"gulp": "^3.9.0",
"gulp-coveralls": "^0.1.4",
"gulp-docco": "0.0.4",
"gulp-header": "^1.7.1",
"gulp-istanbul": "^0.10.3",
"gulp-mocha": "^2.2.0",
"gulp-rename": "^1.2.2",
"gulp-tslint": "^4.3.1",
"gulp-typedoc": "^1.2.1",
"gulp-typescript": "^2.10.0",
"gulp-uglify": "^1.5.1",
"istanbul": "^0.4.2",
"mocha": "^2.3.4",
"run-sequence": "^1.1.5",
"sinon": "^1.17.3",
"tslint": "^3.2.2",
"typescript": "^1.7.5",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
"vinyl-source-stream": "^1.1.0",
"wallabify": "0.0.14"
}
}
Loading

0 comments on commit 4c129e3

Please sign in to comment.