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.”
Start by creating a folder for your project. Inside that folder you should have a Source folder and the file 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.
/* --- name: Person requires: - Core/Class provides: Person ... */
... 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 unices.