36
Exploring The New Titanium Command Line Interface Chris Barber Sr. Platform Lead Appcelerator @cb1kenobi [email protected]

Codestrong 2012 breakout session exploring the new titanium command line interface (cli)

Embed Size (px)

Citation preview

Page 1: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Exploring The New Titanium Command Line Interface

Chris BarberSr. Platform Lead

Appcelerator@cb1kenobi

[email protected]

Page 2: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

About Me

• Chris Barber

• JavaScript Team Lead

• Mobile Web, CLI

• @cb1kenobi

Page 3: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Why Create a New CLI?

If it ain’t broke, don’t fix it

Page 4: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Old School

• Python 2.7.x

• Poorly documented

• Difficult to maintain

• Inconsistent arguments

• Rigid plugin system

Page 5: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Building a New CLI

• Python 3? Node.js? Ruby? Java+Rhino?

• How comfortable are we with these technologies?

• Compatible license?

• What libraries are available?• XML/JSON parsing

• Code minification

• Image resizing

Page 6: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Appc ♥ Node.js

• JavaScript!

• MIT License

• Small size

• No native dependencies

• Package manager (npm)

• Tons of great community modules

Page 7: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Getting Started

Installing the Titanium CLI

Page 8: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

First Things First

• Node.js• 0.8 or newer

• NPM

Page 9: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Installation

Note: may need to run as npm sudo

npm install -g titanium

Page 10: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Touring the CLI

Built-in Commands

Page 11: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Running The CLI

chris@yojimbo:~$ titaniumTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Usage: titanium <command> [options]

Commands: config get and set config options help displays this help screen info display development environment information login logs into the Appcelerator network logout logs out of the Appcelerator network module manages installed Titanium Modules plugin manages installed Titanium Plugins sdk manages installed Titanium SDKs setup run the setup wizard status displays session information Global Flags: --banner, --no-banner displays Titanium version banner [default: true] --colors, --no-colors use colors in the terminal [default: true] -h, --help displays help --prompt, --no-prompt prompt for missing options [default: true] -q, --quiet suppress all output -v, --version displays the current version

Page 12: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Help!

chris@yojimbo:~$ titanium help configTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Usage: titanium config [--remove] [--output <value>] [<key>] [<value>] Gets and sets config options. If no key is specified, then all key/values are returned.

The config file is located at: /Users/chris/.titanium/config.json Config Arguments: <key> the key to get or set <value> the value to set the specified key Config Flags: -r, --remove remove the specified config key and all its descendants Config Options: -o, --output <value> output format [report, json]

Global Flags: --banner, --no-banner displays Titanium version banner [default: true] --colors, --no-colors use colors in the terminal [default: true] -h, --help displays help --prompt, --no-prompt prompt for missing options [default: true] -q, --quiet suppress all output -v, --version displays the current version

titanium <cmd> -h

titanium <cmd> --help

titanium help <cmd>

Page 13: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Setup Wizard

• Initializes the CLI configuration

chris@yojimbo:~$ titanium setupTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Enter ctrl-c at any time to quit

What is your name? (this is used as the default for the "author" field in the tiapp.xml or module manifest file when creating new projects) (Chris Barber) What is your email address used for logging into the Appcelerator Network? ([email protected]) What would you like as your default locale? (examples: "en", "de", "fr") (en-us) What Titanium SDK would you like to use by default? (2.1.3.GA) Path to your workspace where your projects should be created: (~/appc/workspace) Path to the Android SDK: (this is needed for building Android apps)

Configuration saved

Basic Setuptitanium setup

Advanced Setuptitanium setup -a

Page 14: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Manual Configuration

• Get and set config settings

chris@yojimbo:~$ titanium configandroid.ndkPath = "/opt/android-ndk"android.sdkPath = ""app.idprefix = "com.appcelerator"app.publisher = "Appcelerator"app.sdk = "2.1.3.GA"app.url = ""app.workspace = "~/appc/workspace"cli.colors = truecli.failOnWrongSDK = falsecli.logLevel = "trace"cli.prompt = truecli.quiet = falseios.developerName = "Chris Barber"ios.distributionName = "Appcelerator, Inc."paths.commands = []paths.hooks = []paths.plugins = ["~/appc/ti.alloy"]user.email = "[email protected]"user.locale = "en-us"user.name = "Chris Barber"

Get All Valuestitanium config

Get All User.* Settingstitanium config user

Set Android SDK Pathtitanium config android.sdkPath “/path/to/sdk”

Page 15: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Authentication

