- Creating a new application
- Creating a new application using a test application
- Generating components
- Extracting localization strings
- Compiling a specific view-controller
- Building an application
- Installing special project components
Alloy provides a command-line interface to create a new projects, generate skeleton components, and compile Alloy code to Titanium code. See Command-Line Interface Installation for directions on installing the latest released Alloy CLI.
appc alloy --help to see all available target options or see the Alloy Command-Line Interface Reference.
Creating a new application
To create an Alloy application, run the following command from your work space directory:
You will be prompted to enter an application name and application ID.
A new skeleton Alloy project will be generated in the directory named after the application name.
A new Alloy project has a folder named
app that contains the skeleton Alloy application.
Creating a new application using a test application
Starting with Appcelerator CLI 5.0.0 or Alloy 1.7.6, you can generate a new Alloy project using a test application from the Alloy Github repo. (The source code is copied from the global or local install of the Alloy npm package.)
To create an Alloy application based on a test application, first create a skeleton Titanium project, then run the Alloy new command with the
--testapp <path_to_test_app> option. Pass the option the relative path to the test application after the
The CLI can generate skeleton controllers (with views and styles), models, database migrations and widgets. The following commands can be ran from the root folder of the project or the location of the project may be specified with the
-o command-line option. You can also create platform-specific views or controllers using the
--platform option. You can also create views, styles and controllers for a widget by specifying the
--widgetname option with the name of the widget.
Generating a controller
To generate a controller with a style and view, run the following command:
Generating a view
To generate a view and style without a controller, run the following command:
Generating a style
To generate a style for a view-controller, run the following command:
Alloy uses the id and attribute names in the markup file to populate the skeleton style file. This creates
To generate style files for all view-controllers, run the following command:
If you add new id or class attributes to the markup file, running either of these commands updates the style file with the new attributes.
Generating a model
To generate a model, run the following command:
The fourth parameter selects the adapter type, either
sql for SQLite engine (Android and iOS platforms) or
properties for storing models locally in Titanium SDK context.
The fifth parameter defines the table schema. This is required for 'sql' and 'properties' adapter types.
app/migrations/DATETIME_<name>.js if the adapter type is 'sql'.
Generating a migration
To generate a standalone migration for a specific model, run the following command:
This creates a timestamp-ordered migration file for the model specified, that is,
Generating a widget
To generate a basic widget, run the following command:
This creates a default widget in the project's
app/widgets path, generating a configuration file, controller, style and view:
app/widgets/<name>/views/widget.xml. The widget is automatically added as a dependency in the Alloy project's configuration file
To generate the build customization file
alloy.jmk, run the following command:
app/alloy.jmk with a few task hooks in place. Refer to Build Configuration File (alloy.jmk) for more details.
Extracting localization strings
alloy extract-i18n command inspects your JS and TSS (since Alloy 1.2.0), and XML files (since Alloy 1.6.0) for instances of Titanium's localization functions and adds those strings to an i18n strings.xml file. The command has the following syntax:
language– Optional. The two-letter language code (
es, for example) of the target language. If not specified, the default is
--apply– Optional. If present, the command writes new localization entries to the target language's strings.xml file. Existing i18n entries are left untouched. If the XML file doesn't exist, it is created for you. If this parameter is absent, a preview of the changes are displayed in the terminal window.
The following localization functions are supported:
To create an English language localization file, run the following command:
app/i18n/en/strings.xml or (before Alloy 1.8.0)
i18n/en/strings.xml in your project directory, if it doesn't exist. The contents of the generated XML file would appear as follows:
If you later add more localization functions to your code and run the same command again, the new entries would be added to strings.xml. Existing entries are left untouched.
To generate a strings.xml for a specific language, pass the two-letter language code as a parameter. For example, the following command creates a strings.xml file for Spanish language locales (
app/i18n/es/strings.xml or - before Alloy 1.8.0 -
When called with
--apply, the command only adds new i18n entries and leaves existing entries untouched. For this reason,
alloy extract-i18n --apply is a safe operation, but you can also preview changes in the terminal by calling the command without
--apply , as shown below.
The output of this command shows the content of the current en/strings.xml file (before) and its content once you apply the changes (after) with
Compiling a specific view-controller
Starting with Appcelerator CLI 5.0.0 or Alloy 1.7.6, you can select which Alloy view-controller to compile to Titanium code. Use the command to update the Titanium base code for incremental changes to the Alloy project. Pass the
file=<filename> to the
--config option when running the Alloy compile command.
Building an application
To build and run an application, execute the following command:
Running this from the root directory of the project compiles the files to the correct location automatically.
See the Titanium Command-Line Interface Reference guide for a complete explanation of the available options.
Installing special project components
Installing the compiler plugin
To install the compiler plugin that hooks the Alloy project to Studio, run the following command:
Use this command to update the compiler plugin if your project was created using an older version of Alloy.