UNPKG

4.83 kBMarkdownView Raw
1# Auton
2## Your plastic pal who's fun to code with
3
4Auton 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:
5
6- Automatically regenerate files when updated
7- Immediately running a linter or associated test when
8- CommonJS to AMD translation for server/browser parity
9- Monitor your resource compiling and server debug output in the same window!
10
11Auton's file watcher API (currently using watchr underneath) provides an API that should feel comfortable to anyone used to programming in express.
12
13```javascript
14var Auton = require('auton').Auton;
15var mw = Auton.Middleware;
16
17var robot = new Auton( {
18 root : __dirname ,
19 server : { path: 'server.js' }
20} );
21
22robot.watch('src/js', 'src/css', 'src/templates');
23
24robot.use( /\.(js(on)?|styl|less|css)$/, mw.read() ); // run for all matched files
25robot.use( '*.js', mw.jshint() );
26
27robot.file('src/js/**/*.js', mw.destination(['src/js', 'public/_/js' ]), mw.checkAge(), mw.commonJsToAmd(), mw.uglifyjs(), mw.save(), robot.server.middleware() );
28robot.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() );
29robot.file('src/vendor/**/*', mw.copy({ destination: ['src/vendor','public/_/vendor']}) );
30
31robot.server.start();
32robot.watcher.start();
33robot.scanAll();
34```
35
36```javascript
37 function someMiddleware( options ) {
38 function( file, next ) {
39 var filename = file.path; // all middleware always have this
40 var fullpath = file.fullpath; // same with this
41
42 var destname = file.destination; // these are normally generated by Auton.Middleware.destination()
43 var fullpath = file.fulldestination; // but any middleware could manually set them
44
45 var root = file.root; // Auton's root directory
46
47 // In addition, middleware can cause Auton to output using one of the following. Auton's UI may throw these messages away or display them depending on user preference:
48 this.success("It Worked!");
49 this.error("Something bad happened!");
50 this.info("Helpful Information");
51 this.warning("Caution: something you maybe didn't expect is happening");
52 this.debug("probably more information than is needed");
53 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.");
54 }
55 };
56```
57
58
59## Built-In Middleware
60### Auton.Middleware.read()
61- reads contents of file located at file.path into file.data.
62###
63
64### Auton.Middleware.destination()
65This middleware sets file.destination to a path which is calculated from file.path.
66```javascript
67
68
69 // using a static filename
70 robot.file('somefile.js', mw.destination( {filename: 'outputfile.js'} )); // somefile.js -> outputfile.js
71 robot.file('somefile.js', mw.destination('outputfile.js' )); // somefile.js -> outputfile.js
72
73 // mw.destination(a,b) and mw.destination([a,b]) get turned into file.replace(a,b)
74 robot.file('somedir/*.js', mw.destination( ['somedir/', 'outputdir/'] )); // somedir/file.js -> outputdir/file.js
75 robot.file('banana-man.js', mw.destination( /[aeiou]/g, 'oo' )); // banana-man.js -> boonoonoo-moon.js
76 robot.file('src/**/*.js', mw.destination( {pattern: p, replace: r} )); // equivalent to mw.destination( p, r );
77
78 // "mw.destination( someFunction );" is a shortcut for "file.destination = someFunction( file.path );"
79 var _coffee = function(_input) {
80 return _input
81 .replace(/\.coffee/g, '.js')
82 .replace('src', 'public')
83 ;
84 };
85 robot.file('src/foo.coffee', mw.destination( { transform: _coffee } )); // function which takes input filename and returns output filename
86 robot.file('src/foo.coffee', mw.destination( _coffee )); // shortcut for above, both do: src/foo.coffee -> public/foo.js
87```
88
89Both 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.)
90
91### Auton.Middleware.save()
92
93### Auton.Middleware.copy()
94
95### Auton.Middleware.checkAge()
96
97### Auton.Middleware.last()
98
99### Auton.Middleware.commonJsToAmd()
100
101Performs 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.
\No newline at end of file