Mojito comes with a command-line tool that provides a number of key capabilities for the developer, from generating code skeletons, to running tests and test coverage, to cleaning up and documenting the code base.
All commands except mojito create must be run from within the application directory.
To show top-level help for this command line tool:
$ mojito help
To show help for a specific command:
$ mojito help <command>
Archetypes are used to create skeletons for the different types of artifacts in a Mojito application. The skeletons only contain stripped down boilerplate code that is easier to create using the command-line tool rather than by hand.
To create a skeleton for a Mojito application:
$ mojito create app [<archetype-name>] <path/to/app-name>
This will create an empty application (i.e., one with no mojits) with the name provided. The application is created in a directory named <app-name> within the specified directory. If no archetype name is provided, the default archetype is used.
From the application directory, use the following command to create a skeleton for a mojit:
$ mojito create mojit [<archetype-name>] <mojit-name>
This will create an empty mojit with the name provided. The command assumes it is being executed within an application directory. Thus, the mojit is created in a directory named <mojit-name> within a mojits subdirectory of the application directory. For example, the mojit MyMojit would be created in mojits/MyMojit.
As with application creation, if no archetype name is provided, the default archetype is used. Depending upon the archetype, the skeleton may include any or all of the controller, model, view, and binder.
Mojito offers the following three archetypes for applications and mojits.
You can also customize archetypes and then use them to generate code. For example, if you customized the template code that Mojito uses (or create your own) to generate boilerplate code, such as an application or a mojit, you could have Mojito use your archetype to generate code with the following command:
$ mojito create mojit <archetype-path> <generated_code-path>
For example: $ mojito create app ./my_archetypes/mobile_web_app ./my_apps/micro_blog
Unit tests are run using YUI Test invoked using the Mojito command-line tool. Test output is written to the console and also to the file {CWD}/artifacts/test/result.xml, where {CWD} is the current working directory. Note when you run tests, the output may overwrite the results of past tests. To avoid this, you can use the long option --directory or an abbreviation such as --dir to to specify where to write test results.
To run tests for an application:
$ mojito test [app] [.]
To run the unit tests for a specific mojit, use one of the following:
To run the unit tests for one or more modules of a mojit, use one of the following:
If one or more mojit modules (i.e., the YUI modules for a portion of the mojit) are specified, only the tests for those modules will be run. Otherwise all tests for the mojit will be run.
To specify the output directory for test results:
To run functional and unit tests for the Mojito framework, you would use the test framework Yahoo! Arrow. Follow the instructions in Running Mojito’s Built-In Tests to run the framework tests for Mojito.
Code coverage is invoked in the same way as unit testing, but with the added option --coverage or -c. To run code coverage tests, you need to have Java installed. You can specify where to write the coverage results using the option --directory or --dir. Coverage results are written to the directory {CWD}/artifacts/test/coverage/ by default. You can also specify the path to write results with the long option --directory or an abbreviation such as --dir (see example below).
To run code coverage for a Mojito application:
$ mojito test [app] --coverage
To run code coverage for a specific mojit:
$ mojito test -c [mojit] <mojit-path>
To specify the output directory for test results:
The coverage results will be written to <path>/coverage/.
Use the following to start the server and run the application.
$ mojito start [<port>] [--context "key1:value1,key2:value2,key3:value3"]
The port number specified in the command above overrides the port number in the application configuration file, application.json. The default port number is 8666. See Specifying Context to learn how to use the --context option.
Static code analysis is run using JSLint invoked using the Mojito command-line tool. By default, the JSLint error report is written to {CWD}/artifacts/jslint/jslint.html. You can also specify the directory to write the error report to with the long option --directory or an abbreviation such as --dir.
To run JSLint on the Mojito framework code:
$ mojito jslint mojito
To run JSLint on an application, including its mojits:
$ mojito jslint app .
To run JSLint on a specific mojit:
$ mojito jslint mojit <mojit-path>
To run JSLInt on all the files in a path:
$ mojito jslint [<path>]
To write the error report to a specific directory:
$ mojito jslint app . --dir <path>
API documentation is generated using YUI Doc, which is invoked using the Mojito command-line tool. Documentation output is written to files in the locations specified below. Because it’s based on YUI Doc, you can start a server that displays the documentation with the option --server and specify a port with --port. You can also specify the output directory with the the option --directory or an abbreviation such as --dir.
To generate documentation for the Mojito framework itself:
$ mojito docs mojito
Output is written to {CWD}/artifacts/docs/mojito/, where {CWD} is the current working directory.
To generate documentation for an application, including all of its (owned) mojits, run the following from the application directory:
$ mojito docs app
Output is written to {app-dir}/artifacts/docs/.
To generate documentation for a specific mojit, run one of the following:
Output is written to {app-dir}/artifacts/docs/mojits/{mojit-name}/.
To start a server for the documentation:
$ mojito docs app --server [--port <port_number>]
To display the version of the mojito-cli package:
$ mojito version
To show the version of an application and the locally installed version of Mojito:
$ mojito version app
To show the version for a mojit, run the following from the application directory:
$ mojito version mojit <mojit-name>
Note
Showing the version of the application and mojit requires that they have a package.json file.
Mojito comes with a build command for generating an HTML5 offline Mojito application that runs in different environments. The command must be run inside of the application you want built.
$ mojito build <type> [<output-path>] [--context "key1:value1,key2:value2,key3:value3"]
Output is written to {app-dir}/artifacts/builds/{type} by default. See Specifying Context to learn about the --context option.
The following sections describe the available build type.
To build an HTML 5 application, use the the following:
$ mojito build html5app
This generates a HTML5 Offline Application with a cache.manifest listing all the files that will be available offline. An index.hb.html page is generated from the result of calling the Web root / of the Mojito application that this command was run within. You can build other pages by specifying the pages in the "builds": "html5app" object in application.json. The html5 object lets you add the manifest attribute to the html element, configure relative paths, and specify a list of URLs to pages to generate.
The command below generates the Graphviz file {CWD}/artifacts/gv/yui.client.dot ({CWD} represents the current working directory) that describes the YUI module dependencies.
$ mojito gv
The mojito gv command has the following options:
Note
To render the Graphviz files into GIF images, you need the Graphviz - Graph Visualization Software.
When configuration files are read, a context is applied to determine which values will be used for a given key. The applied context is a combination of the dynamic context determined for each HTTP request and a static context specified when the server is started. See Using Context Configurations for more information.
The static context can be specified by a command-line option whose value is a comma-separated list of key-value pairs. Each key-value pair is separated by a colon. Try to avoid using whitespace, commas, and colons in the keys and values.
$ mojito start --context "key1:value1,key2:value2,key3:value3"