Code Monkey home page Code Monkey logo

sorcerer's Introduction

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

// 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

module.exports = {
	whateverYouWantHere: 'yeah'
}

/src/util/Decorator.js

module.exports = function(App)
{
	// this will evaluate since it is referencing an active resource
	App.name = 'Decorated App';
}

/sorcerer.config.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

// 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);
});

sorcerer's People

Contributors

rvanasa avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.