microframework
Advanced tools
Comparing version 0.5.5 to 0.6.0
@@ -1,10 +0,16 @@ | ||
export * from "./ConfigLoader"; | ||
export * from "./decorators"; | ||
export * from "./MicroFrameworkBootstrapper"; | ||
export * from "./MicroFrameworkConfig"; | ||
export * from "./MicroFrameworkRegistry"; | ||
export * from "./MicroFrameworkSettings"; | ||
export * from "./MicroFrameworkUtils"; | ||
export * from "./Module"; | ||
export * from "./ModulesRegistry"; | ||
export * from "./MicroFramework"; | ||
import { Microframework } from "./Microframework"; | ||
import { MicroframeworkBootstrapConfig } from "./MicroframeworkBootstrapConfig"; | ||
import { MicroframeworkModule } from "./MicroframeworkModule"; | ||
export * from "./MicroframeworkBootstrapSettings"; | ||
export * from "./Microframework"; | ||
export * from "./MicroframeworkModule"; | ||
export * from "./MicroframeworkShutdownHandler"; | ||
export * from "./MicroframeworkConfig"; | ||
/** | ||
* Creates a new microframework instance that can be configured and launched. | ||
*/ | ||
export declare function bootstrapMicroframework(config: MicroframeworkBootstrapConfig): Promise<Microframework>; | ||
/** | ||
* Creates a new microframework instance that can be configured and launched. | ||
*/ | ||
export declare function bootstrapMicroframework(modules: MicroframeworkModule[]): Promise<Microframework>; |
25
index.js
@@ -5,9 +5,20 @@ "use strict"; | ||
} | ||
__export(require("./ConfigLoader")); | ||
__export(require("./decorators")); | ||
__export(require("./MicroFrameworkBootstrapper")); | ||
__export(require("./MicroFrameworkRegistry")); | ||
__export(require("./MicroFrameworkUtils")); | ||
__export(require("./ModulesRegistry")); | ||
__export(require("./MicroFramework")); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Microframework_1 = require("./Microframework"); | ||
// ------------------------------------------------------------------------- | ||
// Handy Exports | ||
// ------------------------------------------------------------------------- | ||
__export(require("./MicroframeworkBootstrapSettings")); | ||
__export(require("./Microframework")); | ||
/** | ||
* Creates a new microframework instance that can be configured and launched. | ||
*/ | ||
function bootstrapMicroframework(configOrModules) { | ||
var bootstrapConfig = configOrModules instanceof Array ? { modules: configOrModules } : configOrModules; | ||
return new Microframework_1.Microframework() | ||
.config(bootstrapConfig.config) | ||
.registerModules(bootstrapConfig.modules) | ||
.bootstrap(); | ||
} | ||
exports.bootstrapMicroframework = bootstrapMicroframework; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "microframework", | ||
"private": false, | ||
"version": "0.5.5", | ||
"description": "Micro framework is a bundle of express.js, mongodb ODM, validator, dependancy injection framework and restful controllers for your apps using Typescript", | ||
"license": "Apache-2.0", | ||
"version": "0.6.0", | ||
"description": "Microframework is a minimalistic framework you can use with TypeScript and JavaScript.", | ||
"license": "MIT", | ||
"readmeFilename": "README.md", | ||
@@ -24,26 +24,30 @@ "author": { | ||
], | ||
"dependencies": { | ||
"configuration-manager": "~0.4.1", | ||
"find-root": "0.1.1", | ||
"path": "^0.12.7", | ||
"typedi": "~0.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.0.35", | ||
"@types/node": "^7.0.5", | ||
"@types/winston": "^2.2.0", | ||
"ascii-art": "^1.4.2", | ||
"chai": "^3.4.1", | ||
"chai-as-promised": "^5.2.0", | ||
"del": "^2.0.2", | ||
"chai-as-promised": "^6.0.0", | ||
"del": "^2.2.2", | ||
"express": "^4.15.1", | ||
"gulp": "^3.9.1", | ||
"gulp-mocha": "^2.2.0", | ||
"gulp-mocha": "^4.0.1", | ||
"gulp-replace": "^0.5.4", | ||
"gulp-shell": "^0.5.0", | ||
"gulp-tslint": "^4.3.3", | ||
"gulpclass": "0.1.0", | ||
"mocha": "^2.3.4", | ||
"sinon": "^1.17.2", | ||
"gulp-shell": "^0.6.1", | ||
"gulp-tslint": "^7.1.0", | ||
"gulpclass": "0.1.2", | ||
"i": "^0.3.5", | ||
"mocha": "^3.2.0", | ||
"mysql": "^2.13.0", | ||
"npm": "^4.3.0", | ||
"sinon": "^1.17.7", | ||
"sinon-chai": "^2.8.0", | ||
"tslint": "^3.5.0", | ||
"tslint-stylish": "^2.1.0-beta", | ||
"typescript": "^1.8.7", | ||
"typings": "^0.7.7" | ||
"ts-node": "^2.1.0", | ||
"tslint": "^4.5.1", | ||
"tslint-stylish": "^2.1.0", | ||
"typeorm": "0.0.9", | ||
"typescript": "^2.2.1", | ||
"winston": "^2.3.1" | ||
} | ||
} |
244
README.md
@@ -1,127 +0,161 @@ | ||
# MicroFramework | ||
# Microframework | ||
Micro framework integrates popular libraries like [express.js][1], [Mongodb ODM][2], [validator.ts][5], | ||
[controllers.ts][4], [event-dispatcher.ts][7] | ||
and others for use in your Typescript application. Framework ships by default [dependency injection framework][3] and | ||
[configuration framework][6] to make all modules to work like a sh | ||
Microframework is a simple tool that allows you to execute your modules in a proper order, | ||
helping you to organize bootstrap code in your application. | ||
## Notice | ||
## Usage | ||
Library is under active development and API may change from version to version. | ||
Please consider it before using this library. | ||
First, install the module: | ||
## Installation | ||
``` | ||
npm i microframework | ||
``` | ||
You use framework with one or more the available modules. Lets say you want to use [express.js][1], [Mongodb ODM][2], | ||
[validator][5], [event-dispatcher][7] and [restful controllers][4]. | ||
Second, create a simple "module" named `expressModule`: | ||
1. Install npm modules: | ||
```javascript | ||
import {MicroframeworkBootstrapSettings} from "microframework"; | ||
`npm install microframework microframework-express microframework-typeodm microframework-controllers.ts | ||
microframework-validator.ts microframework-event-dispatcher.ts configurator.ts controllers.ts typedi typeodm validator.ts --save` | ||
export function expressModule(settings: MicroframeworkBootstrapSettings) { | ||
2. Use [typings](https://github.com/typings/typings) to install all required definition dependencies. | ||
// create express app | ||
const app = express(); | ||
`typings install` | ||
// register all routes, Routes are just routes that should be stored outside of this module | ||
const routes: any = Routes; | ||
Object.keys(routes).forEach(routePath => app.get(routePath, routes[routePath])); | ||
3. ES6 features are used, so you may want to install [es6-shim](https://github.com/paulmillr/es6-shim) too: | ||
// run application to listen on given port | ||
app.listen(3000); | ||
// your module also can return a promise | ||
} | ||
``` | ||
`npm install es6-shim --save` | ||
Create `app.ts` and bootstrap a microframework and your express module: | ||
you may want to `require("es6-shim");` in your app | ||
```javascript | ||
import {bootstrapMicroframework} from "microframework"; | ||
import {expressModule} from "./expressModule"; | ||
## Usage | ||
bootstrapMicroframework([ | ||
expressModule | ||
]) | ||
.then(() => console.log("Application is up and running.")) | ||
.catch(error => console.log("Application is crashed: " + error)); | ||
``` | ||
1. Create `src/app.ts`: | ||
```javascript | ||
import {MicroFrameworkBootstrapper} from "microframework/MicroFrameworkBootstrapper"; | ||
import {ExpressModule} from "microframework-express/ExpressModule"; | ||
import {ControllersTsModule} from "microframework-controllers.ts/ControllersTsModule"; | ||
import {TypeOdmModule} from "microframework-typeodm/TypeOdmModule"; | ||
import {ValidatorTsModule} from "microframework-validator.ts/ValidatorTsModule"; | ||
import {EventDispatcherTsModule} from "microframework-event-dispatcher.ts/EventDispatcherTsModule"; | ||
new MicroFrameworkBootstrapper({ srcDirectory: __dirname }) | ||
.registerModules([ | ||
new ExpressModule(), | ||
new TypeOdmModule(), | ||
new ControllersTsModule(), | ||
new ValidatorTsModule(), | ||
new EventDispatcherTsModule() | ||
]) | ||
.bootstrap() | ||
.then(result => console.log("Module is running. Open localhost:3000")) | ||
.catch(error => console.error("Error: ", error)); | ||
``` | ||
2. Create configuration file `config/config.json` (note: its not in the same dir where your source is, | ||
folder is near your `package.json` file): | ||
```json | ||
{ | ||
"express": { | ||
"port": "3000", | ||
"bodyParser": { | ||
"type": "json" | ||
} | ||
}, | ||
"typeodm": { | ||
"connection": { | ||
"url": "mongodb://localhost:27017/microframework-sample" | ||
} | ||
} | ||
} | ||
``` | ||
3. Now create your first controller, lets say QuestionController: `src/controller/QuestionController.ts`: | ||
```javascript | ||
import {JsonController, Get} from "controllers.ts/Annotations"; | ||
import {Response, Request} from "express"; | ||
That's all. You can do same for other modules. | ||
Take a look on sample to understand better how concept of modules and their bootstrapping in microframework. | ||
@JsonController() | ||
export class QuestionController { | ||
## Settings | ||
You can specify additional options to microframework. | ||
* `logo` - Logo needs to be used before application launches. To use logo ansi-art module should be installed. | ||
* `showBootstrapTime` - If set to true then framework shows how much time was spend to bootstrap all modules. | ||
* `bootstrapTimeout` - Number of milliseconds to wait before framework will bootstrap all modules. | ||
Example of using settings: | ||
```javascript | ||
import {bootstrapMicroframework} from "microframework"; | ||
bootstrapMicroframework({ | ||
config: { | ||
logo: "MyApp", | ||
showBootstrapTime: true, | ||
bootstrapTimeout: 10 | ||
}, | ||
modules: [ | ||
expressModule, | ||
// ... | ||
] | ||
}) | ||
.then(() => console.log("Application is up and running.")) | ||
.catch(error => console.log("Application is crashed: " + error)); | ||
``` | ||
## Sharing data across modules | ||
Sometimes few modules need to communicate between each other and use shared data. | ||
For such purpose you can store the data in `settings` object passed to each module | ||
and use stored data across all other modules. For example: | ||
```javascript | ||
import {MicroframeworkBootstrapSettings} from "microframework"; | ||
export function expressModule(settings: MicroframeworkBootstrapSettings) { | ||
// create express app | ||
const app = express(); | ||
// register all routes, Routes are just routes that should be stored outside of this module | ||
const routes: any = Routes; | ||
Object.keys(routes).forEach(routePath => app.get(routePath, routes[routePath])); | ||
// run application to listen on given port | ||
app.listen(3000); | ||
@Get("/questions") | ||
all(): any[] { | ||
return [ | ||
{ title: "Which processor to choose?", text: "Which processor is better: Core i5 or Core i7?" }, | ||
{ title: "When new star wars gonna be released?", text: "When star wars gonna be released? I think in december" } | ||
]; | ||
} | ||
} | ||
``` | ||
settings.setData("express_app", app); | ||
} | ||
``` | ||
4. Run your app and open `http://localhost:3000/questions` in browser. You should see list of your questions. | ||
And another modules can use data this way: | ||
## Available Modules | ||
```javascript | ||
import {MicroframeworkBootstrapSettings} from "microframework"; | ||
* [microframework-express](https://github.com/pleerock/microframework-express) - integration with [express.js][1] | ||
* [microframework-typeodm](https://github.com/pleerock/microframework-typeodm) - integration with [TypeODM][2] | ||
* [microframework-controllers.ts](https://github.com/pleerock/microframework-controllers.ts) - integration with [controllers.ts][4] | ||
* [microframework-validator.ts](https://github.com/pleerock/microframework-validator.ts) - integration with [validator.ts][5] | ||
* [microframework-event-dispatcher.ts](https://github.com/pleerock/microframework-event-dispatcher.ts) - integration with [event-dispatcher.ts][7] | ||
* [microframework-winston](https://github.com/pleerock/microframework-winston) - integration with [winston][8] | ||
* [microframework-elasticsearch](https://github.com/pleerock/microframework-elasticsearch) - integration with [elasticsearch][9] | ||
* [microframework-rabbit.ts](https://github.com/pleerock/microframework-rabbit.ts) - integration with [rabbit.js][10] | ||
export function socketIoModule(settings: MicroframeworkBootstrapSettings) { | ||
const io = io(); | ||
io.useExpress(settings.getData("express_app")); | ||
} | ||
``` | ||
## Todos | ||
## Application Shutdown | ||
* cover with tests | ||
* more documentation and examples | ||
* more modules | ||
* add ability to include other configs by include path in the object? | ||
* add yo generator | ||
* good to have todo mvc sample | ||
In the case if you want to shutdown running application you need to do following: | ||
[1]: http://expressjs.com/ | ||
[2]: https://github.com/pleerock/typeodm | ||
[3]: https://github.com/pleerock/typedi | ||
[4]: https://github.com/pleerock/controllers.ts | ||
[5]: https://github.com/pleerock/validator.ts | ||
[6]: https://github.com/pleerock/configurator.ts | ||
[7]: https://github.com/pleerock/event-dispatcher.ts | ||
[8]: https://github.com/winstonjs/winston | ||
[9]: https://github.com/elastic/elasticsearch-js | ||
[10]: https://github.com/squaremo/rabbit.js/ | ||
```javascript | ||
import {bootstrapMicroframework} from "microframework"; | ||
bootstrapMicroframework({ | ||
config: { | ||
logo: "MyApp", | ||
showBootstrapTime: true, | ||
bootstrapTimeout: 10 | ||
}, | ||
modules: [ | ||
expressModule, | ||
// ... | ||
] | ||
}) | ||
.then(framework => { | ||
// do something before shutdown | ||
// and shutdown everything | ||
return framework.shutdown(); | ||
}) | ||
.then(() => { | ||
// now everything is turned off | ||
}) | ||
.catch(error => console.log("Application is crashed: " + error)); | ||
``` | ||
All modules which use resources should release them, for example: | ||
```javascript | ||
export async function typeormModule(settings: MicroframeworkBootstrapSettings) { | ||
const connection = await createConnection({ | ||
driver: { | ||
type: "mysql", | ||
host: "localhost", | ||
username: "test", | ||
password: "test", | ||
database: "test" | ||
} | ||
}); | ||
settings.addShutdownHandler(() => connection.close()); | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
161
0
30023
26
29
443
1
- Removedconfiguration-manager@~0.4.1
- Removedfind-root@0.1.1
- Removedpath@^0.12.7
- Removedtypedi@~0.4.0
- Removedconfiguration-manager@0.4.1(transitive)
- Removedfind-root@0.1.1(transitive)
- Removedinherits@2.0.3(transitive)
- Removedpath@0.12.7(transitive)
- Removedprocess@0.11.10(transitive)
- Removedtypedi@0.4.3(transitive)
- Removedutil@0.10.4(transitive)