acute

0.0.3 • Public • Published

acute.js

The no strings attached JavaScript build solution.

Note: This project is very much in its infancy. Feel free to contribute to get it moving!

Why?

Because organising your client side application shouldn't be a chore. acute.js let's you do it however you please, and build it with a single command.

How?

At its core, *acute.js* uses the /// import and /// export directives to describe a modules context in the project. The triple-slash comments allows acute.js modules to be incredibly portable.

The hello world! example demonstrates, pretty much, all the components of acute.js.

Getting Started

acute.js is best installed globally.

npm install -g acute

Now let's whip up a quick hello world! library to demonstrate acute.js's fool proof module system.

hello.js

/// exports foo.hello from bar;
var bar = 'hello';

First we create a namespace foo.hello and give it the object bar.

world.js

/// exports foo.world;
var world = 'world';

Now we create a namespace foo.world and it infers that it should receive the object world.

example.js

/// exports example;
/// imports foo.hello;
/// imports foo.world to bar;
var example = function() {
  console.log(hello + ' ' + bar + '!');
};

This will be our entry point. It creates a namespace example which infers the function we've defined and it also imports our namespaces foo.hello and foo.world. In this instance we've imported foo.world as bar.

So how do build this trivial little example? With an acute.json file of course!

acute.json

{
  "root": "./",
  "public": {
    "example": "foo"
  },
  "output": "./build.js"
}

So what is this telling us? Well assuming all our files are in the same directory, acute.json is going to instruct the compiler that all source files are located in the ./, this directory; it wants to make the namespace example publically accessible as window.foo, and finally; it wants to output the result to a file ./build.js. Now it's simply a matter of executing the acute.js compiler on the command line.

$ acute .

And voila! We now have a portable JavaScript hello world! library!

API Reference

Directives

Directives are the meat of acute.js. The following directives are currently defined.

Built In Directives

export namespace[ from identifier]

namespace A dot-delimited address describing where the module sits in the tree.

identifier The name of the identifier in the module to export to the namespace. This defaults to the most low-level namespace element.

import namespace[ to identifier]

namespace A dot-delimited address describing where the module to import is located in the tree.

identifier The name of the identifier to import the module to. This defaults to the most low-level namespace element.

Custom Directives

You can define your own directives by creating a id.js file in the parser/directives directory. Directives take the following form.

module.exports = function(module, args, done) {
 
  done(null, 'replacement');
 
};

The directive function takes the following arguments and its identifier is the name of the file it is defined in bar the extension.

module An object containing the module currently being processed. module has the following properties.

  • path The path to the source file the module is loaded from.
  • source The current state of the source code defining the module.
  • imports An array of namespace-alias pairs describing which modules to import.
  • exports A namespace-alias pair describing what and where to export.

args The arguments passed to the directive. This is simply the text after the directive identifier and before the newline, delimited by a space.

done A callback to be executed when the directive has finished processing. The done callback takes two arguments.

  • err An error if one was trigger. May be set to null.
  • replacement A string to replace the directive with. The default is undefined, removing the directive from the source.

Programmatic API

If you decide you would like to use acute.js in your Gruntfile, or anything else, you can execute a build by requiring acute in your source code.

var $acute = require('acute');
$acute.make('./path/to/acute.json', function(err) {
  if (err) return console.log(err);
  console.log('All good man!');
);

Questions, Comments?

Feel free to email or submit an issue!

Contributing

To say acute.js is in its infancy would be an understatement. Please feel free to contribute by forkng this repository and issuing a pull request! Please maintain the coding style if you do!

Readme

Keywords

none

Package Sidebar

Install

npm i acute

Weekly Downloads

1

Version

0.0.3

License

MIT

Last publish

Collaborators

  • markschad