Code Monkey home page Code Monkey logo

carton's Introduction

Carton

Manage your library files throughout your codebase without worrying about anything except maybe some trivial things like making sure your code works.

##Example

Boostrappin' your application in, for example, index.js;

var carton = require('carton');

carton.add(require('./awesomeModule'));
carton.add(require('./magicalModule'));
carton.add(require('./coolModule'));
carton.add(require('./whateverModule'));

carton.setup(function() {
    
	carton.cool.beans();
	
});

Inside of coolModule.js

//Your module needs to have a name for Carton to recognize it.
exports.name = 'cool';

//Carton first calls all init functions. 
//You should not use modules loaded with Carton at this point. 
//This function is not required.
exports.init = function (cb) {
    console.log('I am called first!');
    cb();
};

//Carton call setup once all modules have been initialized.
//You can now access all carton modules. 
//This function is not required.
exports.setup = function (cb) {
    console.log('I am called after all other modules have been intialized.');
    cb();
};

exports.beans = function () {
    console.log('Okey Dokey Artichoke');
};

##Configuration files Although Carton is designed to provide as little functionality out of the box as possible, it has one module to load configuration files. Configuration files should be valid JSON. Let's say that this is your configuration file:

{
	"foo": "bar",
	"nested": {
		"objects": {
			"are": {
				"cool": "too"
			}
		}
	},
	"array": [
		"this", "is", "an", "array"
	]
}

Then you can access your configuration files like this;

var assert = require('assert');
var carton = require('carton');
carton.cfg.load('/location/to/your/file.json');

var nestedObjects = carton.cfg.get('nested.objects');
assert.equals(nestedObjects.are.cool, 'too');

var arr = carton.cfg.get('arrays');
assert.equals(arr.length, 4);

var foo = carton.cfg.get('foo');
assert.equals(foo, 'bar');

##Appplication directory Carton has a way to set the app directory so that you can access it via carton.appDir.

carton.setAppDir('/var/www/carton');

##Testing Run make test and watch the magic happen.

carton's People

Contributors

briandeheus avatar brianfields avatar

Stargazers

 avatar

Watchers

 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.