Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

microframework

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microframework - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

MicroframeworkLoader.d.ts

6

index.d.ts
import { Microframework } from "./Microframework";
import { MicroframeworkBootstrapConfig } from "./MicroframeworkBootstrapConfig";
import { MicroframeworkModule } from "./MicroframeworkModule";
import { MicroframeworkLoader } from "./MicroframeworkLoader";
export * from "./MicroframeworkSettings";
export * from "./Microframework";
export * from "./MicroframeworkModule";
export * from "./MicroframeworkLoader";
export * from "./ShutdownHandler";

@@ -17,2 +17,2 @@ export * from "./MicroframeworkConfig";

*/
export declare function bootstrapMicroframework(modules: MicroframeworkModule[]): Promise<Microframework>;
export declare function bootstrapMicroframework(modules: MicroframeworkLoader[]): Promise<Microframework>;

@@ -16,6 +16,6 @@ "use strict";

function bootstrapMicroframework(configOrModules) {
var bootstrapConfig = configOrModules instanceof Array ? { modules: configOrModules } : configOrModules;
var bootstrapConfig = configOrModules instanceof Array ? { loaders: configOrModules } : configOrModules;
return new Microframework_1.Microframework()
.config(bootstrapConfig.config)
.registerModules(bootstrapConfig.modules)
.registerLoaders(bootstrapConfig.loaders)
.bootstrap();

@@ -22,0 +22,0 @@ }

import { MicroframeworkSettings } from "./MicroframeworkSettings";
import { MicroframeworkModule } from "./MicroframeworkModule";
import { MicroframeworkLoader } from "./MicroframeworkLoader";
import { MicroframeworkConfig } from "./MicroframeworkConfig";

@@ -13,7 +13,11 @@ /**

/**
* Stores all registered microframework modules.
* Stores configurations from all configuration files provided to microframework.
*/
private modules;
private allConfiguration;
/**
* Stores all settings of modules bootstrapped by microframework.
* Stores all registered microframework loaders.
*/
private loaders;
/**
* Stores all settings of loaders bootstrapped by microframework.
* If its undefined it means framework is not bootstrapped yet.

@@ -25,25 +29,25 @@ */

*/
config(config: MicroframeworkConfig): this;
config(config: MicroframeworkConfig | string | string[]): this;
/**
* Registers module in the framework.
* Registers loader in the framework.
*/
registerModule(module: MicroframeworkModule): this;
registerLoader(loader: MicroframeworkLoader): this;
/**
* Registers modules in the framework.
* Registers loaders in the framework.
*/
registerModules(modules: MicroframeworkModule[]): this;
registerLoaders(loaders: MicroframeworkLoader[]): this;
/**
* Registers modules in the framework.
* Registers loaders in the framework.
*/
registerModules(...modules: MicroframeworkModule[]): this;
registerLoaders(...loaders: MicroframeworkLoader[]): this;
/**
* Bootstraps all modules.
* Bootstraps microframework and loads all loaders.
*/
bootstrap(): Promise<this>;
/**
* Shutdowns all modules.
* Shutdowns microframework and everything loaders registered for shutdown.
*/
shutdown(): Promise<this>;
/**
* Returns microframework settings used and modified by bootstrapped modules.
* Returns microframework settings used and modified by bootstrapped loaders.
* If framework was not bootstrapped yet, this accessor will throw an error.

@@ -50,0 +54,0 @@ */

@@ -15,5 +15,9 @@ "use strict";

/**
* Stores all registered microframework modules.
* Stores configurations from all configuration files provided to microframework.
*/
this.modules = [];
this.allConfiguration = {};
/**
* Stores all registered microframework loaders.
*/
this.loaders = [];
}

@@ -27,23 +31,37 @@ // -------------------------------------------------------------------------

