Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rvanasa/sorcerer
Simple Inversion-of-Control framework for NodeJS developers who like Java/Spring.
https://github.com/rvanasa/sorcerer
angularjs dependency-injection dependency-injection-framework ioc nodejs organization spring
Last synced: about 1 month ago
JSON representation
Simple Inversion-of-Control framework for NodeJS developers who like Java/Spring.
- Host: GitHub
- URL: https://github.com/rvanasa/sorcerer
- Owner: rvanasa
- Created: 2016-07-31T23:07:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-02T01:47:42.000Z (about 6 years ago)
- Last Synced: 2024-11-09T16:08:15.692Z (about 1 month ago)
- Topics: angularjs, dependency-injection, dependency-injection-framework, ioc, nodejs, organization, spring
- Language: JavaScript
- Size: 43.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## A super straightforward dependency injection library for Node.js, inspired by AngularJS and the Java Spring Framework.
#### Example Project Layout
```
- src
- App.js
- Config.js
- util
- Decorator.js
- index.js
- sorcerer.config.js
```#### /src/App.js
```js
// all files in the provided directory use this general format
module.exports = function(Config)
{
var app = {};
console.log('Initialize some sort of app here');
return app;
}
```#### /src/Config.js
```js
module.exports = {
whateverYouWantHere: 'yeah'
}
```#### /src/util/Decorator.js
```js
module.exports = function(App)
{
// this will evaluate since it is referencing an active resource
App.name = 'Decorated App';
}
```#### /sorcerer.config.js
```js
module.exports = {
basePath: __dirname, // default: execution directory
verbose: true, // default: false (you can use strings/arrays to allow verbosity in specific environments)
packages: [{
env: 'production', // use specified env (process.env.NODE_ENV by default)
path: '/src', // you can also just pass the path string instead of a config object
}, {
name: 'globals', // optional
include: { // note that you can use both `path` and `include` in the same package
Config: () => 'Some example resource',
},
}],
};
```#### /index.js
```js// simple example (no config object)
require('sorc')(__dirname + '/src', 'App');// using externalized config
var config = require('./sorcerer.config');// configure a directory
require('sorc')(config, (App) =>
{
// You can use any file as an entry point
console.log(App);
});// or, configure a directory with a specified environment
require('sorc')(config, 'test', (App, Config) =>
{
console.log(App, Config);
});// or, configure a directory with error handling
require('sorc')(config, (err, App) =>
{
if(err) return console.error(err);
console.log(App);
});
```