Auton
Your plastic pal who's fun to code with
Auton is an automated node.js development environment & resource compiler which is meant to be flexible and extensible. A few things you can pull off with Auton:
- Automatically regenerate files when updated
- Immediately running a linter or associated test when
- CommonJS to AMD translation for server/browser parity
- Monitor your resource compiling and server debug output in the same window!
Auton's file watcher API (currently using watchr underneath) provides an API that should feel comfortable to anyone used to programming in express.
var Auton = require('auton').Auton;
var mw = Auton.Middleware;
var robot = new Auton( {
root : __dirname ,
server : { path: 'server.js' }
} );
robot.watch('src/js', 'src/css', 'src/templates');
robot.use( /\.(js(on)?|styl|less|css)$/, mw.read() );
robot.use( '*.js', mw.jshint() );
robot.file('src/js/**/*.js', mw.destination(['src/js', 'public/_/js' ]), mw.checkAge(), mw.commonJsToAmd(), mw.uglifyjs(), mw.save(), robot.server.middleware() );
robot.file('src/css/**/*.styl', mw.destination(function(input) { return input.replace(/\.styl$/,'.css').replace('src/css','public/_/css'); }), mw.checkAge(), mw.stylus(), mw.cssmin(), mw.save() );
robot.file('src/vendor/**/*', mw.copy({ destination: ['src/vendor','public/_/vendor']}) );
robot.server.start();
robot.watcher.start();
robot.scanAll();
function someMiddleware( options ) {
function( file, next ) {
var filename = file.path;
var fullpath = file.fullpath;
var destname = file.destination;
var fullpath = file.fulldestination;
var root = file.root;
this.success("It Worked!");
this.error("Something bad happened!");
this.info("Helpful Information");
this.warning("Caution: something you maybe didn't expect is happening");
this.debug("probably more information than is needed");
this.debug2("apparently you really want to see a ridiculous amount of information about what's happening. if you care about this you're probably fixing something. and you're probably me.");
}
};
Built-In Middleware
Auton.Middleware.read()
- reads contents of file located at file.path into file.data.
Auton.Middleware.destination()
This middleware sets file.destination to a path which is calculated from file.path.
robot.file('somefile.js', mw.destination( {filename: 'outputfile.js'} ));
robot.file('somefile.js', mw.destination('outputfile.js' ));
robot.file('somedir/*.js', mw.destination( ['somedir/', 'outputdir/'] ));
robot.file('banana-man.js', mw.destination( /[aeiou]/g, 'oo' ));
robot.file('src/**/*.js', mw.destination( {pattern: p, replace: r} ));
var _coffee = function(_input) {
return _input
.replace(/\.coffee/g, '.js')
.replace('src', 'public')
;
};
robot.file('src/foo.coffee', mw.destination( { transform: _coffee } ));
robot.file('src/foo.coffee', mw.destination( _coffee ));
Both mw.copy() and mw.save() use this middleware to determine the proper file to save to. Underneath, all it does is set file.destination = newPath, so you can replace a call to mw.destination() with a middleware which sets file.destination to a string value of your choice and both .save() and .copy() would listen to you (unless they're called with a custom destination, in which case this field is ignored. see below.)
Auton.Middleware.save()
Auton.Middleware.copy()
Auton.Middleware.checkAge()
Auton.Middleware.last()
Auton.Middleware.commonJsToAmd()
Performs a CommonJS to AMD translation, useful for code meant to run both natively under node and in the browser through an AMD-compatible loader such as require.js.