• Required for most commands

• Adds your app to my.appcelerator.com

• Username is your e-mail address

chris@yojimbo:~$ titanium loginTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Username: ([email protected]) Password:

Logged in successfully

Logging Intitanium login <username>

Am I Logged In?titanium status

Logging outtitanium logout

chris@yojimbo:~$ titanium statusTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

You are currently logged in as [email protected]

chris@yojimbo:~$ titanium logoutTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Logged out successfully

Page 16: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

System Info

chris@yojimbo:~$ titanium infoTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Operating System Name = Mac OS X Version = 10.8.2 Memory = 16.0GB node.js node.js Version = v0.8.12 npm Version = 1.1.63 Xcode4.4.1 (build 4F1003) Install Location = /Applications/Xcode44.app/Contents/Developer iOS SDKs = 5.1 iOS Simulators = 5.0, 5.14.5 (build 4G182) Install Location = /Applications/Xcode45.app/Contents/Developer iOS SDKs = 6.0 iOS Simulators = 5.0, 5.1, 6.0 iOS Certificates Development = Chris Barber (XXXXXXXXXX) Distribution = Appcelerator, Inc. Apple WWDR = installed Development iOS Provisioning ProfilesMy Provisioning Profile UUID = XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX App Prefix = XXXXXXXXXX App Id = com.appcelerator.*

iOS Keychains System Default = System Default login.keychain = /Users/chris/Library/Keychains/login.keychain Microsoft_Intermediate_Certificates = /Users/chris/Library/Keychains/Microsoft_Intermediate_Certificates System.keychain = /Library/Keychains/System.keychain Titanium SDKs2.1.3.GA Install Location = /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/2.1.3.GA Platforms = android, iphone, mobileweb git Hash = unknown git Timestamp = unknown

Android Platformsandroid-8 Name = Android 2.2 API Level = 8 Revision = 3 Skins = HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854 ABIs = armeabi Path = /opt/android-sdk/platforms/android-8

Android Add-onsGoogle Inc.:Google APIs:8 Name = Google APIs Vendor = Google Inc. Revision = 2 Description = Android + Google APIs Skins = WVGA854, WQVGA400, HVGA, WQVGA432, WVGA800 (default), QVGA ABIs = armeabi Path = /opt/android-sdk/add-ons/addon-google_apis-google-10 Based On = Android 2.2 (API level 8) Libraries = com.google.android.maps: API for Google Maps (maps.jar)

Includes:• OS info• node.js & npm• Xcode versions• iOS SDKs &

simulators• iOS provisioning

profiles & keychains

• Titanium SDKs• Android SDKs,

addons, and AVDs

Get All Infotitanium info

OS Info Onlytitanium info -t os

iOS Info Onlytitanium info -t ios

Android & Node.js Info Onlytitanium info -t android,nodejs

Output as JSONtitanium info -o json

Page 17: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Modules & Plugins

chris@yojimbo:~$ titanium moduleTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Global Modules

Android ti.cloudpush 2.0.5 /Users/chris/Library/Application Support/Titanium/modules/android/ti.cloudpush/2.0.5 2.0.7 /Users/chris/Library/Application Support/Titanium/modules/android/ti.cloudpush/2.0.7 CommonJS ti.cloud 2.1.0 /Users/chris/Library/Application Support/Titanium/modules/commonjs/ti.cloud/2.1.0 2.2.0 /Users/chris/Library/Application Support/Titanium/modules/commonjs/ti.cloud/2.2.0 2.3.0 /Users/chris/Library/Application Support/Titanium/modules/commonjs/ti.cloud/2.3.0 2.0.5 /Library/Application Support/Titanium/modules/commonjs/ti.cloud/2.0.5 iPhone ti.jira 1.0 /Users/chris/Library/Application Support/Titanium/modules/iphone/ti.jira/1.0 Mobile Web ti.oldmodule 0.1 /Users/chris/Library/Application Support/Titanium/modules/mobileweb/ti.oldmodule/0.1

Get Installed Modulestitanium module

Get Installed Modules Including a Projecttitanium module –project-dir /path/to/project

Get Installed Pluginstitanium plugin

Output as JSONtitanium plugin -o json

chris@yojimbo:~$ titanium pluginTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

User Path Plugins

No project plugins found Global Plugins

another_plugin 1.0 /Users/chris/Library/Application Support/Titanium/plugins/another_plugin/1.0 test_plugin 1.0 /Users/chris/Library/Application Support/Titanium/plugins/test_plugin/1.0 ti.alloy 1.0 /Users/chris/Library/Application Support/Titanium/plugins/ti.alloy/1.0

Page 18: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Wait!

Where’s the create and build commands?

Page 19: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Downloading An SDK

chris@yojimbo:~$ titanium sdkTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Installed SDKs: 2.1.3.GA [default] /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/2.1.3.GA 2.1.2.GA /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/2.1.2.GA 2.1.0.GA /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/2.1.0.GA 2.0.2.GA /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/2.0.2.GA

List Intalled SDKstitanium sdk

Install Latest 3.0titanium sdk install --branch 3_0_X --default

Install Latest Stabletitanium sdk install

Install Latest Stable & Set as Default SDKtitanium sdk install --default

Install Bleeding Edgetitanium sdk install --branch master

chris@yojimbo:~$ titanium sdk install --branch 3_0_X --defaultTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Downloading http://builds.appcelerator.com.s3.amazonaws.com/mobile/3_0_X/mobilesdk-3.0.0.v20121018214614-osx.zip 100% [=================================================================] 0.0s

Extracting SDK...

Saving SDK 3.0.0.v20121018214614 as the default.Titanium SDK 3.0.0.v20121018214614 successfully installed!

Page 20: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

New Commands!

chris@yojimbo:~$ titaniumTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Usage: titanium <command> [options]

Commands: build builds a project clean removes previous build directories config get and set config options create creates a new mobile application or module help displays this help screen info display development environment information login logs into the Appcelerator network logout logs out of the Appcelerator network module manages installed Titanium Modules plugin manages installed Titanium Plugins project get and set tiapp.xml settings sdk manages installed Titanium SDKs setup run the setup wizard status displays session information Global Flags: --banner, --no-banner displays Titanium version banner [default: true] --colors, --no-colors use colors in the terminal [default: true] -h, --help displays help --prompt, --no-prompt prompt for missing options [default: true] -q, --quiet suppress all output -v, --version displays the current version

Page 21: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

SDK Commands

create, project, build, clean

Page 22: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Creating a Project

chris@yojimbo:~$ titanium createTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Target platforms: (android,ios,ipad,iphone,mobileweb) App ID: com.appcelerator.myappProject name: myapp

