malta

lightning builder allows to compose on the fly and update packed and full coded huge javascript files, edit its parts as files, splitted and glued as You need

npm install malta
51 downloads in the last week
94 downloads in the last month

Malta

Malta allows to built on the fly big files editing its parts in separated files and assembling in one following a main template file.
As You start Malta you can start editing every file involved and the resulting file will be updated on the fly, and if it's javascript, you'll find even the minified version in the output folder.

Installation

If You do not have node installed yet, run:

$ curl http://npmjs.org/install.sh | sh 

then install malta running:

$ [sudo] npm install malta [-g]

Usage

$ malta templateFile outDirectory
  • templateFile
    is the base template used as base file. Note that the extension will be inherited by output files.

  • outDirectory
    is the folder where the output files will be written in.

Seen that most of times it would be handy to engage many builds at once it`s possible to start Malta as follows:

$ malta list.json

where list.json is a file containing one or more pairs, that commits Malta to build more than one file in one shot:

  • list.json :

      {
          "common.less" : "../../public_html/css",
          "common.js" : "../../public_html/js",
          ...
      }
    

Placeholders

Malta uses two kind of placeholders, to be used in the main template or in any file involved (but vars.json)

  • $$filePath$$
    filepath is the path to the desired file relative to the templateFile directory

  • $varname$
    varname is the key for a variable that Malta will search in a vars.json file that should be found in the template folder

Hints

  • absolutely use only spaces and tabs before file placeholders

  • minified files really slow down the parsing, so the best thing is to avoid the inclusion of minified/packed files.

  • to avoid loops Malta stops digging at the tenth nesting level.

Wired vars

There are some placeholders that can be used within any involved file:

  • __TIME__ : the HH : MM : SS build time
  • __DATE__ : the D / M / YYYY build date
  • __YEAR__ : the YYYY format build year
  • __FILESNUM__ : the number of files glued togheter
  • __VERSION__ : Malta version
  • __BUILDNUMBER__ : build number

Foo sample

Supposing in ~/myproject/ folder there is the following

myfile.js
vars.json
out/
src/
|- a.js
|- inner/
   |- b.js


The most important is the Malta template file being the first file used to build the glued file.

Here use the Malta placeholders and/or the wired vars to specify which files/variables must be included.

myfile.js :

/**
// use the `name` and `author` variables from the vars.json
// the wired __DATE__ variable
//
Name : $name$             
Author: $author$
Date: __DATE__
*/
+function(){
    var name = 'what';

    // write here the content of the src/a.js file 
    // the path is relative to the template folder
    //
    $$src/a.js$$    
}();


and here is the src/a.js :

function hello(n) {
    alert('Hello ' + n);

    // as before, always relative to the template
    // even if this was at 10th inclusion level
    //
    $$src/inner/b.js$$    
}                        
hello('Federico'), hello('Federico');


the last content file for that dummy sample is src/inner/b.js :

hello = function () {
    alert('Hello again ' + n);
};


and least but not last vars.json :

{
"name":"myFabulousProject",
"author":"Federico"
}  


Now from ~ execute:

 malta myproject/myfile.js myproject/out

in a while Malta will confirm the first creation of myproject/out/myfile.js and myproject/out/myfile.min.js.

The myproject/out/myfile.js will look like:

/**
Name : myFabulousProject
Author: Federico
Date: 11/9/2013
*/
+function(){
    var name = 'what';
    function hello(n) {
        alert('Hello ' + n);
        hello = function () {
            alert('Hello again ' + n);
        };
    }
    hello('Federico'), hello('Federico');
}();


Let Malta run and try editing the myproject/myfile.js or the myproject/vars.json or one of the involved files, and get a look at the output folder content. To stop it use Ctrl + c.


Less, Sass and minification

  • When dealing with .less or .scss template files they will be compiled thanks to less and sass npmjs packages.

  • Thank to other two packages, uglify-js & uglifycss, for every output .js and.css file will be written even a minified version (thus even for .less and .scss).

Changelog

  • 1.1.0 updated console usage message
  • 1.0.21 fixed a bug naming minified css
  • 1.0.20 added support for .scss files, fixed a bug using less package
  • 1.0.19 fixed a bug that hanged the process when, being not caught, a parsing exception was thrown by uglify-js and/or uglifycss
  • 1.0.18 some refactors and corrections to console output
  • 1.0.17 automatically write even minified version for css files (even less originated)
  • 1.0.16 accepts a json to execute multiple builds with one call
  • 1.0.15 removed beginning os specific slash in inclusion comments
  • 1.0.14 some fixes and refactor
  • 1.0.13 __BUILDNUMBER__ predefined build number var (file based)
  • 1.0.12 fixed path sep for win####
  • 1.0.11 fixed deadly circular inclusion check; update only modified files
  • 1.0.10 xml files indentation for inner files removed
  • 1.0.9 some minor fixes on messages
  • 1.0.8 hint paths changed
  • 1.0.7 added support for .less files
  • 1.0.5 real path is included only for .xml .js .css files
  • 1.0.3 real path included just before every inclusion
  • 1.0.1 not found $vname$ placeholders are untouched
  • 1.0 added __FILESNUM__, __VERSION__ to the placeholders builtin set
  • 0.0.11 fixed inclusion indentation
  • 0.0.10 involved files count fixed
  • 0.0.9 fixed build on vars.json change
  • 0.0.8 parse error thrown by uglify is catched and stops no more Malta

npm loves you