It is now possible and recommended to generate MooTools (and its plugins) yourself using MooTools Packager or MooTools Depender. These libraries combine multiple javascript files into one for single file deployment. Once you understand the convention these libraries use, building a single production file is a breeze. This article focuses on setting up your javascript files for use primarily with Packager. Once created though, the files can be used with Packager or Depender.

Packager

"Packager is a PHP 5.2+ library to concatenate libraries split in multiple files in a single file. It automatically calculates dependancies. Packager requires a yml header syntax in every file, and a package.yml manifest file, as seen on the MooTools project."

Structure

Start by creating a folder for your project. Inside that folder you should have a Source folder and the file package.yml.


- PeopleProject/
    - package.yml
    - Source/
        - Employee.js
        - Person.js


Package.yml
Below is a sample package.yml file.

name: People
sources:
- "Source/Person.js"
- "Source/Employee.js"
  • The name property specifies the name of your project. It is the name that will be registered with the project manifest.
  • The sources property specifies the location of your javascript source files.

Note: Other properties can be added to this manifest file. Some properties are specific for use with MooTools forge.

Source Files Source files consists of whatever javascript code you choose. The header of these javascript files is what is important. The header syntax should be in YAML as follows:

/*
---
name: Person
requires:
- Core/Class
provides: Person
...
*/

The --- and ... are very important. They are required by YAML and specify the start and end of a YAML block.

  • The name property specifies the name of the source file and is used by Packager to reference the source file.
  • The requires property specifies the dependencies of the source file. This can be written using a YAML collection block sequence with each entry on its own line and preceded by a dash and a space or by using a flow sequence with entry separated by a comma within square brackets [].
  • The provides property specifies the code that is provided by the source file. A source file can provide several blocks of code. When any one of those blocks is required by another source file, the entire file is included.

As with the manifest file, this YAML block can contain other useful properties such as author, description, license, etc.

Command line usage

With the manifest and the source files properly configured, using Packager from the command line is simple.

First you must register the manifest by issuing the register command:

./packager register [[path-to-manifest]]

After the manifest has been registered, you can issue several build commands depending on your needs.

./packager build +components People/Person People/Employee

Which builds the passed in components (and their dependancies) using your registered packages. You can get the same results with the command:

./packager build People/Person People/Employee

You can build every component from your project with the command:

./packager build People/*

To write the results of the commands to a file, use the following:

./packager build People/* > people.js

More commands and explanations can be found on the packager project page.

Note: The command line script only works on unix.