Microframework.prototype.config = function (config) {
this.frameworkConfig = config;
var appRootDir = require("app-root-path").path;
if (config instanceof String) {
this.allConfiguration = require(appRootDir + "/" + config + ".json") || {};
if (this.allConfiguration.microframework)
this.frameworkConfig = this.allConfiguration.microframework;
}
else if (config instanceof Array) {
if (config.length > 0) {
this.allConfiguration = {};
Object.assign.apply(Object, [this.allConfiguration].concat(config.map(function (conf) { return require(appRootDir + "/" + conf + ".json") || {}; })));
}
}
else {
this.frameworkConfig = config;
}
return this;
};
/**
* Registers module in the framework.
* Registers loader in the framework.
*/
Microframework.prototype.registerModule = function (module) {
this.modules.push(module);
Microframework.prototype.registerLoader = function (loader) {
this.loaders.push(loader);
return this;
};
/**
* Registers modules in the framework.
* Registers loaders in the framework.
*/
Microframework.prototype.registerModules = function (modules /* MicroframeworkModule[]|MicroframeworkModule[][] */) {
Microframework.prototype.registerLoaders = function (loaders /* MicroframeworkModule[]|MicroframeworkModule[][] */) {
var _this = this;
(modules || []).forEach(function (module) {
if (module instanceof Array) {
(_a = _this.modules).push.apply(_a, module);
(loaders || []).forEach(function (loader) {
if (loader instanceof Array) {
(_a = _this.loaders).push.apply(_a, loader);
}
else {
_this.modules.push(module);
_this.loaders.push(loader);
}

@@ -55,7 +73,7 @@ var _a;

/**
* Bootstraps all modules.
* Bootstraps microframework and loads all loaders.
*/
Microframework.prototype.bootstrap = function () {
var _this = this;
var settings = new MicroframeworkSettings_1.MicroframeworkSettings();
var settings = new MicroframeworkSettings_1.MicroframeworkSettings(this.allConfiguration);
var bootstrapTime = +new Date();

@@ -68,5 +86,5 @@ return this.generateLogo()

}).then(function () {
return _this.runInSequence(_this.modules, function (module) {
var moduleResult = module(settings);
return moduleResult instanceof Promise ? moduleResult : Promise.resolve();
return _this.runInSequence(_this.loaders, function (loader) {
var loaderResult = loader(settings);
return loaderResult instanceof Promise ? loaderResult : Promise.resolve();
});

@@ -80,3 +98,3 @@ }).then(function () {

/**
* Shutdowns all modules.
* Shutdowns microframework and everything loaders registered for shutdown.
*/

@@ -94,3 +112,3 @@ Microframework.prototype.shutdown = function () {

/**
* Returns microframework settings used and modified by bootstrapped modules.
* Returns microframework settings used and modified by bootstrapped loaders.
* If framework was not bootstrapped yet, this accessor will throw an error.

@@ -97,0 +115,0 @@ */

import { MicroframeworkConfig } from "./MicroframeworkConfig";
import { MicroframeworkModule } from "./MicroframeworkModule";
import { MicroframeworkLoader } from "./MicroframeworkLoader";
/**

@@ -9,8 +9,10 @@ * Microframework bootstrap configuration.

* Microframework configuration.
* Can be file name, or array of file names from where to read configuration.
* File should be relative to package.json of the project (project root).
*/
config?: MicroframeworkConfig;
config?: MicroframeworkConfig | string | string[];
/**
* Modules needs to be registered in microframework.
* Loaders to be registered in microframework and executed on microframework bootstrap.
*/
modules?: MicroframeworkModule[];
loaders?: MicroframeworkLoader[];
}
import { ShutdownHandler } from "./ShutdownHandler";
/**
* Bootstrap settings used across all modules.
* Bootstrap settings used across all loader.
* Used to register shutdown handlers - special functions that will be executed when framework is shutdown.

@@ -8,2 +8,3 @@ * Also can be used to store and share data across modules.

export declare class MicroframeworkSettings {
private config;
/**

@@ -17,2 +18,3 @@ * Data which can be used to share data across modules.

private shutdownHandlers;
constructor(config: any);
/**

@@ -19,0 +21,0 @@ * Sets data that can be used across other modules.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Bootstrap settings used across all modules.
* Bootstrap settings used across all loader.
* Used to register shutdown handlers - special functions that will be executed when framework is shutdown.

@@ -9,3 +9,7 @@ * Also can be used to store and share data across modules.

var MicroframeworkSettings = (function () {
function MicroframeworkSettings() {
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
function MicroframeworkSettings(config) {
this.config = config;
// -------------------------------------------------------------------------

@@ -12,0 +16,0 @@ // Private Properties

{
"name": "microframework",
"private": false,
"version": "0.6.2",
"version": "0.6.3",
"description": "Microframework is a minimalistic framework you can use with TypeScript and JavaScript.",

@@ -50,3 +50,6 @@ "license": "MIT",

"winston": "^2.3.1"
},
"dependencies": {
"app-root-path": "^2.0.1"
}
}
# Microframework
Microframework is a simple tool that allows you to execute your modules in a proper order,
Microframework is a simple tool that allows you to execute and configure your modules (called *loaders*) in a proper order,
helping you to organize bootstrap code in your application.

@@ -8,3 +8,3 @@

First, install the module:
First, install microframework:

@@ -15,3 +15,5 @@ ```

Second, create a simple "module" named `expressModule`:
Second, create a simple "loader" named `expressLoader`.
Loader is a place where you can configure all your modules during microframework bootstrap.
All loaders are executed one by one in a sequential order.

@@ -21,3 +23,3 @@ ```javascript

export function expressModule(settings: MicroframeworkSettings) {
export function expressLoader(settings: MicroframeworkSettings) {

@@ -34,14 +36,14 @@ // create express app

// your module also can return a promise
// your loader also can return a promise and microframework will wait for it in a proper order
}
```
Create `app.ts` and bootstrap a microframework and your express module:
Create `app.ts` and bootstrap a microframework and your express loader:
```javascript
import {bootstrapMicroframework} from "microframework";
import {expressModule} from "./expressModule";
import {expressLoader} from "./expressLoader";
bootstrapMicroframework([
expressModule
expressLoader
])

@@ -52,4 +54,4 @@ .then(() => console.log("Application is up and running."))

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.
That's all. You can do same for other loaders.
Take a look on sample to understand better how concept of loaders and their bootstrapping in microframework.

@@ -60,5 +62,5 @@ ## Settings

* `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.
* `logo` - Logo needs to be used before application launches. To use logo ansi-art node module should be installed.
* `showBootstrapTime` - If set to true then framework shows how much time was spend to bootstrap microframework.
* `bootstrapTimeout` - Number of milliseconds to wait before framework will bootstrap.

@@ -69,2 +71,3 @@ Example of using settings:

import {bootstrapMicroframework} from "microframework";
import {expressLoader} from "./expressLoader";

@@ -77,4 +80,4 @@ bootstrapMicroframework({

},
modules: [
expressModule,
loaders: [
expressLoader,
// ...

@@ -87,7 +90,7 @@ ]

## Sharing data across modules
## Sharing data across loaders
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:
Sometimes few loaders need to communicate between each other and use shared data.
For such purpose you can store the data in `settings` object passed to each loader
and use stored data across all other loaders. For example:

@@ -97,3 +100,3 @@ ```javascript

export function expressModule(settings: MicroframeworkSettings) {
export function expressLoader(settings: MicroframeworkSettings) {

@@ -103,3 +106,3 @@ // create express app

// register all routes, Routes are just routes that should be stored outside of this module
// register all routes, Routes are just routes that should be stored outside of this loader
const routes: any = Routes;

@@ -115,3 +118,3 @@ Object.keys(routes).forEach(routePath => app.get(routePath, routes[routePath]));

And another modules can use data this way:
And another loaders can use data this way:

@@ -121,3 +124,3 @@ ```javascript

export function socketIoModule(settings: MicroframeworkSettings) {
export function socketIoLoader(settings: MicroframeworkSettings) {
const io = io();

@@ -134,2 +137,3 @@ io.useExpress(settings.getData("express_app"));

import {bootstrapMicroframework} from "microframework";
import {expressLoader} from "./expressLoader";

@@ -142,4 +146,4 @@ bootstrapMicroframework({

},
modules: [
expressModule,
loaders: [
expressLoader,
// ...

@@ -160,3 +164,3 @@ ]

All modules which use resources should release them, for example:
All loaders which use resources should release them, for example:

@@ -175,4 +179,4 @@ ```javascript

settings.onShutdown(() => connection.close());
settings.onShutdown(() => connection.close()); // closing connection on microframework shutdown
}
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc