phonegap / node-phonegap-build

PhoneGap Build node module to login, create, and build apps.
Apache License 2.0
25 stars 25 forks source link

PhoneGap Build Node Module Build Status

Node module to create and build PhoneGap projects with PhoneGap Build.

Getting Started

Install

package.json:

{
    "dependencies": {
        "phonegap-build": "*"
    }
}

Require

var phonegapbuild = require('phonegap-build');

API

Login

Authenticates with PhoneGap Build, saves the token, and return an API object. When the save token exists, the authentication step is skipped.

Options:

Events:

Examples:

//
// given the login credentials
//

var options = { username: 'mwbrooks@adobe.com', password: 'abc123' };

phonegapbuild.login(data, function(e, api) {
    // now logged in
});

//
// get login credentials on demand
//

phonegapbuild.on('login', function(options, callback) {
    options.username = options.username || 'mwbrooks@adobe.com';
    options.password = options.password || 'abc123';
    callback(null, options);
});

phonegapbuild.login(function(e, api) {
    // now logged in
});

Login Event

This event is called whenever a task must authenticate with PhoneGap/Build and the credentials are unknown. If only the username or only the password is known, the it is passed into the event as the options object.

The developer should listen on this event and correctly retrieve the login credentials: looking them up from storage or prompting the user. Once the credentials are found, the callback can be fired with the correct credentials.

Options:

Examples:

phonegapbuild.on('login', function(options, callback) {
    options.username = options.username || 'mwbrooks@adobe.com';
    options.password = options.password || 'abc123';
    callback(null, options);
});

Logout

Logout the user by deleting the token key from the config file.

Options:

Events:

Examples:

phonegapbuild.logout({}, function(e) {
    // now logged out unless e is defined
});

Create an App

Creates an application on the local filesystem. The remote application is created on-demand during the first build.

Options:

Events:

Examples:

var options = { path: '~/development/my-app' };

phonegapbuild.create(options, function(e) {
    if (e) {
        console.error('failed to create the project:', e.message);
    }
    else {
        console.log('created the project:', path);
    }
});

Build an App

Builds the application using PhoneGap/Build. If the application does not exist, then it is first created. Currently, the build task only supports file transfers (zip) but will be extended to git repositories in the future.

Options:

Events:

Examples:

var options = { platforms: ['android'] };

phonegapbuild.build(options, function(e, data) {
    if (e) {
        console.error('failed to build the app:', e);
    }
    else {
        console.log('successfully built the app:', data);
    }
});