[INFO] Creating Titanium Mobile application project[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default => /Users/chris/myapp[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources => /Users/chris/myapp/Resources[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android => /Users/chris/myapp/Resources/android[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images => /Users/chris/myapp/Resources/android/images[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-long-land-hdpi => /Users/chris/myapp/Resources/android/images/res-long-land-hdpi[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-long-land-ldpi => /Users/chris/myapp/Resources/android/images/res-long-land-ldpi[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-long-port-hdpi => /Users/chris/myapp/Resources/android/images/res-long-port-hdpi[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-long-port-ldpi => /Users/chris/myapp/Resources/android/images/res-long-port-ldpi[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-notlong-land-hdpi => /Users/chris/myapp/Resources/android/images/res-notlong-land-hdpi[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-notlong-land-ldpi => /Users/chris/myapp/Resources/android/images/res-notlong-land-ldpi[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-notlong-land-mdpi => /Users/chris/myapp/Resources/android/images/res-notlong-land-mdpi[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-notlong-port-hdpi => /Users/chris/myapp/Resources/android/images/res-notlong-port-hdpi[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-notlong-port-ldpi => /Users/chris/myapp/Resources/android/images/res-notlong-port-ldpi[DEBUG] Copying /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.0.0.v20121018214614/android/templates/app/default/Resources/android/images/res-notlong-port-mdpi => /Users/chris/myapp/Resources/android/images/res-notlong-port-mdpi[INFO] Project 'myapp' created successfully in 32ms

Create a Projecttitanium create

Create Project With All Argumentstitanium sdk create --id com.appc.myapp --name myapp --platforms android,iphone,ipad,mobileweb --workspace-dir /path/to/workspace

Page 23: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Getting Project Info

• Tool for interacting with the tiapp.xml

chris@yojimbo:~/myapp$ titanium projectTitanium Command-Line Interface, version 3.0.7Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

Deployment Targets: android = true ipad = false iphone = true mobileweb = true Project Properties: sdk-version = 3.0.0 id = com.appcelerator.myapp name = myapp version = 1.0 publisher = not specified url = not specified description = not specified copyright = not specified icon = appicon.png analytics = true guid = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Basic Infotitanium project

Copy Platform Resource Filestitanium project --deployment-targets android,ios,mobileweb

Page 24: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Building a Project

chris@yojimbo:~/myapp$ titanium build --platform iosTitanium Command-Line Interface, version 3.0.6Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

[DEBUG] No project level plugins to load[DEBUG] Loaded plugin hooks:[DEBUG] /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.1.0/cli/hooks/plugins.js[DEBUG] /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.1.0/iphone/cli/hooks/install.js[DEBUG] /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.1.0/iphone/cli/hooks/package.js[DEBUG] /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.1.0/iphone/cli/hooks/run.js[INFO] Build type: development[DEBUG] Titanium iOS SDK directory: /Users/chris/Library/Application Support/Titanium/mobilesdk/osx/3.1.0/iphone[INFO] Building for target: simulator[INFO] Building using iOS SDK: 6.0[INFO] Building for iOS Simulator: 6.0[INFO] Building for device family: universal[DEBUG] Setting Xcode target to Debug[DEBUG] Setting Xcode build OS to iphonesimulator6.0[DEBUG] Xcode installation: /Applications/Xcode45.app/Contents/Developer[DEBUG] iOS WWDR certificate: installed[INFO] Building for iOS 6.0; using 4.3 as minimum iOS version[DEBUG] Minimum iOS version: 4.3[INFO] Debugging disabled[DEBUG] Building for the following architectures: armv7 armv7s i386[DEBUG] Forcing rebuild: githash changed since last build[DEBUG] Was: a50c927[DEBUG] Now: ab2b280[INFO] Cleaning old build directory[DEBUG] Would be firing "compile" legacy plugin hook if it was supported[INFO] Building Info.plist[INFO] No Titanium Modules required, continuing[INFO] Performing full rebuild[INFO] Copying Xcode iOS files

...

Platforms:• iOS• Mobile Web• Android

Special Hooks:• Run in Simulator• Install on Device• Package for

Distribution

Page 25: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Cleaning the Project

• Completely removes the platform specific build directories

chris@yojimbo:~/myapp$ titanium cleanTitanium Command-Line Interface, version 3.0.6Copyright (c) 2012, Appcelerator, Inc. All Rights Reserved.

[INFO] Project cleaned successfully in 1ms

Nuke All Platform Build Directoriestitanium clean

Nuke a Specific Platform’s Build Directorytitanium clean –platform android

Page 26: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Extending the CLI

Plugins, commands, and hooks

Page 27: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Plugins

• Similar to Titanium Modules

• Legacy plugin.py not supported today

• CLI commands & hooks

• Installed globally or in project directory

• Enabled via the tiapp.xml <plugins>

Page 28: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Sample Command

myplugin/1.0/cli/commands/magic.js

exports.cliVersion = '>=3.X';exports.desc = 'does magical things’;

exports.config = function (logger, config, cli) { return { flags: { extra: { abbr: 'e', desc: 'adds more magic’ } } };};

exports.validate = function (logger, config, cli) { // nothing to validate};

exports.run = function (logger, config, cli) { var s = 'doing magical stuff!';

if (cli.argv.extra) { s = s.replace(/./g, function (c, i) { return i % 2 == 0 ? c.toUpperCase() : c.toLowerCase(); }); }

logger.log(s);};

Page 29: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Sample Hook

myplugin/1.0/cli/hooks/buildhook.js

exports.cliVersion = '>=3.X';

exports.init = function (logger, config, cli) { cli.addHook('build.pre.compile', function (data, finished) { logger.log('modifying some code before build starts'); finished(); });

cli.addHook('build.post.compile', { priority: 900, post: function (data, finished) { logger.log('packaging some extra files after the build'); finished(); } });

cli.addHook('build.finalize', function (data, finished) { logger.log('cleaning up my mess'); finished(); });};

Page 30: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Demo

Kick the tires & light the fires

Page 31: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

What’s Next?

Page 32: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

// TODO:

• More plugin hooks

• Project exporting & migration tools

• Better support for multiple Titanium SDKs

• What would you like to see?

Page 33: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Summary

Just in case you were sleeping

Page 34: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

The New CLI Rocks

• Easy to install, easy to use

• Fast as shit

• Built-in documentation

• Extensible plugin architecture

• Consistent arguments

• Argument prompting

• Internationalization

• Colors!

Page 35: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Get It Today!

Note: may need to run npm as sudo

npm install -g titanium

titanium sdk install --branch 3_0_X --default

Page 36: Codestrong 2012 breakout session   exploring the new titanium command line interface (cli)

Chris Barber@cb1kenobi

[email protected]