Skip to content
Josh Bavari edited this page May 14, 2015 · 8 revisions

Ionic-CLI

This wiki is to assist any users in understanding the Ionic CLI project.

About the project

The CLI was first built with everything contained in one project. The idea came about - how do we improve the project to make components of the CLI reusable?

This is where the ionic-app-lib came about - this project contains all the core logic and functionality the CLI had. The CLI will just parse out command line arguments, and pass them to the lib. This way, we can consume the CLI functionality from other GUI's or projects, as well as easing the testing process.

Entry Point

This is specified by the package.json file with the bin attribute. In the Ionic CLI, it is pointed at bin/ionic.

This file is just JavaScript, setting first the terminal title to 'ionic', pulling off the args from the command line (using optimist), and then running the IonicCli.run method with those arguments.

This was done to help improve testing - now we can saturate those args with what we want and test based off of those instead of dealing with parsing command line arguments.

The Cli module

Tasks / Commands

The Ionic CLI has many commands to be used (see them in ionic help). These tasks are stored in the lib/ionic/tasks/cliTasks.js.

One question may come to mind: Why not use the standard opts hash that many other libraries use? This is still an artifact of when the project was born, and has been kept that way until being pulling into its own file. (See the history on the ionic.js file 🎱 )

Each task/command specifies its name, a title in the help menu, a quick help summary, and arguments for options and arguments.

  {
    title: 'start',
    name: 'start',
    summary: 'Starts a new Ionic project in the specified PATH',
    args: {
      '[options]': 'any flags for the command',
      '<PATH>': 'directory for the new project',
      '[template]': 'Template name, ex: tabs, sidemenu, blank\n' +
                    'Codepen url, ex: http://codepen.io/ionic/pen/odqCz\n' +
                    'Defaults to Ionic "tabs" starter template'
    },
    options: {
      '--appname|-a': 'Human readable name for the app (Use quotes around the name)',
      '--id|-i': 'Package name for <widget id> config, ex: com.mycompany.myapp',
      '--no-cordova|-w': 'Create a basic structure without Cordova requirements',
      '--sass|-s': 'Setup the project to use Sass CSS precompiling',
      '--list|-l': 'List starter templates available',
      '--io-app-id': 'The Ionic.io app ID to use'
    },
    module: './ionic/start'
  }
Clone this wiki locally