Alloy provides hooks to customize the compilation process using a special
JavaScript file called a JS Makefile (JMK). The file needs to be named
alloy.jmk
and located in the project's app
directory. This file can be used for common administration tasks or to
fine tune the build process. It will be loaded automatically by the Alloy
command line during compilation.
Example of a JMK file:
task( 'pre:compile' , function (event, logger) { logger.showTimestamp = true ; logger.info( 'building project at ' + event.dir.project); }); task( 'post:compile' , function (event, logger) { logger.info( 'compile finished!' ); }); |
To customize the build process, call the task function with the event name and provide a function callback, which will be called when the event is triggered by the compiler.
These are the event names (or compiler tasks):
pre:load:
called after the project is cleaned and before copying any assets to theResources
folder.pre:compile
: called before the compiler starts.post:compile
: called after the compiler finishes but before it exits.compile:app.js
: called just after the compilation of the mainapp.js
file but before the code is written to disk.
The function callback provides two arguments: event
and logger
.
The event
object provides a set of objects and values which may be useful for building
tasks:
Object/Value |
Description |
---|---|
adapters |
List of adapters. |
alloyConfig |
Contains Alloy compiler configuration information.
|
autoStyle |
If set to true , autostyle is enabled for the entire project. |
dependencies (Object) |
Value of the dependencies key in the config.json file. |
dir |
Contains directory paths to various resources.
|
sourcemap (Boolean) |
If true , generates the source mapping files for use with the Studio debugger and
other functions.These files maps the generated Titanium files in the Resources directory to the ones in the app directory. |
theme |
Name of the theme being used. |
code |
Only present for the |
appJSFile |
Only present for the |
The logger
object provides a reference to the logger, which defines the following
methods and properties:
Properties
DEBUG: Number READONLY
Output all log messages.
INFO: Number READONLY
Output all log messages except debug messages.
WARN: Number READONLY
Output only warning and error log messages.
ERROR: Number READONLY
Output only error log messages.
NONE: Number READONLY
Disable log messages.
logLevel: Number
Sets which log messages to output.
showTimestamp: Boolean
If true, outputs timestamp with the log messages.
stripColors: Boolean
If true, suppresses color output.
Methods
debug (String msg)
Outputs a debug log message.
Parameters:
- msg : String
Message to output.
Returns:
- void
info (String msg)
Outputs an info log message.
Parameters:
- msg : String
Message to output.
Returns:
- void
warn (String msg)
Outputs a warning log message.
Parameters:
- msg : String
Message to output.
Returns:
- void
error (String msg)
Outputs an error log message.
Parameters:
- msg : String
Message to output.
Returns:
- void
3 コメント
Carlos
Hello, good evening.
Thanks for this. I'd really appreciate if you can tell me where can I find an extended example or a specification about the use and capabilities of this file. What I have been trying to do is set a new path for my views folder, after recognize if the device is either a tablet or a handheld. I have not been able to get this done but I think the most useful approach can be around here.
Hope you can help me, regards.
Fokke Zandbergen
Hello Carlos. The alloy.jmk file allows you to hook into compile-time events, whereas form factor can only be determined on run-time. For form factor specific views use the formFactor attribute in your XML Views as described in the Alloy Views guide.
Carlos
Hello Fokke, thanks for your answer.
I was thinking about using it as a temporal solution, but if it is determined on runtime I will make it permanent then.
Thanks, have a nice week.